From 7d9ad994680f113b61552a66a98976f2c0a92cf1 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 8 Jun 2019 22:03:18 +0100 Subject: [PATCH 001/274] Added DOI --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 26d2536..5bc5e13 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build Status](https://travis-ci.com/ikorotkin/dae-cpp.svg?branch=master)](https://travis-ci.com/ikorotkin/dae-cpp) [![BCH compliance](https://bettercodehub.com/edge/badge/ikorotkin/dae-cpp?branch=master)](https://bettercodehub.com/) +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3241871.svg)](https://doi.org/10.5281/zenodo.3241871) A simple but powerful C++ solver for Differential Algebraic Equation (DAE) systems. From 0804f95914790a306132e02897747017dcc157f9 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 10 Jun 2019 20:57:29 +0100 Subject: [PATCH 002/274] Solver now returns status of the integration. Refactored solver memory release. Cleaned up some includes. --- src/matrix_add.cpp | 8 +- src/matrix_checker.cpp | 2 +- src/solver.cpp | 191 ++++++++++++++++------------------------ src/solver.h | 53 +++++++++-- src/solver_options.h | 4 - src/time_integrator.cpp | 16 ++-- src/time_integrator.h | 8 +- 7 files changed, 139 insertions(+), 143 deletions(-) diff --git a/src/matrix_add.cpp b/src/matrix_add.cpp index 5ba8bb6..bef3566 100644 --- a/src/matrix_add.cpp +++ b/src/matrix_add.cpp @@ -8,10 +8,10 @@ namespace daecpp_namespace_name { -void TimeIntegrator::matrix_add(const float_type alpha, - const sparse_matrix_holder &A, - const sparse_matrix_holder &B, - sparse_matrix_holder &C) +void TimeIntegrator::m_matrix_add(const float_type alpha, + const sparse_matrix_holder &A, + const sparse_matrix_holder &B, + sparse_matrix_holder &C) { // For compatibility with mkl_dcsradd() #ifdef DAE_FORTRAN_STYLE diff --git a/src/matrix_checker.cpp b/src/matrix_checker.cpp index 61f99f5..0bfcf8f 100644 --- a/src/matrix_checker.cpp +++ b/src/matrix_checker.cpp @@ -14,7 +14,7 @@ namespace daecpp_namespace_name { -int TimeIntegrator::matrix_checker(sparse_matrix_holder &A, MKL_INT size) +int TimeIntegrator::m_matrix_checker(sparse_matrix_holder &A, MKL_INT size) { sparse_checker_error_values check_err_val; sparse_struct pt; diff --git a/src/solver.cpp b/src/solver.cpp index 3c2ded9..f0a87aa 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -7,10 +7,10 @@ #include #include -#include #include #include "solver.h" +#include "time_integrator.h" namespace daecpp_namespace_name { @@ -19,10 +19,10 @@ namespace daecpp_namespace_name * The main solver * ============================================================================= */ -void Solver::operator()(state_type &x, const double t1) +int Solver::operator()(state_type &x, const double t1) { - // Matrix size - MKL_INT size = (MKL_INT)(x.size()); + // Set system size + m_size = (MKL_INT)(x.size()); // Check user-defined solver options m_opt.check_options(); @@ -33,7 +33,7 @@ void Solver::operator()(state_type &x, const double t1) std::cout << "ERROR: Integration time t1 = " << t1 << " cannot be less than the initial time t0 = " << m_opt.t0 << std::endl; - exit(7); + return 1; } // Check the initial time step @@ -49,12 +49,12 @@ void Solver::operator()(state_type &x, const double t1) dt[1] = dt[0]; // Initialise time integrator - TimeIntegrator ti(m_rhs, m_jac, m_mass, m_opt, size); + TimeIntegrator ti(m_rhs, m_jac, m_mass, m_opt, m_size); // Initial output if(m_opt.verbosity > 1) { - std::cout << "Number of equations: " << size << std::endl; + std::cout << "Number of equations: " << m_size << std::endl; std::cout << "Float precision: " << 8 * sizeof(float_type) << " bit\n"; std::cout << "Integer precision: " << 8 * sizeof(MKL_INT) << " bit\n"; @@ -67,61 +67,30 @@ void Solver::operator()(state_type &x, const double t1) int current_scheme = 1; // Contains a few latest successful time steps for Time Integrator - state_type_matrix x_prev(m_opt.bdf_order, state_type(size)); + state_type_matrix x_prev(m_opt.bdf_order, state_type(m_size)); // Full Jacobian matrix holder sparse_matrix_holder J; // Full RHS vector - state_type b(size); + state_type b(m_size); // Solution vector used for Newton iterations - state_type xk(size); + state_type xk(m_size); // Copy current state vector into the history vector x_prev[0] = x; - // PARDISO control parameters - MKL_INT phase; // Current phase of the solver - MKL_INT maxfct = 1; // Maximum number of numerical factorizations - MKL_INT mnum = 1; // Which factorization to use - MKL_INT mtype = 11; // Real unsymmetric matrix - MKL_INT nrhs = 1; // Number of right hand sides - MKL_INT msglvl = 0; // Print statistical information - MKL_INT error = 0; // Initialize error flag - - MKL_INT *ia = nullptr; - MKL_INT *ja = nullptr; - - float_type *mkl_a = nullptr; - float_type *mkl_b = b.data(); - float_type *mkl_x = xk.data(); - - // Internal solver memory pointer pt, - // 32-bit: int pt[64]; 64-bit: long int pt[64] - // or void *pt[64] should be OK on both architectures - void *pt[64]; - - // Initialise the internal solver memory pointer. This is only - // necessary for the FIRST call of the PARDISO solver. - for(MKL_INT i = 0; i < 64; i++) - { - pt[i] = 0; - } + // Reset PARDISO pointers + m_mkl_b = b.data(); + m_mkl_x = xk.data(); - // Auxiliary variables - double ddum; // Double dummy - MKL_INT idum; // Integer dummy + // Load Intel MKL PARDISO iparm parameter from solver_options class + m_opt.set_iparm_for_pardiso(m_iparm); // Memory control variables int peak_mem1 = 0, peak_mem2 = 0, peak_mem3 = 0; - // Intel MKL PARDISO iparm parameter - MKL_INT iparm[64]; - - // Load iparm from solver_options class - m_opt.set_iparm_for_pardiso(iparm); - /* * Start the solver * ========================================================================= @@ -172,25 +141,26 @@ void Solver::operator()(state_type &x, const double t1) // Jacobian can change its size and can be re-allocated. // Catch up new array addresses. - mkl_a = J.A.data(); - ia = J.ia.data(); - ja = J.ja.data(); + m_mkl_a = J.A.data(); + m_ia = J.ia.data(); + m_ja = J.ja.data(); // PHASE 1. // Reordering and Symbolic Factorization. This step also // allocates all memory that is necessary for the factorization - phase = 11; - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, mkl_a, ia, - ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error); + m_phase = 11; + PARDISO(m_pt, &m_maxfct, &m_mnum, &m_mtype, &m_phase, &m_size, + m_mkl_a, m_ia, m_ja, &m_idum, &m_nrhs, m_iparm, + &m_msglvl, &m_ddum, &m_ddum, &m_error); if(m_opt.verbosity > 1) { - if(iparm[14] > peak_mem1 || iparm[15] > peak_mem2 || - iparm[16] > peak_mem3) + if(m_iparm[14] > peak_mem1 || m_iparm[15] > peak_mem2 || + m_iparm[16] > peak_mem3) { - peak_mem1 = iparm[14]; - peak_mem2 = iparm[15]; - peak_mem3 = iparm[16]; + peak_mem1 = m_iparm[14]; + peak_mem2 = m_iparm[15]; + peak_mem3 = m_iparm[16]; std::cout << "\nPeak memory on symbolic factorization: " << (double)peak_mem1 / 1024.0 << " Mb"; @@ -204,32 +174,25 @@ void Solver::operator()(state_type &x, const double t1) } } - if(error != 0) + if(m_error != 0) { std::cout << "\nERROR during symbolic factorization...\n"; - check_pardiso_error(error); - phase = -1; // Release memory - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, &ddum, - ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, - &error); - exit(1); + m_check_pardiso_error(m_error); + return 11; } // PHASE 2. // Numerical factorization - phase = 22; - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, mkl_a, ia, - ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error); + m_phase = 22; + PARDISO(m_pt, &m_maxfct, &m_mnum, &m_mtype, &m_phase, &m_size, + m_mkl_a, m_ia, m_ja, &m_idum, &m_nrhs, m_iparm, + &m_msglvl, &m_ddum, &m_ddum, &m_error); - if(error != 0) + if(m_error != 0) { std::cout << "\nERROR during numerical factorization...\n"; - check_pardiso_error(error); - phase = -1; // Release memory - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, &ddum, - ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, - &error); - exit(2); + m_check_pardiso_error(m_error); + return 22; } } else @@ -240,18 +203,16 @@ void Solver::operator()(state_type &x, const double t1) // PHASE 3. // Back substitution and iterative refinement - phase = 33; - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, mkl_a, ia, ja, - &idum, &nrhs, iparm, &msglvl, mkl_b, mkl_x, &error); + m_phase = 33; + PARDISO(m_pt, &m_maxfct, &m_mnum, &m_mtype, &m_phase, &m_size, + m_mkl_a, m_ia, m_ja, &m_idum, &m_nrhs, m_iparm, &m_msglvl, + m_mkl_b, m_mkl_x, &m_error); - if(error != 0) + if(m_error != 0) { std::cout << "\nERROR during solution...\n"; - check_pardiso_error(error); - phase = -1; // Release memory - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, &ddum, ia, - ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error); - exit(3); + m_check_pardiso_error(m_error); + return 33; } calls++; @@ -259,23 +220,24 @@ void Solver::operator()(state_type &x, const double t1) double tol = 0.0; - for(MKL_INT i = 0; i < size; i++) + for(MKL_INT i = 0; i < m_size; i++) { - double adiff = std::abs(mkl_x[i]); - if(adiff > m_opt.value_max || std::isnan(mkl_x[i])) + double adiff = std::abs(m_mkl_x[i]); + + if(adiff > m_opt.value_max || std::isnan(m_mkl_x[i])) { std::cout << "\nERROR: Newton iterations diverged. " << "Review the tolerances and/or adaptive time " "stepping.\n"; - phase = -1; // Release memory - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, &ddum, - ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, - &error); - exit(6); + return 2; } + if(adiff > tol) + { tol = adiff; - x[i] -= mkl_x[i]; + } + + x[i] -= m_mkl_x[i]; } if(m_opt.verbosity > 0) @@ -309,10 +271,7 @@ void Solver::operator()(state_type &x, const double t1) { std::cout << "\nERROR: The time step was reduced to " << dt[0] << " but the Newton method failed to converge\n"; - phase = -1; // Release memory - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, &ddum, ia, - ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, &error); - exit(4); + return 3; } x = x_prev[0]; t += dt[0]; @@ -339,7 +298,7 @@ void Solver::operator()(state_type &x, const double t1) if(iter < m_opt.dt_increase_threshold) { dt[0] *= m_opt.dt_increase_factor; - current_scheme = reset_ti_scheme(m_opt, step_counter); + current_scheme = m_reset_ti_scheme(m_opt, step_counter); if(dt[0] > m_opt.dt_max) dt[0] = m_opt.dt_max; if(m_opt.verbosity > 0) @@ -348,18 +307,14 @@ void Solver::operator()(state_type &x, const double t1) else if(iter >= m_opt.dt_decrease_threshold - 1) { dt[0] /= m_opt.dt_decrease_factor; - current_scheme = reset_ti_scheme(m_opt, step_counter); + current_scheme = m_reset_ti_scheme(m_opt, step_counter); if(dt[0] < m_opt.dt_min) { std::cout << "\nERROR: The time step was reduced to " << dt[0] << " but the error is still above the " "threshold\n"; - phase = -1; // Release memory - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, &ddum, - ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, - &error); - exit(5); + return 4; } if(m_opt.verbosity > 0) std::cout << '<'; @@ -371,7 +326,7 @@ void Solver::operator()(state_type &x, const double t1) double norm2 = 0.0; // Estimate NORM(C(n+1) - C(n)) and NORM(C(n)) - for(MKL_INT i = 0; i < size; i++) + for(MKL_INT i = 0; i < m_size; i++) { norm1 += (x[i] - x_prev[0][i]) * (x[i] - x_prev[0][i]); norm2 += x_prev[0][i] * x_prev[0][i]; @@ -394,18 +349,14 @@ void Solver::operator()(state_type &x, const double t1) m_steps--; final_time_step = false; dt[0] /= m_opt.dt_decrease_factor; - current_scheme = reset_ti_scheme(m_opt, step_counter); + current_scheme = m_reset_ti_scheme(m_opt, step_counter); if(dt[0] < m_opt.dt_min) { std::cout << "\nERROR: The time step was reduced to " << dt[0] << " but the relative error is still above the " "threshold\n"; - phase = -1; // Release memory - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, &ddum, - ia, ja, &idum, &nrhs, iparm, &msglvl, &ddum, &ddum, - &error); - exit(5); + return 5; } x = x_prev[0]; t += dt[0]; @@ -418,7 +369,7 @@ void Solver::operator()(state_type &x, const double t1) if(eta < m_opt.dt_eta_min) { dt[0] *= m_opt.dt_increase_factor; - current_scheme = reset_ti_scheme(m_opt, step_counter); + current_scheme = m_reset_ti_scheme(m_opt, step_counter); if(dt[0] > m_opt.dt_max) dt[0] = m_opt.dt_max; if(m_opt.verbosity > 0) @@ -456,16 +407,22 @@ void Solver::operator()(state_type &x, const double t1) std::cout << "\nLinear algebra solver calls: " << calls << " (total: " << m_calls << ")\n"; - // Termination and release of memory - phase = -1; - PARDISO(pt, &maxfct, &mnum, &mtype, &phase, &size, &ddum, ia, ja, &idum, - &nrhs, iparm, &msglvl, &ddum, &ddum, &error); + // Success + return 0; +} + +Solver::~Solver() +{ + m_phase = -1; // Termination and release of memory + PARDISO(m_pt, &m_maxfct, &m_mnum, &m_mtype, &m_phase, &m_size, &m_ddum, + m_ia, m_ja, &m_idum, &m_nrhs, m_iparm, &m_msglvl, &m_ddum, &m_ddum, + &m_error); } /* * Updates time integrator scheme when the time step changes */ -int Solver::reset_ti_scheme(SolverOptions &m_opt, const int step_counter) +int Solver::m_reset_ti_scheme(SolverOptions &m_opt, const int step_counter) { if(step_counter && m_opt.bdf_order == 2) return 2; // BDF-2 @@ -476,7 +433,7 @@ int Solver::reset_ti_scheme(SolverOptions &m_opt, const int step_counter) /* * Checks PARDISO solver error messages */ -void Solver::check_pardiso_error(MKL_INT err) +void Solver::m_check_pardiso_error(MKL_INT err) { if(!err) { diff --git a/src/solver.h b/src/solver.h index 21a104f..0a415e1 100644 --- a/src/solver.h +++ b/src/solver.h @@ -1,5 +1,5 @@ /* - * The main solver class + * The main solver class definition */ #pragma once @@ -9,7 +9,6 @@ #include "jacobian.h" #include "mass_matrix.h" #include "solver_options.h" -#include "time_integrator.h" namespace daecpp_namespace_name { @@ -24,14 +23,46 @@ class Solver SolverOptions &m_opt; // Solver options + MKL_INT m_size; // System size + size_t m_steps = 0; // Internal time iteration counter size_t m_calls = 0; // Internal solver calls counter + // Intel MKL PARDISO control parameters + MKL_INT m_phase; // Current phase of the solver + MKL_INT m_maxfct = 1; // Maximum number of numerical factorizations + MKL_INT m_mnum = 1; // Which factorization to use + MKL_INT m_mtype = 11; // Real unsymmetric matrix + MKL_INT m_nrhs = 1; // Number of right hand sides + MKL_INT m_msglvl = 0; // Print statistical information + MKL_INT m_error = 0; // Error flag + + // Intel MKL PARDISO sparse matrix indeces + MKL_INT *m_ia = nullptr; + MKL_INT *m_ja = nullptr; + + // Intel MKL PARDISO vectors and sparse matrix non-zero elements + float_type *m_mkl_a = nullptr; + float_type *m_mkl_b = nullptr; + float_type *m_mkl_x = nullptr; + + // Intel MKL PARDISO internal solver memory pointer pt, + // 32-bit: int pt[64]; 64-bit: long int pt[64] + // or void *pt[64] should be OK on both architectures + void *m_pt[64]; + + // Intel MKL PARDISO auxiliary variables + double m_ddum; // Double dummy + MKL_INT m_idum; // Integer dummy + + // Intel MKL PARDISO iparm parameter + MKL_INT m_iparm[64]; + // Updates time integrator scheme when the time step changes - int reset_ti_scheme(SolverOptions &m_opt, const int step_counter); + int m_reset_ti_scheme(SolverOptions &m_opt, const int step_counter); // Checks PARDISO solver error messages - void check_pardiso_error(MKL_INT err); + void m_check_pardiso_error(MKL_INT err); public: /* @@ -40,15 +71,27 @@ class Solver Solver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) : m_rhs(rhs), m_jac(jac), m_mass(mass), m_opt(opt) { + // Initialise the internal solver memory pointer. This is only + // necessary for the FIRST call of the PARDISO solver. + for(MKL_INT i = 0; i < 64; i++) + { + m_pt[i] = 0; + } } + /* + * Releases memory. Defined in solver.cpp. + */ + ~Solver(); + /* * Integrates the system of DAEs on the interval t = [t0; t1] and returns * result in the array x. Parameter t0 can be overriden in the solver * options (t0 = 0 by default). * The data stored in x (initial conditions) will be overwritten. + * Returns 0 in case of success or error code if integration failed. */ - void operator()(state_type &x, const double t1); + int operator()(state_type &x, const double t1); /* * Virtual Observer. Called by the solver every time step. diff --git a/src/solver_options.h b/src/solver_options.h index 52b8866..acd1bd9 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -14,10 +14,6 @@ namespace daecpp_namespace_name class SolverOptions { public: - /* - * List of public solver options - */ - // You can control the parallel execution of the solver by explicitly // setting the MKL_NUM_THREADS environment variable. If fewer OpenMP threads // are available than specified, the execution may slow down instead of diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index 09d651e..4360894 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -22,9 +22,9 @@ TimeIntegrator::TimeIntegrator(RHS &rhs, Jacobian &jac, MassMatrix &mass, m_mass(m_M); // User defined sparse matrix check - if(matrix_checker(m_M, size)) + if(m_matrix_checker(m_M, size)) { - std::cout << "Error in Mass matrix.\n"; + std::cout << "Error in Mass matrix. This error is fatal.\n"; exit(11); } @@ -53,8 +53,8 @@ TimeIntegrator::TimeIntegrator(RHS &rhs, Jacobian &jac, MassMatrix &mass, if(sp_status != SPARSE_STATUS_SUCCESS) { std::cout << "ERROR: Could not create sparse matrix descriptor for " - "Mass matrix.\n"; - exit(11); + "Mass matrix. This error is fatal.\n"; + exit(12); } // Analyze sparse matrix, choose proper kernels and workload @@ -137,10 +137,10 @@ void TimeIntegrator::operator()(sparse_matrix_holder &J, state_type &b, m_jac(m_J, x, t); // Sparse matrix check - if(matrix_checker(m_J, size)) + if(m_matrix_checker(m_J, size)) { - std::cout << "Error in Jacobian matrix.\n"; - exit(12); + std::cout << "Error in Jacobian matrix. This error is fatal.\n"; + exit(13); } size_t nzmax = m_M.A.size() + m_J.A.size(); @@ -154,7 +154,7 @@ void TimeIntegrator::operator()(sparse_matrix_holder &J, state_type &b, // Replaces deprecated mkl_dcsradd() // J: = m_J - M*alpha - matrix_add(-alpha, m_M, m_J, J); + m_matrix_add(-alpha, m_M, m_J, J); } } diff --git a/src/time_integrator.h b/src/time_integrator.h index dfd544d..2dccee4 100644 --- a/src/time_integrator.h +++ b/src/time_integrator.h @@ -1,5 +1,5 @@ /* - * Numerical time integrator class + * Numerical time integrator class definition */ #pragma once @@ -56,14 +56,14 @@ class TimeIntegrator /* * Sparse matrix checker */ - int matrix_checker(sparse_matrix_holder &A, MKL_INT size); + int m_matrix_checker(sparse_matrix_holder &A, MKL_INT size); /* * Performs matrix-matrix addition: C = alpha*A + B. * Replaces deprecated Intel MKL mkl_dcsradd() function. */ - void matrix_add(const float_type alpha, const sparse_matrix_holder &A, - const sparse_matrix_holder &B, sparse_matrix_holder &C); + void m_matrix_add(const float_type alpha, const sparse_matrix_holder &A, + const sparse_matrix_holder &B, sparse_matrix_holder &C); public: TimeIntegrator(RHS &rhs, Jacobian &jac, MassMatrix &mass, From 7481763a0bf945fee3f9e29bfdcc7dcac4178619 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 10 Jun 2019 21:51:11 +0100 Subject: [PATCH 003/274] Refactored perovskite example data structure. Tweaked solver output slightly. --- examples/perovskite/perovskite.cpp | 46 +++++++++++---------- examples/perovskite/perovskite_parameters.h | 18 +++----- src/solver.cpp | 5 +++ 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/examples/perovskite/perovskite.cpp b/examples/perovskite/perovskite.cpp index 177585a..19a10ba 100644 --- a/examples/perovskite/perovskite.cpp +++ b/examples/perovskite/perovskite.cpp @@ -54,33 +54,31 @@ int solution_check(dae::state_type &x); */ int main() { - // These parameters can be obtained from a parameter file or as command line - // options. Here for simplicity we define them as constants. - const MKL_INT N = 4000; // Number of points - const double L = 1.0; // Space interval length - const double lambda = 1.0; // Lambda parameter - const double t1 = 10.0; // Integration time (0 < t < t1) - - // Pass the parameters to the user-defined container - MyParams p(N, L, lambda, t1); + // Parameters of the problem (i.e. number of the cells, etc.) can be + // obtained from a parameter file or as command line options. Here for + // simplicity we define them in the user-defined structure MyParams as + // constants. + MyParams p; + // Print all std::cout << "N = " << p.N << "; lambda = " << p.lambda << "; t = " << p.t1 << '\n'; + // Integration time control using clock = std::chrono::high_resolution_clock; using time_unit = std::chrono::milliseconds; // Define state vectors. Here 2*N is the total number of the equations. // We are going to carry out two independent simulations: with analytical // Jacobian and with numerically estimated one, hence two vectors. - dae::state_type x1(2 * N); - dae::state_type x2(2 * N); + dae::state_type x1(2 * p.N); + dae::state_type x2(2 * p.N); // Initial conditions - for(MKL_INT i = 0; i < N; i++) + for(MKL_INT i = 0; i < p.N; i++) { - x1[i] = 1.0; // for P - ion concentration - x1[i + N] = 0.0; // for Phi - potential + x1[i] = 1.0; // for P - ion concentration + x1[i + p.N] = 0.0; // for Phi - potential } x2 = x1; // x1 and x2 will be overwritten by the solver @@ -100,7 +98,7 @@ int main() // Set up the Mass Matrix of the problem. // MyMassMatrix inherits abstract MassMatrix class from dae-cpp library. - MyMassMatrix mass(N); + MyMassMatrix mass(p.N); // Create an instance of the solver options and update some of the solver // parameters defined in solver_options.h @@ -121,13 +119,16 @@ int main() // Instanse of the solver with the user-defined observer: // MySolver solve_observer(rhs, jac, mass, opt); + // Solver status + int status = 0; + // Now we are ready to solve the set of DAEs std::cout << "\nStarting DAE solver...\n"; { auto tic0 = clock::now(); - solve(x1, p.t1); // Solve the system without observer - // solve_observer(x1, p.t1); // Use observer + status = solve(x1, p.t1); // Solve the system without observer + // status = solve_observer(x1, p.t1); // Use observer auto tic1 = clock::now(); // If we need to produce intermediate results, for example, for @@ -172,13 +173,16 @@ int main() opt.t0 = 0.0; // Initial integration time opt.dt_init = 0.1; // Initial time step + // Solver status + int status_slow; + // Solve the set of DAEs again std::cout << "\nStarting DAE solver with estimated Jacobian...\n"; { - auto tic0 = clock::now(); - solve_slow(x2, p.t1); - auto tic1 = clock::now(); + auto tic0 = clock::now(); + status_slow = solve_slow(x2, p.t1); + auto tic1 = clock::now(); std::cout << "Solver execution time: " @@ -217,7 +221,7 @@ int main() plt::save(filename); #endif - if(check_result) + if(check_result || status || status_slow) std::cout << "...Test FAILED\n\n"; else std::cout << "...done\n\n"; diff --git a/examples/perovskite/perovskite_parameters.h b/examples/perovskite/perovskite_parameters.h index 7ae3450..3949146 100644 --- a/examples/perovskite/perovskite_parameters.h +++ b/examples/perovskite/perovskite_parameters.h @@ -1,25 +1,17 @@ /* * Parameter container for the perovskite problem. - * For simplicity all parameters in this example are public. Generally, they - * should be private with getters/setters. */ #pragma once -class MyParams +struct MyParams { -public: - MKL_INT N; // Number of cells - double L; // Space interval length - double lambda; // Lambda parameter - double t1; // Integration time (0 < t < t1) + const MKL_INT N = 4000; // Number of points + const double L = 1.0; // Space interval length + const double lambda = 1.0; // Lambda parameter + const double t1 = 10.0; // Integration time (0 < t < t1) // Derived parameters const double h = L / (double)(N - 1); // cell size const double invh = 1.0 / h; // inverse cell size - - MyParams(MKL_INT N, double L, double lambda, double t1) - : N(N), L(L), lambda(lambda), t1(t1) - { - } }; diff --git a/src/solver.cpp b/src/solver.cpp index f0a87aa..6db1e90 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -163,9 +163,11 @@ int Solver::operator()(state_type &x, const double t1) peak_mem3 = m_iparm[16]; std::cout << "\nPeak memory on symbolic factorization: " + << " " << (double)peak_mem1 / 1024.0 << " Mb"; std::cout << "\nPermanent memory on symbolic factorization: " + << " " << (double)peak_mem2 / 1024.0 << " Mb"; std::cout << "\nPeak memory on numerical factorization " "and solution: " @@ -337,6 +339,9 @@ int Solver::operator()(state_type &x, const double t1) // Monitor function double eta = norm1 / (norm2 + m_opt.dt_eps_m); + if(m_opt.verbosity > 1) + std::cout << "(eta = " << eta << ")"; + // The time step should be reduced, scrape the current time // iteration if(eta > m_opt.dt_eta_max) From e4cb5569304773115ea92b7c146b2ad97a96a30a Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 10 Jun 2019 22:01:43 +0100 Subject: [PATCH 004/274] Updated README.md (mentioned solver status) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5bc5e13..867aa13 100644 --- a/README.md +++ b/README.md @@ -205,12 +205,12 @@ Now we are ready to create an instance of the solver with particular RHS, Mass m ```cpp dae::Solver solve(rhs, jac, mass, opt); -solve(x, t1); +int status = solve(x, t1); ``` Here *t*1 is the integration time (0 < *t* < *t*1), and **x** is the initial condition vector defined above. -Solution at time *t*1 will be written into vector **x** (initial conditions will be overwritten). That's it! +The solver returns 0 if integration is successful or error code otherwise. Solution at time *t*1 will be written into vector **x** (initial conditions will be overwritten). That's it! #### Optional: Set up Observer From 921b46b708fc46138375ed4e33cb87c2cdb65bc8 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 10 Jun 2019 23:31:14 +0100 Subject: [PATCH 005/274] Updated README --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 867aa13..b23717e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # dae-cpp [![Build Status](https://travis-ci.com/ikorotkin/dae-cpp.svg?branch=master)](https://travis-ci.com/ikorotkin/dae-cpp) -[![BCH compliance](https://bettercodehub.com/edge/badge/ikorotkin/dae-cpp?branch=master)](https://bettercodehub.com/) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3241871.svg)](https://doi.org/10.5281/zenodo.3241871) A simple but powerful C++ solver for Differential Algebraic Equation (DAE) systems. @@ -239,12 +238,18 @@ Solution can be visualised using a simple [C++ interface](https://github.com/lav Note that by default the plotting is switched off in the examples, but the plotting-related code can be activated using `#define PLOTTING` at the very beginning of each example. Activating the plotting refers to `matplotlibcpp.h` header located in `src/external/matplotlib-cpp/` directory. -The second example, [diffusion_2d](https://github.com/ikorotkin/dae-cpp/tree/master/examples/diffusion_2d) will produce a two-dimensional Gaussian function, a solution of two-dimensional diffusion problem with an instantaneous point source in the middle of the plane: +The second example, [diffusion_2d](https://github.com/ikorotkin/dae-cpp/tree/master/examples/diffusion_2d), will produce a two-dimensional Gaussian function, a solution of two-dimensional diffusion problem with an instantaneous point source in the middle of the plane:

+## Contribution and feedback + +Please feel free to contribute into the project! + +If you have any questions, suggestion, or a feedback, please, submit an [issue](https://github.com/ikorotkin/dae-cpp/issues). + ## Licensing - dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). From 0ac8f7d22d439d3713509b6ef70cf6ef8cf7fe15 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 11 Jun 2019 16:21:35 +0100 Subject: [PATCH 006/274] Add Codacy automated code analyser --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b23717e..f0cd6e7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # dae-cpp [![Build Status](https://travis-ci.com/ikorotkin/dae-cpp.svg?branch=master)](https://travis-ci.com/ikorotkin/dae-cpp) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4aa33eb3a2834808a6cd1b81e0d8cc23)](https://www.codacy.com/app/ikorotkin/dae-cpp?utm_source=github.com&utm_medium=referral&utm_content=ikorotkin/dae-cpp&utm_campaign=Badge_Grade) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3241871.svg)](https://doi.org/10.5281/zenodo.3241871) A simple but powerful C++ solver for Differential Algebraic Equation (DAE) systems. @@ -23,13 +24,13 @@ BDF time stepper reduces the original DAE system to a system of nonlinear equati ### The main features of the solver -- Can resolve DAE systems of 108 equations and even more (depending on the machine's RAM). -- A user can provide analytical Jacobian matrix for better performance or use built-in parallel function provided by the solver to estimate numerical Jacobian. -- Utilises all available cores on the machine for better performance (this can be overridden by a user). -- Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. On the other hand, this is optional. Default values should work fine in most cases. -- A user can get access to the solution at each time step by overriding Observer function (this is optional). -- The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. -- Easy-to-follow examples (see, for example, [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp)) to kick-start the user's project. + - Can resolve DAE systems of 108 equations and even more (depending on the machine's RAM). + - A user can provide analytical Jacobian matrix for better performance or use built-in parallel function provided by the solver to estimate numerical Jacobian. + - Utilises all available cores on the machine for better performance (this can be overridden by a user). + - Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. On the other hand, this is optional. Default values should work fine in most cases. + - A user can get access to the solution at each time step by overriding Observer function (this is optional). + - The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. + - Easy-to-follow examples (see, for example, [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp)) to kick-start the user's project. ## Installation @@ -102,17 +103,16 @@ During this test the solver will solve DAE systems from [examples](https://githu #### More building options -- `DAE_LONG_INT` - Use long integer representation for huge systems (more than ~107 equations). This option is OFF by default. For relatively small systems it is recommended to leave it OFF. -- `DAE_FORTRAN_STYLE` - If ON, the matrices will be defined using FORTRAN style (one-based indexing of columns and rows). By default it is OFF (zero-based indexing). -- `DAE_SINGLE` - If ON, the single precision will be used in the solver instead of double. Single precision may ruin the accuracy. It is highly recommended to leave this option OFF. This option exists for the future compatibility with CUDA implementations of the solver. -- `DAE_BUILD_EXAMPLES` - Build all the examples, ON by default. -- `DAE_TEST` - Build automatic solver test, ON by default. The test can be executed by the command `ctest` from the building directory. + - `DAE_LONG_INT` - Use long integer representation for huge systems (more than ~107 equations). This option is OFF by default. For relatively small systems it is recommended to leave it OFF. + - `DAE_FORTRAN_STYLE` - If ON, the matrices will be defined using FORTRAN style (one-based indexing of columns and rows). By default it is OFF (zero-based indexing). + - `DAE_SINGLE` - If ON, the single precision will be used in the solver instead of double. Single precision may ruin the accuracy. It is highly recommended to leave this option OFF. This option exists for the future compatibility with CUDA implementations of the solver. + - `DAE_BUILD_EXAMPLES` - Build all the examples, ON by default. + - `DAE_TEST` - Build automatic solver test, ON by default. The test can be executed by the command `ctest` from the building directory. ### Windows Setting up the solver in Microsoft Visual Studio 2017. This has been tested but needs to be described... - ## How to use Please refer to [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. @@ -252,5 +252,5 @@ If you have any questions, suggestion, or a feedback, please, submit an [issue]( ## Licensing -- dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). -- Intel MKL is free for use and redistribution under [Intel Simplified Software License](https://software.intel.com/en-us/license/intel-simplified-software-license). + - dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). + - Intel MKL is free for use and redistribution under [Intel Simplified Software License](https://software.intel.com/en-us/license/intel-simplified-software-license). From e55ebb2d729054a212da2e1cda9ccc52a2af248a Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 12 Jun 2019 11:37:41 +0100 Subject: [PATCH 007/274] Tweak numerical Jacobian --- src/jacobian.cpp | 15 +++++++-------- src/jacobian.h | 7 ++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/jacobian.cpp b/src/jacobian.cpp index fe76e6b..e6b0bfe 100644 --- a/src/jacobian.cpp +++ b/src/jacobian.cpp @@ -2,13 +2,14 @@ * Performs numerical differentiation of the RHS with the given tolerance to * estimate numerical Jacobian matrix */ + #include // std::cout #include // std::setw etc. #include // std::abs #include // std::copy #if defined(_OPENMP) -#include // to catch omp_get_max_threads() +#include // to catch omp_get_max_threads(), omp_get_thread_num() #endif #include "jacobian.h" @@ -29,9 +30,7 @@ void Jacobian::operator()(sparse_matrix_holder &J, const state_type &x, const double t) { const MKL_INT size = (MKL_INT)(x.size()); - const double tol = m_tol; - const double tol2 = tol * tol; - const double invtol = 1.0 / tol; + const double invtol = 1.0 / m_tol; // Get max number of threads. // This can be defined using "export OMP_NUM_THREADS=N", @@ -83,11 +82,11 @@ void Jacobian::operator()(sparse_matrix_holder &J, const state_type &x, float_type x1_backup = x1[j]; #if JACOBIAN_SCHEME == 0 - x1[j] -= tol; + x1[j] -= m_tol; m_rhs(x1, f0, t); - x1[j] = x1_backup + tol; + x1[j] = x1_backup + m_tol; #else - x1[j] += tol; + x1[j] += m_tol; #endif m_rhs(x1, f1, t); @@ -96,7 +95,7 @@ void Jacobian::operator()(sparse_matrix_holder &J, const state_type &x, { double diff = f1[i] - f0[i]; - if(std::abs(diff) < tol2) + if(std::abs(diff) < m_eps) continue; #if JACOBIAN_SCHEME == 0 diff --git a/src/jacobian.h b/src/jacobian.h index 8295ebe..b5e6171 100644 --- a/src/jacobian.h +++ b/src/jacobian.h @@ -14,13 +14,14 @@ namespace daecpp_namespace_name class Jacobian { - RHS &m_rhs; #ifdef DAE_SINGLE - double m_tol = 5.0e-3; + const double m_tol = 1.0e-3; // Default tolerance + const double m_eps = 1.0e-6; // The order of the rounding unit #else - double m_tol = 1.0e-5; + const double m_tol = 1.0e-6; // Default tolerance + const double m_eps = 1.0e-13; // The order of the rounding unit #endif public: From d34c0baffaafe7749f5ad2466781e8e989ac558b Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 12 Jun 2019 12:02:21 +0100 Subject: [PATCH 008/274] Tweak RHS of the diffusion_2d example --- examples/diffusion_2d/diffusion_2d.cpp | 22 +++++++++------------- examples/diffusion_2d/diffusion_2d_RHS.cpp | 17 +++++++---------- examples/diffusion_2d/diffusion_2d_RHS.h | 4 ++-- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/examples/diffusion_2d/diffusion_2d.cpp b/examples/diffusion_2d/diffusion_2d.cpp index b29a0ce..dfda0b4 100644 --- a/examples/diffusion_2d/diffusion_2d.cpp +++ b/examples/diffusion_2d/diffusion_2d.cpp @@ -49,8 +49,10 @@ int main() { // These parameters can be obtained from a parameter file or as command line // options. Here for simplicity we define them as constants. - const MKL_INT N = 51; // Number of cells along one axis - const double D = 1.0; // Diffusion coefficient + const MKL_INT N = 51; // Number of cells along one axis. Should be odd + // in order to place an instantaneous point source + // exactly in the middle of the plane + const double D = 1.0; // Diffusion coefficient (dimensionless) const double t1 = 0.01; // Integration time (0 < t < t1) std::cout << "N = " << N << "; D = " << D << "; t = " << t1 << '\n'; @@ -66,7 +68,7 @@ int main() { x[i] = 0.0; } - x[N * N / 2] = N * N; // 1/(h*h) -- numerical delta-function + x[N * N / 2] = N * N; // = 1/(h*h) -- numerical delta-function // Set up the RHS of the problem. // Class MyRHS inherits abstract RHS class from dae-cpp library. @@ -192,27 +194,21 @@ int solution_check(dae::state_type &x, MKL_INT N, double t, double D) double yi = (double)i * h + h * 0.5; double an = analyt(xi, yi, t, D); - double error; - if(an > 1.0) { - error = (x[ind] - an) / an * 100.0; // relative error + double error = (x[ind] - an) / an * 100.0; // relative error - if(fabs(error) > err_max) + if(std::abs(error) > err_max) { - err_max = fabs(error); + err_max = std::abs(error); } } - else - { - // error = (x[ind] - an); // absolute error - } } } total_C *= h * h; - double err_conc = fabs(total_C - 1.0) * 100; + double err_conc = std::abs(total_C - 1.0) * 100; std::cout << "Total concentration: " << total_C << " (" << err_conc << "% deviation from the analytical value)\n"; diff --git a/examples/diffusion_2d/diffusion_2d_RHS.cpp b/examples/diffusion_2d/diffusion_2d_RHS.cpp index 963fce3..2f1a573 100644 --- a/examples/diffusion_2d/diffusion_2d_RHS.cpp +++ b/examples/diffusion_2d/diffusion_2d_RHS.cpp @@ -10,14 +10,11 @@ void MyRHS::operator()(const daecpp::state_type &x, daecpp::state_type &f, // Number of cells along x and y axis const MKL_INT N = m_N; - // Using `daecpp::float_type` here instead of `double` to support single - // precision (only if DAE_SINGLE=ON). But in most cases this is not - // necessary, one can use `double` only since `daecpp::float_type` is - // equivalent to `double` by default (DAE_SINGLE=OFF). - const daecpp::float_type dinvh2 = m_D * (double)(N) * (double)(N); + // Helper coefficient + const double dinvh2 = m_D * (double)(N) * (double)(N); // Flux value on the boundaries - const daecpp::float_type bflux = 0.0; + const double bflux = 0.0; // clang-format off for(MKL_INT i = 0; i < N; i++) @@ -31,10 +28,10 @@ void MyRHS::operator()(const daecpp::state_type &x, daecpp::state_type &f, // moving them into a separate loop over all boundary cells in order // to avoid if-conditions within the loop. But the way suggested // bellow is less messy and much easier to read/modify for a human. - const daecpp::float_type Fr = (j != N-1) ? (x[ind+1] - x[ind]) : bflux; // Right - const daecpp::float_type Fu = (i != N-1) ? (x[ind+N] - x[ind]) : bflux; // Up - const daecpp::float_type Fl = (j != 0) ? (x[ind] - x[ind-1]) : bflux; // Left - const daecpp::float_type Fd = (i != 0) ? (x[ind] - x[ind-N]) : bflux; // Down + double Fr = (j != N-1) ? (x[ind+1] - x[ind]) : bflux; // Right + double Fu = (i != N-1) ? (x[ind+N] - x[ind]) : bflux; // Up + double Fl = (j != 0) ? (x[ind] - x[ind-1]) : bflux; // Left + double Fd = (i != 0) ? (x[ind] - x[ind-N]) : bflux; // Down f[ind] = (Fr - Fl + Fu - Fd)*dinvh2; } diff --git a/examples/diffusion_2d/diffusion_2d_RHS.h b/examples/diffusion_2d/diffusion_2d_RHS.h index 66c573e..27a802d 100644 --- a/examples/diffusion_2d/diffusion_2d_RHS.h +++ b/examples/diffusion_2d/diffusion_2d_RHS.h @@ -8,8 +8,8 @@ class MyRHS : public daecpp::RHS { - MKL_INT m_N; - double m_D; + const MKL_INT m_N; // Number of cells along axis + const double m_D; // Diffusion coefficient (dimensionless) public: MyRHS(MKL_INT N, double D) : daecpp::RHS(), m_N(N), m_D(D) {} From 647e95f1922580665bdda134b561dde2f21d0fa3 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 14 Jun 2019 21:28:34 +0100 Subject: [PATCH 009/274] Refactored adaptive time stepping algorithm --- src/solver.cpp | 192 +++++++++------------------------------- src/solver.h | 31 ++++++- src/solver_options.h | 1 + src/time_integrator.cpp | 2 +- src/time_integrator.h | 2 +- src/time_stepper.cpp | 152 +++++++++++++++++++++++++++++++ src/typedefs.h | 2 +- 7 files changed, 225 insertions(+), 157 deletions(-) create mode 100644 src/time_stepper.cpp diff --git a/src/solver.cpp b/src/solver.cpp index 6db1e90..b6b01c0 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -41,12 +41,18 @@ int Solver::operator()(state_type &x, const double t1) (m_opt.dt_init > (t1 - m_opt.t0)) ? (t1 - m_opt.t0) : m_opt.dt_init; // Initial time - double t = m_opt.t0; + m_iterator_state.t = m_opt.t0; // Initial time step - double dt[2]; - dt[0] = m_opt.dt_init; - dt[1] = dt[0]; + m_iterator_state.dt[0] = m_opt.dt_init; + m_iterator_state.dt[1] = m_iterator_state.dt[0]; + + // Initialise the time integrator state structure. + // Solver starts the first time step using BDF-1 method + // (since it doesn't have enough history yet) + m_iterator_state.current_scheme = 1; + m_iterator_state.step_counter_local = 0; + m_iterator_state.final_time_step = false; // Initialise time integrator TimeIntegrator ti(m_rhs, m_jac, m_mass, m_opt, m_size); @@ -62,10 +68,6 @@ int Solver::operator()(state_type &x, const double t1) << std::endl; } - // Solver starts the first time step using BDF-1 method - // (since it doesn't have enough history yet) - int current_scheme = 1; - // Contains a few latest successful time steps for Time Integrator state_type_matrix x_prev(m_opt.bdf_order, state_type(m_size)); @@ -98,35 +100,32 @@ int Solver::operator()(state_type &x, const double t1) // TODO: Start timer here - t += dt[0]; + m_iterator_state.t += m_iterator_state.dt[0]; - bool final_time_step = false; // Do final time step - int step_counter = 0; // Counts time steps - int calls = 0; // Counts linear algebra solver calls - - while(t < (t1 + dt[0] * 0.5)) + while(m_iterator_state.t < (t1 + m_iterator_state.dt[0] * 0.5)) { - step_counter++; + m_iterator_state.step_counter_local++; m_steps++; if(m_opt.verbosity > 0) { std::cout << std::left; std::cout << "\nStep " << std::setw(7) << m_steps - << " :: t = " << std::setw(12) << t << " :: "; + << " :: t = " << std::setw(12) << m_iterator_state.t + << " :: "; std::cout.flush(); } if(m_opt.verbosity > 1) { - std::cout << "BDF-" << current_scheme << ": "; + std::cout << "BDF-" << m_iterator_state.current_scheme << ": "; } - ti.set_scheme(current_scheme); + ti.set_scheme(m_iterator_state.current_scheme); - if(current_scheme < m_opt.bdf_order) + if(m_iterator_state.current_scheme < m_opt.bdf_order) { - current_scheme++; + m_iterator_state.current_scheme++; } int iter; // We need this value later @@ -137,7 +136,7 @@ int Solver::operator()(state_type &x, const double t1) if(m_opt.fact_every_iter || iter == 0) { // Time Integrator with updated Jacobian - ti(J, b, x, x_prev, t, dt, true); + ti(J, b, x, x_prev, m_iterator_state.t, m_iterator_state.dt, true); // Jacobian can change its size and can be re-allocated. // Catch up new array addresses. @@ -200,7 +199,7 @@ int Solver::operator()(state_type &x, const double t1) else { // Time Integrator with the previous Jacobian - ti(J, b, x, x_prev, t, dt, false); + ti(J, b, x, x_prev, m_iterator_state.t, m_iterator_state.dt, false); } // PHASE 3. @@ -217,7 +216,6 @@ int Solver::operator()(state_type &x, const double t1) return 33; } - calls++; m_calls++; double tol = 0.0; @@ -261,134 +259,38 @@ int Solver::operator()(state_type &x, const double t1) if(m_opt.verbosity > 0) std::cout << " <- redo"; - // Decrease the time step, scrape the current time iteration and - // carry out it again. - t -= dt[0]; - step_counter--; - m_steps--; - final_time_step = false; - dt[0] /= m_opt.dt_decrease_factor; - current_scheme = 1; // Fall back to BDF-1 for better stability - if(dt[0] < m_opt.dt_min) - { - std::cout << "\nERROR: The time step was reduced to " << dt[0] - << " but the Newton method failed to converge\n"; - return 3; - } - x = x_prev[0]; - t += dt[0]; + if(m_reset_ti_state(x, x_prev)) + return 3; // Newton method failed to converge + continue; } // The solver has reached the target time t1 or the stop condition // triggered. - if(final_time_step) + if(m_iterator_state.final_time_step) { break; } - else if(m_rhs.stop_condition(x, t)) + else if(m_rhs.stop_condition(x, m_iterator_state.t)) { - dt[1] = dt[0]; + m_iterator_state.dt[1] = m_iterator_state.dt[0]; break; } // Simple yet efficient adaptive time stepping - if(m_opt.time_stepping == 1) // S-SATS - { - dt[1] = dt[0]; - - if(iter < m_opt.dt_increase_threshold) - { - dt[0] *= m_opt.dt_increase_factor; - current_scheme = m_reset_ti_scheme(m_opt, step_counter); - if(dt[0] > m_opt.dt_max) - dt[0] = m_opt.dt_max; - if(m_opt.verbosity > 0) - std::cout << '>'; - } - else if(iter >= m_opt.dt_decrease_threshold - 1) - { - dt[0] /= m_opt.dt_decrease_factor; - current_scheme = m_reset_ti_scheme(m_opt, step_counter); - if(dt[0] < m_opt.dt_min) - { - std::cout << "\nERROR: The time step was reduced to " - << dt[0] - << " but the error is still above the " - "threshold\n"; - return 4; - } - if(m_opt.verbosity > 0) - std::cout << '<'; - } - } - else if(m_opt.time_stepping == 2) // A-SATS - { - double norm1 = 0.0; - double norm2 = 0.0; - - // Estimate NORM(C(n+1) - C(n)) and NORM(C(n)) - for(MKL_INT i = 0; i < m_size; i++) - { - norm1 += (x[i] - x_prev[0][i]) * (x[i] - x_prev[0][i]); - norm2 += x_prev[0][i] * x_prev[0][i]; - } - norm1 = sqrt(norm1); - norm2 = sqrt(norm2); - - // Monitor function - double eta = norm1 / (norm2 + m_opt.dt_eps_m); - - if(m_opt.verbosity > 1) - std::cout << "(eta = " << eta << ")"; - - // The time step should be reduced, scrape the current time - // iteration - if(eta > m_opt.dt_eta_max) - { - if(m_opt.verbosity > 0) - std::cout << " <- redo: dt_eta = " << eta; - - t -= dt[0]; - step_counter--; - m_steps--; - final_time_step = false; - dt[0] /= m_opt.dt_decrease_factor; - current_scheme = m_reset_ti_scheme(m_opt, step_counter); - if(dt[0] < m_opt.dt_min) - { - std::cout << "\nERROR: The time step was reduced to " - << dt[0] - << " but the relative error is still above the " - "threshold\n"; - return 5; - } - x = x_prev[0]; - t += dt[0]; - continue; - } - - dt[1] = dt[0]; - - // The time step can be increased - if(eta < m_opt.dt_eta_min) - { - dt[0] *= m_opt.dt_increase_factor; - current_scheme = m_reset_ti_scheme(m_opt, step_counter); - if(dt[0] > m_opt.dt_max) - dt[0] = m_opt.dt_max; - if(m_opt.verbosity > 0) - std::cout << '>'; - } - } // SATS + int status = adaptive_time_stepping(x, x_prev, iter); + if(status < 0) + return 4; // The algorithm failed to converge + else if(status > 0) + continue; // Re-run the current time step // Looks like the solver has reached the target time t1 - if(t + dt[0] >= t1) + if(m_iterator_state.t + m_iterator_state.dt[0] >= t1) { - final_time_step = true; + m_iterator_state.final_time_step = true; // Adjust the last time step size - dt[1] = dt[0]; - dt[0] = t1 - t; + m_iterator_state.dt[1] = m_iterator_state.dt[0]; + m_iterator_state.dt[0] = t1 - m_iterator_state.t; } // Rewrite solution history @@ -399,18 +301,17 @@ int Solver::operator()(state_type &x, const double t1) x_prev[0] = x; // Call Observer to provide a user with intermediate results - observer(x, t); + observer(x, m_iterator_state.t); - t += dt[0]; // Time step lapse + m_iterator_state.t += m_iterator_state.dt[0]; // Time step lapse } // while t - m_opt.t0 = t; - m_opt.dt_init = dt[1]; + m_opt.t0 = m_iterator_state.t; + m_opt.dt_init = m_iterator_state.dt[1]; if(m_opt.verbosity > 0) - std::cout << "\nLinear algebra solver calls: " << calls - << " (total: " << m_calls << ")\n"; + std::cout << "\nLinear algebra solver calls: " << m_calls << '\n'; // Success return 0; @@ -424,17 +325,6 @@ Solver::~Solver() &m_error); } -/* - * Updates time integrator scheme when the time step changes - */ -int Solver::m_reset_ti_scheme(SolverOptions &m_opt, const int step_counter) -{ - if(step_counter && m_opt.bdf_order == 2) - return 2; // BDF-2 - else - return 1; // BDF-1 -} - /* * Checks PARDISO solver error messages */ diff --git a/src/solver.h b/src/solver.h index 0a415e1..fba5dcd 100644 --- a/src/solver.h +++ b/src/solver.h @@ -23,10 +23,19 @@ class Solver SolverOptions &m_opt; // Solver options + struct iterator_state_struct // Keeps the current time layer state + { + double t; // current time + double dt[2]; // current and previous time steps + int current_scheme; // current BDF order + int step_counter_local; // local time step counter + bool final_time_step; // do final time step + } m_iterator_state; + MKL_INT m_size; // System size - size_t m_steps = 0; // Internal time iteration counter - size_t m_calls = 0; // Internal solver calls counter + size_t m_steps = 0; // Total time iteration counter + size_t m_calls = 0; // Total linear algebra solver calls counter // Intel MKL PARDISO control parameters MKL_INT m_phase; // Current phase of the solver @@ -58,8 +67,24 @@ class Solver // Intel MKL PARDISO iparm parameter MKL_INT m_iparm[64]; + // Simple yet efficient Adaptive Time Stepping + int adaptive_time_stepping(state_type &x, const state_type_matrix &x_prev, int iter); + + // Scrapes the current time iteration and decreases the time step + // Return -1 in case the time step is below dt_min + int m_reset_ti_state(state_type &x, const state_type_matrix &x_prev); + // Updates time integrator scheme when the time step changes - int m_reset_ti_scheme(SolverOptions &m_opt, const int step_counter); + int m_reset_ti_scheme(); + + // Increases the time step + void m_increase_dt(); + + // Decreases the time step + void m_decrease_dt(); + + // Checks if dt is within the interval defined in solver_options.h + int m_check_dt(); // Checks PARDISO solver error messages void m_check_pardiso_error(MKL_INT err); diff --git a/src/solver_options.h b/src/solver_options.h index acd1bd9..bfec627 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -112,6 +112,7 @@ class SolverOptions void set_iparm_for_pardiso(MKL_INT *iparm); // Checks correctness of the solver parameters + // TODO: should return error code void check_options(); }; diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index 4360894..57f2037 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -69,7 +69,7 @@ TimeIntegrator::TimeIntegrator(RHS &rhs, Jacobian &jac, MassMatrix &mass, } void TimeIntegrator::operator()(sparse_matrix_holder &J, state_type &b, - state_type &x, const state_type_matrix &x_prev, + const state_type &x, const state_type_matrix &x_prev, const double t, const double dt[], const bool do_jac) { diff --git a/src/time_integrator.h b/src/time_integrator.h index 2dccee4..2b77bfa 100644 --- a/src/time_integrator.h +++ b/src/time_integrator.h @@ -73,7 +73,7 @@ class TimeIntegrator void set_scheme(int scheme) { m_scheme = scheme; } - void operator()(sparse_matrix_holder &J, state_type &b, state_type &x, + void operator()(sparse_matrix_holder &J, state_type &b, const state_type &x, const state_type_matrix &x_prev, const double t, const double dt[], const bool do_jac); }; diff --git a/src/time_stepper.cpp b/src/time_stepper.cpp new file mode 100644 index 0000000..16cd305 --- /dev/null +++ b/src/time_stepper.cpp @@ -0,0 +1,152 @@ +/* +* Simple yet efficient Adaptive Time Stepping +*/ + +#include +#include "solver.h" + +namespace daecpp_namespace_name +{ + +/* + * Simple yet efficient Adaptive Time Stepping + */ +int Solver::adaptive_time_stepping(state_type &x, const state_type_matrix &x_prev, int iter) +{ + if(m_opt.time_stepping == 1) // S-SATS + { + m_iterator_state.dt[1] = m_iterator_state.dt[0]; + + if(iter < m_opt.dt_increase_threshold) + { + m_increase_dt(); + } + else if(iter >= m_opt.dt_decrease_threshold - 1) + { + m_decrease_dt(); + if(m_check_dt()) + return -1; // Method failed to converge + } + } + else if(m_opt.time_stepping == 2) // A-SATS + { + double norm1 = 0.0; + double norm2 = 0.0; + + // Estimate NORM(C(n+1) - C(n)) and NORM(C(n)) + for(MKL_INT i = 0; i < m_size; i++) + { + norm1 += (x[i] - x_prev[0][i]) * (x[i] - x_prev[0][i]); + norm2 += x_prev[0][i] * x_prev[0][i]; + } + norm1 = sqrt(norm1); + norm2 = sqrt(norm2); + + // Monitor function + double eta = norm1 / (norm2 + m_opt.dt_eps_m); + + if(m_opt.verbosity > 1) + std::cout << "(eta = " << eta << ")"; + + // The time step should be reduced, scrape the current time iteration + if(eta > m_opt.dt_eta_max) + { + if(m_opt.verbosity > 0) + std::cout << " <- redo: dt_eta = " << eta; + if(m_reset_ti_state(x, x_prev)) + return -2; // Method failed to converge + return 2; // Re-run the current iteration + } + + m_iterator_state.dt[1] = m_iterator_state.dt[0]; + + // The time step can be increased + if(eta < m_opt.dt_eta_min) + { + m_increase_dt(); + } + } + else + { + // Internal error + return -10; + } + + return 0; +} + +/* + * Scrapes the current time iteration and decreases the time step + */ +int Solver::m_reset_ti_state(state_type &x, const state_type_matrix &x_prev) +{ + m_iterator_state.t -= m_iterator_state.dt[0]; + m_iterator_state.step_counter_local--; + m_steps--; + m_iterator_state.final_time_step = false; + m_iterator_state.dt[0] /= m_opt.dt_decrease_factor; + m_iterator_state.current_scheme = m_reset_ti_scheme(); + m_iterator_state.t += m_iterator_state.dt[0]; + + x = x_prev[0]; + + return m_check_dt(); +} + +/* + * Updates time integrator scheme when the time step changes + */ +int Solver::m_reset_ti_scheme() +{ + if(m_iterator_state.step_counter_local && m_opt.bdf_order == 2) + return 2; // BDF-2 + else + return 1; // BDF-1 +} + +/* + * Increases the time step + */ +void Solver::m_increase_dt() +{ + m_iterator_state.dt[0] *= m_opt.dt_increase_factor; + m_iterator_state.current_scheme = m_reset_ti_scheme(); + if(!m_check_dt() && m_opt.verbosity > 0) + std::cout << '>'; +} + +/* + * Decreases the time step + */ +void Solver::m_decrease_dt() +{ + m_iterator_state.dt[0] /= m_opt.dt_decrease_factor; + m_iterator_state.current_scheme = m_reset_ti_scheme(); + if(!m_check_dt() && m_opt.verbosity > 0) + std::cout << '<'; +} + +/* + * Checks if dt is within the interval defined in solver_options.h + */ +int Solver::m_check_dt() +{ + if(m_iterator_state.dt[0] < m_opt.dt_min) + { + std::cout << "\nERROR: The time step was reduced to " + << m_iterator_state.dt[0] + << " but the scheme failed to converge\n"; + return -1; + } + else if(m_iterator_state.dt[0] > m_opt.dt_max) + { + m_iterator_state.dt[0] = m_opt.dt_max; + return -2; + } + else + { + return 0; + } +} + +} // namespace daecpp_namespace_name diff --git a/src/typedefs.h b/src/typedefs.h index cd044f0..4e3cf50 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -25,7 +25,7 @@ typedef std::vector vector_type_int; typedef std::vector> state_type_matrix; -struct sparse_matrix_holder +struct sparse_matrix_holder // Matrix structure in 3-array CSR format { state_type A; // Non-zero elements of the sparse matrix A vector_type_int ia; // Points to the first column index of the given row From 635fde966508d21b5f29abd20276ba0133ea26cd Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 14 Jun 2019 21:31:07 +0100 Subject: [PATCH 010/274] Updated README.md --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f0cd6e7..13560f5 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ BDF time stepper reduces the original DAE system to a system of nonlinear equati ### The main features of the solver - - Can resolve DAE systems of 108 equations and even more (depending on the machine's RAM). - - A user can provide analytical Jacobian matrix for better performance or use built-in parallel function provided by the solver to estimate numerical Jacobian. - - Utilises all available cores on the machine for better performance (this can be overridden by a user). - - Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. On the other hand, this is optional. Default values should work fine in most cases. - - A user can get access to the solution at each time step by overriding Observer function (this is optional). - - The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. - - Easy-to-follow examples (see, for example, [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp)) to kick-start the user's project. +- Can resolve DAE systems of 108 equations and even more (depending on the machine's RAM). +- A user can provide analytical Jacobian matrix for better performance or use built-in parallel function provided by the solver to estimate numerical Jacobian. +- Utilises all available cores on the machine for better performance (this can be overridden by a user). +- Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. On the other hand, this is optional. Default values should work fine in most cases. +- A user can get access to the solution at each time step by overriding Observer function (this is optional). +- The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. +- Easy-to-follow examples (see, for example, [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp)) to kick-start the user's project. ## Installation @@ -103,11 +103,11 @@ During this test the solver will solve DAE systems from [examples](https://githu #### More building options - - `DAE_LONG_INT` - Use long integer representation for huge systems (more than ~107 equations). This option is OFF by default. For relatively small systems it is recommended to leave it OFF. - - `DAE_FORTRAN_STYLE` - If ON, the matrices will be defined using FORTRAN style (one-based indexing of columns and rows). By default it is OFF (zero-based indexing). - - `DAE_SINGLE` - If ON, the single precision will be used in the solver instead of double. Single precision may ruin the accuracy. It is highly recommended to leave this option OFF. This option exists for the future compatibility with CUDA implementations of the solver. - - `DAE_BUILD_EXAMPLES` - Build all the examples, ON by default. - - `DAE_TEST` - Build automatic solver test, ON by default. The test can be executed by the command `ctest` from the building directory. +- `DAE_LONG_INT` - Use long integer representation for huge systems (more than ~107 equations). This option is OFF by default. For relatively small systems it is recommended to leave it OFF. +- `DAE_FORTRAN_STYLE` - If ON, the matrices will be defined using FORTRAN style (one-based indexing of columns and rows). By default it is OFF (zero-based indexing). +- `DAE_SINGLE` - If ON, the single precision will be used in the solver instead of double. Single precision may ruin the accuracy. It is highly recommended to leave this option OFF. This option exists for the future compatibility with CUDA implementations of the solver. +- `DAE_BUILD_EXAMPLES` - Build all the examples, ON by default. +- `DAE_TEST` - Build automatic solver test, ON by default. The test can be executed by the command `ctest` from the building directory. ### Windows @@ -252,5 +252,5 @@ If you have any questions, suggestion, or a feedback, please, submit an [issue]( ## Licensing - - dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). - - Intel MKL is free for use and redistribution under [Intel Simplified Software License](https://software.intel.com/en-us/license/intel-simplified-software-license). +- dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). +- Intel MKL is free for use and redistribution under [Intel Simplified Software License](https://software.intel.com/en-us/license/intel-simplified-software-license). From 9320a38b19d4d6fa3c2bd196eb82d4e184251850 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 14 Jun 2019 23:03:06 +0100 Subject: [PATCH 011/274] Updated sh-scripts. Fixed time stepping algorithm --- clang-tidy.sh | 1 + src/solver.cpp | 7 ++++--- src/time_stepper.cpp | 16 ++++++++++------ test.sh | 4 ++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/clang-tidy.sh b/clang-tidy.sh index 892e080..4dcaac6 100755 --- a/clang-tidy.sh +++ b/clang-tidy.sh @@ -1,3 +1,4 @@ +#!/bin/bash clang-tidy src/*.cpp -- -I/opt/intel/mkl/include clang-tidy examples/perovskite/*.cpp -- -I/opt/intel/mkl/include clang-tidy examples/diffusion_2d/*.cpp -- -I/opt/intel/mkl/include diff --git a/src/solver.cpp b/src/solver.cpp index b6b01c0..fb7d8b5 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -258,10 +258,8 @@ int Solver::operator()(state_type &x, const double t1) { if(m_opt.verbosity > 0) std::cout << " <- redo"; - if(m_reset_ti_state(x, x_prev)) return 3; // Newton method failed to converge - continue; } @@ -277,7 +275,7 @@ int Solver::operator()(state_type &x, const double t1) break; } - // Simple yet efficient adaptive time stepping + // Adaptive time stepping algorithm int status = adaptive_time_stepping(x, x_prev, iter); if(status < 0) return 4; // The algorithm failed to converge @@ -317,6 +315,9 @@ int Solver::operator()(state_type &x, const double t1) return 0; } +/* + * Releases memory + */ Solver::~Solver() { m_phase = -1; // Termination and release of memory diff --git a/src/time_stepper.cpp b/src/time_stepper.cpp index 16cd305..ae030f3 100644 --- a/src/time_stepper.cpp +++ b/src/time_stepper.cpp @@ -3,13 +3,18 @@ */ #include +#include + #include "solver.h" namespace daecpp_namespace_name { /* - * Simple yet efficient Adaptive Time Stepping + * Simple yet efficient Adaptive Time Stepping. + * Returns negative status if the time stepping method failed to converge, + * positive status if the time step should be restarted from the scratch, + * or 0 in case of success. */ int Solver::adaptive_time_stepping(state_type &x, const state_type_matrix &x_prev, int iter) { @@ -39,8 +44,8 @@ int Solver::adaptive_time_stepping(state_type &x, const state_type_matrix &x_pre norm1 += (x[i] - x_prev[0][i]) * (x[i] - x_prev[0][i]); norm2 += x_prev[0][i] * x_prev[0][i]; } - norm1 = sqrt(norm1); - norm2 = sqrt(norm2); + norm1 = std::sqrt(norm1); + norm2 = std::sqrt(norm2); // Monitor function double eta = norm1 / (norm2 + m_opt.dt_eps_m); @@ -66,9 +71,8 @@ int Solver::adaptive_time_stepping(state_type &x, const state_type_matrix &x_pre m_increase_dt(); } } - else + else // Internal error { - // Internal error return -10; } @@ -141,7 +145,7 @@ int Solver::m_check_dt() else if(m_iterator_state.dt[0] > m_opt.dt_max) { m_iterator_state.dt[0] = m_opt.dt_max; - return -2; + return 1; } else { diff --git a/test.sh b/test.sh index 9fb7e48..d84d45e 100755 --- a/test.sh +++ b/test.sh @@ -1,3 +1,6 @@ +#!/bin/bash + +# Single precision test rm -r build_single/ mkdir build_single cd build_single @@ -6,6 +9,7 @@ make -j 4 ctest cd .. +# Double precision test rm -r build/ mkdir build cd build From 2118a644dbcf8dfb6757163f25479262ced8c9c7 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 14 Jun 2019 23:27:55 +0100 Subject: [PATCH 012/274] Updated diffusion_2d example --- examples/diffusion_2d/diffusion_2d.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/diffusion_2d/diffusion_2d.cpp b/examples/diffusion_2d/diffusion_2d.cpp index dfda0b4..b55cfdd 100644 --- a/examples/diffusion_2d/diffusion_2d.cpp +++ b/examples/diffusion_2d/diffusion_2d.cpp @@ -99,14 +99,20 @@ int main() { auto tic0 = clock::now(); - solve(x, t1 / 4); // This line can be removed. It is given here just as - // an example. Here we produce an intermediate - // solution at time t = (t1 / 4). This solution - // will be stored in the vector x. Note that a better - // way to get intermediate results is to override - // observer function from daecpp::Solver class. - solve(x, t1); // Reuse vector x as an initial condition and get - // the final solution at time t = t1. + + solve(x, t1 / 10); // This line is given here just as an example. + // Here we produce an intermediate solution at time + // t = (t1 / 4). This solution will be stored in the + // vector x. Note that a better way to get + // intermediate results is to override observer + // function from daecpp::Solver class. + + // Tweak the solver paramters between the solver calls + opt.dt_increase_factor = 2.0; + + solve(x, t1); // Reuse vector x as an initial condition and get the + // final solution at time t = t1. + auto tic1 = clock::now(); std::cout From e634c427b1445d6e824f25e616e1942f2d204e43 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 14 Jun 2019 23:54:41 +0100 Subject: [PATCH 013/274] Add travis_retry --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c02475a..1ca21ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ before_install: - sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB - sudo sh -c 'echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list' - sudo apt-get update - - sudo apt-get install intel-mkl-2019.3-062 cmake + - travis_retry sudo apt-get install intel-mkl-2019.3-062 cmake env: matrix: From 3b8e1662167748ca6188c5397a64da3478b72005 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 15 Jun 2019 00:34:21 +0100 Subject: [PATCH 014/274] Add MS Visual Studio 15 default project files --- README.md | 2 +- msvc/msvc15.zip | Bin 0 -> 9577 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 msvc/msvc15.zip diff --git a/README.md b/README.md index 13560f5..ecec683 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ During this test the solver will solve DAE systems from [examples](https://githu ### Windows -Setting up the solver in Microsoft Visual Studio 2017. This has been tested but needs to be described... +An example of default solution file for Microsoft Visual Studio 15 (2017) is given in [msvc](https://github.com/ikorotkin/dae-cpp/tree/master/msvc) folder. Unpack the zip-archive into the current directory and open dae-cpp.sln. Note that you may need to retarget solution and change the paths to Intel MKL library. ## How to use diff --git a/msvc/msvc15.zip b/msvc/msvc15.zip new file mode 100644 index 0000000000000000000000000000000000000000..c020b7b35948f40859650f170982676ad1d61fdc GIT binary patch literal 9577 zcmd6tbyQUE_WuV2>F(~7E{UN;L8QC8dx!x9kxl{W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327z|3IYA+rTqzo8-S)0ZB$9vEL^3 zj+nYD0Ft^^0&_-R3s|Vp%y>i`X3cTGtoi$#kn6XF+|(ByHgBo@ep(LDT-3Tn_>C=T!Xxy8TYB|C9I$11tJ# zsQTaTMxed-{sU~24TM~s;4)go9qRc;=|9yq{ z;pV;fN97+=-G>5NmA+*NG!rntZK2W>`=0`TU)gvl;Dq>>!0+oE4}~1xi!Z?33;njw z*&u&;^7lmgp%BgeJsf{{@@qc*P{q1U@z<`uZARL^)(`)$zsJT8Rn~s0Je(c=5s{p1 zTpNq~2>iAc9{*bZhr(a;$cGBMXn!dDJBc6q0hv`}{27+tc8w#>`lsrDsQh&*|4@Yx z=fA7`x7dv8WB&5#wh4(+yejb<)9Xlni_~po-_Mz0@r)v+T z(D47G0{jsk2X9aMpMTVE8;$(0^~3!U{yGtOxIYfzf9(HXg7bVr<5zHgTL-oqx<7;S zcT;?*VMF%cH2zy?y0Tn<`SaU~kbr-!ANuomjeMxpbAQvw|EQP`10&W=@@wNit)dM4 T Date: Sat, 15 Jun 2019 00:38:03 +0100 Subject: [PATCH 015/274] Removed single precision - long integer test from travis test matrix --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1ca21ef..3542b7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,6 @@ env: - DAE_SINGLE=OFF DAE_LONG_INT=OFF - DAE_SINGLE=OFF DAE_LONG_INT=ON - DAE_SINGLE=ON DAE_LONG_INT=OFF - - DAE_SINGLE=ON DAE_LONG_INT=ON script: - mkdir build && pushd build && cmake -DDAE_SINGLE=$DAE_SINGLE -DDAE_LONG_INT=$DAE_LONG_INT .. && make -j4 && ctest -V From 4af40633b797071849a6c608ff91045b48c71a9e Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 17 Jun 2019 17:18:53 +0100 Subject: [PATCH 016/274] Stiff Robertson problem draft --- .vscode/tasks.json | 33 ++++ examples/robertson/robertson.cpp | 296 +++++++++++++++++++++++++++++++ 2 files changed, 329 insertions(+) create mode 100644 examples/robertson/robertson.cpp diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c356fdc..788c393 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -69,6 +69,39 @@ "$gcc" ] }, + { + "label": "build-robertson", + "type": "shell", + "command": "g++", + "args": [ + "-O3", + "-Wall", + "-std=c++11", + "-m64", + "-fopenmp", + "./examples/robertson/*.cpp", + "./src/*.cpp", + "-o", + "robertson.exe", + "-I/opt/intel/mkl/include", + "-I./src/external", + //"-I/usr/include/python3.6m", + //"-I/usr/local/lib/python3.6/dist-packages/numpy/core/include", + //"-lpython3.6m", + "-L/opt/intel/mkl/lib/intel64", + "-Wl,--no-as-needed", + "-lmkl_intel_lp64", + "-lmkl_gnu_thread", + "-lmkl_core", + "-lgomp", + "-lpthread", + "-lm", + "-ldl" + ], + "problemMatcher": [ + "$gcc" + ] + }, { "label": "build-intel-omp", "type": "shell", diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp new file mode 100644 index 0000000..3256a87 --- /dev/null +++ b/examples/robertson/robertson.cpp @@ -0,0 +1,296 @@ +/* + * TODO: Description + * + * Keywords: Robertson problem, stiff DAE. + */ + +#include +#include + +#include "../../src/solver.h" // the main header of dae-cpp library solver + +using namespace daecpp; + +// python3 + numpy + matplotlib should be installed in order to enable plotting +// #define PLOTTING + +#ifdef PLOTTING +#include "../../src/external/matplotlib-cpp/matplotlibcpp.h" +namespace plt = matplotlibcpp; +#endif + +// To compare dae-cpp solution with the analytical solution +// int solution_check(state_type &x, MKL_INT N, double t, double D); + +class MyMassMatrix : public MassMatrix +{ +public: + void operator()(daecpp::sparse_matrix_holder &M) + { + M.A.resize(3); + M.ja.resize(3); + M.ia.resize(4); + + M.A[0] = 1; + M.A[1] = 1; + M.A[2] = 0; + + M.ja[0] = 0; + M.ja[1] = 1; + M.ja[2] = 2; + + M.ia[0] = 0; + M.ia[1] = 1; + M.ia[2] = 2; + M.ia[3] = 3; + } +}; + +/* + * RHS of the problem + * ============================================================================= + */ +class MyRHS : public RHS +{ +public: + void operator()(const daecpp::state_type &x, daecpp::state_type &f, + const double t) + { + f[0] = -0.04 * x[0] + 1.0e4 * x[1] * x[2]; + f[1] = 0.04 * x[0] - 1.0e4 * x[1] * x[2] - 3.0e7 * x[1] * x[1]; + f[2] = x[0] + x[1] + x[2] - 1; + } +}; + +class MySolver : public Solver +{ +public: + MySolver(daecpp::RHS &rhs, daecpp::Jacobian &jac, daecpp::MassMatrix &mass, + daecpp::SolverOptions &opt) + : daecpp::Solver(rhs, jac, mass, opt) + { + } + + /* + * Overloaded observer. + * Receives current solution vector and the current time every time step. + * Prints current time t and potential phi on the right boundary. + */ + void observer(daecpp::state_type &x, const double t) + { + std::cout << " | " << x[0] << ' ' << 1e4 * x[1] << ' ' << x[2] + << " == " << x[0] + x[1] + x[2] - 1.0; + } +}; + +class MyJacobian : public Jacobian +{ +public: + MyJacobian(daecpp::RHS &rhs) : daecpp::Jacobian(rhs) {} + + void operator()(daecpp::sparse_matrix_holder &J, + const daecpp::state_type &x, const double t) + { + J.A.resize(9); + J.ja.resize(9); + J.ia.resize(4); + + J.A[0] = -0.04; + J.A[1] = 1.0e4 * x[2]; + J.A[2] = 1.0e4 * x[1]; + J.A[3] = 0.04; + J.A[4] = -1.0e4 * x[2] - 6.0e7 * x[1]; + J.A[5] = -1.0e4 * x[1]; + J.A[6] = 1.0; + J.A[7] = 1.0; + J.A[8] = 1.0; + + J.ja[0] = 0; + J.ja[1] = 1; + J.ja[2] = 2; + J.ja[3] = 0; + J.ja[4] = 1; + J.ja[5] = 2; + J.ja[6] = 0; + J.ja[7] = 1; + J.ja[8] = 2; + + J.ia[0] = 0; + J.ia[1] = 3; + J.ia[2] = 6; + J.ia[3] = 9; + } +}; + +/* + * MAIN FUNCTION + * ============================================================================= + * Returns '0' if solution comparison is OK or '1' if solution error is above + * acceptable tolerance. + */ +int main() +{ + const double t1 = 4.0e6; + + // Define state vector + state_type x(3); + + // Initial conditions + // Use inconsistent initial condition to test initialization + x[0] = 1; + x[1] = 0; + x[2] = 1e-3; // Should be 0 + + // Set up the RHS of the problem. + + // Class MyRHS inherits abstract RHS class from dae-cpp library. + MyRHS rhs; + + // Set up the Mass Matrix of the problem. In this case this matrix is + // identity, so we can use a helper class provided by dae-cpp library. + MyMassMatrix mass; + + // Create an instance of the solver options and update some of the solver + // parameters defined in solver_options.h + SolverOptions opt; + + opt.dt_init = 1.0e-6; // Change initial time step + // opt.fact_every_iter = false; // Gain some speed (delay the update + // of Jacobian and the matrix factorisation) + + opt.verbosity = 2; + opt.dt_max = t1 / 100; + opt.time_stepping = 1; + opt.dt_increase_threshold = 2; + // opt.dt_decrease_threshold = 6; + // opt.atol = 1e-7; + // opt.bdf_order = 6; + + // We can override Jacobian class from dae-cpp library and provide + // analytical Jacobian. But we will use numerically estimated one. + Jacobian jac_est(rhs, 1e-10); + jac_est.print(x, 0); + + MyJacobian jac(rhs); + jac.print(x, 0); + + // Create an instance of the solver with particular RHS, Mass matrix, + // Jacobian and solver options + MySolver solve(rhs, jac, mass, opt); + + // Now we are ready to solve the set of DAEs + std::cout << "\nStarting DAE solver...\n"; + + solve(x, t1); + + std::cout << " | " << x[0] << ' ' << 1e4 * x[1] << ' ' << x[2] + << " == " << x[0] + x[1] + x[2] << '\n'; + + // Compare result with the analytical solution + const double x_ref[3] = {0.00051675, 2.068e-9, 0.99948324}; + const double conservation = std::abs(x[0] + x[1] + x[2] - 1); + double result = 0.0; + for(int i = 0; i < 3; i++) + result += std::abs(x[i] - x_ref[i]) / x_ref[i] * 100; + + std::cout << result << "% " << conservation << '\n'; + // int check_result = solution_check(x, N, t1, D); + + // Plot the solution +#ifdef PLOTTING + const double h = 1.0 / (double)N; + + dae::state_type_matrix x_axis, y_axis, z_axis; + + for(MKL_INT i = 0; i < N; i++) + { + dae::state_type x_row, y_row, z_row; + + for(MKL_INT j = 0; j < N; j++) + { + x_row.push_back((double)j * h + h * 0.5); + y_row.push_back((double)i * h + h * 0.5); + z_row.push_back(x[j + i * N]); + } + + x_axis.push_back(x_row); + y_axis.push_back(y_row); + z_axis.push_back(z_row); + } + + plt::figure(); + plt::figure_size(800, 600); + plt::plot_surface(x_axis, y_axis, z_axis); + + // Save figure + const char *filename = "diffusion_2d.png"; + std::cout << "Saving result to " << filename << "...\n"; + plt::save(filename); +#endif + + const bool check_result = (result > 1.0 || conservation > 1e-14); + + if(check_result) + std::cout << "...Test FAILED\n\n"; + else + std::cout << "...done\n\n"; + + return check_result; +} + +/* + * Returns '0' if solution comparison is OK or '1' if the error is above + * acceptable tolerance + */ +/* +int solution_check(state_type &x, MKL_INT N, double t, double D) +{ + std::cout << "Solution check:\n"; + + const double h = 1.0 / (double)N; + + double total_C = 0; + double err_max = 0; + + for(MKL_INT i = 0; i < N; i++) + { + for(MKL_INT j = 0; j < N; j++) + { + MKL_INT ind = j + i * N; + + total_C += x[ind]; + + double xi = (double)j * h + h * 0.5; + double yi = (double)i * h + h * 0.5; + double an = analyt(xi, yi, t, D); + + if(an > 1.0) + { + double error = (x[ind] - an) / an * 100.0; // relative error + + if(std::abs(error) > err_max) + { + err_max = std::abs(error); + } + } + } + } + + total_C *= h * h; + + double err_conc = std::abs(total_C - 1.0) * 100; + + std::cout << "Total concentration: " << total_C << " (" << err_conc + << "% deviation from the analytical value)\n"; + std::cout << "Maximum relative error: " << err_max << "%\n"; + +#ifdef DAE_SINGLE + if(err_max < 1.0 && err_conc < 2.0e-5) +#else + if(err_max < 1.0 && err_conc < 1.0e-10) +#endif + return 0; + else + return 1; +} +*/ \ No newline at end of file From 762a84d52a43a060f8099ab3b484064efe4d4c1b Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 20 Jun 2019 18:29:03 +0100 Subject: [PATCH 017/274] Add Robertson example to MSVC project file. Updated description of the example. --- examples/robertson/robertson.cpp | 185 ++++++++++++++++--------------- msvc/msvc15.zip | Bin 9577 -> 11351 bytes 2 files changed, 93 insertions(+), 92 deletions(-) diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index 3256a87..84b0dba 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -1,7 +1,28 @@ /* - * TODO: Description + * Solves Robertson Problem as Semi-Explicit Differential Algebraic Equations + * (see https://www.mathworks.com/help/matlab/ref/ode15s.html): * - * Keywords: Robertson problem, stiff DAE. + * x1' = -0.04*x1 + 1e4*x2*x3 + * x2' = 0.04*x1 - 1e4*x2*x3 - 3e7*x2^2 + * 0 = x1 + x2 + x3 - 1 + * + * Initial conditions are: x1 = 1, x2 = 0, x3 = 0. + * + * The 3rd equation in the system is basically a conservation law. It will be + * tested that x1 + x2 + x3 = 1 exactly every time step. + * + * From MATLAB ode15s description: + * + * This problem is used as an example in the prolog to LSODI [1]. Though + * consistent initial conditions are obvious, the guess x3 = 1e-3 is used + * to test initialization. A logarithmic scale is appropriate for plotting + * the solution on the long time interval. x2 is small and its major change + * takes place in a relatively short time. + * + * [1] A.C. Hindmarsh, LSODE and LSODI, two new initial value ordinary + * differential equation solvers, SIGNUM Newsletter, 15 (1980), pp. 10-11. + * + * Keywords: Robertson problem, stiff DAE system, comparison with MATLAB ode15s. */ #include @@ -19,26 +40,37 @@ using namespace daecpp; namespace plt = matplotlibcpp; #endif -// To compare dae-cpp solution with the analytical solution -// int solution_check(state_type &x, MKL_INT N, double t, double D); - +/* + * Singular mass matrix in 3-array sparse format + * ============================================================================= + * The matrix has the following form: + * |1 0 0| + * M = |0 1 0| + * |0 0 0| + * + * For more information about the sparse format see + * https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format + */ class MyMassMatrix : public MassMatrix { public: void operator()(daecpp::sparse_matrix_holder &M) { - M.A.resize(3); - M.ja.resize(3); - M.ia.resize(4); + M.A.resize(3); // Matrix size + M.ja.resize(3); // Matrix size + M.ia.resize(4); // Matrix size + 1 + // Non-zero and/or diagonal elements M.A[0] = 1; M.A[1] = 1; M.A[2] = 0; + // Column index of each element given above M.ja[0] = 0; M.ja[1] = 1; M.ja[2] = 2; + // Index of the first element for each row M.ia[0] = 0; M.ia[1] = 1; M.ia[2] = 2; @@ -53,6 +85,10 @@ class MyMassMatrix : public MassMatrix class MyRHS : public RHS { public: + /* + * Receives current solution vector x and the current time t. Defines the + * RHS f for each element in x. + */ void operator()(const daecpp::state_type &x, daecpp::state_type &f, const double t) { @@ -62,6 +98,12 @@ class MyRHS : public RHS } }; +/* + * (Optional) Observer + * ============================================================================= + * Checks conservation law x1 + x2 + x3 = 1 every time step and prints solution + * to console. + */ class MySolver : public Solver { public: @@ -74,7 +116,6 @@ class MySolver : public Solver /* * Overloaded observer. * Receives current solution vector and the current time every time step. - * Prints current time t and potential phi on the right boundary. */ void observer(daecpp::state_type &x, const double t) { @@ -83,18 +124,31 @@ class MySolver : public Solver } }; +/* + * (Optional) Analytical Jacobian in 3-array sparse format + * ============================================================================= + * + * For more information about the sparse format see + * https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format + */ class MyJacobian : public Jacobian { public: MyJacobian(daecpp::RHS &rhs) : daecpp::Jacobian(rhs) {} + /* + * Receives current solution vector x and the current time t. Defines the + * analytical Jacobian matrix J. + */ void operator()(daecpp::sparse_matrix_holder &J, const daecpp::state_type &x, const double t) { + // Initialize Jacobian in sparse format J.A.resize(9); J.ja.resize(9); J.ia.resize(4); + // Non-zero elements J.A[0] = -0.04; J.A[1] = 1.0e4 * x[2]; J.A[2] = 1.0e4 * x[1]; @@ -105,6 +159,7 @@ class MyJacobian : public Jacobian J.A[7] = 1.0; J.A[8] = 1.0; + // Column index of each element given above J.ja[0] = 0; J.ja[1] = 1; J.ja[2] = 2; @@ -115,6 +170,7 @@ class MyJacobian : public Jacobian J.ja[7] = 1; J.ja[8] = 2; + // Index of the first element for each row J.ia[0] = 0; J.ia[1] = 3; J.ia[2] = 6; @@ -130,49 +186,48 @@ class MyJacobian : public Jacobian */ int main() { + // Solution time 0 <= t <= t1 const double t1 = 4.0e6; - // Define state vector + // Define the state vector state_type x(3); - // Initial conditions - // Use inconsistent initial condition to test initialization + // Initial conditions. + // We will use slightly inconsistent initial condition to test initialization. x[0] = 1; x[1] = 0; - x[2] = 1e-3; // Should be 0 + x[2] = 1e-3; // Should be 0 theoretically // Set up the RHS of the problem. - // Class MyRHS inherits abstract RHS class from dae-cpp library. MyRHS rhs; - // Set up the Mass Matrix of the problem. In this case this matrix is - // identity, so we can use a helper class provided by dae-cpp library. + // Set up the Mass Matrix of the problem. + // MyMassMatrix inherits abstract MassMatrix class from dae-cpp library. MyMassMatrix mass; // Create an instance of the solver options and update some of the solver // parameters defined in solver_options.h SolverOptions opt; + //////////////////////////////////// Adjust this opt.dt_init = 1.0e-6; // Change initial time step - // opt.fact_every_iter = false; // Gain some speed (delay the update - // of Jacobian and the matrix factorisation) - opt.verbosity = 2; opt.dt_max = t1 / 100; opt.time_stepping = 1; opt.dt_increase_threshold = 2; - // opt.dt_decrease_threshold = 6; - // opt.atol = 1e-7; // opt.bdf_order = 6; // We can override Jacobian class from dae-cpp library and provide - // analytical Jacobian. But we will use numerically estimated one. - Jacobian jac_est(rhs, 1e-10); - jac_est.print(x, 0); - + // analytical Jacobian MyJacobian jac(rhs); - jac.print(x, 0); + // jac.print(x, 0); // print it out for t = 0 + + // Or use numerically estimated one with a given tolerance + // (commented out since we have analytical Jacobian above). + // Jacobian jac_est(rhs, 1e-10); // Obviously this tolerance is + // inacceptable in single precision + // jac_est.print(x, 0); // print Jacobian out for t = 0 // Create an instance of the solver with particular RHS, Mass matrix, // Jacobian and solver options @@ -180,23 +235,22 @@ int main() // Now we are ready to solve the set of DAEs std::cout << "\nStarting DAE solver...\n"; - solve(x, t1); - std::cout << " | " << x[0] << ' ' << 1e4 * x[1] << ' ' << x[2] - << " == " << x[0] + x[1] + x[2] << '\n'; - - // Compare result with the analytical solution + // Compare results with MATLAB ode15s solution const double x_ref[3] = {0.00051675, 2.068e-9, 0.99948324}; const double conservation = std::abs(x[0] + x[1] + x[2] - 1); - double result = 0.0; + + // Find total relative deviation from the reference solution + double result = 0.0; for(int i = 0; i < 3; i++) result += std::abs(x[i] - x_ref[i]) / x_ref[i] * 100; - std::cout << result << "% " << conservation << '\n'; - // int check_result = solution_check(x, N, t1, D); + std::cout << "Total relative error: " << result << "%\n"; + std::cout << "Conservation law absolute deviation: " << conservation + << '\n'; - // Plot the solution + // Plot the solution -- TODO: Update this! #ifdef PLOTTING const double h = 1.0 / (double)N; @@ -228,7 +282,11 @@ int main() plt::save(filename); #endif +#ifdef DAE_SINGLE + const bool check_result = (result > 1.0 || conservation > 1e-6); +#else const bool check_result = (result > 1.0 || conservation > 1e-14); +#endif if(check_result) std::cout << "...Test FAILED\n\n"; @@ -237,60 +295,3 @@ int main() return check_result; } - -/* - * Returns '0' if solution comparison is OK or '1' if the error is above - * acceptable tolerance - */ -/* -int solution_check(state_type &x, MKL_INT N, double t, double D) -{ - std::cout << "Solution check:\n"; - - const double h = 1.0 / (double)N; - - double total_C = 0; - double err_max = 0; - - for(MKL_INT i = 0; i < N; i++) - { - for(MKL_INT j = 0; j < N; j++) - { - MKL_INT ind = j + i * N; - - total_C += x[ind]; - - double xi = (double)j * h + h * 0.5; - double yi = (double)i * h + h * 0.5; - double an = analyt(xi, yi, t, D); - - if(an > 1.0) - { - double error = (x[ind] - an) / an * 100.0; // relative error - - if(std::abs(error) > err_max) - { - err_max = std::abs(error); - } - } - } - } - - total_C *= h * h; - - double err_conc = std::abs(total_C - 1.0) * 100; - - std::cout << "Total concentration: " << total_C << " (" << err_conc - << "% deviation from the analytical value)\n"; - std::cout << "Maximum relative error: " << err_max << "%\n"; - -#ifdef DAE_SINGLE - if(err_max < 1.0 && err_conc < 2.0e-5) -#else - if(err_max < 1.0 && err_conc < 1.0e-10) -#endif - return 0; - else - return 1; -} -*/ \ No newline at end of file diff --git a/msvc/msvc15.zip b/msvc/msvc15.zip index c020b7b35948f40859650f170982676ad1d61fdc..b6e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D3B#l5jCl5XrLOO%No#=g3!a-#Bm zTC-&0PaH03vE(kHCOt|OuJ^h+oC!2y7&sP5xjMy>26QZha7Am;bqxTULRR}aeb{Ptbz(D9vnO;i3FFWuoaxp>`h%q0t%XXBm&|6+ww z$dKVF(Jn|cbeZ}r_~;V2($=u*5D5CIbNYstc3R)zfD57Q`k8&fgK%<8O!;ZcmF`M~ zVmQ2>MLYSjjLRD9Su&BfyVePEFdT7tFXn6?xvhRa`)waNIG=t6b^USrwL6nu$4pDLS*@K4EVF2UhrCX`JNnzI0R%V<)Gy#p( zIQ$@Q8#{-E` zT3{uxm0nTP`!T7T@N5d4f=*0Sb<{Aj(=V1Yev&eobI*(36HbEoXtRe>Rc}}wtAuf% z{UUC5ExhW|Vk##Scz1GeUf%26I|X$jVD6hbCYnD8!(k(cO!J#||KEHT{EvLrRK>!U{p}0>=fNa0m+PO0oYLq*H_!yu zzaoRiqR_LO{-4wSIssw<07wDsH#Xzf1-xlJ*hn&NrrSmzf-3OXkfPiWEO#V~TSf2R zt;wIW*lrF*|C3Q6{GAg3zyi<$9NIL0Yx!5q%FslXa0_BBA<^6lz`x7`{V(hDXZ|e` zWH!lNia*o!&**XAD75B*VAE3mdW)>*kp%u*sr@UB67{cv9KS2?pSh0cs~l`^KGUBO zImaV_eUp`pSMImCzw6tz5VK5~~=2)WCH!}zDI rqxnlzH_NZVvi~MZu8V>5m#F_4HC1tM|5`2Lo4X4K0EqszY=Hj)37^3t From 59a1149d4b39fbaae9ce65768b707771c0e1f1a2 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 21 Jun 2019 14:29:08 +0100 Subject: [PATCH 018/274] Tweak solver for stiff problems, adjust single precision parameters --- examples/robertson/robertson.cpp | 48 ++++++++++++++++++----------- set_MKL_env | 2 ++ src/jacobian.h | 9 ++++-- src/solver.cpp | 22 +++++++++----- src/solver.h | 9 +++--- src/solver_options.h | 24 +++++++++------ src/time_stepper.cpp | 52 ++++++++++++++++++++++++-------- 7 files changed, 111 insertions(+), 55 deletions(-) create mode 100644 set_MKL_env diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index 84b0dba..d97f2ab 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -193,7 +193,8 @@ int main() state_type x(3); // Initial conditions. - // We will use slightly inconsistent initial condition to test initialization. + // We will use slightly inconsistent initial condition to test + // initialization. x[0] = 1; x[1] = 0; x[2] = 1e-3; // Should be 0 theoretically @@ -210,32 +211,43 @@ int main() // parameters defined in solver_options.h SolverOptions opt; - //////////////////////////////////// Adjust this - opt.dt_init = 1.0e-6; // Change initial time step - opt.verbosity = 2; - opt.dt_max = t1 / 100; - opt.time_stepping = 1; - opt.dt_increase_threshold = 2; - // opt.bdf_order = 6; + opt.dt_init = 1.0e-6; // Change initial time step + opt.dt_max = t1 / 100; // Set maximum time step + opt.time_stepping = 1; // S-SATS works better here + opt.dt_increase_threshold = 2; // Time step amplification threshold + opt.atol = 1e-6; // Absolute tolerance + opt.bdf_order = 6; // Set BDF-6 // We can override Jacobian class from dae-cpp library and provide - // analytical Jacobian + // analytical Jacobian. We shall do this for single precision: +#ifdef DAE_SINGLE MyJacobian jac(rhs); - // jac.print(x, 0); // print it out for t = 0 - // Or use numerically estimated one with a given tolerance - // (commented out since we have analytical Jacobian above). - // Jacobian jac_est(rhs, 1e-10); // Obviously this tolerance is - // inacceptable in single precision - // jac_est.print(x, 0); // print Jacobian out for t = 0 + // Print it out for t = 0: + // jac.print(x, 0); +#endif + + // Or we can use numerically estimated Jacobian with the given tolerance. + // Let's use it as a test for double precision: +#ifndef DAE_SINGLE + Jacobian jac_est(rhs, 1e-10); // Obviously this tolerance is + // inacceptable for single precision + + // Print Jacobian out for t = 0: + // jac_est.print(x, 0); +#endif // Create an instance of the solver with particular RHS, Mass matrix, // Jacobian and solver options +#ifdef DAE_SINGLE MySolver solve(rhs, jac, mass, opt); +#else + MySolver solve(rhs, jac_est, mass, opt); +#endif // Now we are ready to solve the set of DAEs std::cout << "\nStarting DAE solver...\n"; - solve(x, t1); + int status = solve(x, t1); // Compare results with MATLAB ode15s solution const double x_ref[3] = {0.00051675, 2.068e-9, 0.99948324}; @@ -283,9 +295,9 @@ int main() #endif #ifdef DAE_SINGLE - const bool check_result = (result > 1.0 || conservation > 1e-6); + const bool check_result = (result > 1.0 || conservation > 1e-6 || status); #else - const bool check_result = (result > 1.0 || conservation > 1e-14); + const bool check_result = (result > 1.0 || conservation > 1e-14 || status); #endif if(check_result) diff --git a/set_MKL_env b/set_MKL_env new file mode 100644 index 0000000..9bad63e --- /dev/null +++ b/set_MKL_env @@ -0,0 +1,2 @@ +# Default Intel MKL library path +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/intel/mkl/lib/intel64/:/opt/intel/lib/intel64/ diff --git a/src/jacobian.h b/src/jacobian.h index b5e6171..d835eac 100644 --- a/src/jacobian.h +++ b/src/jacobian.h @@ -25,11 +25,14 @@ class Jacobian #endif public: - Jacobian(RHS &rhs) : m_rhs(rhs) {} - Jacobian(RHS &rhs, const double tol) : m_rhs(rhs), m_tol(tol) {} + explicit Jacobian(RHS &rhs) : m_rhs(rhs) {} + Jacobian(RHS &rhs, const double tol) : m_rhs(rhs), m_tol(tol) + { + // TODO: Check user's tol parameter. Too small tol may lead to crash. + } /* - * Can be overriden to provide analytical Jacobian. + * Can be overriden to provide analytical Jacobian */ virtual void operator()(sparse_matrix_holder &J, const state_type &x, const double t); diff --git a/src/solver.cpp b/src/solver.cpp index fb7d8b5..614cc80 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -47,14 +47,14 @@ int Solver::operator()(state_type &x, const double t1) m_iterator_state.dt[0] = m_opt.dt_init; m_iterator_state.dt[1] = m_iterator_state.dt[0]; - // Initialise the time integrator state structure. + // Initialize the time integrator state structure. // Solver starts the first time step using BDF-1 method // (since it doesn't have enough history yet) m_iterator_state.current_scheme = 1; m_iterator_state.step_counter_local = 0; m_iterator_state.final_time_step = false; - // Initialise time integrator + // Initialize time integrator TimeIntegrator ti(m_rhs, m_jac, m_mass, m_opt, m_size); // Initial output @@ -136,7 +136,8 @@ int Solver::operator()(state_type &x, const double t1) if(m_opt.fact_every_iter || iter == 0) { // Time Integrator with updated Jacobian - ti(J, b, x, x_prev, m_iterator_state.t, m_iterator_state.dt, true); + ti(J, b, x, x_prev, m_iterator_state.t, m_iterator_state.dt, + true); // Jacobian can change its size and can be re-allocated. // Catch up new array addresses. @@ -166,8 +167,8 @@ int Solver::operator()(state_type &x, const double t1) << (double)peak_mem1 / 1024.0 << " Mb"; std::cout << "\nPermanent memory on symbolic factorization: " - << " " - << (double)peak_mem2 / 1024.0 << " Mb"; + << " " << (double)peak_mem2 / 1024.0 + << " Mb"; std::cout << "\nPeak memory on numerical factorization " "and solution: " << (double)peak_mem3 / 1024.0 << " Mb" @@ -199,7 +200,8 @@ int Solver::operator()(state_type &x, const double t1) else { // Time Integrator with the previous Jacobian - ti(J, b, x, x_prev, m_iterator_state.t, m_iterator_state.dt, false); + ti(J, b, x, x_prev, m_iterator_state.t, m_iterator_state.dt, + false); } // PHASE 3. @@ -253,7 +255,8 @@ int Solver::operator()(state_type &x, const double t1) } // for iter - // Newton iterator failed to converge within max_Newton_iter iterations + // Newton iterator failed to converge within max_Newton_iter iterations. + // Trying to reduce the time step. if(iter == m_opt.max_Newton_iter) { if(m_opt.verbosity > 0) @@ -276,7 +279,7 @@ int Solver::operator()(state_type &x, const double t1) } // Adaptive time stepping algorithm - int status = adaptive_time_stepping(x, x_prev, iter); + int status = m_adaptive_time_stepping(x, x_prev, iter); if(status < 0) return 4; // The algorithm failed to converge else if(status > 0) @@ -305,6 +308,9 @@ int Solver::operator()(state_type &x, const double t1) } // while t + // Catch up the last time step + observer(x, m_iterator_state.t); + m_opt.t0 = m_iterator_state.t; m_opt.dt_init = m_iterator_state.dt[1]; diff --git a/src/solver.h b/src/solver.h index fba5dcd..69d96ed 100644 --- a/src/solver.h +++ b/src/solver.h @@ -23,7 +23,7 @@ class Solver SolverOptions &m_opt; // Solver options - struct iterator_state_struct // Keeps the current time layer state + struct m_iterator_state_struct // Keeps the current time layer state { double t; // current time double dt[2]; // current and previous time steps @@ -68,7 +68,8 @@ class Solver MKL_INT m_iparm[64]; // Simple yet efficient Adaptive Time Stepping - int adaptive_time_stepping(state_type &x, const state_type_matrix &x_prev, int iter); + int m_adaptive_time_stepping(state_type &x, const state_type_matrix &x_prev, + int iter); // Scrapes the current time iteration and decreases the time step // Return -1 in case the time step is below dt_min @@ -96,7 +97,7 @@ class Solver Solver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) : m_rhs(rhs), m_jac(jac), m_mass(mass), m_opt(opt) { - // Initialise the internal solver memory pointer. This is only + // Initialize the internal solver memory pointer. This is only // necessary for the FIRST call of the PARDISO solver. for(MKL_INT i = 0; i < 64; i++) { @@ -114,7 +115,7 @@ class Solver * result in the array x. Parameter t0 can be overriden in the solver * options (t0 = 0 by default). * The data stored in x (initial conditions) will be overwritten. - * Returns 0 in case of success or error code if integration failed. + * Returns 0 in case of success or error code if integration is failed. */ int operator()(state_type &x, const double t1); diff --git a/src/solver_options.h b/src/solver_options.h index bfec627..c496ef4 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -32,7 +32,7 @@ class SolverOptions // Time stepping algorithm: // 1 - Stability-based Simple Adaptive Time Stepping (S-SATS), - // 2 - Accuracy-based Simple Adaptive Time Stepping (A-SATS) from + // 2 - Variability-based Simple Adaptive Time Stepping (V-SATS) from // https://www.sciencedirect.com/science/article/pii/S0377042705005534 int time_stepping = 2; @@ -43,11 +43,11 @@ class SolverOptions #ifdef DAE_SINGLE double atol = 1.0e-3; // Absolute tolerance for the Newton algorithm - double dt_eps_m = 1.0e-5; // The order of the rounding unit (A-SATS only) + double dt_eps_m = 1.0e-6; // The order of the rounding unit double value_max = 1.0e20; // Solution shouldn't be higher than this #else double atol = 1.0e-6; // Absolute tolerance for the Newton algorithm - double dt_eps_m = 1.0e-10; // The order of the rounding unit (A-SATS only) + double dt_eps_m = 1.0e-12; // The order of the rounding unit double value_max = 1.0e100; // Solution shouldn't be higher than this #endif @@ -57,23 +57,29 @@ class SolverOptions // Initial integration time t0 -- will be equal to t1 after integration double t0 = 0.0; - // Minimum and maximum time steps + // Minimum time step double dt_min = dt_eps_m; - double dt_max = 100.0; + + // Maximum time step + double dt_max = 1.0 / dt_eps_m; // Verbosity level of the solver: // 0 - be silent, 1 - prints some basic information, 2 - chatterbox int verbosity = 1; // Simple Adaptive Time Stepping options - int dt_increase_threshold = 4; // Time step amplification threshold + int dt_increase_threshold = 3; // Time step amplification threshold // (S-SATS only) - int dt_decrease_threshold = 8; // Time step reduction threshold + int dt_decrease_threshold = 7; // Time step reduction threshold // (S-SATS only) double dt_increase_factor = 2.0; // Time step amplification factor double dt_decrease_factor = 2.0; // Time step reduction factor - double dt_eta_min = 0.05; // Monitor function lower threshold (A-SATS only) - double dt_eta_max = 0.5; // Monitor function higher threshold (A-SATS only) + double dt_eta_min = 0.05; // Monitor function lower threshold (V-SATS only) + double dt_eta_max = 0.5; // Monitor function higher threshold (V-SATS only) + + // 1 - V-SATS will use NORM_infinity to estimate solution variability, + // 2 - V-SATS will use NORM_2 (default) + int vsats_norm = 2; // Intel MKL PARDISO parameters (iparam). More about iparam: // https://software.intel.com/en-us/mkl-developer-reference-c-pardiso-iparm-parameter diff --git a/src/time_stepper.cpp b/src/time_stepper.cpp index ae030f3..1742421 100644 --- a/src/time_stepper.cpp +++ b/src/time_stepper.cpp @@ -1,6 +1,6 @@ /* -* Simple yet efficient Adaptive Time Stepping -*/ + * Simple yet efficient Adaptive Time Stepping algorithm + */ #include #include @@ -16,9 +16,10 @@ namespace daecpp_namespace_name * positive status if the time step should be restarted from the scratch, * or 0 in case of success. */ -int Solver::adaptive_time_stepping(state_type &x, const state_type_matrix &x_prev, int iter) +int Solver::m_adaptive_time_stepping(state_type &x, + const state_type_matrix &x_prev, int iter) { - if(m_opt.time_stepping == 1) // S-SATS + if(m_opt.time_stepping == 1) // S-SATS (Stability-based time stepping) { m_iterator_state.dt[1] = m_iterator_state.dt[0]; @@ -33,19 +34,41 @@ int Solver::adaptive_time_stepping(state_type &x, const state_type_matrix &x_pre return -1; // Method failed to converge } } - else if(m_opt.time_stepping == 2) // A-SATS + else if(m_opt.time_stepping == 2) // V-SATS (Variability-based) { double norm1 = 0.0; double norm2 = 0.0; // Estimate NORM(C(n+1) - C(n)) and NORM(C(n)) - for(MKL_INT i = 0; i < m_size; i++) + if(m_opt.vsats_norm == 2) // NORM_2 + { + for(MKL_INT i = 0; i < m_size; i++) + { + norm1 += (x[i] - x_prev[0][i]) * (x[i] - x_prev[0][i]); + norm2 += x_prev[0][i] * x_prev[0][i]; + } + + norm1 = std::sqrt(norm1); + norm2 = std::sqrt(norm2); + } + else // NORM_inf (experimental) { - norm1 += (x[i] - x_prev[0][i]) * (x[i] - x_prev[0][i]); - norm2 += x_prev[0][i] * x_prev[0][i]; + for(MKL_INT i = 0; i < m_size; i++) + { + double adiff1 = std::abs(x[i] - x_prev[0][i]); + double adiff2 = std::abs(x_prev[0][i]); + + if(adiff1 > norm1) + { + norm1 = adiff1; + + if(adiff2 < m_opt.dt_eps_m) + norm2 = 1; + else + norm2 = adiff2; + } + } } - norm1 = std::sqrt(norm1); - norm2 = std::sqrt(norm2); // Monitor function double eta = norm1 / (norm2 + m_opt.dt_eps_m); @@ -114,9 +137,12 @@ int Solver::m_reset_ti_scheme() void Solver::m_increase_dt() { m_iterator_state.dt[0] *= m_opt.dt_increase_factor; - m_iterator_state.current_scheme = m_reset_ti_scheme(); - if(!m_check_dt() && m_opt.verbosity > 0) - std::cout << '>'; + if(!m_check_dt()) + { + m_iterator_state.current_scheme = m_reset_ti_scheme(); + if(m_opt.verbosity > 0) + std::cout << '>'; + } } /* From cf7b1dde450eea3a44f42ad0eed4b9d3f50b99a8 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 21 Jun 2019 14:42:55 +0100 Subject: [PATCH 019/274] Add robertson example to CMakeLists and clang-tidy script --- CMakeLists.txt | 2 +- clang-tidy.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d21fcd0..f0cea0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ add_subdirectory(src) if(DAE_BUILD_EXAMPLES) - set(EXAMPLE_LIST "perovskite" "diffusion_2d") + set(EXAMPLE_LIST "perovskite" "diffusion_2d" "robertson") unset(LIB_MKL_INTEL_LP64 CACHE) diff --git a/clang-tidy.sh b/clang-tidy.sh index 4dcaac6..18f8599 100755 --- a/clang-tidy.sh +++ b/clang-tidy.sh @@ -2,3 +2,4 @@ clang-tidy src/*.cpp -- -I/opt/intel/mkl/include clang-tidy examples/perovskite/*.cpp -- -I/opt/intel/mkl/include clang-tidy examples/diffusion_2d/*.cpp -- -I/opt/intel/mkl/include +clang-tidy examples/robertson/*.cpp -- -I/opt/intel/mkl/include From df94e3dabebe64d7354864a3d3b36f87a5b3a6b6 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 21 Jun 2019 16:16:00 +0100 Subject: [PATCH 020/274] Added plotting to robertson example --- .vscode/c_cpp_properties.json | 3 +- .vscode/tasks.json | 10 +---- examples/robertson/robertson.cpp | 64 +++++++++++++++----------------- 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 2869520..199bbb5 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,8 @@ "name": "Linux", "includePath": [ "${workspaceFolder}/**", - "/opt/intel/mkl/include" + "/opt/intel/mkl/include", + "/usr/include/python3.6m" ], "defines": [], "compilerPath": "/usr/bin/gcc", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 788c393..b3697a2 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -20,7 +20,6 @@ "-I/opt/intel/mkl/include", "-I./src/external", //"-I/usr/include/python3.6m", - //"-I/usr/local/lib/python3.6/dist-packages/numpy/core/include", //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", @@ -53,7 +52,6 @@ "-I/opt/intel/mkl/include", "-I./src/external", //"-I/usr/include/python3.6m", - //"-I/usr/local/lib/python3.6/dist-packages/numpy/core/include", //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", @@ -85,9 +83,8 @@ "robertson.exe", "-I/opt/intel/mkl/include", "-I./src/external", - //"-I/usr/include/python3.6m", - //"-I/usr/local/lib/python3.6/dist-packages/numpy/core/include", - //"-lpython3.6m", + "-I/usr/include/python3.6m", + "-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -118,7 +115,6 @@ "-I/opt/intel/mkl/include", "-I./src/external", //"-I/usr/include/python3.6m", - //"-I/usr/local/lib/python3.6/dist-packages/numpy/core/include", //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-L/opt/intel/lib/intel64", @@ -152,7 +148,6 @@ "-I/opt/intel/mkl/include", "-I./src/external", //"-I/usr/include/python3.6m", - //"-I/usr/local/lib/python3.6/dist-packages/numpy/core/include", //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", @@ -185,7 +180,6 @@ "-I/opt/intel/mkl/include", "-I./src/external", //"-I/usr/include/python3.6m", - //"-I/usr/local/lib/python3.6/dist-packages/numpy/core/include", //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index d97f2ab..9a917a3 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -54,7 +54,7 @@ namespace plt = matplotlibcpp; class MyMassMatrix : public MassMatrix { public: - void operator()(daecpp::sparse_matrix_holder &M) + void operator()(sparse_matrix_holder &M) { M.A.resize(3); // Matrix size M.ja.resize(3); // Matrix size @@ -89,8 +89,7 @@ class MyRHS : public RHS * Receives current solution vector x and the current time t. Defines the * RHS f for each element in x. */ - void operator()(const daecpp::state_type &x, daecpp::state_type &f, - const double t) + void operator()(const state_type &x, state_type &f, const double t) { f[0] = -0.04 * x[0] + 1.0e4 * x[1] * x[2]; f[1] = 0.04 * x[0] - 1.0e4 * x[1] * x[2] - 3.0e7 * x[1] * x[1]; @@ -107,20 +106,31 @@ class MyRHS : public RHS class MySolver : public Solver { public: - MySolver(daecpp::RHS &rhs, daecpp::Jacobian &jac, daecpp::MassMatrix &mass, - daecpp::SolverOptions &opt) - : daecpp::Solver(rhs, jac, mass, opt) + MySolver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) + : Solver(rhs, jac, mass, opt) { } +#ifdef PLOTTING + state_type x_axis, x0, x1, x2; // For plotting +#endif + /* * Overloaded observer. * Receives current solution vector and the current time every time step. */ - void observer(daecpp::state_type &x, const double t) + void observer(state_type &x, const double t) { std::cout << " | " << x[0] << ' ' << 1e4 * x[1] << ' ' << x[2] << " == " << x[0] + x[1] + x[2] - 1.0; + +#ifdef PLOTTING + // Save data for plotting + x_axis.push_back(t); + x0.push_back(x[0]); + x1.push_back(1.0e4 * x[1]); + x2.push_back(x[2]); +#endif } }; @@ -134,14 +144,14 @@ class MySolver : public Solver class MyJacobian : public Jacobian { public: - MyJacobian(daecpp::RHS &rhs) : daecpp::Jacobian(rhs) {} + explicit MyJacobian(RHS &rhs) : Jacobian(rhs) {} /* * Receives current solution vector x and the current time t. Defines the * analytical Jacobian matrix J. */ - void operator()(daecpp::sparse_matrix_holder &J, - const daecpp::state_type &x, const double t) + void operator()(sparse_matrix_holder &J, const state_type &x, + const double t) { // Initialize Jacobian in sparse format J.A.resize(9); @@ -262,34 +272,20 @@ int main() std::cout << "Conservation law absolute deviation: " << conservation << '\n'; - // Plot the solution -- TODO: Update this! + // Plot the solution #ifdef PLOTTING - const double h = 1.0 / (double)N; - - dae::state_type_matrix x_axis, y_axis, z_axis; - - for(MKL_INT i = 0; i < N; i++) - { - dae::state_type x_row, y_row, z_row; - - for(MKL_INT j = 0; j < N; j++) - { - x_row.push_back((double)j * h + h * 0.5); - y_row.push_back((double)i * h + h * 0.5); - z_row.push_back(x[j + i * N]); - } - - x_axis.push_back(x_row); - y_axis.push_back(y_row); - z_axis.push_back(z_row); - } - plt::figure(); - plt::figure_size(800, 600); - plt::plot_surface(x_axis, y_axis, z_axis); + plt::figure_size(640, 480); + plt::named_semilogx("x0", solve.x_axis, solve.x0); + plt::named_semilogx("x1", solve.x_axis, solve.x1); + plt::named_semilogx("x2", solve.x_axis, solve.x2); + plt::xlabel("time"); + plt::title("Robertson DAE problem with a Conservation Law"); + plt::grid(true); + plt::legend(); // Save figure - const char *filename = "diffusion_2d.png"; + const char *filename = "robertson.png"; std::cout << "Saving result to " << filename << "...\n"; plt::save(filename); #endif From d3eff626901689372cb9a353773161b63ab06c48 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 21 Jun 2019 19:48:52 +0100 Subject: [PATCH 021/274] Added Robertson stiff DAE example to README.md --- README.md | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ecec683..7ab79ea 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ BDF time stepper reduces the original DAE system to a system of nonlinear equati - Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. On the other hand, this is optional. Default values should work fine in most cases. - A user can get access to the solution at each time step by overriding Observer function (this is optional). - The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. -- Easy-to-follow examples (see, for example, [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp)) to kick-start the user's project. +- Easy-to-follow examples (see, for example, [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp)) to kick-start the user's project. ## Installation @@ -68,6 +68,12 @@ On Linux make sure you have `git`, `cmake` and `g++` installed: sudo apt-get install g++ cmake cmake-curses-gui git ``` +In order to enable plotting (optional), `python3`, `matplotlib` and `numpy` should be installed: + +```bash +sudo apt-get install python3 python3-numpy python3-matplotlib +``` + Then download dae-cpp library: ```bash @@ -115,7 +121,7 @@ An example of default solution file for Microsoft Visual Studio 15 (2017) is giv ## How to use -Please refer to [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. +Please refer to [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. The main usage algorithm can be the following. Consider we have a system of DAEs written in a matrix-vector form, with some Mass matrix, RHS, and some initial conditions. @@ -147,7 +153,7 @@ We can get access to each element of the state vector **x** as to `std::vector` ### Step 2. Set up the RHS -Create MyRHS class that inherits the abstract `daecpp::RHS` class from dae-cpp library. The parent RHS class contains a pure virtual functor (operator `()`), that must be overridden in the child class. See, for example, [perovskite_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_RHS.cpp) or [diffusion_2d_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d_RHS.cpp). +Create MyRHS class that inherits the abstract `daecpp::RHS` class from dae-cpp library. The parent RHS class contains a pure virtual functor (operator `()`), that must be overridden in the child class. See, for example, [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_RHS.cpp) or [diffusion_2d_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d_RHS.cpp). Once the RHS class is overridden, we can create an instance of the child class with some user-defined parameter container *p*: @@ -159,7 +165,7 @@ In the child MyRHS class the user can also override `stop_condition` virtual fun ### Step 3. Set up the Mass matrix -Create MyMassMatrix class that inherits the abstract `daecpp::MassMatrix` class from dae-cpp library. Similar to the previous step, the parent MassMatrix class contains a pure virtual functor (operator `()`), that must be overridden in the child class. Refer to [perovskite_Mass.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Mass.cpp) as an example. Note that the matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format). +Create MyMassMatrix class that inherits the abstract `daecpp::MassMatrix` class from dae-cpp library. Similar to the previous step, the parent MassMatrix class contains a pure virtual functor (operator `()`), that must be overridden in the child class. Refer to [perovskite_Mass.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Mass.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) as an example. Note that the matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format). Create an instance of the child MyMassMatrix class with the given size *N*: @@ -175,7 +181,7 @@ dae::MassMatrixIdentity mass(N); ### Step 4. Set up Jacobian matrix -We can provide analytical Jacobian by overriding `daecpp::Jacobian` class from the dae-cpp library ([example](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Jacobian.cpp)) or just use numerically estimated one (this may significantly slow down the computation for large *N*). If provided, analytical Jacobian matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format) similar to the Mass matrix. +We can provide analytical Jacobian by overriding `daecpp::Jacobian` class from the dae-cpp library (see [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite_Jacobian.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Jacobian.cpp)) or just use numerically estimated one (this may significantly slow down the computation for large *N*). If provided, analytical Jacobian matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format) similar to the Mass matrix. If we don't provide analytical Jacobian we should estimate it with the given tolerance: @@ -226,7 +232,7 @@ solve(x, t1); // continues solving in the interval [t_c; t1] and Every call the solver will take the previous solution **x** (if available from the previous call) and overwrite it with a new one at the given time. -But a proper (and more efficient) way to get intermediate results is to override `virtual void observer(...)` function from `daecpp::Solver` class. This observer function receives the current solution vector **x** and the current time *t* every time step and allows a user to get access to the solution at each time layer. An example of a simple observer is given in the file [perovskite_observer.h](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_observer.h). +But a proper (and more efficient) way to get intermediate results is to override `virtual void observer(...)` function from `daecpp::Solver` class. This observer function receives the current solution vector **x** and the current time *t* every time step and allows a user to get access to the solution at each time layer. An example of a simple observer is given in the file [perovskite_observer.h](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_observer.h), also in [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp). ### Step 7 (optional). Plot results @@ -236,14 +242,20 @@ Solution can be visualised using a simple [C++ interface](https://github.com/lav

-Note that by default the plotting is switched off in the examples, but the plotting-related code can be activated using `#define PLOTTING` at the very beginning of each example. Activating the plotting refers to `matplotlibcpp.h` header located in `src/external/matplotlib-cpp/` directory. - The second example, [diffusion_2d](https://github.com/ikorotkin/dae-cpp/tree/master/examples/diffusion_2d), will produce a two-dimensional Gaussian function, a solution of two-dimensional diffusion problem with an instantaneous point source in the middle of the plane:

+The third example, [robertson](https://github.com/ikorotkin/dae-cpp/tree/master/examples/robertson), solves Robertson stiff DAE problem with a conservation law. It produces the following figure: + +

+ +

+ +Note that by default the plotting is switched off in the examples, but the plotting-related code can be activated using `#define PLOTTING` at the very beginning of each example. Activating the plotting refers to `matplotlibcpp.h` header located in `src/external/matplotlib-cpp/` directory. + ## Contribution and feedback Please feel free to contribute into the project! From 9dc6229460e336af120e8755007835322a5cb3cd Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 25 Jun 2019 16:05:13 +0100 Subject: [PATCH 022/274] Updated README.md, added pictures for each example --- .gitignore | 1 - README.md | 22 ++++++++++++---------- examples/diffusion_2d/diffusion_2d.png | Bin 0 -> 90553 bytes examples/perovskite/perovskite.png | Bin 0 -> 17709 bytes examples/robertson/robertson.png | Bin 0 -> 24997 bytes 5 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 examples/diffusion_2d/diffusion_2d.png create mode 100644 examples/perovskite/perovskite.png create mode 100644 examples/robertson/robertson.png diff --git a/.gitignore b/.gitignore index d4c8b6b..90db366 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.exe -*.png .vs/ .vscode/ipch/ Debug/ diff --git a/README.md b/README.md index 7ab79ea..416ea24 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A simple but powerful C++ solver for Differential Algebraic Equation (DAE) syste ## What is dae-cpp -A cross-platform, parallel C++ library for solving a user-defined system of DAEs (an initial value problem). The system may contain both differential and algebraic equations and can be written in the following matrix-vector form: +A cross-platform, parallel C++ library for solving user-defined, stiff systems of DAEs (an initial value problem). The system may contain both differential and algebraic equations and can be written in the following matrix-vector form:

@@ -20,17 +20,17 @@ For the numerical integration the solver uses implicit [BDF](https://en.wikipedi ### How does it work -BDF time stepper reduces the original DAE system to a system of nonlinear equations that the solver resolves using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorisation of Jacobian matrix, then numerical factorisation, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. +BDF time stepper reduces the original DAE system to a system of nonlinear equations that the solver resolves using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. ### The main features of the solver -- Can resolve DAE systems of 108 equations and even more (depending on the machine's RAM). +- Can resolve DAE systems of 108 equations and even more (depending on the Jacobian matrix sparsity and machine's RAM). - A user can provide analytical Jacobian matrix for better performance or use built-in parallel function provided by the solver to estimate numerical Jacobian. - Utilises all available cores on the machine for better performance (this can be overridden by a user). - Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. On the other hand, this is optional. Default values should work fine in most cases. - A user can get access to the solution at each time step by overriding Observer function (this is optional). - The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. -- Easy-to-follow examples (see, for example, [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp)) to kick-start the user's project. +- Easy-to-follow examples (see, for example, [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp)) to kick-start the user's project. ## Installation @@ -136,7 +136,7 @@ namespace dae = daecpp; ### Step 1. Define the DAE parameters and initial state vector -For example, for *N* equations we should define the state vector with the size *N* and initialise it in accordance with the initial conditions: +For example, for *N* equations we should define the state vector with the size *N* and initialize it in accordance with the initial conditions: ```cpp // State vector @@ -232,26 +232,28 @@ solve(x, t1); // continues solving in the interval [t_c; t1] and Every call the solver will take the previous solution **x** (if available from the previous call) and overwrite it with a new one at the given time. -But a proper (and more efficient) way to get intermediate results is to override `virtual void observer(...)` function from `daecpp::Solver` class. This observer function receives the current solution vector **x** and the current time *t* every time step and allows a user to get access to the solution at each time layer. An example of a simple observer is given in the file [perovskite_observer.h](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_observer.h), also in [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp). +But a proper (and more efficient) way to get intermediate results is to override `virtual void observer(...)` function from `daecpp::Solver` class. This observer function receives the current solution vector **x** and the current time *t* every time step and allows a user to get access to the solution at each time layer. An example of a simple observer is given in the file [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), also in [perovskite_observer.h](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_observer.h). ### Step 7 (optional). Plot results Solution can be visualised using a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module. For example, if `python`, `numpy` and `matplotlib` are installed, the [perovskite](https://github.com/ikorotkin/dae-cpp/tree/master/examples/perovskite) example will produce the following plot:

- +

+Here *P(x)* is the ion concentration in a perovskite solar cell, and *Phi(x)* is the corresponding potential distribution. + The second example, [diffusion_2d](https://github.com/ikorotkin/dae-cpp/tree/master/examples/diffusion_2d), will produce a two-dimensional Gaussian function, a solution of two-dimensional diffusion problem with an instantaneous point source in the middle of the plane:

- +

-The third example, [robertson](https://github.com/ikorotkin/dae-cpp/tree/master/examples/robertson), solves Robertson stiff DAE problem with a conservation law. It produces the following figure: +The third example, [robertson](https://github.com/ikorotkin/dae-cpp/tree/master/examples/robertson), solves [Robertson stiff DAE problem](https://www.mathworks.com/help/matlab/ref/ode15s.html) with a conservation law. It produces the following figure:

- +

Note that by default the plotting is switched off in the examples, but the plotting-related code can be activated using `#define PLOTTING` at the very beginning of each example. Activating the plotting refers to `matplotlibcpp.h` header located in `src/external/matplotlib-cpp/` directory. diff --git a/examples/diffusion_2d/diffusion_2d.png b/examples/diffusion_2d/diffusion_2d.png new file mode 100644 index 0000000000000000000000000000000000000000..8e37ec1a098733793edd0fdb33637d9e1ab0279f GIT binary patch literal 90553 zcmXVXbzGFq_ckHj-GX#UNh}=#3rk6NgOt+U9nwpebax6!cS$b7gVGJsDYftI_xJv> zpJkVOXXebDyv{W-A5_6On3R|Z2naZe3bGmq2#77f%K;q;_(o9T_!xLYbkhLKAkG-a$=&7j+%=s(x_gB5-riJ&7ONNnhuDF7SkzjYn zmGJ9p)s?ReqL_~oH-FwO{#q#PJkmYut?u0KS;w)JLZ+MzrshW&Mf~@-YY`#{_uqF( zL^ype|NCFAEkeS-XHa)!k)5f5cYZn+%HVCm>O<8O2=;&x?hnVqHU0v-EoCeI|htqeF2=2q( z*(7o@K*2FIH2k%)azANvU*SA%Dod&}@Sz7u?QHeCQ1B!oj=~ZGHJsckO0Mfo{$DI2 z66zBxD{FIeb6?+13#LgD4zz)DKnR3{p!0!?O21fV6?64*9P0RqnHe<*#6rLsgI*gu z0Tp=YImQ8ast+mF46B;__3OZs6@ic@9G^~Bl%>Cam(>#^14r@z zlm1I-)F$#bPPA*kIz-S*j}om%BUPLryP)9he5n$&ae|RLHa2#9Ym0F~NF!>KAA7$y zcjcdW>+b>a?sPvkRJ>Z{GU;Nas0J2YQc_aCdB8dhxsTqDm?jMp#*f51xKjd-G=TUu zgf?!En{cB8-^E2vF2bs2%MkPZ7jWGxYTmEVL$BeXq13dr!y2vBA>B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?m+9#&U_{&wLBMuddgggn0UeOfQ1k0EGipKE zW9z>WG)sV>{nwDDM2YKIU@#z?gV1<0UmW-HYSagC`5)hpH9wuF4mxb3gh>jkDKKZu zNy~Ta;0klBJmH13A_(0ELvUbq8=kL&uv15GZ{S=6W0@i>b+V0t1^)Xh zkf&>Fd$Wqpird70Z&laoBI#q=+iQX6M=KE48m!9YVD3G430&!&p8fq9QJIwFWQZ;u z;H-1=mKc=CiEiw8+`p&#XZ@X9N&dbeB#n*XD*lB0A4|Rf+J_Kpah4t)IZnD7Y%#P! zKF66hdW+CYCRjdrKqO%rC3)~|KQQHu60Ef$H5NzJ~3NQviJ1{gg5Z?kK zF1ovM9Xd4Nbmi?|fnExZtL_OYG%e_e2Xx#rJ-)yv@6{HRRqvw51Aq7KYN?bdJq`UA DHDx+f literal 0 HcmV?d00001 diff --git a/examples/perovskite/perovskite.png b/examples/perovskite/perovskite.png new file mode 100644 index 0000000000000000000000000000000000000000..cafaf65a07d49e22c3a44814de51902ab122ada0 GIT binary patch literal 17709 zcmbWf2UOGB6F(RpDk=yn(nR6el`4dYbfqdFAYED%B=p`piXhSz0TY@?@6tO_=_T|I zg7gm3ArRP`08jk=clVs#cg~B4kj(eqxpSv{<}H_1aju_BT;z>ijjf3qTPUh4U1R@&sSoEQyz1I9s z68j6C*c0ZD+21@mRd%fkeY;-lSp1`N=j6T#x00$(iN$I7oO~LWtRi}jUgg|-$m!cB zPkNt-dqf$xasK47A24&u^XEUzZMofA(am|o{`J+9Z0PoGl*95I^77&hvxx}qU}MCh z99WdY2^cYWJ^BCfwRRO292Mn?U7eN+W5ZEEAj`C@`MG0lKN_UIQcA<2tEYyDAdoF@ zYAvnTk^M{MM&( z#8i7iGg9U_gNRqEO6Kn7XyEGmnjoSq@3X!qv%K}Q;%|geYccQ;@C`ZWx4R;u-ePZ5Gr~ecLxY088uw;zZf-I&ygUDkCBqX% zOBU*=d?bzi`(9q?=NuKw#7aQ6rdb`U|`OM1X8}569nGpu*bv4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d*FOnVSDPJqxcCqT>q9JL=F(qIbq6R!;u#m6r-V4z{_6%`MiZ|vr# zeeuj5XzSY>i#6470&WTUW!@HI*(ADKIu0Z6ZsEsPwaOg9s2yl8Egd91ElA=J(TWiU|4QB_48e_I?J$ShidLjv#*th@v}fiqrK zy~De0)RFYvL)yAdTqO^vhhckbYw4R$gkROuy8SI9C9CyT@ z(@PdGxwpEp;kGp%R$w+HV`K!*08gTDZSskT7G-o{tj^?XVPX&KiM)0fa%lcBY+6OH;JwNTUtInVv5S+zj z*rC7qdzfF&5Rm7Wc$3Z_z%+5kPsq>_qn9_&~e?jRk?>8xU@P z&(iIM5;30(TVM#>-q?oQA2c4Aoi4S+O9Q^h^efM9g^|WyPRG?Lz~sb5o35uI99q_!<6-cHA@p8ew-zZm zxuC=H^?5MJ7>2r+2P@ezmCIXq}|TW4mF#`Bbpp9P-BnYNd-EW zU|5!f>S^-;M)&X!PY|N*r&?kF0RTVl3C^urK^a_dfc0Lvas@1$&vj=L^w5Ffh!1sK zlzm2(e%`v(Ok+bfk~f5bHghFG`ZnDtEdVS6r#tI8`V3^}hnF{CN>P6mBSVA57=Y*mO0baZvIVmGgy!9J>^ ztqB5dPVo0P;tQJK2%hXsA|a6H;z@K6NUg~K-&c2MDtdbL6vaE+;SWs)OMAiJQveOW z>a*V*<)Dx)6EF#?$O=k$sYj0rXERDpP%t#gLR101@)@$aID`f$KYQtKVL%#6$3^u* zlIYz33Hta^G0#w`I3a7t2|@fB0Xh8*jCg{TK)NR=fEEhfjkzI5zP>O{`&s{M@BF% literal 0 HcmV?d00001 diff --git a/examples/robertson/robertson.png b/examples/robertson/robertson.png new file mode 100644 index 0000000000000000000000000000000000000000..53584ecdb3299c3237161fb74e8ccdbc03a00842 GIT binary patch literal 24997 zcmc$`WmuG38#YWMjX@0pB7#aIB@H4al9EFT5;HJ>(kYFC2nJn4!@vLnGju8jAzd?+ zf#d*^((gUEw;SK*{q_C%et2+z_pJL`YhCM#^E}r))zwy`p#)J95D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o`hwOK5&ZWtR4eW1M2B{CS#KBOm zphvv4F8knP)#j#$y+yUfE3e+}ZjIgxcLU#eSNVUVd@B9Yn?NA&c?Se25LSRJLsE9& zNmNu+(Eb9iot<52rH!hZ8mpMZ;-#<0ZxR(_xl$@BR=_|&Uqh)`y$(QFo}c@C31uaR z>)}dX6QlKYbztcC)TNpwP(L4^ zwk8(`hyN_MewMhVVrKnC6QsYNO2*OB(pHu54JUPjB_wn@=x3u|f{Nj-o5fx3-&fD7BnqzlUS3e;sc1C{WO)Pz_3q{J7!ZkrutB!hDYabk-r|pazIDi!A=f1Rsg@sTk_3~(WSgUa^7bj=07v=BVJ0sV6 zCur}SfII|1Aig!uXZ2U8_0u6r-RA-DNamJ>gs5Yp z;x>90wMwI(ISB@SW3ahz!;$E*Fbsk!!QgQLssV1VJ}(9}!yn^PYGXBR%EL+1@bY%9ULga$LxN&DWM5-;zO{p z8d&AlmttPN6nn`~x|4S46KeWnemW{uc4^aJ z(#?FN@tJ~3o>$5-zOs@Cyb9z??z{DQ^uq@^Sy_5ciBEIkyoYN|M4U5ZOUK6AXPYn@ z^aDS0-tP-P9bNR$&>j0sWirD|Wp8L=qL(INw=v(T4!3yiqi<3Nh$jE7ei^sv*PLu@ zJ0DsPx4~^qR|*OQz{K}@P>}_UO`nWel}$VLS}XVY^MOkPSyN3&CXPS&6cn<2BbAwf z1&k{2%X#IY1JkGD9Vh%Ht_6S{R*k?+OuD^*L=Mgod};jzxo-eP`BZls@a(OOq11S& zRF0EBv8{65tg$_J6&n5UaCb>RJYNw|QH`EUZxTS{qFsrzRBfguz;-ERSAt4~{`Vh% zM8v Date: Tue, 25 Jun 2019 17:42:31 +0100 Subject: [PATCH 023/274] Update DOI to the latest version of the solver --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 416ea24..440c8b5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.com/ikorotkin/dae-cpp.svg?branch=master)](https://travis-ci.com/ikorotkin/dae-cpp) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/4aa33eb3a2834808a6cd1b81e0d8cc23)](https://www.codacy.com/app/ikorotkin/dae-cpp?utm_source=github.com&utm_medium=referral&utm_content=ikorotkin/dae-cpp&utm_campaign=Badge_Grade) -[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3241871.svg)](https://doi.org/10.5281/zenodo.3241871) +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3241870.svg)](https://doi.org/10.5281/zenodo.3241870) A simple but powerful C++ solver for Differential Algebraic Equation (DAE) systems. From 98e427f808b7a0df6e3acd0628187804f105f830 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 28 Jun 2019 15:37:07 +0100 Subject: [PATCH 024/274] Fixed possible bug in numerical Jacobian operator that could appear for some singular Jacobians --- src/jacobian.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jacobian.cpp b/src/jacobian.cpp index e6b0bfe..1062f32 100644 --- a/src/jacobian.cpp +++ b/src/jacobian.cpp @@ -95,7 +95,7 @@ void Jacobian::operator()(sparse_matrix_holder &J, const state_type &x, { double diff = f1[i] - f0[i]; - if(std::abs(diff) < m_eps) + if((std::abs(diff) < m_eps) && (i != j)) continue; #if JACOBIAN_SCHEME == 0 From b53c5d73973fc54bb73de5a7d2e61b8976641280 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 8 Jul 2019 15:47:39 +0100 Subject: [PATCH 025/274] Fixed Jacobian output, identity matrix, matrix addition. Other minor changes. --- .vscode/tasks.json | 10 ++-------- src/jacobian.cpp | 24 ++++++++++++++++++------ src/mass_matrix.cpp | 11 +++++++---- src/matrix_add.cpp | 33 ++++++++++++++++----------------- src/solver.cpp | 6 +++++- src/time_integrator.cpp | 17 +++++++++++------ 6 files changed, 59 insertions(+), 42 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b3697a2..5783670 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -83,8 +83,8 @@ "robertson.exe", "-I/opt/intel/mkl/include", "-I./src/external", - "-I/usr/include/python3.6m", - "-lpython3.6m", + //"-I/usr/include/python3.6m", + //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -114,8 +114,6 @@ "a_iomp.exe", "-I/opt/intel/mkl/include", "-I./src/external", - //"-I/usr/include/python3.6m", - //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-L/opt/intel/lib/intel64", "-Wl,--no-as-needed", @@ -147,8 +145,6 @@ "dbg.exe", "-I/opt/intel/mkl/include", "-I./src/external", - //"-I/usr/include/python3.6m", - //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -179,8 +175,6 @@ "dbg.exe", "-I/opt/intel/mkl/include", "-I./src/external", - //"-I/usr/include/python3.6m", - //"-lpython3.6m", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", diff --git a/src/jacobian.cpp b/src/jacobian.cpp index 1062f32..25ba9cb 100644 --- a/src/jacobian.cpp +++ b/src/jacobian.cpp @@ -198,18 +198,30 @@ void Jacobian::print(const state_type &x, const double t) << std::setw(10) << "J.ja |" << std::setw(8) << "J.ia"; std::cout << "\n-----------------------------------------\n"; - for(std::size_t i = 0; i < J.A.size(); i++) + size_t size = (J.A.size() > J.ia.size()) ? J.A.size() : J.ia.size(); + + for(std::size_t i = 0; i < size; i++) { - std::cout << std::setw(7) << i << ": " << std::setw(12) << J.A[i] - << " | "; + std::cout << std::setw(7) << i << ": "; + std::cout << std::setw(12); + + if(i < J.A.size()) + std::cout << J.A[i] ; + else + std::cout << ' '; + + std::cout << " | " << std::setw(7); if(i < J.ja.size()) - std::cout << std::setw(7) << J.ja[i] << " | "; + std::cout << J.ja[i]; else - std::cout << std::setw(7) << "???" - << " | "; // Error in Jacobian matrix structure + std::cout << ' '; + + std::cout << " | "; + if(i < J.ia.size()) std::cout << std::setw(7) << J.ia[i]; + std::cout << std::endl; } } diff --git a/src/mass_matrix.cpp b/src/mass_matrix.cpp index d85af84..d4b7eb0 100644 --- a/src/mass_matrix.cpp +++ b/src/mass_matrix.cpp @@ -9,14 +9,17 @@ namespace daecpp_namespace_name void MassMatrixIdentity::operator()(daecpp::sparse_matrix_holder &M) { + M.A.resize(m_N, 1); + M.ja.resize(m_N); + M.ia.resize(m_N + 1); + for(MKL_INT i = 0; i < m_N; i++) { - M.A.push_back(1.0); - M.ja.push_back(i); - M.ia.push_back(i); + M.ja[i] = i; + M.ia[i] = i; } - M.ia.push_back(m_N); + M.ia[m_N] = m_N; } } // namespace daecpp_namespace_name diff --git a/src/matrix_add.cpp b/src/matrix_add.cpp index bef3566..3512e81 100644 --- a/src/matrix_add.cpp +++ b/src/matrix_add.cpp @@ -26,7 +26,6 @@ void TimeIntegrator::m_matrix_add(const float_type alpha, MKL_INT jb = 0; MKL_INT a_row = 0; MKL_INT b_row = 0; - MKL_INT ic = 0; MKL_INT jc = 0; MKL_INT c_row = -1; @@ -38,12 +37,12 @@ void TimeIntegrator::m_matrix_add(const float_type alpha, // ib and jb point to the element before if(b_row < a_row || (b_row == a_row && B.ja[jb] < A.ja[ja])) { - C.A[jc] = B.A[jb]; - C.ja[jc] = B.ja[jb]; + C.A.push_back(B.A[jb]); + C.ja.push_back(B.ja[jb]); if(c_row < b_row) { - C.ia[ic++] = jc + FORTRAN_STYLE; + C.ia.push_back(jc + FORTRAN_STYLE); c_row++; } @@ -62,12 +61,12 @@ void TimeIntegrator::m_matrix_add(const float_type alpha, // ib and jb point to the same position as ia and ja if(b_row == a_row && B.ja[jb] == A.ja[ja]) { - C.A[jc] = alpha * A.A[ja] + B.A[jb]; - C.ja[jc] = A.ja[ja]; + C.A.push_back(alpha * A.A[ja] + B.A[jb]); + C.ja.push_back(A.ja[ja]); if(c_row < a_row) { - C.ia[ic++] = jc + FORTRAN_STYLE; + C.ia.push_back(jc + FORTRAN_STYLE); c_row++; } @@ -93,12 +92,12 @@ void TimeIntegrator::m_matrix_add(const float_type alpha, // ib and jb point to the element after if(b_row > a_row || (b_row == a_row && B.ja[jb] > A.ja[ja])) { - C.A[jc] = alpha * A.A[ja]; - C.ja[jc] = A.ja[ja]; + C.A.push_back(alpha * A.A[ja]); + C.ja.push_back(A.ja[ja]); if(c_row < a_row) { - C.ia[ic++] = jc + FORTRAN_STYLE; + C.ia.push_back(jc + FORTRAN_STYLE); c_row++; } @@ -117,12 +116,12 @@ void TimeIntegrator::m_matrix_add(const float_type alpha, while(ja < sizeA) { - C.A[jc] = alpha * A.A[ja]; - C.ja[jc] = A.ja[ja]; + C.A.push_back(alpha * A.A[ja]); + C.ja.push_back(A.ja[ja]); if(c_row < a_row) { - C.ia[ic++] = jc + FORTRAN_STYLE; + C.ia.push_back(jc + FORTRAN_STYLE); c_row++; } @@ -132,12 +131,12 @@ void TimeIntegrator::m_matrix_add(const float_type alpha, while(jb < sizeB) { - C.A[jc] = B.A[jb]; - C.ja[jc] = B.ja[jb]; + C.A.push_back(B.A[jb]); + C.ja.push_back(B.ja[jb]); if(c_row < b_row) { - C.ia[ic++] = jc + FORTRAN_STYLE; + C.ia.push_back(jc + FORTRAN_STYLE); c_row++; } @@ -145,7 +144,7 @@ void TimeIntegrator::m_matrix_add(const float_type alpha, jc++; } - C.ia[ic] = jc + FORTRAN_STYLE; + C.ia.push_back(jc + FORTRAN_STYLE); } } // namespace daecpp_namespace_name diff --git a/src/solver.cpp b/src/solver.cpp index 614cc80..2e91b06 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -27,8 +27,12 @@ int Solver::operator()(state_type &x, const double t1) // Check user-defined solver options m_opt.check_options(); + // We don't need to do anything if t1 == t0. Return initial conditions. + if(t1 == m_opt.t0) + return 0; + // Assert t1 > t0 - if(t1 <= m_opt.t0) + if(t1 < m_opt.t0) { std::cout << "ERROR: Integration time t1 = " << t1 << " cannot be less than the initial time t0 = " << m_opt.t0 diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index 57f2037..eaaa8fb 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -124,6 +124,7 @@ void TimeIntegrator::operator()(sparse_matrix_holder &J, state_type &b, if(do_jac) { + // Clear temporary Jacobian m_J.A.clear(); m_J.ia.clear(); m_J.ja.clear(); @@ -143,14 +144,18 @@ void TimeIntegrator::operator()(sparse_matrix_holder &J, state_type &b, exit(13); } + // Clear previous Jacobian matrix + J.A.clear(); + J.ia.clear(); + J.ja.clear(); + size_t nzmax = m_M.A.size() + m_J.A.size(); - if(J.A.size() != nzmax) - J.A.resize(nzmax); - if(J.ia.size() != (size_t)(size) + 1) - J.ia.resize(size + 1); - if(J.ja.size() != nzmax) - J.ja.resize(nzmax); + // If new size is greater than the current capacity, + // a reallocation happens + J.A.reserve(nzmax); + J.ia.reserve(size + 1); + J.ja.reserve(nzmax); // Replaces deprecated mkl_dcsradd() // J: = m_J - M*alpha From 437f0dbe0aa00dbccc5b3587a395e639ff333bf2 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 8 Jul 2019 21:16:38 +0100 Subject: [PATCH 026/274] Refactor the solver. Now the solver keeps solution history from the previous starts. --- src/solver.cpp | 137 +++++++++++++++++++++++++--------------- src/solver.h | 22 +++---- src/solver_options.h | 4 +- src/time_integrator.cpp | 18 +++--- src/time_integrator.h | 8 +-- 5 files changed, 110 insertions(+), 79 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 2e91b06..f894817 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -10,11 +10,44 @@ #include #include "solver.h" -#include "time_integrator.h" namespace daecpp_namespace_name { +/* + * The solver constructor + */ +Solver::Solver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) + : m_rhs(rhs), m_jac(jac), m_mass(mass), m_opt(opt) +{ + // Initialises the internal solver memory pointer. This is only + // necessary for the FIRST call of the PARDISO solver. + for(MKL_INT i = 0; i < 64; i++) + { + m_pt[i] = 0; + } + + // Initialises current integration time + m_iterator_state.t = opt.t0; + + // Sets initial time steps + m_iterator_state.dt[0] = opt.dt_init; + m_iterator_state.dt[1] = 0.0; + + // Solver starts the first time step using BDF-1 method + // (since it doesn't have enough history yet) + m_iterator_state.current_scheme = 1; + + // Initialises the time integrator + m_ti = new TimeIntegrator(rhs, jac, mass, opt); + + // Initialises solution history for the time integrator + m_x_prev.resize(opt.bdf_order); + + // Loads Intel MKL PARDISO iparm parameter from solver_options class + opt.set_iparm_for_pardiso(m_iparm); +} + /* * The main solver * ============================================================================= @@ -28,39 +61,28 @@ int Solver::operator()(state_type &x, const double t1) m_opt.check_options(); // We don't need to do anything if t1 == t0. Return initial conditions. - if(t1 == m_opt.t0) + if(t1 == m_iterator_state.t) return 0; // Assert t1 > t0 - if(t1 < m_opt.t0) + if(t1 < m_iterator_state.t) { std::cout << "ERROR: Integration time t1 = " << t1 - << " cannot be less than the initial time t0 = " << m_opt.t0 - << std::endl; + << " cannot be less than the initial time t0 = " + << m_iterator_state.t << std::endl; return 1; } - // Check the initial time step - m_opt.dt_init = - (m_opt.dt_init > (t1 - m_opt.t0)) ? (t1 - m_opt.t0) : m_opt.dt_init; - - // Initial time - m_iterator_state.t = m_opt.t0; - - // Initial time step - m_iterator_state.dt[0] = m_opt.dt_init; - m_iterator_state.dt[1] = m_iterator_state.dt[0]; + // Check initial time steps + m_iterator_state.dt[0] = + (m_iterator_state.dt[0] > (t1 - m_iterator_state.t)) + ? (t1 - m_iterator_state.t) + : m_iterator_state.dt[0]; // Initialize the time integrator state structure. - // Solver starts the first time step using BDF-1 method - // (since it doesn't have enough history yet) - m_iterator_state.current_scheme = 1; m_iterator_state.step_counter_local = 0; m_iterator_state.final_time_step = false; - // Initialize time integrator - TimeIntegrator ti(m_rhs, m_jac, m_mass, m_opt, m_size); - // Initial output if(m_opt.verbosity > 1) { @@ -72,8 +94,15 @@ int Solver::operator()(state_type &x, const double t1) << std::endl; } - // Contains a few latest successful time steps for Time Integrator - state_type_matrix x_prev(m_opt.bdf_order, state_type(m_size)); + // Reserve memory for the solution history. This will be done only once + if(m_x_prev[0].size() == 0) + { + for(int i = 0; i < m_opt.bdf_order; i++) + m_x_prev[i].resize(m_size); + } + + // Copy current state vector into the history vector + m_x_prev[0] = x; // Full Jacobian matrix holder sparse_matrix_holder J; @@ -84,16 +113,10 @@ int Solver::operator()(state_type &x, const double t1) // Solution vector used for Newton iterations state_type xk(m_size); - // Copy current state vector into the history vector - x_prev[0] = x; - // Reset PARDISO pointers m_mkl_b = b.data(); m_mkl_x = xk.data(); - // Load Intel MKL PARDISO iparm parameter from solver_options class - m_opt.set_iparm_for_pardiso(m_iparm); - // Memory control variables int peak_mem1 = 0, peak_mem2 = 0, peak_mem3 = 0; @@ -125,7 +148,7 @@ int Solver::operator()(state_type &x, const double t1) std::cout << "BDF-" << m_iterator_state.current_scheme << ": "; } - ti.set_scheme(m_iterator_state.current_scheme); + m_ti->set_scheme(m_iterator_state.current_scheme); if(m_iterator_state.current_scheme < m_opt.bdf_order) { @@ -140,8 +163,8 @@ int Solver::operator()(state_type &x, const double t1) if(m_opt.fact_every_iter || iter == 0) { // Time Integrator with updated Jacobian - ti(J, b, x, x_prev, m_iterator_state.t, m_iterator_state.dt, - true); + m_ti->integrate(J, b, x, m_x_prev, m_iterator_state.t, + m_iterator_state.dt, true); // Jacobian can change its size and can be re-allocated. // Catch up new array addresses. @@ -204,8 +227,8 @@ int Solver::operator()(state_type &x, const double t1) else { // Time Integrator with the previous Jacobian - ti(J, b, x, x_prev, m_iterator_state.t, m_iterator_state.dt, - false); + m_ti->integrate(J, b, x, m_x_prev, m_iterator_state.t, + m_iterator_state.dt, false); } // PHASE 3. @@ -233,8 +256,7 @@ int Solver::operator()(state_type &x, const double t1) if(adiff > m_opt.value_max || std::isnan(m_mkl_x[i])) { std::cout << "\nERROR: Newton iterations diverged. " - << "Review the tolerances and/or adaptive time " - "stepping.\n"; + << "Review the solver options.\n"; return 2; } @@ -265,25 +287,21 @@ int Solver::operator()(state_type &x, const double t1) { if(m_opt.verbosity > 0) std::cout << " <- redo"; - if(m_reset_ti_state(x, x_prev)) + if(m_reset_ti_state(x, m_x_prev)) return 3; // Newton method failed to converge continue; } // The solver has reached the target time t1 or the stop condition // triggered. - if(m_iterator_state.final_time_step) + if(m_iterator_state.final_time_step || + m_rhs.stop_condition(x, m_iterator_state.t)) { break; } - else if(m_rhs.stop_condition(x, m_iterator_state.t)) - { - m_iterator_state.dt[1] = m_iterator_state.dt[0]; - break; - } // Adaptive time stepping algorithm - int status = m_adaptive_time_stepping(x, x_prev, iter); + int status = m_adaptive_time_stepping(x, m_x_prev, iter); if(status < 0) return 4; // The algorithm failed to converge else if(status > 0) @@ -292,18 +310,28 @@ int Solver::operator()(state_type &x, const double t1) // Looks like the solver has reached the target time t1 if(m_iterator_state.t + m_iterator_state.dt[0] >= t1) { - m_iterator_state.final_time_step = true; // Adjust the last time step size - m_iterator_state.dt[1] = m_iterator_state.dt[0]; - m_iterator_state.dt[0] = t1 - m_iterator_state.t; + double dt_eval = t1 - m_iterator_state.t; + + if(dt_eval == 0.0) + { + break; // The solver has reached t1 + } + else + { + m_iterator_state.final_time_step = true; + + m_iterator_state.dt[1] = m_iterator_state.dt[0]; + m_iterator_state.dt[0] = dt_eval; + } } // Rewrite solution history for(int d = m_opt.bdf_order - 1; d > 0; d--) { - x_prev[d] = x_prev[d - 1]; + m_x_prev[d] = m_x_prev[d - 1]; } - x_prev[0] = x; + m_x_prev[0] = x; // Call Observer to provide a user with intermediate results observer(x, m_iterator_state.t); @@ -312,11 +340,18 @@ int Solver::operator()(state_type &x, const double t1) } // while t + // Rewrite solution history + for(int d = m_opt.bdf_order - 1; d > 0; d--) + { + m_x_prev[d] = m_x_prev[d - 1]; + } + m_x_prev[0] = x; + // Catch up the last time step observer(x, m_iterator_state.t); - m_opt.t0 = m_iterator_state.t; - m_opt.dt_init = m_iterator_state.dt[1]; + // Copy the previous time step size + m_iterator_state.dt[1] = m_iterator_state.dt[0]; if(m_opt.verbosity > 0) std::cout << "\nLinear algebra solver calls: " << m_calls << '\n'; diff --git a/src/solver.h b/src/solver.h index 69d96ed..3a07014 100644 --- a/src/solver.h +++ b/src/solver.h @@ -9,6 +9,7 @@ #include "jacobian.h" #include "mass_matrix.h" #include "solver_options.h" +#include "time_integrator.h" namespace daecpp_namespace_name { @@ -23,6 +24,8 @@ class Solver SolverOptions &m_opt; // Solver options + TimeIntegrator *m_ti; // Pointer to the time integrator + struct m_iterator_state_struct // Keeps the current time layer state { double t; // current time @@ -37,6 +40,9 @@ class Solver size_t m_steps = 0; // Total time iteration counter size_t m_calls = 0; // Total linear algebra solver calls counter + // Contains a few latest successful time steps for the time integrator + state_type_matrix m_x_prev; + // Intel MKL PARDISO control parameters MKL_INT m_phase; // Current phase of the solver MKL_INT m_maxfct = 1; // Maximum number of numerical factorizations @@ -92,18 +98,10 @@ class Solver public: /* - * Receives user-defined RHS, Jacobian, Mass matrix and solver options + * Receives user-defined RHS, Jacobian, Mass matrix and solver options. + * Defined in solver.cpp */ - Solver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) - : m_rhs(rhs), m_jac(jac), m_mass(mass), m_opt(opt) - { - // Initialize the internal solver memory pointer. This is only - // necessary for the FIRST call of the PARDISO solver. - for(MKL_INT i = 0; i < 64; i++) - { - m_pt[i] = 0; - } - } + Solver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt); /* * Releases memory. Defined in solver.cpp. @@ -127,7 +125,7 @@ class Solver */ virtual void observer(state_type &x, const double t) { - return; // It does nothing by deafult + return; // It does nothing by default } }; diff --git a/src/solver_options.h b/src/solver_options.h index c496ef4..4c8e612 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -51,10 +51,10 @@ class SolverOptions double value_max = 1.0e100; // Solution shouldn't be higher than this #endif - // Initial time step -- will store actual last time step after integration + // Initial time step double dt_init = 0.1; - // Initial integration time t0 -- will be equal to t1 after integration + // Initial integration time t0 double t0 = 0.0; // Minimum time step diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index eaaa8fb..83d47e7 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -10,17 +10,15 @@ namespace daecpp_namespace_name { TimeIntegrator::TimeIntegrator(RHS &rhs, Jacobian &jac, MassMatrix &mass, - SolverOptions &opt, const MKL_INT size) + SolverOptions &opt) : m_rhs(rhs), m_jac(jac), m_mass(mass), m_opt(opt) { - // Reserve memory for at least 1-diagonal mass matrix - m_M.A.reserve(size); - m_M.ja.reserve(size); - m_M.ia.reserve(size + 1); - // Get static mass matrix m_mass(m_M); + // Extract the mass matrix size + const MKL_INT size = m_M.ia.size() - 1; + // User defined sparse matrix check if(m_matrix_checker(m_M, size)) { @@ -68,10 +66,10 @@ TimeIntegrator::TimeIntegrator(RHS &rhs, Jacobian &jac, MassMatrix &mass, } } -void TimeIntegrator::operator()(sparse_matrix_holder &J, state_type &b, - const state_type &x, const state_type_matrix &x_prev, - const double t, const double dt[], - const bool do_jac) +void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, + const state_type &x, + const state_type_matrix &x_prev, const double t, + const double dt[], const bool do_jac) { const MKL_INT size = (MKL_INT)(x.size()); diff --git a/src/time_integrator.h b/src/time_integrator.h index 2b77bfa..a196e7d 100644 --- a/src/time_integrator.h +++ b/src/time_integrator.h @@ -67,15 +67,15 @@ class TimeIntegrator public: TimeIntegrator(RHS &rhs, Jacobian &jac, MassMatrix &mass, - SolverOptions &opt, const MKL_INT size); + SolverOptions &opt); ~TimeIntegrator() { mkl_sparse_destroy(m_csrA); } void set_scheme(int scheme) { m_scheme = scheme; } - void operator()(sparse_matrix_holder &J, state_type &b, const state_type &x, - const state_type_matrix &x_prev, const double t, - const double dt[], const bool do_jac); + void integrate(sparse_matrix_holder &J, state_type &b, const state_type &x, + const state_type_matrix &x_prev, const double t, + const double dt[], const bool do_jac); }; } // namespace daecpp_namespace_name From e563103e2c063189462412c758624f0d95b675c0 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 8 Jul 2019 22:20:17 +0100 Subject: [PATCH 027/274] Fix debug output and the time step after the solver restart --- src/solver.cpp | 4 ++++ src/time_stepper.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/solver.cpp b/src/solver.cpp index f894817..5c7a5cc 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -146,6 +146,8 @@ int Solver::operator()(state_type &x, const double t1) if(m_opt.verbosity > 1) { std::cout << "BDF-" << m_iterator_state.current_scheme << ": "; + std::cout << "dt=" << m_iterator_state.dt[0] + << ", dt_prev=" << m_iterator_state.dt[1] << ": "; } m_ti->set_scheme(m_iterator_state.current_scheme); @@ -315,6 +317,8 @@ int Solver::operator()(state_type &x, const double t1) if(dt_eval == 0.0) { + // dt[0] could be changed, restore + m_iterator_state.dt[0] = m_iterator_state.dt[1]; break; // The solver has reached t1 } else diff --git a/src/time_stepper.cpp b/src/time_stepper.cpp index 1742421..1a9cd1f 100644 --- a/src/time_stepper.cpp +++ b/src/time_stepper.cpp @@ -74,7 +74,7 @@ int Solver::m_adaptive_time_stepping(state_type &x, double eta = norm1 / (norm2 + m_opt.dt_eps_m); if(m_opt.verbosity > 1) - std::cout << "(eta = " << eta << ")"; + std::cout << " (eta = " << eta << ")"; // The time step should be reduced, scrape the current time iteration if(eta > m_opt.dt_eta_max) From 7d05dbeda6cd7c262b9190d454dfcb971e5c0f1b Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 9 Jul 2019 10:36:45 +0100 Subject: [PATCH 028/274] Added clock, fixed solver destructor, solver options re-use in perovskite example --- examples/perovskite/perovskite.cpp | 14 ++++---------- src/solver.cpp | 22 ++++++++++++++++++++-- src/solver.h | 3 ++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/perovskite/perovskite.cpp b/examples/perovskite/perovskite.cpp index 19a10ba..05ac8b5 100644 --- a/examples/perovskite/perovskite.cpp +++ b/examples/perovskite/perovskite.cpp @@ -120,7 +120,7 @@ int main() // MySolver solve_observer(rhs, jac, mass, opt); // Solver status - int status = 0; + int status = -1; // Now we are ready to solve the set of DAEs std::cout << "\nStarting DAE solver...\n"; @@ -162,19 +162,13 @@ int main() // with a given tolerance: dae::Jacobian jac_est(rhs, opt.atol); - // Create a new instance of the solver for estimated Jacobian - dae::Solver solve_slow(rhs, jac_est, mass, opt); - + // Create a new instance of the solver for estimated Jacobian. // We have re-used RHS, Mass matrix and the solver options from // the previous solution. - // Parameters t0 (initial time) and dt_init (initial time step) were - // updated by the solver, so we could continue simulation but we want - // to start from the scratch: - opt.t0 = 0.0; // Initial integration time - opt.dt_init = 0.1; // Initial time step + dae::Solver solve_slow(rhs, jac_est, mass, opt); // Solver status - int status_slow; + int status_slow = -1; // Solve the set of DAEs again std::cout << "\nStarting DAE solver with estimated Jacobian...\n"; diff --git a/src/solver.cpp b/src/solver.cpp index 5c7a5cc..dd57418 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -120,12 +121,17 @@ int Solver::operator()(state_type &x, const double t1) // Memory control variables int peak_mem1 = 0, peak_mem2 = 0, peak_mem3 = 0; + // Initialise clock + using clock = std::chrono::high_resolution_clock; + using time_unit = std::chrono::milliseconds; + /* * Start the solver * ========================================================================= */ - // TODO: Start timer here + // Timer starts here + auto tic0 = clock::now(); m_iterator_state.t += m_iterator_state.dt[0]; @@ -315,7 +321,7 @@ int Solver::operator()(state_type &x, const double t1) // Adjust the last time step size double dt_eval = t1 - m_iterator_state.t; - if(dt_eval == 0.0) + if(std::abs(dt_eval) < m_opt.dt_eps_m) { // dt[0] could be changed, restore m_iterator_state.dt[0] = m_iterator_state.dt[1]; @@ -344,6 +350,9 @@ int Solver::operator()(state_type &x, const double t1) } // while t + // Stop timer + auto tic1 = clock::now(); + // Rewrite solution history for(int d = m_opt.bdf_order - 1; d > 0; d--) { @@ -358,7 +367,14 @@ int Solver::operator()(state_type &x, const double t1) m_iterator_state.dt[1] = m_iterator_state.dt[0]; if(m_opt.verbosity > 0) + { std::cout << "\nLinear algebra solver calls: " << m_calls << '\n'; + std::cout + << "Time spent by the solver: " + << std::chrono::duration_cast(tic1 - tic0).count() / + 1000.0 + << " sec." << '\n'; + } // Success return 0; @@ -373,6 +389,8 @@ Solver::~Solver() PARDISO(m_pt, &m_maxfct, &m_mnum, &m_mtype, &m_phase, &m_size, &m_ddum, m_ia, m_ja, &m_idum, &m_nrhs, m_iparm, &m_msglvl, &m_ddum, &m_ddum, &m_error); + + delete m_ti; } /* diff --git a/src/solver.h b/src/solver.h index 3a07014..b9d18a9 100644 --- a/src/solver.h +++ b/src/solver.h @@ -30,6 +30,7 @@ class Solver { double t; // current time double dt[2]; // current and previous time steps + double dt_eval; // new time step int current_scheme; // current BDF order int step_counter_local; // local time step counter bool final_time_step; // do final time step @@ -106,7 +107,7 @@ class Solver /* * Releases memory. Defined in solver.cpp. */ - ~Solver(); + virtual ~Solver(); /* * Integrates the system of DAEs on the interval t = [t0; t1] and returns From 00e80916970ba180f0a269f9bef8f47fc8f17194 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 9 Jul 2019 11:18:15 +0100 Subject: [PATCH 029/274] Refactored time stepper to proper keep solution history from the previous solver calls --- clang-tidy.sh | 8 ++++---- examples/robertson/robertson.cpp | 1 - src/solver.cpp | 27 +++++++++++++-------------- src/solver_options.h | 4 ++-- src/time_stepper.cpp | 23 ++++++++++++----------- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/clang-tidy.sh b/clang-tidy.sh index 18f8599..6f86468 100755 --- a/clang-tidy.sh +++ b/clang-tidy.sh @@ -1,5 +1,5 @@ #!/bin/bash -clang-tidy src/*.cpp -- -I/opt/intel/mkl/include -clang-tidy examples/perovskite/*.cpp -- -I/opt/intel/mkl/include -clang-tidy examples/diffusion_2d/*.cpp -- -I/opt/intel/mkl/include -clang-tidy examples/robertson/*.cpp -- -I/opt/intel/mkl/include +clang-tidy-6.0 src/*.cpp -- -I/opt/intel/mkl/include +clang-tidy-6.0 examples/perovskite/*.cpp -- -I/opt/intel/mkl/include +clang-tidy-6.0 examples/diffusion_2d/*.cpp -- -I/opt/intel/mkl/include +clang-tidy-6.0 examples/robertson/*.cpp -- -I/opt/intel/mkl/include diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index 9a917a3..241002a 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -224,7 +224,6 @@ int main() opt.dt_init = 1.0e-6; // Change initial time step opt.dt_max = t1 / 100; // Set maximum time step opt.time_stepping = 1; // S-SATS works better here - opt.dt_increase_threshold = 2; // Time step amplification threshold opt.atol = 1e-6; // Absolute tolerance opt.bdf_order = 6; // Set BDF-6 diff --git a/src/solver.cpp b/src/solver.cpp index dd57418..2458128 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -75,10 +75,11 @@ int Solver::operator()(state_type &x, const double t1) } // Check initial time steps - m_iterator_state.dt[0] = + m_iterator_state.dt_eval = (m_iterator_state.dt[0] > (t1 - m_iterator_state.t)) ? (t1 - m_iterator_state.t) : m_iterator_state.dt[0]; + m_iterator_state.dt[0] = m_iterator_state.dt_eval; // Initialize the time integrator state structure. m_iterator_state.step_counter_local = 0; @@ -133,10 +134,10 @@ int Solver::operator()(state_type &x, const double t1) // Timer starts here auto tic0 = clock::now(); - m_iterator_state.t += m_iterator_state.dt[0]; - while(m_iterator_state.t < (t1 + m_iterator_state.dt[0] * 0.5)) { + m_iterator_state.t += m_iterator_state.dt[0]; // Time step lapse + m_iterator_state.step_counter_local++; m_steps++; @@ -316,23 +317,19 @@ int Solver::operator()(state_type &x, const double t1) continue; // Re-run the current time step // Looks like the solver has reached the target time t1 - if(m_iterator_state.t + m_iterator_state.dt[0] >= t1) + if(m_iterator_state.t + m_iterator_state.dt_eval >= t1) { // Adjust the last time step size - double dt_eval = t1 - m_iterator_state.t; + double dt_max = t1 - m_iterator_state.t; - if(std::abs(dt_eval) < m_opt.dt_eps_m) + if(std::abs(dt_max) < m_opt.dt_eps_m) { - // dt[0] could be changed, restore - m_iterator_state.dt[0] = m_iterator_state.dt[1]; break; // The solver has reached t1 } else { m_iterator_state.final_time_step = true; - - m_iterator_state.dt[1] = m_iterator_state.dt[0]; - m_iterator_state.dt[0] = dt_eval; + m_iterator_state.dt_eval = dt_max; } } @@ -343,17 +340,19 @@ int Solver::operator()(state_type &x, const double t1) } m_x_prev[0] = x; + // Update time step history + m_iterator_state.dt[1] = m_iterator_state.dt[0]; + m_iterator_state.dt[0] = m_iterator_state.dt_eval; + // Call Observer to provide a user with intermediate results observer(x, m_iterator_state.t); - m_iterator_state.t += m_iterator_state.dt[0]; // Time step lapse - } // while t // Stop timer auto tic1 = clock::now(); - // Rewrite solution history + // Update solution history for(int d = m_opt.bdf_order - 1; d > 0; d--) { m_x_prev[d] = m_x_prev[d - 1]; diff --git a/src/solver_options.h b/src/solver_options.h index 4c8e612..59b0a2d 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -47,7 +47,7 @@ class SolverOptions double value_max = 1.0e20; // Solution shouldn't be higher than this #else double atol = 1.0e-6; // Absolute tolerance for the Newton algorithm - double dt_eps_m = 1.0e-12; // The order of the rounding unit + double dt_eps_m = 1.0e-14; // The order of the rounding unit double value_max = 1.0e100; // Solution shouldn't be higher than this #endif @@ -68,7 +68,7 @@ class SolverOptions int verbosity = 1; // Simple Adaptive Time Stepping options - int dt_increase_threshold = 3; // Time step amplification threshold + int dt_increase_threshold = 2; // Time step amplification threshold // (S-SATS only) int dt_decrease_threshold = 7; // Time step reduction threshold // (S-SATS only) diff --git a/src/time_stepper.cpp b/src/time_stepper.cpp index 1a9cd1f..adc6b19 100644 --- a/src/time_stepper.cpp +++ b/src/time_stepper.cpp @@ -21,8 +21,6 @@ int Solver::m_adaptive_time_stepping(state_type &x, { if(m_opt.time_stepping == 1) // S-SATS (Stability-based time stepping) { - m_iterator_state.dt[1] = m_iterator_state.dt[0]; - if(iter < m_opt.dt_increase_threshold) { m_increase_dt(); @@ -86,8 +84,6 @@ int Solver::m_adaptive_time_stepping(state_type &x, return 2; // Re-run the current iteration } - m_iterator_state.dt[1] = m_iterator_state.dt[0]; - // The time step can be increased if(eta < m_opt.dt_eta_min) { @@ -113,7 +109,6 @@ int Solver::m_reset_ti_state(state_type &x, const state_type_matrix &x_prev) m_iterator_state.final_time_step = false; m_iterator_state.dt[0] /= m_opt.dt_decrease_factor; m_iterator_state.current_scheme = m_reset_ti_scheme(); - m_iterator_state.t += m_iterator_state.dt[0]; x = x_prev[0]; @@ -136,10 +131,13 @@ int Solver::m_reset_ti_scheme() */ void Solver::m_increase_dt() { - m_iterator_state.dt[0] *= m_opt.dt_increase_factor; + m_iterator_state.dt_eval = + m_iterator_state.dt[0] * m_opt.dt_increase_factor; + if(!m_check_dt()) { m_iterator_state.current_scheme = m_reset_ti_scheme(); + if(m_opt.verbosity > 0) std::cout << '>'; } @@ -150,8 +148,11 @@ void Solver::m_increase_dt() */ void Solver::m_decrease_dt() { - m_iterator_state.dt[0] /= m_opt.dt_decrease_factor; + m_iterator_state.dt_eval = + m_iterator_state.dt[0] / m_opt.dt_decrease_factor; + m_iterator_state.current_scheme = m_reset_ti_scheme(); + if(!m_check_dt() && m_opt.verbosity > 0) std::cout << '<'; } @@ -161,16 +162,16 @@ void Solver::m_decrease_dt() */ int Solver::m_check_dt() { - if(m_iterator_state.dt[0] < m_opt.dt_min) + if(m_iterator_state.dt_eval < m_opt.dt_min) { std::cout << "\nERROR: The time step was reduced to " - << m_iterator_state.dt[0] + << m_iterator_state.dt_eval << " but the scheme failed to converge\n"; return -1; } - else if(m_iterator_state.dt[0] > m_opt.dt_max) + else if(m_iterator_state.dt_eval > m_opt.dt_max) { - m_iterator_state.dt[0] = m_opt.dt_max; + m_iterator_state.dt_eval = m_opt.dt_max; return 1; } else From bbfddbde56bee460b5d800f36c5b755c1000c3bc Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 16 Jul 2019 15:10:06 +0100 Subject: [PATCH 030/274] Fixed bug when the time stepper could not roll back to the previous time step properly in some cases --- src/time_stepper.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/time_stepper.cpp b/src/time_stepper.cpp index adc6b19..29c73ef 100644 --- a/src/time_stepper.cpp +++ b/src/time_stepper.cpp @@ -19,6 +19,8 @@ namespace daecpp_namespace_name int Solver::m_adaptive_time_stepping(state_type &x, const state_type_matrix &x_prev, int iter) { + m_iterator_state.dt_eval = m_iterator_state.dt[0]; + if(m_opt.time_stepping == 1) // S-SATS (Stability-based time stepping) { if(iter < m_opt.dt_increase_threshold) @@ -108,6 +110,7 @@ int Solver::m_reset_ti_state(state_type &x, const state_type_matrix &x_prev) m_steps--; m_iterator_state.final_time_step = false; m_iterator_state.dt[0] /= m_opt.dt_decrease_factor; + m_iterator_state.dt_eval = m_iterator_state.dt[0]; m_iterator_state.current_scheme = m_reset_ti_scheme(); x = x_prev[0]; From bb14d47bd4736b87043426fc057a137347f4d54f Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 16 Jul 2019 20:41:13 +0100 Subject: [PATCH 031/274] Add Jacobian and linear algebra solver time outputs --- src/solver.cpp | 36 +++++++++++++++++++++++++++++++----- src/time_integrator.cpp | 11 +++++++++++ src/time_integrator.h | 7 +++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 2458128..3c3125f 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -122,6 +122,12 @@ int Solver::operator()(state_type &x, const double t1) // Memory control variables int peak_mem1 = 0, peak_mem2 = 0, peak_mem3 = 0; + // Reset Jacobian timer + m_ti->reset_jac_time(); + + // Reset linear algebra solver timer + double lin_alg_time = 0.0; + // Initialise clock using clock = std::chrono::high_resolution_clock; using time_unit = std::chrono::milliseconds; @@ -181,6 +187,8 @@ int Solver::operator()(state_type &x, const double t1) m_ia = J.ia.data(); m_ja = J.ja.data(); + auto tic_phase1 = clock::now(); + // PHASE 1. // Reordering and Symbolic Factorization. This step also // allocates all memory that is necessary for the factorization @@ -232,6 +240,11 @@ int Solver::operator()(state_type &x, const double t1) m_check_pardiso_error(m_error); return 22; } + + lin_alg_time += std::chrono::duration_cast( + clock::now() - tic_phase1) + .count() / + 1000.0; } else { @@ -240,6 +253,8 @@ int Solver::operator()(state_type &x, const double t1) m_iterator_state.dt, false); } + auto tic_phase3 = clock::now(); + // PHASE 3. // Back substitution and iterative refinement m_phase = 33; @@ -254,6 +269,11 @@ int Solver::operator()(state_type &x, const double t1) return 33; } + lin_alg_time += + std::chrono::duration_cast(clock::now() - tic_phase3) + .count() / + 1000.0; + m_calls++; double tol = 0.0; @@ -367,12 +387,18 @@ int Solver::operator()(state_type &x, const double t1) if(m_opt.verbosity > 0) { + double solver_time = + std::chrono::duration_cast(tic1 - tic0).count() / 1000.0; + double jac_time = m_ti->get_jac_time(); + double jac_time_rel = jac_time / solver_time * 100.0; + double lin_alg_time_rel = lin_alg_time / solver_time * 100.0; std::cout << "\nLinear algebra solver calls: " << m_calls << '\n'; - std::cout - << "Time spent by the solver: " - << std::chrono::duration_cast(tic1 - tic0).count() / - 1000.0 - << " sec." << '\n'; + std::cout << "Time spent by linear algebra solver: " << lin_alg_time + << " sec. (" << lin_alg_time_rel << "%)" << '\n'; + std::cout << "Time spent to calculate Jacobian: " << jac_time + << " sec. (" << jac_time_rel << "%)" << '\n'; + std::cout << "Total time spent by the solver: " << solver_time + << " sec. (100.0%)" << '\n'; } // Success diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index 83d47e7..a0dcf26 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -3,6 +3,7 @@ */ #include +#include #include "time_integrator.h" @@ -122,6 +123,10 @@ void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, if(do_jac) { + // Initialise clock + using clock = std::chrono::high_resolution_clock; + using time_unit = std::chrono::milliseconds; + // Clear temporary Jacobian m_J.A.clear(); m_J.ia.clear(); @@ -133,7 +138,13 @@ void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, m_J.ja.reserve(3 * size); // Calculate Jacobian + auto tic0 = clock::now(); m_jac(m_J, x, t); + auto tic1 = clock::now(); + + // Update Jacobian timer + m_jac_time += + std::chrono::duration_cast(tic1 - tic0).count() / 1000.0; // Sparse matrix check if(m_matrix_checker(m_J, size)) diff --git a/src/time_integrator.h b/src/time_integrator.h index a196e7d..161f9c1 100644 --- a/src/time_integrator.h +++ b/src/time_integrator.h @@ -41,6 +41,9 @@ class TimeIntegrator // The first time step will be performed using BDF-1 int m_scheme = 1; + // Total time spent to estimate Jacobian, sec. + double m_jac_time = 0.0; + // Temporary Jacobian matrix holder sparse_matrix_holder m_J; @@ -73,6 +76,10 @@ class TimeIntegrator void set_scheme(int scheme) { m_scheme = scheme; } + void reset_jac_time() { m_jac_time = 0.0; } + + double get_jac_time() { return m_jac_time; } + void integrate(sparse_matrix_holder &J, state_type &b, const state_type &x, const state_type_matrix &x_prev, const double t, const double dt[], const bool do_jac); From dd618f1871a76e1178bc6b0e25ed19258db1194b Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 17 Jul 2019 15:41:18 +0100 Subject: [PATCH 032/274] Update matplotlibcpp to the latest version --- src/external/matplotlib-cpp/matplotlibcpp.h | 256 +++++++++++--------- 1 file changed, 142 insertions(+), 114 deletions(-) diff --git a/src/external/matplotlib-cpp/matplotlibcpp.h b/src/external/matplotlib-cpp/matplotlibcpp.h index 2797295..e626c4c 100644 --- a/src/external/matplotlib-cpp/matplotlibcpp.h +++ b/src/external/matplotlib-cpp/matplotlibcpp.h @@ -15,6 +15,10 @@ #ifndef WITHOUT_NUMPY # define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION # include + +# ifdef WITH_OPENCV +# include +# endif // WITH_OPENCV #endif // WITHOUT_NUMPY #if PY_MAJOR_VERSION >= 3 @@ -45,6 +49,7 @@ struct _interpreter { PyObject *s_python_function_fill; PyObject *s_python_function_fill_between; PyObject *s_python_function_hist; + PyObject *s_python_function_imshow; PyObject *s_python_function_scatter; PyObject *s_python_function_subplot; PyObject *s_python_function_legend; @@ -84,6 +89,18 @@ struct _interpreter { return ctx; } + PyObject* safe_import(PyObject* module, std::string fname) { + PyObject* fn = PyObject_GetAttrString(module, fname.c_str()); + + if (!fn) + throw std::runtime_error(std::string("Couldn't find required function: ") + fname); + + if (!PyFunction_Check(fn)) + throw std::runtime_error(fname + std::string(" is unexpectedly not a PyFunction.")); + + return fn; + } + private: #ifndef WITHOUT_NUMPY @@ -151,120 +168,48 @@ struct _interpreter { Py_DECREF(pylabname); if (!pylabmod) { throw std::runtime_error("Error loading module pylab!"); } - s_python_function_show = PyObject_GetAttrString(pymod, "show"); - s_python_function_close = PyObject_GetAttrString(pymod, "close"); - s_python_function_draw = PyObject_GetAttrString(pymod, "draw"); - s_python_function_pause = PyObject_GetAttrString(pymod, "pause"); - s_python_function_figure = PyObject_GetAttrString(pymod, "figure"); - s_python_function_fignum_exists = PyObject_GetAttrString(pymod, "fignum_exists"); - s_python_function_plot = PyObject_GetAttrString(pymod, "plot"); - s_python_function_quiver = PyObject_GetAttrString(pymod, "quiver"); - s_python_function_semilogx = PyObject_GetAttrString(pymod, "semilogx"); - s_python_function_semilogy = PyObject_GetAttrString(pymod, "semilogy"); - s_python_function_loglog = PyObject_GetAttrString(pymod, "loglog"); - s_python_function_fill = PyObject_GetAttrString(pymod, "fill"); - s_python_function_fill_between = PyObject_GetAttrString(pymod, "fill_between"); - s_python_function_hist = PyObject_GetAttrString(pymod,"hist"); - s_python_function_scatter = PyObject_GetAttrString(pymod,"scatter"); - s_python_function_subplot = PyObject_GetAttrString(pymod, "subplot"); - s_python_function_legend = PyObject_GetAttrString(pymod, "legend"); - s_python_function_ylim = PyObject_GetAttrString(pymod, "ylim"); - s_python_function_title = PyObject_GetAttrString(pymod, "title"); - s_python_function_axis = PyObject_GetAttrString(pymod, "axis"); - s_python_function_xlabel = PyObject_GetAttrString(pymod, "xlabel"); - s_python_function_ylabel = PyObject_GetAttrString(pymod, "ylabel"); - s_python_function_xticks = PyObject_GetAttrString(pymod, "xticks"); - s_python_function_yticks = PyObject_GetAttrString(pymod, "yticks"); - s_python_function_grid = PyObject_GetAttrString(pymod, "grid"); - s_python_function_xlim = PyObject_GetAttrString(pymod, "xlim"); - s_python_function_ion = PyObject_GetAttrString(pymod, "ion"); - s_python_function_ginput = PyObject_GetAttrString(pymod, "ginput"); - s_python_function_save = PyObject_GetAttrString(pylabmod, "savefig"); - s_python_function_annotate = PyObject_GetAttrString(pymod,"annotate"); - s_python_function_clf = PyObject_GetAttrString(pymod, "clf"); - s_python_function_errorbar = PyObject_GetAttrString(pymod, "errorbar"); - s_python_function_tight_layout = PyObject_GetAttrString(pymod, "tight_layout"); - s_python_function_stem = PyObject_GetAttrString(pymod, "stem"); - s_python_function_xkcd = PyObject_GetAttrString(pymod, "xkcd"); - s_python_function_text = PyObject_GetAttrString(pymod, "text"); - s_python_function_suptitle = PyObject_GetAttrString(pymod, "suptitle"); - s_python_function_bar = PyObject_GetAttrString(pymod,"bar"); - s_python_function_subplots_adjust = PyObject_GetAttrString(pymod,"subplots_adjust"); - - if( !s_python_function_show - || !s_python_function_close - || !s_python_function_draw - || !s_python_function_pause - || !s_python_function_figure - || !s_python_function_fignum_exists - || !s_python_function_plot - || !s_python_function_quiver - || !s_python_function_semilogx - || !s_python_function_semilogy - || !s_python_function_loglog - || !s_python_function_fill - || !s_python_function_fill_between - || !s_python_function_subplot - || !s_python_function_legend - || !s_python_function_ylim - || !s_python_function_title - || !s_python_function_axis - || !s_python_function_xlabel - || !s_python_function_ylabel - || !s_python_function_grid - || !s_python_function_xlim - || !s_python_function_ion - || !s_python_function_ginput - || !s_python_function_save - || !s_python_function_clf - || !s_python_function_annotate - || !s_python_function_errorbar - || !s_python_function_errorbar - || !s_python_function_tight_layout - || !s_python_function_stem - || !s_python_function_xkcd - || !s_python_function_text - || !s_python_function_suptitle - || !s_python_function_bar - || !s_python_function_subplots_adjust - ) { throw std::runtime_error("Couldn't find required function!"); } - - if ( !PyFunction_Check(s_python_function_show) - || !PyFunction_Check(s_python_function_close) - || !PyFunction_Check(s_python_function_draw) - || !PyFunction_Check(s_python_function_pause) - || !PyFunction_Check(s_python_function_figure) - || !PyFunction_Check(s_python_function_fignum_exists) - || !PyFunction_Check(s_python_function_plot) - || !PyFunction_Check(s_python_function_quiver) - || !PyFunction_Check(s_python_function_semilogx) - || !PyFunction_Check(s_python_function_semilogy) - || !PyFunction_Check(s_python_function_loglog) - || !PyFunction_Check(s_python_function_fill) - || !PyFunction_Check(s_python_function_fill_between) - || !PyFunction_Check(s_python_function_subplot) - || !PyFunction_Check(s_python_function_legend) - || !PyFunction_Check(s_python_function_annotate) - || !PyFunction_Check(s_python_function_ylim) - || !PyFunction_Check(s_python_function_title) - || !PyFunction_Check(s_python_function_axis) - || !PyFunction_Check(s_python_function_xlabel) - || !PyFunction_Check(s_python_function_ylabel) - || !PyFunction_Check(s_python_function_grid) - || !PyFunction_Check(s_python_function_xlim) - || !PyFunction_Check(s_python_function_ion) - || !PyFunction_Check(s_python_function_ginput) - || !PyFunction_Check(s_python_function_save) - || !PyFunction_Check(s_python_function_clf) - || !PyFunction_Check(s_python_function_tight_layout) - || !PyFunction_Check(s_python_function_errorbar) - || !PyFunction_Check(s_python_function_stem) - || !PyFunction_Check(s_python_function_xkcd) - || !PyFunction_Check(s_python_function_text) - || !PyFunction_Check(s_python_function_suptitle) - || !PyFunction_Check(s_python_function_bar) - || !PyFunction_Check(s_python_function_subplots_adjust) - ) { throw std::runtime_error("Python object is unexpectedly not a PyFunction."); } + s_python_function_show = safe_import(pymod, "show"); + s_python_function_close = safe_import(pymod, "close"); + s_python_function_draw = safe_import(pymod, "draw"); + s_python_function_pause = safe_import(pymod, "pause"); + s_python_function_figure = safe_import(pymod, "figure"); + s_python_function_fignum_exists = safe_import(pymod, "fignum_exists"); + s_python_function_plot = safe_import(pymod, "plot"); + s_python_function_quiver = safe_import(pymod, "quiver"); + s_python_function_semilogx = safe_import(pymod, "semilogx"); + s_python_function_semilogy = safe_import(pymod, "semilogy"); + s_python_function_loglog = safe_import(pymod, "loglog"); + s_python_function_fill = safe_import(pymod, "fill"); + s_python_function_fill_between = safe_import(pymod, "fill_between"); + s_python_function_hist = safe_import(pymod,"hist"); + s_python_function_scatter = safe_import(pymod,"scatter"); + s_python_function_subplot = safe_import(pymod, "subplot"); + s_python_function_legend = safe_import(pymod, "legend"); + s_python_function_ylim = safe_import(pymod, "ylim"); + s_python_function_title = safe_import(pymod, "title"); + s_python_function_axis = safe_import(pymod, "axis"); + s_python_function_xlabel = safe_import(pymod, "xlabel"); + s_python_function_ylabel = safe_import(pymod, "ylabel"); + s_python_function_xticks = safe_import(pymod, "xticks"); + s_python_function_yticks = safe_import(pymod, "yticks"); + s_python_function_grid = safe_import(pymod, "grid"); + s_python_function_xlim = safe_import(pymod, "xlim"); + s_python_function_ion = safe_import(pymod, "ion"); + s_python_function_ginput = safe_import(pymod, "ginput"); + s_python_function_save = safe_import(pylabmod, "savefig"); + s_python_function_annotate = safe_import(pymod,"annotate"); + s_python_function_clf = safe_import(pymod, "clf"); + s_python_function_errorbar = safe_import(pymod, "errorbar"); + s_python_function_tight_layout = safe_import(pymod, "tight_layout"); + s_python_function_stem = safe_import(pymod, "stem"); + s_python_function_xkcd = safe_import(pymod, "xkcd"); + s_python_function_text = safe_import(pymod, "text"); + s_python_function_suptitle = safe_import(pymod, "suptitle"); + s_python_function_bar = safe_import(pymod,"bar"); + s_python_function_subplots_adjust = safe_import(pymod,"subplots_adjust"); +#ifndef WITHOUT_NUMPY + s_python_function_imshow = safe_import(pymod, "imshow"); +#endif s_python_empty_tuple = PyTuple_New(0); } @@ -623,6 +568,78 @@ bool hist(const std::vector& y, long bins=10,std::string color="b", return res; } +#ifndef WITHOUT_NUMPY + namespace internal { + void imshow(void *ptr, const NPY_TYPES type, const int rows, const int columns, const int colors, const std::map &keywords) + { + assert(type == NPY_UINT8 || type == NPY_FLOAT); + assert(colors == 1 || colors == 3 || colors == 4); + + detail::_interpreter::get(); //interpreter needs to be initialized for the numpy commands to work + + // construct args + npy_intp dims[3] = { rows, columns, colors }; + PyObject *args = PyTuple_New(1); + PyTuple_SetItem(args, 0, PyArray_SimpleNewFromData(colors == 1 ? 2 : 3, dims, type, ptr)); + + // construct keyword args + PyObject* kwargs = PyDict_New(); + for(std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) + { + PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); + } + + PyObject *res = PyObject_Call(detail::_interpreter::get().s_python_function_imshow, args, kwargs); + Py_DECREF(args); + Py_DECREF(kwargs); + if (!res) + throw std::runtime_error("Call to imshow() failed"); + Py_DECREF(res); + } + } + + void imshow(const unsigned char *ptr, const int rows, const int columns, const int colors, const std::map &keywords = {}) + { + internal::imshow((void *) ptr, NPY_UINT8, rows, columns, colors, keywords); + } + + void imshow(const float *ptr, const int rows, const int columns, const int colors, const std::map &keywords = {}) + { + internal::imshow((void *) ptr, NPY_FLOAT, rows, columns, colors, keywords); + } + +#ifdef WITH_OPENCV + void imshow(const cv::Mat &image, const std::map &keywords = {}) + { + // Convert underlying type of matrix, if needed + cv::Mat image2; + NPY_TYPES npy_type = NPY_UINT8; + switch (image.type() & CV_MAT_DEPTH_MASK) { + case CV_8U: + image2 = image; + break; + case CV_32F: + image2 = image; + npy_type = NPY_FLOAT; + break; + default: + image.convertTo(image2, CV_MAKETYPE(CV_8U, image.channels())); + } + + // If color image, convert from BGR to RGB + switch (image2.channels()) { + case 3: + cv::cvtColor(image2, image2, CV_BGR2RGB); + break; + case 4: + cv::cvtColor(image2, image2, CV_BGRA2RGBA); + } + + internal::imshow(image2.data, npy_type, image2.rows, image2.cols, image2.channels(), keywords); + } +#endif // WITH_OPENCV +#endif // WITHOUT_NUMPY + template bool scatter(const std::vector& x, const std::vector& y, @@ -1044,6 +1061,14 @@ bool plot(const std::vector& y, const std::string& format = "") return plot(x,y,format); } +template +bool plot(const std::vector& y, const std::map& keywords) +{ + std::vector x(y.size()); + for(size_t i=0; i bool stem(const std::vector& y, const std::string& format = "") { @@ -1116,6 +1141,9 @@ inline bool fignum_exists(long number) inline void figure_size(size_t w, size_t h) { + // Make sure interpreter is initialised + detail::_interpreter::get(); + const size_t dpi = 100; PyObject* size = PyTuple_New(2); PyTuple_SetItem(size, 0, PyFloat_FromDouble((double)w / dpi)); From 16c1d3675fba3066899261dfca336d405817c9ed Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 17 Jul 2019 16:23:59 +0100 Subject: [PATCH 033/274] The solver now returns the final integration time, so t1 is not a constant now. Updated examples accordingly. --- examples/diffusion_2d/diffusion_2d.cpp | 24 ++++++++++++++---------- examples/perovskite/perovskite.cpp | 19 ++++++++++++------- examples/robertson/robertson.cpp | 2 +- src/solver.cpp | 5 ++++- src/solver.h | 2 +- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/examples/diffusion_2d/diffusion_2d.cpp b/examples/diffusion_2d/diffusion_2d.cpp index b55cfdd..e396113 100644 --- a/examples/diffusion_2d/diffusion_2d.cpp +++ b/examples/diffusion_2d/diffusion_2d.cpp @@ -100,18 +100,22 @@ int main() { auto tic0 = clock::now(); - solve(x, t1 / 10); // This line is given here just as an example. - // Here we produce an intermediate solution at time - // t = (t1 / 4). This solution will be stored in the - // vector x. Note that a better way to get - // intermediate results is to override observer - // function from daecpp::Solver class. - - // Tweak the solver paramters between the solver calls + double t = t1 / 10; // Produce intermediate results at t = t1 / 10 + + solve(x, t); // This line is given here just as an example. + // Here we produce an intermediate solution at time + // t = (t1 / 10). This solution will be stored in the + // vector x. Note that a better way to get + // intermediate results is to override observer + // function from daecpp::Solver class. + + // Tweak the solver paramters between the solver calls, for example, opt.dt_increase_factor = 2.0; - solve(x, t1); // Reuse vector x as an initial condition and get the - // final solution at time t = t1. + t = t1; // Now produce the final solution at time t = t1 + + solve(x, t); // Reuse vector x as an initial condition and get the + // final solution at time t = t1. auto tic1 = clock::now(); diff --git a/examples/perovskite/perovskite.cpp b/examples/perovskite/perovskite.cpp index 05ac8b5..02494c0 100644 --- a/examples/perovskite/perovskite.cpp +++ b/examples/perovskite/perovskite.cpp @@ -127,23 +127,27 @@ int main() { auto tic0 = clock::now(); - status = solve(x1, p.t1); // Solve the system without observer - // status = solve_observer(x1, p.t1); // Use observer + double t = p.t1; + status = solve(x1, t); // Solve the system without observer + // status = solve_observer(x1, t); // Use observer auto tic1 = clock::now(); // If we need to produce intermediate results, for example, for // t = 1.0, 5.0, 10.0, we can execute the solver several times: // // auto tic0 = clock::now(); - // solve(x1, 1.0); - // solve(x1, 5.0); - // solve(x1, 10.0); + // t = 1.0; + // solve(x1, t); + // t = 5.0; + // solve(x1, t); + // t = 10.0; + // solve(x1, t); // auto tic1 = clock::now(); // // After each solver call the vector x1 will contain solution at // the corresponding time t. Then it will be re-used as an initial // condition for the next solver call, so overall performance will be - // almost the same as a single "solve(x1, 10.0);" call. + // almost the same as a single "solve(x1, t);" call, where t = 10. // Note that a better way to get intermediate results is to override // observer function from daecpp::Solver class @@ -175,7 +179,8 @@ int main() { auto tic0 = clock::now(); - status_slow = solve_slow(x2, p.t1); + double t = p.t1; + status_slow = solve_slow(x2, t); auto tic1 = clock::now(); std::cout diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index 241002a..735858e 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -197,7 +197,7 @@ class MyJacobian : public Jacobian int main() { // Solution time 0 <= t <= t1 - const double t1 = 4.0e6; + double t1 = 4.0e6; // Define the state vector state_type x(3); diff --git a/src/solver.cpp b/src/solver.cpp index 3c3125f..04ce1e3 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -53,7 +53,7 @@ Solver::Solver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) * The main solver * ============================================================================= */ -int Solver::operator()(state_type &x, const double t1) +int Solver::operator()(state_type &x, double &t1) { // Set system size m_size = (MKL_INT)(x.size()); @@ -372,6 +372,9 @@ int Solver::operator()(state_type &x, const double t1) // Stop timer auto tic1 = clock::now(); + // Update solution time + t1 = m_iterator_state.t; + // Update solution history for(int d = m_opt.bdf_order - 1; d > 0; d--) { diff --git a/src/solver.h b/src/solver.h index b9d18a9..0345f1d 100644 --- a/src/solver.h +++ b/src/solver.h @@ -116,7 +116,7 @@ class Solver * The data stored in x (initial conditions) will be overwritten. * Returns 0 in case of success or error code if integration is failed. */ - int operator()(state_type &x, const double t1); + int operator()(state_type &x, double &t1); /* * Virtual Observer. Called by the solver every time step. From 48d50c131d6fedd7a231bb2e685abf4043d64f12 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 18 Jul 2019 10:17:15 +0100 Subject: [PATCH 034/274] Restore the previous time step after the solver restart (should improve accuracy a little) --- src/solver.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 04ce1e3..70986ca 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -385,8 +385,10 @@ int Solver::operator()(state_type &x, double &t1) // Catch up the last time step observer(x, m_iterator_state.t); - // Copy the previous time step size - m_iterator_state.dt[1] = m_iterator_state.dt[0]; + // Restore the previous time step size + m_iterator_state.dt_eval = m_iterator_state.dt[1]; + m_iterator_state.dt[1] = m_iterator_state.dt[0]; + m_iterator_state.dt[0] = m_iterator_state.dt_eval; if(m_opt.verbosity > 0) { From 1e73bc75f915ca60691e614e5e20e0ff668cec95 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 18 Jul 2019 10:24:01 +0100 Subject: [PATCH 035/274] Mention in README.md that t1 will be re-written by the solver if it stops earlier (stop condition triggered) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 440c8b5..755e80b 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ int status = solve(x, t1); Here *t*1 is the integration time (0 < *t* < *t*1), and **x** is the initial condition vector defined above. -The solver returns 0 if integration is successful or error code otherwise. Solution at time *t*1 will be written into vector **x** (initial conditions will be overwritten). That's it! +The solver returns 0 if integration is successful or error code otherwise. Solution at time *t*1 will be written into vector **x** (initial conditions will be overwritten). The actual integration time *t*1 will be returned (in case the solver terminates integration earlier). That's it! #### Optional: Set up Observer From fbca6dec526219cdfc050d54c47a7853835081e0 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 18 Jul 2019 10:44:48 +0100 Subject: [PATCH 036/274] Assert dt is not zero and positive --- src/solver.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/solver.cpp b/src/solver.cpp index 70986ca..8b82ddc 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -74,6 +74,10 @@ int Solver::operator()(state_type &x, double &t1) return 1; } + // Assert dt > dt_min + if(m_iterator_state.dt[0] < m_opt.dt_min) + m_iterator_state.dt[0] = m_opt.dt_init; + // Check initial time steps m_iterator_state.dt_eval = (m_iterator_state.dt[0] > (t1 - m_iterator_state.t)) From 919f82b9d5e38f7d2388ed9f41729d29f25639b8 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 24 Jul 2019 13:16:07 +0100 Subject: [PATCH 037/274] Updated the solver output and verbosity levels --- src/solver.cpp | 76 +++++++++++++++++++++++++++++------------ src/solver_options.h | 6 ++-- src/time_integrator.cpp | 22 ++++++++---- src/time_integrator.h | 5 +++ src/time_stepper.cpp | 8 ++--- 5 files changed, 83 insertions(+), 34 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 8b82ddc..8215c88 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -90,9 +91,12 @@ int Solver::operator()(state_type &x, double &t1) m_iterator_state.final_time_step = false; // Initial output - if(m_opt.verbosity > 1) + if(m_opt.verbosity > 0) { std::cout << "Number of equations: " << m_size << std::endl; + } + if(m_opt.verbosity > 1) + { std::cout << "Float precision: " << 8 * sizeof(float_type) << " bit\n"; std::cout << "Integer precision: " << 8 * sizeof(MKL_INT) << " bit\n"; @@ -124,7 +128,8 @@ int Solver::operator()(state_type &x, double &t1) m_mkl_x = xk.data(); // Memory control variables - int peak_mem1 = 0, peak_mem2 = 0, peak_mem3 = 0; + int peak_mem1 = 0, peak_mem2 = 0, peak_mem3 = 0; + double total_peak_mem = 0.0; // Reset Jacobian timer m_ti->reset_jac_time(); @@ -134,7 +139,13 @@ int Solver::operator()(state_type &x, double &t1) // Initialise clock using clock = std::chrono::high_resolution_clock; - using time_unit = std::chrono::milliseconds; + using time_unit = std::chrono::microseconds; + + if(m_opt.verbosity == 1) + { + std::cout << "Calculating..."; + std::cout.flush(); + } /* * Start the solver @@ -151,7 +162,7 @@ int Solver::operator()(state_type &x, double &t1) m_iterator_state.step_counter_local++; m_steps++; - if(m_opt.verbosity > 0) + if(m_opt.verbosity > 1) { std::cout << std::left; std::cout << "\nStep " << std::setw(7) << m_steps @@ -160,7 +171,7 @@ int Solver::operator()(state_type &x, double &t1) std::cout.flush(); } - if(m_opt.verbosity > 1) + if(m_opt.verbosity > 2) { std::cout << "BDF-" << m_iterator_state.current_scheme << ": "; std::cout << "dt=" << m_iterator_state.dt[0] @@ -201,7 +212,7 @@ int Solver::operator()(state_type &x, double &t1) m_mkl_a, m_ia, m_ja, &m_idum, &m_nrhs, m_iparm, &m_msglvl, &m_ddum, &m_ddum, &m_error); - if(m_opt.verbosity > 1) + if(m_opt.verbosity > 2) { if(m_iparm[14] > peak_mem1 || m_iparm[15] > peak_mem2 || m_iparm[16] > peak_mem3) @@ -223,6 +234,11 @@ int Solver::operator()(state_type &x, double &t1) << std::endl; } } + if(m_opt.verbosity > 0) + { + total_peak_mem = + (double)(m_iparm[14] + m_iparm[16]) / 1024.0; + } if(m_error != 0) { @@ -247,8 +263,8 @@ int Solver::operator()(state_type &x, double &t1) lin_alg_time += std::chrono::duration_cast( clock::now() - tic_phase1) - .count() / - 1000.0; + .count() * + 1e-6; } else { @@ -275,8 +291,8 @@ int Solver::operator()(state_type &x, double &t1) lin_alg_time += std::chrono::duration_cast(clock::now() - tic_phase3) - .count() / - 1000.0; + .count() * + 1e-6; m_calls++; @@ -301,7 +317,7 @@ int Solver::operator()(state_type &x, double &t1) x[i] -= m_mkl_x[i]; } - if(m_opt.verbosity > 0) + if(m_opt.verbosity > 1) { std::cout << "#"; std::cout.flush(); @@ -318,7 +334,7 @@ int Solver::operator()(state_type &x, double &t1) // Trying to reduce the time step. if(iter == m_opt.max_Newton_iter) { - if(m_opt.verbosity > 0) + if(m_opt.verbosity > 1) std::cout << " <- redo"; if(m_reset_ti_state(x, m_x_prev)) return 3; // Newton method failed to converge @@ -397,17 +413,35 @@ int Solver::operator()(state_type &x, double &t1) if(m_opt.verbosity > 0) { double solver_time = - std::chrono::duration_cast(tic1 - tic0).count() / 1000.0; - double jac_time = m_ti->get_jac_time(); + std::chrono::duration_cast(tic1 - tic0).count() * 1e-6; + double jac_time = m_ti->get_jac_time(); + double rhs_time = m_ti->get_rhs_time(); + double other_time = solver_time - (lin_alg_time + rhs_time + jac_time); double jac_time_rel = jac_time / solver_time * 100.0; + double rhs_time_rel = rhs_time / solver_time * 100.0; double lin_alg_time_rel = lin_alg_time / solver_time * 100.0; - std::cout << "\nLinear algebra solver calls: " << m_calls << '\n'; - std::cout << "Time spent by linear algebra solver: " << lin_alg_time - << " sec. (" << lin_alg_time_rel << "%)" << '\n'; - std::cout << "Time spent to calculate Jacobian: " << jac_time - << " sec. (" << jac_time_rel << "%)" << '\n'; - std::cout << "Total time spent by the solver: " << solver_time - << " sec. (100.0%)" << '\n'; + double other_time_rel = + 100.0 - (lin_alg_time_rel + rhs_time_rel + jac_time_rel); + + std::stringstream ss; + + ss << std::setprecision(3); + ss << "\nLinear algebra solver calls: " << m_calls << '\n'; + ss << "Peak memory for the linear solver: " << total_peak_mem << " Mb" + << std::endl; + ss << "Time spent:\n by linear algebra solver: " << lin_alg_time + << " sec. (" << lin_alg_time_rel << "%)" << '\n'; + ss << " to calculate the RHS: " << rhs_time << " sec. (" + << rhs_time_rel << "%)" << '\n'; + ss << " to calculate Jacobian: " << jac_time << " sec. (" + << jac_time_rel << "%)" << '\n'; + ss << " other calculations: " << other_time << " sec. (" + << other_time_rel << "%)" << '\n'; + ss << "Total time spent by the solver: " << solver_time + << " sec. (100.0%)" << '\n'; + ss << std::endl; + + std::cout << ss.str(); } // Success diff --git a/src/solver_options.h b/src/solver_options.h index 59b0a2d..0e7a587 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -19,6 +19,8 @@ class SolverOptions // are available than specified, the execution may slow down instead of // speeding up. If MKL_NUM_THREADS is not defined, then the solver uses all // available processors. + // In order to control the parallel execution of the numerical Jacobian, use + // OMP_NUM_THREADS environment variable (uses all cores by default). // Perform Jacobian update, Reordering, Symbolic and Numerical Factorization // every Newton iteration. Changing to 'false' can increase speed but also @@ -64,8 +66,8 @@ class SolverOptions double dt_max = 1.0 / dt_eps_m; // Verbosity level of the solver: - // 0 - be silent, 1 - prints some basic information, 2 - chatterbox - int verbosity = 1; + // 0 - silent, 1 - basic information, 2 - time stepping info, 3 - all info + int verbosity = 2; // Simple Adaptive Time Stepping options int dt_increase_threshold = 2; // Time step amplification threshold diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index a0dcf26..54a1a07 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -109,8 +109,20 @@ void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, alpha = invdt * ALPHA_COEF[scheme]; } - // Calculate RHS - m_rhs(x, b, t); + // Initialise clock + using clock = std::chrono::high_resolution_clock; + using time_unit = std::chrono::microseconds; + + // Calculate the RHS + { + auto tic0 = clock::now(); + m_rhs(x, b, t); + auto tic1 = clock::now(); + + // Update the RHS timer + m_rhs_time += + std::chrono::duration_cast(tic1 - tic0).count() * 1e-6; + } // b := -M * dxdt + b #ifdef DAE_SINGLE @@ -123,10 +135,6 @@ void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, if(do_jac) { - // Initialise clock - using clock = std::chrono::high_resolution_clock; - using time_unit = std::chrono::milliseconds; - // Clear temporary Jacobian m_J.A.clear(); m_J.ia.clear(); @@ -144,7 +152,7 @@ void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, // Update Jacobian timer m_jac_time += - std::chrono::duration_cast(tic1 - tic0).count() / 1000.0; + std::chrono::duration_cast(tic1 - tic0).count() * 1e-6; // Sparse matrix check if(m_matrix_checker(m_J, size)) diff --git a/src/time_integrator.h b/src/time_integrator.h index 161f9c1..592598d 100644 --- a/src/time_integrator.h +++ b/src/time_integrator.h @@ -44,6 +44,9 @@ class TimeIntegrator // Total time spent to estimate Jacobian, sec. double m_jac_time = 0.0; + // Total time spent to calculate the RHS, sec. + double m_rhs_time = 0.0; + // Temporary Jacobian matrix holder sparse_matrix_holder m_J; @@ -80,6 +83,8 @@ class TimeIntegrator double get_jac_time() { return m_jac_time; } + double get_rhs_time() { return m_rhs_time; } + void integrate(sparse_matrix_holder &J, state_type &b, const state_type &x, const state_type_matrix &x_prev, const double t, const double dt[], const bool do_jac); diff --git a/src/time_stepper.cpp b/src/time_stepper.cpp index 29c73ef..9ad457c 100644 --- a/src/time_stepper.cpp +++ b/src/time_stepper.cpp @@ -73,13 +73,13 @@ int Solver::m_adaptive_time_stepping(state_type &x, // Monitor function double eta = norm1 / (norm2 + m_opt.dt_eps_m); - if(m_opt.verbosity > 1) + if(m_opt.verbosity > 2) std::cout << " (eta = " << eta << ")"; // The time step should be reduced, scrape the current time iteration if(eta > m_opt.dt_eta_max) { - if(m_opt.verbosity > 0) + if(m_opt.verbosity > 1) std::cout << " <- redo: dt_eta = " << eta; if(m_reset_ti_state(x, x_prev)) return -2; // Method failed to converge @@ -141,7 +141,7 @@ void Solver::m_increase_dt() { m_iterator_state.current_scheme = m_reset_ti_scheme(); - if(m_opt.verbosity > 0) + if(m_opt.verbosity > 1) std::cout << '>'; } } @@ -156,7 +156,7 @@ void Solver::m_decrease_dt() m_iterator_state.current_scheme = m_reset_ti_scheme(); - if(!m_check_dt() && m_opt.verbosity > 0) + if(!m_check_dt() && m_opt.verbosity > 1) std::cout << '<'; } From 1cf56c774065d4c1f28d17339e36e42d5577129f Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 24 Jul 2019 21:46:06 +0100 Subject: [PATCH 038/274] Add two solver options related to the time stepping algorithm --- src/solver.cpp | 22 ++++++++++++++++++---- src/solver_options.h | 8 ++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 8215c88..17b637b 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -190,7 +190,7 @@ int Solver::operator()(state_type &x, double &t1) for(iter = 0; iter < m_opt.max_Newton_iter; iter++) { // Reordering, Symbolic and Numerical Factorization - if(m_opt.fact_every_iter || iter == 0) + if(m_opt.fact_every_iter || iter == 0 || !(iter % m_opt.fact_iter)) { // Time Integrator with updated Jacobian m_ti->integrate(J, b, x, m_x_prev, m_iterator_state.t, @@ -304,9 +304,23 @@ int Solver::operator()(state_type &x, double &t1) if(adiff > m_opt.value_max || std::isnan(m_mkl_x[i])) { - std::cout << "\nERROR: Newton iterations diverged. " - << "Review the solver options.\n"; - return 2; + if(!m_opt.redo_newton || m_opt.verbosity > 1) + { + std::cout << "\nNewton iterations diverged. " + << "Review the solver options.\n"; + } + + if(m_opt.redo_newton) + { + if(m_opt.verbosity > 1) + std::cout << "Trying to recover...\n"; + iter = m_opt.max_Newton_iter; + break; + } + else + { + return 2; + } } if(adiff > tol) diff --git a/src/solver_options.h b/src/solver_options.h index 0e7a587..bf9031e 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -27,6 +27,10 @@ class SolverOptions // can lead to instability. bool fact_every_iter = true; + // If fact_every_iter = false, update Jacobian every fact_iter Newton + // iterations + int fact_iter = 15; + // Order of BDF implicit numerical integration method: // 1 - first order BDF, 2 - BDF-2, ..., 6 - BDF-6 // Default is BDF-2 since it fully supports variable time stepping @@ -79,6 +83,10 @@ class SolverOptions double dt_eta_min = 0.05; // Monitor function lower threshold (V-SATS only) double dt_eta_max = 0.5; // Monitor function higher threshold (V-SATS only) + // Try to roll back and reduce the time step if Newton iterations diverged. + // Otherwise stop with error message. + bool redo_newton = false; + // 1 - V-SATS will use NORM_infinity to estimate solution variability, // 2 - V-SATS will use NORM_2 (default) int vsats_norm = 2; From 201c1e86dbb1b31c0b5820fe0d48029551e914ca Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 25 Jul 2019 13:39:12 +0100 Subject: [PATCH 039/274] Fix RHS computation time output --- src/solver.cpp | 3 ++- src/time_integrator.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/solver.cpp b/src/solver.cpp index 17b637b..1d0bf05 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -131,8 +131,9 @@ int Solver::operator()(state_type &x, double &t1) int peak_mem1 = 0, peak_mem2 = 0, peak_mem3 = 0; double total_peak_mem = 0.0; - // Reset Jacobian timer + // Reset time integrator timers m_ti->reset_jac_time(); + m_ti->reset_rhs_time(); // Reset linear algebra solver timer double lin_alg_time = 0.0; diff --git a/src/time_integrator.h b/src/time_integrator.h index 592598d..ba1ba24 100644 --- a/src/time_integrator.h +++ b/src/time_integrator.h @@ -81,6 +81,8 @@ class TimeIntegrator void reset_jac_time() { m_jac_time = 0.0; } + void reset_rhs_time() { m_rhs_time = 0.0; } + double get_jac_time() { return m_jac_time; } double get_rhs_time() { return m_rhs_time; } From d2112a9bc4da5f5ef1ace9294d0f8c04ed15eb10 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 26 Jul 2019 12:32:45 +0100 Subject: [PATCH 040/274] Update final output --- src/solver.cpp | 58 ++++++++++++++++++++++++++++++++++++++------------ src/solver.h | 9 ++++++++ 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 1d0bf05..573ae62 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -142,6 +142,9 @@ int Solver::operator()(state_type &x, double &t1) using clock = std::chrono::high_resolution_clock; using time_unit = std::chrono::microseconds; + // Counts linear solver calls + size_t calls = 0; + if(m_opt.verbosity == 1) { std::cout << "Calculating..."; @@ -295,6 +298,7 @@ int Solver::operator()(state_type &x, double &t1) .count() * 1e-6; + calls++; m_calls++; double tol = 0.0; @@ -425,6 +429,7 @@ int Solver::operator()(state_type &x, double &t1) m_iterator_state.dt[1] = m_iterator_state.dt[0]; m_iterator_state.dt[0] = m_iterator_state.dt_eval; + // Final output if(m_opt.verbosity > 0) { double solver_time = @@ -438,28 +443,53 @@ int Solver::operator()(state_type &x, double &t1) double other_time_rel = 100.0 - (lin_alg_time_rel + rhs_time_rel + jac_time_rel); + m_timer_lin += lin_alg_time; + m_timer_rhs += rhs_time; + m_timer_jac += jac_time; + m_timer_tot += solver_time; + + double timer_other = + m_timer_tot - (m_timer_lin + m_timer_rhs + m_timer_jac); + std::stringstream ss; - ss << std::setprecision(3); - ss << "\nLinear algebra solver calls: " << m_calls << '\n'; - ss << "Peak memory for the linear solver: " << total_peak_mem << " Mb" - << std::endl; + ss << std::fixed << std::setprecision(3); + ss << "\nLinear algebra solver calls: " << calls; + if(m_dae_solver_calls) + ss << " (" << m_calls << " total)"; + ss << "\nPeak memory for the linear solver: " << total_peak_mem + << " Mb\n"; ss << "Time spent:\n by linear algebra solver: " << lin_alg_time - << " sec. (" << lin_alg_time_rel << "%)" << '\n'; - ss << " to calculate the RHS: " << rhs_time << " sec. (" - << rhs_time_rel << "%)" << '\n'; - ss << " to calculate Jacobian: " << jac_time << " sec. (" - << jac_time_rel << "%)" << '\n'; - ss << " other calculations: " << other_time << " sec. (" - << other_time_rel << "%)" << '\n'; - ss << "Total time spent by the solver: " << solver_time - << " sec. (100.0%)" << '\n'; - ss << std::endl; + << " sec. (" << lin_alg_time_rel << "%)"; + if(m_dae_solver_calls) + ss << " --> " << m_timer_lin << " sec. (" + << m_timer_lin / m_timer_tot * 100.0 << "%)"; + ss << "\n to calculate the RHS: " << rhs_time << " sec. (" + << rhs_time_rel << "%)"; + if(m_dae_solver_calls) + ss << " --> " << m_timer_rhs << " sec. (" + << m_timer_rhs / m_timer_tot * 100.0 << "%)"; + ss << "\n to calculate Jacobian: " << jac_time << " sec. (" + << jac_time_rel << "%)"; + if(m_dae_solver_calls) + ss << " --> " << m_timer_jac << " sec. (" + << m_timer_jac / m_timer_tot * 100.0 << "%)"; + ss << "\n other calculations: " << other_time << " sec. (" + << other_time_rel << "%)"; + if(m_dae_solver_calls) + ss << " --> " << timer_other << " sec. (" + << timer_other / m_timer_tot * 100.0 << "%)"; + ss << "\nTotal time spent by the solver: " << solver_time + << " sec. (100.0%)"; + if(m_dae_solver_calls) + ss << " --> " << m_timer_tot << " sec. (100.0%)"; + ss << "\n\n"; std::cout << ss.str(); } // Success + m_dae_solver_calls++; return 0; } diff --git a/src/solver.h b/src/solver.h index 0345f1d..2c4329d 100644 --- a/src/solver.h +++ b/src/solver.h @@ -41,6 +41,15 @@ class Solver size_t m_steps = 0; // Total time iteration counter size_t m_calls = 0; // Total linear algebra solver calls counter + // Count the number of the DAE solver calls (for output) + size_t m_dae_solver_calls = 0; + + // Timers + double m_timer_lin = 0; + double m_timer_rhs = 0; + double m_timer_jac = 0; + double m_timer_tot = 0; + // Contains a few latest successful time steps for the time integrator state_type_matrix m_x_prev; From 0d4b84093395bb1ad2da5f384c9b55de0b4b8ae5 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 26 Jul 2019 13:35:07 +0100 Subject: [PATCH 041/274] Add relative tolerance option for the Newton algorithm --- src/solver.cpp | 22 ++++++++++++++++++---- src/solver_options.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 573ae62..cdcaa80 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -301,7 +301,7 @@ int Solver::operator()(state_type &x, double &t1) calls++; m_calls++; - double tol = 0.0; + bool is_converged = true; for(MKL_INT i = 0; i < m_size; i++) { @@ -328,9 +328,23 @@ int Solver::operator()(state_type &x, double &t1) } } - if(adiff > tol) + if(is_converged) { - tol = adiff; + if(x[i] != 0.0) + { + double rdiff = adiff / std::abs(x[i]); + if(adiff > m_opt.atol && rdiff > m_opt.rtol) + { + is_converged = false; + } + } + else + { + if(adiff > m_opt.atol) + { + is_converged = false; + } + } } x[i] -= m_mkl_x[i]; @@ -342,7 +356,7 @@ int Solver::operator()(state_type &x, double &t1) std::cout.flush(); } - if(tol < m_opt.atol) + if(is_converged) { break; } diff --git a/src/solver_options.h b/src/solver_options.h index bf9031e..7069437 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -49,10 +49,12 @@ class SolverOptions #ifdef DAE_SINGLE double atol = 1.0e-3; // Absolute tolerance for the Newton algorithm + double rtol = 1.0e-6; // Relative tolerance for the Newton algorithm double dt_eps_m = 1.0e-6; // The order of the rounding unit double value_max = 1.0e20; // Solution shouldn't be higher than this #else double atol = 1.0e-6; // Absolute tolerance for the Newton algorithm + double rtol = 1.0e-6; // Relative tolerance for the Newton algorithm double dt_eps_m = 1.0e-14; // The order of the rounding unit double value_max = 1.0e100; // Solution shouldn't be higher than this #endif From c1282f1121aeffcfdacf8646724dd76d32831453 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 26 Jul 2019 15:37:09 +0100 Subject: [PATCH 042/274] Move initial output to the solver's constructor partially --- src/solver.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index cdcaa80..0ff8265 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -22,6 +22,16 @@ namespace daecpp_namespace_name Solver::Solver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) : m_rhs(rhs), m_jac(jac), m_mass(mass), m_opt(opt) { + // Initial output + if(m_opt.verbosity > 1) + { + std::cout << "Float precision: " << 8 * sizeof(float_type) + << " bit\n"; + std::cout << "Integer precision: " << 8 * sizeof(MKL_INT) << " bit\n"; + std::cout << "Numerical algorithm: BDF-" << m_opt.bdf_order + << std::endl; + } + // Initialises the internal solver memory pointer. This is only // necessary for the FIRST call of the PARDISO solver. for(MKL_INT i = 0; i < 64; i++) @@ -95,14 +105,6 @@ int Solver::operator()(state_type &x, double &t1) { std::cout << "Number of equations: " << m_size << std::endl; } - if(m_opt.verbosity > 1) - { - std::cout << "Float precision: " << 8 * sizeof(float_type) - << " bit\n"; - std::cout << "Integer precision: " << 8 * sizeof(MKL_INT) << " bit\n"; - std::cout << "Numerical algorithm: BDF-" << m_opt.bdf_order - << std::endl; - } // Reserve memory for the solution history. This will be done only once if(m_x_prev[0].size() == 0) From b7850ec32f18ee5af351b2ef081ab6f2821ff12f Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 5 Aug 2019 14:59:25 +0100 Subject: [PATCH 043/274] Minor changes in perovskite example --- examples/perovskite/perovskite.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/perovskite/perovskite.cpp b/examples/perovskite/perovskite.cpp index 02494c0..aaabdba 100644 --- a/examples/perovskite/perovskite.cpp +++ b/examples/perovskite/perovskite.cpp @@ -116,7 +116,7 @@ int main() // step, we can override observer function in Solver class and, for example, // print out some results while the solver solves the system. // See perovskite_observer.h as an example. - // Instanse of the solver with the user-defined observer: + // Instance of the solver with the user-defined observer: // MySolver solve_observer(rhs, jac, mass, opt); // Solver status @@ -135,14 +135,12 @@ int main() // If we need to produce intermediate results, for example, for // t = 1.0, 5.0, 10.0, we can execute the solver several times: // - // auto tic0 = clock::now(); // t = 1.0; // solve(x1, t); // t = 5.0; // solve(x1, t); // t = 10.0; // solve(x1, t); - // auto tic1 = clock::now(); // // After each solver call the vector x1 will contain solution at // the corresponding time t. Then it will be re-used as an initial @@ -220,12 +218,14 @@ int main() plt::save(filename); #endif - if(check_result || status || status_slow) + const bool check = (check_result || status || status_slow); + + if(check) std::cout << "...Test FAILED\n\n"; else std::cout << "...done\n\n"; - return check_result; + return check; } /* From 36ffb5a29e2029e50e8b5fc0bfba0281829820f4 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 5 Aug 2019 17:12:13 +0100 Subject: [PATCH 044/274] Expose solver options for the observer --- src/solver.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/solver.h b/src/solver.h index 2c4329d..53a3bac 100644 --- a/src/solver.h +++ b/src/solver.h @@ -16,14 +16,17 @@ namespace daecpp_namespace_name class Solver { +protected: + // Expose solver options for the observer in the children classes + SolverOptions &m_opt; // Solver options + +private: RHS &m_rhs; // RHS Jacobian &m_jac; // Jacobian matrix MassMatrix &m_mass; // Mass matrix - SolverOptions &m_opt; // Solver options - TimeIntegrator *m_ti; // Pointer to the time integrator struct m_iterator_state_struct // Keeps the current time layer state From f139d60bd71cf9ba7fadbc2e38994005415f4721 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 6 Aug 2019 11:52:20 +0100 Subject: [PATCH 045/274] Fix warnings in solver.h --- src/solver.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/solver.h b/src/solver.h index 53a3bac..faa5034 100644 --- a/src/solver.h +++ b/src/solver.h @@ -16,11 +16,6 @@ namespace daecpp_namespace_name class Solver { -protected: - // Expose solver options for the observer in the children classes - SolverOptions &m_opt; // Solver options - -private: RHS &m_rhs; // RHS Jacobian &m_jac; // Jacobian matrix @@ -109,6 +104,12 @@ class Solver // Checks PARDISO solver error messages void m_check_pardiso_error(MKL_INT err); +protected: + /* + * Expose solver options for the observer in the children classes + */ + SolverOptions &m_opt; // Solver options + public: /* * Receives user-defined RHS, Jacobian, Mass matrix and solver options. From 9036f0c6477f56e2ddf8479a3d2da4ce19280942 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 5 Sep 2019 10:36:02 +0100 Subject: [PATCH 046/274] Add matplotlib header to install path --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 00bde1f..e074762 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,10 @@ FILE(GLOB DAE_CPP_SOURCES *.cpp) FILE(GLOB DAE_CPP_INCLUDES *.h) +FILE(GLOB DAE_CPP_INCLUDES_PLOTTING external/matplotlib-cpp/*.h) add_library(daecpp SHARED ${DAE_CPP_SOURCES}) add_library(daecpp_static STATIC ${DAE_CPP_SOURCES}) install(TARGETS daecpp daecpp_static DESTINATION lib) install(FILES ${DAE_CPP_INCLUDES} DESTINATION include) +install(FILES ${DAE_CPP_INCLUDES_PLOTTING} DESTINATION include/external/matplotlib-cpp) From 41bb6f1b8b72e2656638bf565982922ff30a6c4b Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 17 Sep 2019 12:11:21 +0100 Subject: [PATCH 047/274] Added Windows and Mac support in cmake file, updated description --- CMakeLists.txt | 171 +++++++++++++++++++++++++++++++++++---------- README.md | 105 ++++++++++++++++++++++++++-- src/CMakeLists.txt | 8 ++- 3 files changed, 239 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0cea0c..7bd0237 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.0) project(dae-cpp) @@ -19,70 +19,167 @@ endif(DAE_TEST) option(DAE_BUILD_EXAMPLES "Build all examples" ON) -set(DAE_MKL_DIR "/opt/intel/mkl" CACHE STRING "Path to Intel MKL root") -unset(DAE_MKL_INCLUDE CACHE) -unset(DAE_MKL_LIB CACHE) +#### Locate Intel MKL #### + +if(DEFINED ENV{MKLROOT}) + message(STATUS "Found MKLROOT environment variable...") + set(MKL_ROOT_DIR $ENV{MKLROOT}) +else(DEFINED ENV{MKLROOT}) + message(STATUS "MKLROOT environment variable not found. Will use default MKL paths...") + if(WIN32) + set(MKL_ROOT_DIR "C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl") + else(WIN32) + set(MKL_ROOT_DIR "/opt/intel/mkl") + endif(WIN32) +endif(DEFINED ENV{MKLROOT}) + +set(DAE_MKL_DIR "${MKL_ROOT_DIR}" CACHE STRING "Path to Intel MKL root directory") + +find_path(DAE_MKL_INCLUDE NAMES mkl.h HINTS ${MKL_ROOT_DIR}/include) + +if(WIN32) + set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/ia32_win") + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../compiler/lib/ia32_win") +else(WIN32) + if(EXISTS ${DAE_MKL_DIR}/lib/intel64) + set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/intel64") + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib/intel64") + else(EXISTS ${DAE_MKL_DIR}/lib/intel64) + set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib") + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib") + endif(EXISTS ${DAE_MKL_DIR}/lib/intel64) +endif(WIN32) + + +#### Locate Python if needed #### + +option(PLOTTING "Use Python interface (matplotlib) for plotting" OFF) + +if(PLOTTING) + find_package(PythonLibs) + if(PYTHONLIBS_FOUND) + set(PYTHON_INCLUDE ${PYTHON_INCLUDE_DIRS} CACHE STRING "Path to Python include file (Python.h) for plotting") + set(PYTHON_LIB ${PYTHON_LIBRARIES} CACHE STRING "Python library for plotting") + else(PYTHONLIBS_FOUND) + set(PYTHON_INCLUDE "" CACHE STRING "Path to Python include file (Python.h) for plotting") + set(PYTHON_LIB "" CACHE STRING "Python library for plotting") + endif(PYTHONLIBS_FOUND) + find_path(PYTHON_NUMPY_INCLUDE numpy/arrayobject.h PATHS + /usr/local/lib/python3.5/dist-packages/numpy/core/include + /usr/local/lib/python3.6/dist-packages/numpy/core/include + /usr/local/lib/python3.7/dist-packages/numpy/core/include + /usr/local/lib/python3.5/site-packages/numpy/core/include + /usr/local/lib/python3.6/site-packages/numpy/core/include + /usr/local/lib/python3.7/site-packages/numpy/core/include + ${PYTHON_INCLUDE}/../Lib/site-packages/numpy/core/include + ${PYTHON_LIB}/../Lib/site-packages/numpy/core/include + DOC "Path to Python numpy include file (numpy/arrayobject.h) for plotting") + include_directories(${PYTHON_INCLUDE} ${PYTHON_NUMPY_INCLUDE}) +endif(PLOTTING) + + +#### Set compiler options #### -set(DAE_MKL_INCLUDE "${DAE_MKL_DIR}/include" CACHE STRING "Path to Intel MKL includes") -set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/intel64" CACHE STRING "Path to Intel MKL libraries") +unset(CMAKE_CXX_FLAGS CACHE) -set(EXT_INCLUDE "${PROJECT_SOURCE_DIR}/src/external") +if(UNIX AND NOT APPLE) + message(STATUS "Unix (not Apple) OS detected...") + if(DAE_LONG_INT) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DMKL_ILP64 -m64 -fopenmp -Wall -Wl,--no-as-needed") + else(DAE_LONG_INT) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -m64 -fopenmp -Wall -Wl,--no-as-needed") + endif(DAE_LONG_INT) -unset(CMAKE_CXX_FLAGS CACHE) +elseif(APPLE) + message(STATUS "Apple OS detected...") + if(DAE_LONG_INT) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DMKL_ILP64 -m64 -fopenmp -Wall -Wl,-rpath,${DAE_MKL_LIB}") + else(DAE_LONG_INT) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -m64 -fopenmp -Wall -Wl,-rpath,${DAE_MKL_LIB}") + endif(DAE_LONG_INT) -if(DAE_LONG_INT) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DMKL_ILP64 -m64 -fopenmp -Wall -Wl,--no-as-needed") -else(DAE_LONG_INT) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -m64 -fopenmp -Wall -Wl,--no-as-needed") -endif(DAE_LONG_INT) +elseif(WIN32) + message(STATUS "Windows OS detected...") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp /EHsc") + +else(UNIX AND NOT APPLE) + message(STATUS "Unknown OS detected... Cannot set up compiler options.") + +endif(UNIX AND NOT APPLE) + + +#### Add include and library paths #### + +configure_file(${PROJECT_SOURCE_DIR}/src/cmake_config.h.in ${PROJECT_SOURCE_DIR}/src/cmake_config.h) + +set(EXT_INCLUDE "${PROJECT_SOURCE_DIR}/src/external") include_directories(${DAE_MKL_INCLUDE} ${EXT_INCLUDE}) +include_directories("${PROJECT_SOURCE_DIR}/src") + link_directories(${DAE_MKL_LIB}) +link_directories(${DAE_INTEL_LIB}) -include_directories("${PROJECT_SOURCE_DIR}/src") -configure_file(${PROJECT_SOURCE_DIR}/src/cmake_config.h.in ${PROJECT_SOURCE_DIR}/src/cmake_config.h) add_subdirectory(src) + +#### Build examples if needed #### + if(DAE_BUILD_EXAMPLES) set(EXAMPLE_LIST "perovskite" "diffusion_2d" "robertson") - - unset(LIB_MKL_INTEL_LP64 CACHE) - if(DAE_LONG_INT) - find_library(LIB_MKL_INTEL_LP64 mkl_intel_ilp64 HINTS ${DAE_MKL_LIB}) - else(DAE_LONG_INT) - find_library(LIB_MKL_INTEL_LP64 mkl_intel_lp64 HINTS ${DAE_MKL_LIB}) - endif(DAE_LONG_INT) - - find_library(LIB_MKL_GNU_THREAD mkl_gnu_thread HINTS ${DAE_MKL_LIB}) - find_library(LIB_MKL_CORE mkl_core HINTS ${DAE_MKL_LIB}) - find_library(LIB_PTHREAD pthread) - find_library(LIB_MATH m) - find_library(LIB_DL dl) - + if(WIN32) + find_library(LIB_MKL_INTEL_LP64 mkl_intel_c.lib HINTS ${DAE_MKL_LIB}) + find_library(LIB_MKL_THREAD mkl_intel_thread.lib HINTS ${DAE_MKL_LIB}) + find_library(LIB_MKL_CORE mkl_core.lib HINTS ${DAE_MKL_LIB}) + find_library(LIB_INTEL_OPENMP libiomp5md.lib HINTS ${DAE_INTEL_LIB}) + set(LIB_PTHREAD "") + set(LIB_MATH "") + set(LIB_DL "") + + else(WIN32) + if(DAE_LONG_INT) + unset(LIB_MKL_INTEL_LP64 CACHE) + find_library(LIB_MKL_INTEL_LP64 mkl_intel_ilp64 HINTS ${DAE_MKL_LIB}) + else(DAE_LONG_INT) + find_library(LIB_MKL_INTEL_LP64 mkl_intel_lp64 HINTS ${DAE_MKL_LIB}) + endif(DAE_LONG_INT) + find_library(LIB_MKL_THREAD mkl_intel_thread HINTS ${DAE_MKL_LIB}) + find_library(LIB_MKL_CORE mkl_core HINTS ${DAE_MKL_LIB}) + find_library(LIB_INTEL_OPENMP iomp5 HINTS ${DAE_INTEL_LIB}) + find_library(LIB_PTHREAD pthread) + find_library(LIB_MATH m) + find_library(LIB_DL dl) + + endif(WIN32) + foreach(EXAMPLE_NAME ${EXAMPLE_LIST}) - + FILE(GLOB SOURCES ${PROJECT_SOURCE_DIR}/examples/${EXAMPLE_NAME}/*.cpp) add_executable(${EXAMPLE_NAME} ${SOURCES}) target_link_libraries(${EXAMPLE_NAME} daecpp_static) - target_link_libraries(${EXAMPLE_NAME} ${LIB_MKL_INTEL_LP64} ${LIB_MKL_GNU_THREAD} ${LIB_MKL_CORE} ${LIB_PTHREAD} ${LIB_MATH} ${LIB_DL}) + target_link_libraries(${EXAMPLE_NAME} ${LIB_MKL_INTEL_LP64} ${LIB_MKL_THREAD} ${LIB_MKL_CORE} ${LIB_INTEL_OPENMP} ${LIB_PTHREAD} ${LIB_MATH} ${LIB_DL}) + + if(PLOTTING) + target_link_libraries(${PROJECT_NAME} ${PYTHON_LIB}) + endif(PLOTTING) install(TARGETS ${EXAMPLE_NAME} DESTINATION bin) - + endforeach() - + if(DAE_TEST) - + include(CTest) - + foreach(EXAMPLE_NAME ${EXAMPLE_LIST}) add_test(${EXAMPLE_NAME}_TEST ${EXAMPLE_NAME}) endforeach() - + endif(DAE_TEST) - + endif(DAE_BUILD_EXAMPLES) diff --git a/README.md b/README.md index 755e80b..f16c14f 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ BDF time stepper reduces the original DAE system to a system of nonlinear equati ## Installation -This is a cross-platform software that should work on both Linux (e.g. Ubuntu) and Windows. It should work under macOS as well (but not tested yet). The main library (DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). +This is a cross-platform software that should work on both Linux (e.g. Ubuntu) and Windows. It should work under macOS as well (but not tested yet). The main library (DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS, the latest version and Full Package. An alternative and probably the most convenient way to download and install Intel MKL on Ubuntu (using APT Repository) is the following. @@ -80,22 +80,22 @@ Then download dae-cpp library: git clone https://github.com/ikorotkin/dae-cpp.git ``` -The easiest way to install the library and compile all examples is just to create a new directory and then execute `cmake` and `make`: +The easiest way to install the library and compile all examples is just to create the build directory, then execute `cmake` (providing installation path) and `make`: ```bash cd dae-cpp mkdir build cd build -cmake -DCMAKE_INSTALL_PREFIX=/install/path .. +cmake -DCMAKE_INSTALL_PREFIX=/install_path .. make make install ``` -where `/install/path` is the user-defined path where the package should be installed. +where `/install_path` is the user-defined path where the package should be installed. -Note that `cmake` will try to find Intel MKL at its default location: `/opt/intel/mkl`. If the installation path is different, please provide it with the following `cmake` option: `-DDAE_MKL_DIR=/path/to/intel/mkl/root/dir`. +Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`.. -Instead of `cmake -DCMAKE_INSTALL_PREFIX=/install/path ..` you might consider using `ccmake ..`, a GUI for `cmake` that will allow you to see all the options available before building the solver. +Instead of `cmake -DCMAKE_INSTALL_PREFIX=/install_path ..` you might consider using `ccmake ..`, a GUI for `cmake` that will allow you to see all the options available before building the solver. #### Test the solver @@ -114,11 +114,104 @@ During this test the solver will solve DAE systems from [examples](https://githu - `DAE_SINGLE` - If ON, the single precision will be used in the solver instead of double. Single precision may ruin the accuracy. It is highly recommended to leave this option OFF. This option exists for the future compatibility with CUDA implementations of the solver. - `DAE_BUILD_EXAMPLES` - Build all the examples, ON by default. - `DAE_TEST` - Build automatic solver test, ON by default. The test can be executed by the command `ctest` from the building directory. +- `DAE_MKL_DIR` - Defines a path to Intel MKL root directory (usually `/opt/intel/mkl`). +- `PLOTTING` - Use [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting, `OFF` by default. If `ON`, `cmake` will try to find Python and `numpy` include directories and libraries. +- `PYTHON_INCLUDE` - Only if `PLOTTING=ON`, defines a path to Python include file (`Python.h`) for plotting. +- `PYTHON_NUMPY_INCLUDE` - Only if `PLOTTING=ON`, defines a path to Python `numpy` include file (`numpy/arrayobject.h`) for plotting. +- `PYTHON_LIB` - Only if `PLOTTING=ON`, defines Python library (e.g. `libpython3.6m`) for plotting. ### Windows +Download and install compiler (e.g. [Microsoft Visual Studio](https://visualstudio.microsoft.com/downloads/)) and [Python 3](https://www.python.org/downloads) with `numpy` and `matplotlib` modules (for plotting, optional). Choose 32-bit version of Python 3 for better compatibility. + +Download and install [Git](https://git-scm.com/download/win) and [CMake](https://cmake.org/download/) for Windows. + +Note if you install `git` for the first time you will need to configure it. Start `Git Bash` and use the following commands (change `Your Name` and `your@email` to your full name and email): + +```bash +git config --global user.name "Your Name" +git config --global user.email your@email +``` + +Then from `Git Bash` command line clone dae-cpp library (you may need to create a working directory first): + +```bash +git clone https://github.com/ikorotkin/dae-cpp.git +``` + +Start CMake (`cmake-gui`), choose the source code path (`dae-cpp` folder) and the target directory (it will contain Visual Studio project files). Press "Configure" button. If asked, leave default compiler for the project and default platform (Win32). + +If CMake cannot find any of the libraries, it will print an error message. You can modify the paths and other parameters (see `More building options` above) and re-configure the project. + +If configuration is successful, press "Configure" again to update the cache and then "Generate". In the target directory you will find Visual Studio project files. + +Double-click on `dae-cpp.sln` to open Visual Studio with the project. Do not forget to change Solution Configuration from `Debug` to `Release`. Compile the solution (`F7` by default). After compilation, the executable files can be found in `Release` folder. + +Note that in order to execute the tests (for example, `robertson.exe`) from `Release` folder you need to set up Intel MKL environment variables by executing `mklvars.bat ia32` from `cmd`. For example, by default: + +```bash +cd +"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" ia32 +robertson.exe +``` + +where `` is the full path to the `Release` directory with executables. + An example of default solution file for Microsoft Visual Studio 15 (2017) is given in [msvc](https://github.com/ikorotkin/dae-cpp/tree/master/msvc) folder. Unpack the zip-archive into the current directory and open dae-cpp.sln. Note that you may need to retarget solution and change the paths to Intel MKL library. +### Mac + +Make sure you have installed: `git`, `cmake` and, optional, Python 3 with `numpy` and `matplotlib` modules (for plotting). If these packages are not installed yet, you may install [Homebrew](https://brew.sh/) (package manager for macOS), then install all necessary packages: + +```bash +brew install cmake git python +pip install numpy matplotlib +``` + +Note if you install `git` for the first time you will need to configure it (change `Your Name` and `your@email` to your full name and email): + +```bash +git config --global user.name "Your Name" +git config --global user.email your@email +``` + +Then from a working directory download dae-cpp library source files: + +```bash +git clone https://github.com/ikorotkin/dae-cpp.git +``` + +The easiest way to install the library and compile all examples is just to create the build directory, then execute `cmake` (providing installation path) and `make`: + +```bash +cd dae-cpp +mkdir build +cd build +cmake -DCMAKE_INSTALL_PREFIX=/install_path .. +make +make install +``` + +where `/install_path` is the user-defined path where the package should be installed. + +Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`.. + +Instead of `cmake -DCMAKE_INSTALL_PREFIX=/install_path ..` you might consider using `ccmake ..`, a GUI for `cmake` that will allow you to see all the options available before building the solver. + +**_Note_** that Apple-provided default C++ compiler (`clang`) does not support OpenMP out of the box. So you may need to install either OpenMP for `clang` or an alternative C++ compiler (e.g. `gcc`): + +```bash +brew install llvm libomp +``` + +or + +```bash +brew install gcc +``` + +If alternative compiler is installed (for example, `gcc-7`), provide its name for `cmake` using the following options: `-DCMAKE_CXX_COMPILER=g++-7` and `-DCMAKE_CC_COMPILER=gcc-7`. + ## How to use Please refer to [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e074762..e16bd67 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,9 +2,13 @@ FILE(GLOB DAE_CPP_SOURCES *.cpp) FILE(GLOB DAE_CPP_INCLUDES *.h) FILE(GLOB DAE_CPP_INCLUDES_PLOTTING external/matplotlib-cpp/*.h) -add_library(daecpp SHARED ${DAE_CPP_SOURCES}) +if(UNIX AND NOT APPLE) + add_library(daecpp SHARED ${DAE_CPP_SOURCES}) + install(TARGETS daecpp DESTINATION lib) +endif(UNIX AND NOT APPLE) + add_library(daecpp_static STATIC ${DAE_CPP_SOURCES}) -install(TARGETS daecpp daecpp_static DESTINATION lib) +install(TARGETS daecpp_static DESTINATION lib) install(FILES ${DAE_CPP_INCLUDES} DESTINATION include) install(FILES ${DAE_CPP_INCLUDES_PLOTTING} DESTINATION include/external/matplotlib-cpp) From 6496421ef881845c50a286a76e2ca44230ad2520 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 17 Sep 2019 12:44:01 +0100 Subject: [PATCH 048/274] Updated scripts for setting up MKL environment variables for Mac and Win. Fixed Codacy style format in README. --- README.md | 4 ++-- set_MKL_env | 2 +- set_MKL_env_win.bat | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 set_MKL_env_win.bat diff --git a/README.md b/README.md index f16c14f..5b850eb 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ git clone https://github.com/ikorotkin/dae-cpp.git Start CMake (`cmake-gui`), choose the source code path (`dae-cpp` folder) and the target directory (it will contain Visual Studio project files). Press "Configure" button. If asked, leave default compiler for the project and default platform (Win32). -If CMake cannot find any of the libraries, it will print an error message. You can modify the paths and other parameters (see `More building options` above) and re-configure the project. +If CMake cannot find any of the libraries, it will print an error message. You can modify the paths and other parameters (see [More building options](https://github.com/ikorotkin/dae-cpp#more-building-options) above) and re-configure the project. If configuration is successful, press "Configure" again to update the cache and then "Generate". In the target directory you will find Visual Studio project files. @@ -198,7 +198,7 @@ Note that `cmake` will try to find Intel MKL at its default location `/opt/intel Instead of `cmake -DCMAKE_INSTALL_PREFIX=/install_path ..` you might consider using `ccmake ..`, a GUI for `cmake` that will allow you to see all the options available before building the solver. -**_Note_** that Apple-provided default C++ compiler (`clang`) does not support OpenMP out of the box. So you may need to install either OpenMP for `clang` or an alternative C++ compiler (e.g. `gcc`): +*Note* that Apple-provided default C++ compiler (`clang`) does not support OpenMP out of the box. So you may need to install either OpenMP for `clang` or an alternative C++ compiler (e.g. `gcc`): ```bash brew install llvm libomp diff --git a/set_MKL_env b/set_MKL_env index 9bad63e..2bbfd07 100644 --- a/set_MKL_env +++ b/set_MKL_env @@ -1,2 +1,2 @@ # Default Intel MKL library path -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/intel/mkl/lib/intel64/:/opt/intel/lib/intel64/ +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/intel/mkl/lib/intel64/:/opt/intel/lib/intel64/:/opt/intel/mkl/lib:/opt/intel/lib diff --git a/set_MKL_env_win.bat b/set_MKL_env_win.bat new file mode 100644 index 0000000..9b81d95 --- /dev/null +++ b/set_MKL_env_win.bat @@ -0,0 +1 @@ +"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" ia32 From 111057d2fe24aa463746c0bfd26c63e8ae34c910 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 17 Sep 2019 18:11:07 +0100 Subject: [PATCH 049/274] Added Windows 64 bit platform support in cmake file --- CMakeLists.txt | 21 +++++++++++++++++---- README.md | 12 ++++-------- examples/perovskite/perovskite.cpp | 8 ++++---- set_MKL_env_win.bat | 6 +++++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bd0237..7bebd94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,8 +39,15 @@ set(DAE_MKL_DIR "${MKL_ROOT_DIR}" CACHE STRING "Path to Intel MKL root directory find_path(DAE_MKL_INCLUDE NAMES mkl.h HINTS ${MKL_ROOT_DIR}/include) if(WIN32) - set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/ia32_win") - set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../compiler/lib/ia32_win") + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + # 64 bits + set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/intel64_win") + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../compiler/lib/intel64_win") + elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + # 32 bits + set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/ia32_win") + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../compiler/lib/ia32_win") + endif() else(WIN32) if(EXISTS ${DAE_MKL_DIR}/lib/intel64) set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/intel64") @@ -131,7 +138,13 @@ if(DAE_BUILD_EXAMPLES) set(EXAMPLE_LIST "perovskite" "diffusion_2d" "robertson") if(WIN32) - find_library(LIB_MKL_INTEL_LP64 mkl_intel_c.lib HINTS ${DAE_MKL_LIB}) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + # 64 bits + find_library(LIB_MKL_INTEL_LP64 mkl_intel_lp64.lib HINTS ${DAE_MKL_LIB}) + elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + # 32 bits + find_library(LIB_MKL_INTEL_LP64 mkl_intel_c.lib HINTS ${DAE_MKL_LIB}) + endif() find_library(LIB_MKL_THREAD mkl_intel_thread.lib HINTS ${DAE_MKL_LIB}) find_library(LIB_MKL_CORE mkl_core.lib HINTS ${DAE_MKL_LIB}) find_library(LIB_INTEL_OPENMP libiomp5md.lib HINTS ${DAE_INTEL_LIB}) @@ -165,7 +178,7 @@ if(DAE_BUILD_EXAMPLES) target_link_libraries(${EXAMPLE_NAME} ${LIB_MKL_INTEL_LP64} ${LIB_MKL_THREAD} ${LIB_MKL_CORE} ${LIB_INTEL_OPENMP} ${LIB_PTHREAD} ${LIB_MATH} ${LIB_DL}) if(PLOTTING) - target_link_libraries(${PROJECT_NAME} ${PYTHON_LIB}) + target_link_libraries(${EXAMPLE_NAME} ${PYTHON_LIB}) endif(PLOTTING) install(TARGETS ${EXAMPLE_NAME} DESTINATION bin) diff --git a/README.md b/README.md index 5b850eb..73adb2e 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ During this test the solver will solve DAE systems from [examples](https://githu ### Windows -Download and install compiler (e.g. [Microsoft Visual Studio](https://visualstudio.microsoft.com/downloads/)) and [Python 3](https://www.python.org/downloads) with `numpy` and `matplotlib` modules (for plotting, optional). Choose 32-bit version of Python 3 for better compatibility. +Download and install compiler (e.g. [Microsoft Visual Studio](https://visualstudio.microsoft.com/downloads/)) and [Python 3](https://www.python.org/downloads/windows/) with `numpy` and `matplotlib` modules (for plotting, optional). Download and install [Git](https://git-scm.com/download/win) and [CMake](https://cmake.org/download/) for Windows. @@ -139,7 +139,7 @@ Then from `Git Bash` command line clone dae-cpp library (you may need to create git clone https://github.com/ikorotkin/dae-cpp.git ``` -Start CMake (`cmake-gui`), choose the source code path (`dae-cpp` folder) and the target directory (it will contain Visual Studio project files). Press "Configure" button. If asked, leave default compiler for the project and default platform (Win32). +Start CMake (`cmake-gui`), choose the source code path (`dae-cpp` folder) and the target directory (it will contain Visual Studio project files). Press "Configure" button. If CMake cannot find any of the libraries, it will print an error message. You can modify the paths and other parameters (see [More building options](https://github.com/ikorotkin/dae-cpp#more-building-options) above) and re-configure the project. @@ -147,16 +147,12 @@ If configuration is successful, press "Configure" again to update the cache and Double-click on `dae-cpp.sln` to open Visual Studio with the project. Do not forget to change Solution Configuration from `Debug` to `Release`. Compile the solution (`F7` by default). After compilation, the executable files can be found in `Release` folder. -Note that in order to execute the tests (for example, `robertson.exe`) from `Release` folder you need to set up Intel MKL environment variables by executing `mklvars.bat ia32` from `cmd`. For example, by default: +Note that in order to execute the tests (for example, `robertson.exe`) from `Release` folder, you need to set up Intel MKL environment variables by executing `mklvars.bat intel64` or `mklvars.bat ia32` (depending on the target platform) from `cmd`. By default `mklvars.bat` is located in MKL root folder in `bin` subdirectory, for example: ```bash -cd -"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" ia32 -robertson.exe +"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64 ``` -where `` is the full path to the `Release` directory with executables. - An example of default solution file for Microsoft Visual Studio 15 (2017) is given in [msvc](https://github.com/ikorotkin/dae-cpp/tree/master/msvc) folder. Unpack the zip-archive into the current directory and open dae-cpp.sln. Note that you may need to retarget solution and change the paths to Intel MKL library. ### Mac diff --git a/examples/perovskite/perovskite.cpp b/examples/perovskite/perovskite.cpp index aaabdba..eb7a757 100644 --- a/examples/perovskite/perovskite.cpp +++ b/examples/perovskite/perovskite.cpp @@ -193,13 +193,13 @@ int main() // Plot the results #ifdef PLOTTING - dae::state_type x_axis(N), P(N), Phi(N); + dae::state_type x_axis(p.N), P(p.N), Phi(p.N); - for(MKL_INT i = 0; i < N; i++) + for(MKL_INT i = 0; i < p.N; i++) { - x_axis[i] = (double)(i) / (N - 1); + x_axis[i] = (double)(i) / (p.N - 1); P[i] = x1[i]; - Phi[i] = x1[i + N]; + Phi[i] = x1[i + p.N]; } plt::figure(); diff --git a/set_MKL_env_win.bat b/set_MKL_env_win.bat index 9b81d95..c30ba4d 100644 --- a/set_MKL_env_win.bat +++ b/set_MKL_env_win.bat @@ -1 +1,5 @@ -"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" ia32 +REM ==== 64 bit ==== +"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64 + +REM ==== 32 bit ==== +REM "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" ia32 From 09d6ec3a9edfa43eb9f8ba880f9afde417c40dd5 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 19 Sep 2019 11:34:08 +0100 Subject: [PATCH 050/274] Updated installation instructions for Mac --- README.md | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 73adb2e..4faec60 100644 --- a/README.md +++ b/README.md @@ -86,14 +86,14 @@ The easiest way to install the library and compile all examples is just to creat cd dae-cpp mkdir build cd build -cmake -DCMAKE_INSTALL_PREFIX=/install_path .. +cmake .. -DCMAKE_INSTALL_PREFIX=/install_path make make install ``` where `/install_path` is the user-defined path where the package should be installed. -Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`.. +Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`. Instead of `cmake -DCMAKE_INSTALL_PREFIX=/install_path ..` you might consider using `ccmake ..`, a GUI for `cmake` that will allow you to see all the options available before building the solver. @@ -126,14 +126,7 @@ Download and install compiler (e.g. [Microsoft Visual Studio](https://visualstud Download and install [Git](https://git-scm.com/download/win) and [CMake](https://cmake.org/download/) for Windows. -Note if you install `git` for the first time you will need to configure it. Start `Git Bash` and use the following commands (change `Your Name` and `your@email` to your full name and email): - -```bash -git config --global user.name "Your Name" -git config --global user.email your@email -``` - -Then from `Git Bash` command line clone dae-cpp library (you may need to create a working directory first): +From `Git Bash` command line clone dae-cpp library (you may need to create a working directory first): ```bash git clone https://github.com/ikorotkin/dae-cpp.git @@ -157,11 +150,11 @@ An example of default solution file for Microsoft Visual Studio 15 (2017) is giv ### Mac -Make sure you have installed: `git`, `cmake` and, optional, Python 3 with `numpy` and `matplotlib` modules (for plotting). If these packages are not installed yet, you may install [Homebrew](https://brew.sh/) (package manager for macOS), then install all necessary packages: +Make sure you have installed: `git`, `cmake`, `gcc` and, optional, Python 3 with `numpy` and `matplotlib` modules (for plotting). If these packages are not installed yet, you may install [Homebrew](https://brew.sh/) (package manager for macOS), then install all necessary packages: ```bash -brew install cmake git python -pip install numpy matplotlib +brew install cmake git gcc python +pip3 install numpy matplotlib ``` Note if you install `git` for the first time you will need to configure it (change `Your Name` and `your@email` to your full name and email): @@ -171,43 +164,41 @@ git config --global user.name "Your Name" git config --global user.email your@email ``` -Then from a working directory download dae-cpp library source files: +Then from the working directory download dae-cpp library source files: ```bash git clone https://github.com/ikorotkin/dae-cpp.git ``` -The easiest way to install the library and compile all examples is just to create the build directory, then execute `cmake` (providing installation path) and `make`: +Check the version of `gcc` compiler by typing `gcc` and pressing `Tab` key a few times in the terminal, it will show you the version of `gcc` currently installed, for example, `gcc-9` (you could use the command `gcc --version` but it may point to `clang` compiler for Mac that does not support OpenMP out of the box). + +Create `build` directory: ```bash cd dae-cpp mkdir build cd build -cmake -DCMAKE_INSTALL_PREFIX=/install_path .. -make -make install ``` -where `/install_path` is the user-defined path where the package should be installed. +Configure the project. *Make sure `g++` and `gcc` versions (9 in the example below) are correct*: -Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`.. +```bash +cmake .. -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_CC_COMPILER=gcc-9 -DCMAKE_INSTALL_PREFIX=$PWD +``` -Instead of `cmake -DCMAKE_INSTALL_PREFIX=/install_path ..` you might consider using `ccmake ..`, a GUI for `cmake` that will allow you to see all the options available before building the solver. +In the command above you may change the user-defined path where the package should be installed (type it instead of `$PWD`). By default the package will be installed into the current `build` directory. -*Note* that Apple-provided default C++ compiler (`clang`) does not support OpenMP out of the box. So you may need to install either OpenMP for `clang` or an alternative C++ compiler (e.g. `gcc`): +Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`. -```bash -brew install llvm libomp -``` +Instead of `cmake ..` you may consider using `ccmake ..`, a UI for `cmake` that will allow you to see and change all the options available before building the solver. -or +Install dae-cpp: ```bash -brew install gcc +make -j2 +make install ``` -If alternative compiler is installed (for example, `gcc-7`), provide its name for `cmake` using the following options: `-DCMAKE_CXX_COMPILER=g++-7` and `-DCMAKE_CC_COMPILER=gcc-7`. - ## How to use Please refer to [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. From e0c27d80419f82effdf42177e68b9d6b3adb7b14 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 24 Sep 2019 14:54:30 +0100 Subject: [PATCH 051/274] Minor changes in the installation instructions --- README.md | 15 ++++++++------- set_MKL_env | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4faec60..8ef045b 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ BDF time stepper reduces the original DAE system to a system of nonlinear equati ## Installation -This is a cross-platform software that should work on both Linux (e.g. Ubuntu) and Windows. It should work under macOS as well (but not tested yet). The main library (DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS, the latest version and Full Package. +This is a cross-platform software that should work on Linux (e.g. Ubuntu), Windows and macOS. The main library (DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS, the latest version and Full Package. An alternative and probably the most convenient way to download and install Intel MKL on Ubuntu (using APT Repository) is the following. @@ -132,15 +132,15 @@ From `Git Bash` command line clone dae-cpp library (you may need to create a wor git clone https://github.com/ikorotkin/dae-cpp.git ``` -Start CMake (`cmake-gui`), choose the source code path (`dae-cpp` folder) and the target directory (it will contain Visual Studio project files). Press "Configure" button. +Start CMake (`cmake-gui`), choose the source code path (`dae-cpp` folder) and empty target directory (it will contain Visual Studio project files). Press "Configure" button. If CMake cannot find any of the libraries, it will print an error message. You can modify the paths and other parameters (see [More building options](https://github.com/ikorotkin/dae-cpp#more-building-options) above) and re-configure the project. If configuration is successful, press "Configure" again to update the cache and then "Generate". In the target directory you will find Visual Studio project files. -Double-click on `dae-cpp.sln` to open Visual Studio with the project. Do not forget to change Solution Configuration from `Debug` to `Release`. Compile the solution (`F7` by default). After compilation, the executable files can be found in `Release` folder. +Double-click on `dae-cpp.sln` to open Visual Studio with the project. Do not forget to change Solution Configuration from `Debug` to `Release`. Build the solution (`F7` by default). After compilation, the executable files can be found in `Release` folder. -Note that in order to execute the tests (for example, `robertson.exe`) from `Release` folder, you need to set up Intel MKL environment variables by executing `mklvars.bat intel64` or `mklvars.bat ia32` (depending on the target platform) from `cmd`. By default `mklvars.bat` is located in MKL root folder in `bin` subdirectory, for example: +Note that in order to execute the tests (for example, `perovskite.exe`) from `Release` folder, you need to set up Intel MKL environment variables by executing `mklvars.bat intel64` or `mklvars.bat ia32` (depending on the target platform) from `cmd`. By default `mklvars.bat` is located in MKL root folder in `bin` subdirectory, for example: ```bash "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64 @@ -192,11 +192,12 @@ Note that `cmake` will try to find Intel MKL at its default location `/opt/intel Instead of `cmake ..` you may consider using `ccmake ..`, a UI for `cmake` that will allow you to see and change all the options available before building the solver. -Install dae-cpp: +Install dae-cpp and perform a quick self test: ```bash make -j2 make install +ctest ``` ## How to use @@ -295,7 +296,7 @@ int status = solve(x, t1); Here *t*1 is the integration time (0 < *t* < *t*1), and **x** is the initial condition vector defined above. -The solver returns 0 if integration is successful or error code otherwise. Solution at time *t*1 will be written into vector **x** (initial conditions will be overwritten). The actual integration time *t*1 will be returned (in case the solver terminates integration earlier). That's it! +The solver returns 0 if integration is successful or error code otherwise. Solution at time *t*1 will be written into vector **x** (initial conditions will be overwritten). The actual integration time *t*1 will be returned (the solver may terminate integration earlier). That's it! #### Optional: Set up Observer @@ -316,7 +317,7 @@ But a proper (and more efficient) way to get intermediate results is to override ### Step 7 (optional). Plot results -Solution can be visualised using a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module. For example, if `python`, `numpy` and `matplotlib` are installed, the [perovskite](https://github.com/ikorotkin/dae-cpp/tree/master/examples/perovskite) example will produce the following plot: +Solution can be visualised using a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module. For example, if `python`, `numpy` and `matplotlib` are installed and the solver was built with `PLOTTING=ON`, the [perovskite](https://github.com/ikorotkin/dae-cpp/tree/master/examples/perovskite) example will produce the following plot:

diff --git a/set_MKL_env b/set_MKL_env index 2bbfd07..9af3b36 100644 --- a/set_MKL_env +++ b/set_MKL_env @@ -1,2 +1,2 @@ # Default Intel MKL library path -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/intel/mkl/lib/intel64/:/opt/intel/lib/intel64/:/opt/intel/mkl/lib:/opt/intel/lib +source /opt/intel/mkl/bin/mklvars.sh intel64 From 65a4e07339874b39d3c4ef1811eaedcb42deff87 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 7 Oct 2019 12:17:00 +0100 Subject: [PATCH 052/274] Fix clang-tidy warnings --- clang-tidy.sh | 8 ++++---- src/solver.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clang-tidy.sh b/clang-tidy.sh index 6f86468..08098bf 100755 --- a/clang-tidy.sh +++ b/clang-tidy.sh @@ -1,5 +1,5 @@ #!/bin/bash -clang-tidy-6.0 src/*.cpp -- -I/opt/intel/mkl/include -clang-tidy-6.0 examples/perovskite/*.cpp -- -I/opt/intel/mkl/include -clang-tidy-6.0 examples/diffusion_2d/*.cpp -- -I/opt/intel/mkl/include -clang-tidy-6.0 examples/robertson/*.cpp -- -I/opt/intel/mkl/include +clang-tidy-6.0 src/*.cpp -- -I./src -I/opt/intel/mkl/include +clang-tidy-6.0 examples/perovskite/*.cpp -- -I./src -I./examples/perovskite -I/opt/intel/mkl/include +clang-tidy-6.0 examples/diffusion_2d/*.cpp -- -I./src -I./examples/diffusion_2d -I/opt/intel/mkl/include +clang-tidy-6.0 examples/robertson/*.cpp -- -I./src -I./examples/robertson -I/opt/intel/mkl/include diff --git a/src/solver.h b/src/solver.h index faa5034..37ea705 100644 --- a/src/solver.h +++ b/src/solver.h @@ -36,11 +36,11 @@ class Solver MKL_INT m_size; // System size - size_t m_steps = 0; // Total time iteration counter - size_t m_calls = 0; // Total linear algebra solver calls counter + std::size_t m_steps = 0; // Total time iteration counter + std::size_t m_calls = 0; // Total linear algebra solver calls counter // Count the number of the DAE solver calls (for output) - size_t m_dae_solver_calls = 0; + std::size_t m_dae_solver_calls = 0; // Timers double m_timer_lin = 0; From 88d34a4243eb63ee4ec8bbcd15a947ac158f404f Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 25 Feb 2020 13:32:35 +0000 Subject: [PATCH 053/274] Exposed MKL iparm[12] (matching algorithm) in the solver options because it may conflict with parallel_fact_control option (known MKL issue) --- src/solver_options.cpp | 9 ++++++++- src/solver_options.h | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/solver_options.cpp b/src/solver_options.cpp index 276e6e8..46b2bb0 100644 --- a/src/solver_options.cpp +++ b/src/solver_options.cpp @@ -41,7 +41,9 @@ void SolverOptions::set_iparm_for_pardiso(MKL_INT *iparm) iparm[10] = 1; // Enable scaling. Default for nonsymmetric matrices. iparm[11] = 0; // Conjugate transposed/transpose solve - iparm[12] = 1; // Maximum weighted matching algorithm is switched-on + + iparm[12] = matching_alg; // Maximum weighted matching algorithm + iparm[13] = 0; // Output: Number of perturbed pivots iparm[14] = 0; // Output: Peak memory on symbolic factorization iparm[15] = 0; // Output: Permanent memory on symbolic factorization @@ -53,6 +55,11 @@ void SolverOptions::set_iparm_for_pardiso(MKL_INT *iparm) iparm[23] = parallel_fact_control; // Parallel factorization control + // Matching algorithm may lead to MKL crash if parallel_fact_control is ON + if(iparm[23] == 10) + { + iparm[12] = 0; // Disable matching + } if(iparm[23] == 1) { iparm[10] = 0; // Disable scaling diff --git a/src/solver_options.h b/src/solver_options.h index 7069437..38313cf 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -96,18 +96,23 @@ class SolverOptions // Intel MKL PARDISO parameters (iparam). More about iparam: // https://software.intel.com/en-us/mkl-developer-reference-c-pardiso-iparm-parameter - // iparam[3]: Controls preconditioned CGS. + // iparm[3]: Controls preconditioned CGS. // 0 - The factorization is always computed as required. // 31 - LU-preconditioned CGS iteration with a stopping criterion of 1.0E-3. // 61 - LU-preconditioned CGS iteration with a stopping criterion of 1.0E-6. MKL_INT preconditioned_CGS = 0; - // iparam[7]: Maximum number of iterative refinement steps. + // iparm[7]: Maximum number of iterative refinement steps. // 0 - The solver automatically performs two steps of iterative refinement. // >0 - Maximum number of iterative refinement steps that the solver // performs. MKL_INT refinement_steps = 2; + // iparm[12]: Maximum weighted matching algorithm. + // 0 - OFF + // 1 - ON (may conflict with parallel_fact_control) + MKL_INT matching_alg = 1; + // iparm[23]: Parallel factorization control. // 0 - Intel MKL PARDISO uses the classic algorithm for factorization. // 1 - Two-level factorization algorithm. This algorithm generally improves From 116a421f9f5fbd9a99e1c2a1c5b4697ea7447d59 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 20 May 2020 22:46:03 +0100 Subject: [PATCH 054/274] Updated License year and VS Code settings --- .vscode/c_cpp_properties.json | 2 +- .vscode/launch.json | 10 ++++++---- .vscode/settings.json | 3 +-- LICENSE | 3 +-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 199bbb5..fd09189 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -10,7 +10,7 @@ "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "c11", - "cppStandard": "c++17", + "cppStandard": "c++11", "intelliSenseMode": "gcc-x64" } ], diff --git a/.vscode/launch.json b/.vscode/launch.json index 6f82182..152219b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,10 +12,12 @@ "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", - //"environment": [{"LD_LIBRARY_PATH":"/opt/intel/mkl/lib/intel64/:/opt/intel/lib/intel64/"}], - "env": { - "LD_LIBRARY_PATH": "/opt/intel/mkl/lib/intel64/:/opt/intel/lib/intel64/" - }, + "environment": [ + { + "name": "LD_LIBRARY_PATH", + "value": "/opt/intel/mkl/lib/intel64/:/opt/intel/lib/intel64/" + } + ], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ diff --git a/.vscode/settings.json b/.vscode/settings.json index 974b02d..094d6e6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,5 @@ { "editor.renderWhitespace": "boundary", - "C_Cpp.updateChannel": "Insiders", "C_Cpp.clang_format_fallbackStyle": "none", - "C_Cpp.clang_format_path": "/usr/bin/clang-format-6.0" + "C_Cpp.clang_format_path": "/usr/bin/clang-format" } \ No newline at end of file diff --git a/LICENSE b/LICENSE index 5758978..adfaaa0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Ivan Korotkin +Copyright (c) 2019-2020 Ivan Korotkin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,4 +19,3 @@ 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. - From 372bf8d246f446230ac1e1779ef4ef784b413795 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 20 May 2020 23:14:13 +0100 Subject: [PATCH 055/274] Updated matplotlibcpp.h to the latest version --- src/external/matplotlib-cpp/matplotlibcpp.h | 789 ++++++++++++++++---- 1 file changed, 643 insertions(+), 146 deletions(-) diff --git a/src/external/matplotlib-cpp/matplotlibcpp.h b/src/external/matplotlib-cpp/matplotlibcpp.h index e626c4c..ea2e4fb 100644 --- a/src/external/matplotlib-cpp/matplotlibcpp.h +++ b/src/external/matplotlib-cpp/matplotlibcpp.h @@ -1,5 +1,9 @@ #pragma once +// Python headers must be included before any system headers, since +// they define _POSIX_C_SOURCE +#include + #include #include #include @@ -10,15 +14,22 @@ #include // requires c++11 support #include -#include - #ifndef WITHOUT_NUMPY # define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION # include # ifdef WITH_OPENCV -# include +# include # endif // WITH_OPENCV + +/* + * A bunch of constants were removed in OpenCV 4 in favour of enum classes, so + * define the ones we need here. + */ +# if CV_MAJOR_VERSION > 3 +# define CV_BGR2RGB cv::COLOR_BGR2RGB +# define CV_BGRA2RGBA cv::COLOR_BGRA2RGBA +# endif #endif // WITHOUT_NUMPY #if PY_MAJOR_VERSION >= 3 @@ -51,7 +62,9 @@ struct _interpreter { PyObject *s_python_function_hist; PyObject *s_python_function_imshow; PyObject *s_python_function_scatter; + PyObject *s_python_function_boxplot; PyObject *s_python_function_subplot; + PyObject *s_python_function_subplot2grid; PyObject *s_python_function_legend; PyObject *s_python_function_xlim; PyObject *s_python_function_ion; @@ -59,10 +72,13 @@ struct _interpreter { PyObject *s_python_function_ylim; PyObject *s_python_function_title; PyObject *s_python_function_axis; + PyObject *s_python_function_axvline; PyObject *s_python_function_xlabel; PyObject *s_python_function_ylabel; + PyObject *s_python_function_gca; PyObject *s_python_function_xticks; PyObject *s_python_function_yticks; + PyObject *s_python_function_tick_params; PyObject *s_python_function_grid; PyObject *s_python_function_clf; PyObject *s_python_function_errorbar; @@ -75,6 +91,7 @@ struct _interpreter { PyObject *s_python_function_text; PyObject *s_python_function_suptitle; PyObject *s_python_function_bar; + PyObject *s_python_function_colorbar; PyObject *s_python_function_subplots_adjust; @@ -183,15 +200,20 @@ struct _interpreter { s_python_function_fill_between = safe_import(pymod, "fill_between"); s_python_function_hist = safe_import(pymod,"hist"); s_python_function_scatter = safe_import(pymod,"scatter"); + s_python_function_boxplot = safe_import(pymod,"boxplot"); s_python_function_subplot = safe_import(pymod, "subplot"); + s_python_function_subplot2grid = safe_import(pymod, "subplot2grid"); s_python_function_legend = safe_import(pymod, "legend"); s_python_function_ylim = safe_import(pymod, "ylim"); s_python_function_title = safe_import(pymod, "title"); s_python_function_axis = safe_import(pymod, "axis"); + s_python_function_axvline = safe_import(pymod, "axvline"); s_python_function_xlabel = safe_import(pymod, "xlabel"); s_python_function_ylabel = safe_import(pymod, "ylabel"); + s_python_function_gca = safe_import(pymod, "gca"); s_python_function_xticks = safe_import(pymod, "xticks"); s_python_function_yticks = safe_import(pymod, "yticks"); + s_python_function_tick_params = safe_import(pymod, "tick_params"); s_python_function_grid = safe_import(pymod, "grid"); s_python_function_xlim = safe_import(pymod, "xlim"); s_python_function_ion = safe_import(pymod, "ion"); @@ -206,11 +228,11 @@ struct _interpreter { s_python_function_text = safe_import(pymod, "text"); s_python_function_suptitle = safe_import(pymod, "suptitle"); s_python_function_bar = safe_import(pymod,"bar"); + s_python_function_colorbar = PyObject_GetAttrString(pymod, "colorbar"); s_python_function_subplots_adjust = safe_import(pymod,"subplots_adjust"); #ifndef WITHOUT_NUMPY s_python_function_imshow = safe_import(pymod, "imshow"); #endif - s_python_empty_tuple = PyTuple_New(0); } @@ -221,7 +243,15 @@ struct _interpreter { } // end namespace detail -// must be called before the first regular call to matplotlib to have any effect +/// Select the backend +/// +/// **NOTE:** This must be called before the first plot command to have +/// any effect. +/// +/// Mainly useful to select the non-interactive 'Agg' backend when running +/// matplotlibcpp in headless mode, for example on a machine with no display. +/// +/// See also: https://matplotlib.org/2.0.2/api/matplotlib_configuration_api.html#matplotlib.use inline void backend(const std::string& name) { detail::s_backend = name; @@ -229,6 +259,8 @@ inline void backend(const std::string& name) inline bool annotate(std::string annotation, double x, double y) { + detail::_interpreter::get(); + PyObject * xy = PyTuple_New(2); PyObject * str = PyString_FromString(annotation.c_str()); @@ -251,6 +283,8 @@ inline bool annotate(std::string annotation, double x, double y) return res; } +namespace detail { + #ifndef WITHOUT_NUMPY // Type selector for numpy array conversion template struct select_npy_type { const static NPY_TYPES type = NPY_NOTYPE; }; //Default @@ -266,29 +300,37 @@ template <> struct select_npy_type { const static NPY_TYPES type = NPY template <> struct select_npy_type { const static NPY_TYPES type = NPY_ULONG; }; template <> struct select_npy_type { const static NPY_TYPES type = NPY_UINT64; }; +// Sanity checks; comment them out or change the numpy type below if you're compiling on +// a platform where they don't apply +static_assert(sizeof(long long) == 8); +template <> struct select_npy_type { const static NPY_TYPES type = NPY_INT64; }; +static_assert(sizeof(unsigned long long) == 8); +template <> struct select_npy_type { const static NPY_TYPES type = NPY_UINT64; }; +// TODO: add int, long, etc. + template PyObject* get_array(const std::vector& v) { - detail::_interpreter::get(); //interpreter needs to be initialized for the numpy commands to work + npy_intp vsize = v.size(); NPY_TYPES type = select_npy_type::type; - if (type == NPY_NOTYPE) - { - std::vector vd(v.size()); - npy_intp vsize = v.size(); - std::copy(v.begin(),v.end(),vd.begin()); - PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, NPY_DOUBLE, (void*)(vd.data())); + if (type == NPY_NOTYPE) { + size_t memsize = v.size()*sizeof(double); + double* dp = static_cast(::malloc(memsize)); + for (size_t i=0; i(varray), NPY_ARRAY_OWNDATA); return varray; } - - npy_intp vsize = v.size(); + PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, type, (void*)(v.data())); return varray; } + template PyObject* get_2darray(const std::vector<::std::vector>& v) { - detail::_interpreter::get(); //interpreter needs to be initialized for the numpy commands to work if (v.size() < 1) throw std::runtime_error("get_2d_array v too small"); npy_intp vsize[2] = {static_cast(v.size()), @@ -323,14 +365,42 @@ PyObject* get_array(const std::vector& v) #endif // WITHOUT_NUMPY +// sometimes, for labels and such, we need string arrays +inline PyObject * get_array(const std::vector& strings) +{ + PyObject* list = PyList_New(strings.size()); + for (std::size_t i = 0; i < strings.size(); ++i) { + PyList_SetItem(list, i, PyString_FromString(strings[i].c_str())); + } + return list; +} + +// not all matplotlib need 2d arrays, some prefer lists of lists +template +PyObject* get_listlist(const std::vector>& ll) +{ + PyObject* listlist = PyList_New(ll.size()); + for (std::size_t i = 0; i < ll.size(); ++i) { + PyList_SetItem(listlist, i, get_array(ll[i])); + } + return listlist; +} + +} // namespace detail + +/// Plot a line through the given x and y data points.. +/// +/// See: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.plot.html template bool plot(const std::vector &x, const std::vector &y, const std::map& keywords) { assert(x.size() == y.size()); + detail::_interpreter::get(); + // using numpy arrays - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); // construct positional args PyObject* args = PyTuple_New(2); @@ -353,6 +423,9 @@ bool plot(const std::vector &x, const std::vector &y, const st return res; } +// TODO - it should be possible to make this work by implementing +// a non-numpy alternative for `detail::get_2darray()`. +#ifndef WITHOUT_NUMPY template void plot_surface(const std::vector<::std::vector> &x, const std::vector<::std::vector> &y, @@ -360,6 +433,8 @@ void plot_surface(const std::vector<::std::vector> &x, const std::map &keywords = std::map()) { + detail::_interpreter::get(); + // We lazily load the modules here the first time this function is called // because I'm not sure that we can assume "matplotlib installed" implies // "mpl_toolkits installed" on all platforms, and we don't want to require @@ -385,9 +460,9 @@ void plot_surface(const std::vector<::std::vector> &x, assert(y.size() == z.size()); // using numpy arrays - PyObject *xarray = get_2darray(x); - PyObject *yarray = get_2darray(y); - PyObject *zarray = get_2darray(z); + PyObject *xarray = detail::get_2darray(x); + PyObject *yarray = detail::get_2darray(y); + PyObject *zarray = detail::get_2darray(z); // construct positional args PyObject *args = PyTuple_New(3); @@ -444,15 +519,103 @@ void plot_surface(const std::vector<::std::vector> &x, Py_DECREF(kwargs); if (res) Py_DECREF(res); } +#endif // WITHOUT_NUMPY + +template +void plot3(const std::vector &x, + const std::vector &y, + const std::vector &z, + const std::map &keywords = + std::map()) +{ + detail::_interpreter::get(); + + // Same as with plot_surface: We lazily load the modules here the first time + // this function is called because I'm not sure that we can assume "matplotlib + // installed" implies "mpl_toolkits installed" on all platforms, and we don't + // want to require it for people who don't need 3d plots. + static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr; + if (!mpl_toolkitsmod) { + detail::_interpreter::get(); + + PyObject* mpl_toolkits = PyString_FromString("mpl_toolkits"); + PyObject* axis3d = PyString_FromString("mpl_toolkits.mplot3d"); + if (!mpl_toolkits || !axis3d) { throw std::runtime_error("couldnt create string"); } + + mpl_toolkitsmod = PyImport_Import(mpl_toolkits); + Py_DECREF(mpl_toolkits); + if (!mpl_toolkitsmod) { throw std::runtime_error("Error loading module mpl_toolkits!"); } + + axis3dmod = PyImport_Import(axis3d); + Py_DECREF(axis3d); + if (!axis3dmod) { throw std::runtime_error("Error loading module mpl_toolkits.mplot3d!"); } + } + + assert(x.size() == y.size()); + assert(y.size() == z.size()); + + PyObject *xarray = detail::get_array(x); + PyObject *yarray = detail::get_array(y); + PyObject *zarray = detail::get_array(z); + + // construct positional args + PyObject *args = PyTuple_New(3); + PyTuple_SetItem(args, 0, xarray); + PyTuple_SetItem(args, 1, yarray); + PyTuple_SetItem(args, 2, zarray); + + // Build up the kw args. + PyObject *kwargs = PyDict_New(); + + for (std::map::const_iterator it = keywords.begin(); + it != keywords.end(); ++it) { + PyDict_SetItemString(kwargs, it->first.c_str(), + PyString_FromString(it->second.c_str())); + } + + PyObject *fig = + PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, + detail::_interpreter::get().s_python_empty_tuple); + if (!fig) throw std::runtime_error("Call to figure() failed."); + + PyObject *gca_kwargs = PyDict_New(); + PyDict_SetItemString(gca_kwargs, "projection", PyString_FromString("3d")); + + PyObject *gca = PyObject_GetAttrString(fig, "gca"); + if (!gca) throw std::runtime_error("No gca"); + Py_INCREF(gca); + PyObject *axis = PyObject_Call( + gca, detail::_interpreter::get().s_python_empty_tuple, gca_kwargs); + + if (!axis) throw std::runtime_error("No axis"); + Py_INCREF(axis); + + Py_DECREF(gca); + Py_DECREF(gca_kwargs); + + PyObject *plot3 = PyObject_GetAttrString(axis, "plot"); + if (!plot3) throw std::runtime_error("No 3D line plot"); + Py_INCREF(plot3); + PyObject *res = PyObject_Call(plot3, args, kwargs); + if (!res) throw std::runtime_error("Failed 3D line plot"); + Py_DECREF(plot3); + + Py_DECREF(axis); + Py_DECREF(args); + Py_DECREF(kwargs); + if (res) Py_DECREF(res); +} template bool stem(const std::vector &x, const std::vector &y, const std::map& keywords) { assert(x.size() == y.size()); + detail::_interpreter::get(); + // using numpy arrays - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); // construct positional args PyObject* args = PyTuple_New(2); @@ -483,9 +646,11 @@ bool fill(const std::vector& x, const std::vector& y, const st { assert(x.size() == y.size()); + detail::_interpreter::get(); + // using numpy arrays - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); // construct positional args PyObject* args = PyTuple_New(2); @@ -514,10 +679,12 @@ bool fill_between(const std::vector& x, const std::vector& y1, assert(x.size() == y1.size()); assert(x.size() == y2.size()); + detail::_interpreter::get(); + // using numpy arrays - PyObject* xarray = get_array(x); - PyObject* y1array = get_array(y1); - PyObject* y2array = get_array(y2); + PyObject* xarray = detail::get_array(x); + PyObject* y1array = detail::get_array(y1); + PyObject* y2array = detail::get_array(y2); // construct positional args PyObject* args = PyTuple_New(3); @@ -544,8 +711,9 @@ template< typename Numeric> bool hist(const std::vector& y, long bins=10,std::string color="b", double alpha=1.0, bool cumulative=false) { + detail::_interpreter::get(); - PyObject* yarray = get_array(y); + PyObject* yarray = detail::get_array(y); PyObject* kwargs = PyDict_New(); PyDict_SetItemString(kwargs, "bins", PyLong_FromLong(bins)); @@ -569,89 +737,101 @@ bool hist(const std::vector& y, long bins=10,std::string color="b", } #ifndef WITHOUT_NUMPY - namespace internal { - void imshow(void *ptr, const NPY_TYPES type, const int rows, const int columns, const int colors, const std::map &keywords) - { - assert(type == NPY_UINT8 || type == NPY_FLOAT); - assert(colors == 1 || colors == 3 || colors == 4); - - detail::_interpreter::get(); //interpreter needs to be initialized for the numpy commands to work - - // construct args - npy_intp dims[3] = { rows, columns, colors }; - PyObject *args = PyTuple_New(1); - PyTuple_SetItem(args, 0, PyArray_SimpleNewFromData(colors == 1 ? 2 : 3, dims, type, ptr)); - - // construct keyword args - PyObject* kwargs = PyDict_New(); - for(std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) - { - PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); - } - - PyObject *res = PyObject_Call(detail::_interpreter::get().s_python_function_imshow, args, kwargs); - Py_DECREF(args); - Py_DECREF(kwargs); - if (!res) - throw std::runtime_error("Call to imshow() failed"); - Py_DECREF(res); - } - } +namespace detail { - void imshow(const unsigned char *ptr, const int rows, const int columns, const int colors, const std::map &keywords = {}) - { - internal::imshow((void *) ptr, NPY_UINT8, rows, columns, colors, keywords); - } +inline void imshow(void *ptr, const NPY_TYPES type, const int rows, const int columns, const int colors, const std::map &keywords, PyObject** out) +{ + assert(type == NPY_UINT8 || type == NPY_FLOAT); + assert(colors == 1 || colors == 3 || colors == 4); + + detail::_interpreter::get(); + + // construct args + npy_intp dims[3] = { rows, columns, colors }; + PyObject *args = PyTuple_New(1); + PyTuple_SetItem(args, 0, PyArray_SimpleNewFromData(colors == 1 ? 2 : 3, dims, type, ptr)); - void imshow(const float *ptr, const int rows, const int columns, const int colors, const std::map &keywords = {}) + // construct keyword args + PyObject* kwargs = PyDict_New(); + for(std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) { - internal::imshow((void *) ptr, NPY_FLOAT, rows, columns, colors, keywords); + PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); } -#ifdef WITH_OPENCV - void imshow(const cv::Mat &image, const std::map &keywords = {}) - { - // Convert underlying type of matrix, if needed - cv::Mat image2; - NPY_TYPES npy_type = NPY_UINT8; - switch (image.type() & CV_MAT_DEPTH_MASK) { - case CV_8U: - image2 = image; - break; - case CV_32F: - image2 = image; - npy_type = NPY_FLOAT; - break; - default: - image.convertTo(image2, CV_MAKETYPE(CV_8U, image.channels())); - } + PyObject *res = PyObject_Call(detail::_interpreter::get().s_python_function_imshow, args, kwargs); + Py_DECREF(args); + Py_DECREF(kwargs); + if (!res) + throw std::runtime_error("Call to imshow() failed"); + if (out) + *out = res; + else + Py_DECREF(res); +} - // If color image, convert from BGR to RGB - switch (image2.channels()) { - case 3: - cv::cvtColor(image2, image2, CV_BGR2RGB); - break; - case 4: - cv::cvtColor(image2, image2, CV_BGRA2RGBA); - } +} // namespace detail + +inline void imshow(const unsigned char *ptr, const int rows, const int columns, const int colors, const std::map &keywords = {}, PyObject** out = nullptr) +{ + detail::imshow((void *) ptr, NPY_UINT8, rows, columns, colors, keywords, out); +} - internal::imshow(image2.data, npy_type, image2.rows, image2.cols, image2.channels(), keywords); +inline void imshow(const float *ptr, const int rows, const int columns, const int colors, const std::map &keywords = {}, PyObject** out = nullptr) +{ + detail::imshow((void *) ptr, NPY_FLOAT, rows, columns, colors, keywords, out); +} + +#ifdef WITH_OPENCV +void imshow(const cv::Mat &image, const std::map &keywords = {}) +{ + // Convert underlying type of matrix, if needed + cv::Mat image2; + NPY_TYPES npy_type = NPY_UINT8; + switch (image.type() & CV_MAT_DEPTH_MASK) { + case CV_8U: + image2 = image; + break; + case CV_32F: + image2 = image; + npy_type = NPY_FLOAT; + break; + default: + image.convertTo(image2, CV_MAKETYPE(CV_8U, image.channels())); + } + + // If color image, convert from BGR to RGB + switch (image2.channels()) { + case 3: + cv::cvtColor(image2, image2, CV_BGR2RGB); + break; + case 4: + cv::cvtColor(image2, image2, CV_BGRA2RGBA); } + + detail::imshow(image2.data, npy_type, image2.rows, image2.cols, image2.channels(), keywords); +} #endif // WITH_OPENCV #endif // WITHOUT_NUMPY template bool scatter(const std::vector& x, const std::vector& y, - const double s=1.0) // The marker size in points**2 + const double s=1.0, // The marker size in points**2 + const std::map & keywords = {}) { + detail::_interpreter::get(); + assert(x.size() == y.size()); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* kwargs = PyDict_New(); PyDict_SetItemString(kwargs, "s", PyLong_FromLong(s)); + for (const auto& it : keywords) + { + PyDict_SetItemString(kwargs, it.first.c_str(), PyString_FromString(it.second.c_str())); + } PyObject* plot_args = PyTuple_New(2); PyTuple_SetItem(plot_args, 0, xarray); @@ -666,39 +846,127 @@ bool scatter(const std::vector& x, return res; } -template< typename Numeric> -bool bar(const std::vector& y, std::string ec = "black", std::string ls = "-", double lw = 1.0, - const std::map& keywords = {}) +template +bool boxplot(const std::vector>& data, + const std::vector& labels = {}, + const std::map & keywords = {}) { - PyObject* yarray = get_array(y); - - std::vector x; - for (int i = 0; i < y.size(); i++) - x.push_back(i); + detail::_interpreter::get(); - PyObject* xarray = get_array(x); + PyObject* listlist = detail::get_listlist(data); + PyObject* args = PyTuple_New(1); + PyTuple_SetItem(args, 0, listlist); PyObject* kwargs = PyDict_New(); - PyDict_SetItemString(kwargs, "ec", PyString_FromString(ec.c_str())); - PyDict_SetItemString(kwargs, "ls", PyString_FromString(ls.c_str())); - PyDict_SetItemString(kwargs, "lw", PyFloat_FromDouble(lw)); + // kwargs needs the labels, if there are (the correct number of) labels + if (!labels.empty() && labels.size() == data.size()) { + PyDict_SetItemString(kwargs, "labels", detail::get_array(labels)); + } - PyObject* plot_args = PyTuple_New(2); - PyTuple_SetItem(plot_args, 0, xarray); - PyTuple_SetItem(plot_args, 1, yarray); + // take care of the remaining keywords + for (const auto& it : keywords) + { + PyDict_SetItemString(kwargs, it.first.c_str(), PyString_FromString(it.second.c_str())); + } - PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_bar, plot_args, kwargs); + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_boxplot, args, kwargs); - Py_DECREF(plot_args); + Py_DECREF(args); Py_DECREF(kwargs); + + if(res) Py_DECREF(res); + + return res; +} + +template +bool boxplot(const std::vector& data, + const std::map & keywords = {}) +{ + detail::_interpreter::get(); + + PyObject* vector = detail::get_array(data); + PyObject* args = PyTuple_New(1); + PyTuple_SetItem(args, 0, vector); + + PyObject* kwargs = PyDict_New(); + for (const auto& it : keywords) + { + PyDict_SetItemString(kwargs, it.first.c_str(), PyString_FromString(it.second.c_str())); + } + + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_boxplot, args, kwargs); + + Py_DECREF(args); + Py_DECREF(kwargs); + if(res) Py_DECREF(res); return res; } +template +bool bar(const std::vector & x, + const std::vector & y, + std::string ec = "black", + std::string ls = "-", + double lw = 1.0, + const std::map & keywords = {}) +{ + detail::_interpreter::get(); + + PyObject * xarray = detail::get_array(x); + PyObject * yarray = detail::get_array(y); + + PyObject * kwargs = PyDict_New(); + + PyDict_SetItemString(kwargs, "ec", PyString_FromString(ec.c_str())); + PyDict_SetItemString(kwargs, "ls", PyString_FromString(ls.c_str())); + PyDict_SetItemString(kwargs, "lw", PyFloat_FromDouble(lw)); + + for (std::map::const_iterator it = + keywords.begin(); + it != keywords.end(); + ++it) { + PyDict_SetItemString( + kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); + } + + PyObject * plot_args = PyTuple_New(2); + PyTuple_SetItem(plot_args, 0, xarray); + PyTuple_SetItem(plot_args, 1, yarray); + + PyObject * res = PyObject_Call( + detail::_interpreter::get().s_python_function_bar, plot_args, kwargs); + + Py_DECREF(plot_args); + Py_DECREF(kwargs); + if (res) Py_DECREF(res); + + return res; +} + +template +bool bar(const std::vector & y, + std::string ec = "black", + std::string ls = "-", + double lw = 1.0, + const std::map & keywords = {}) +{ + using T = typename std::remove_reference::type::value_type; + + detail::_interpreter::get(); + + std::vector x; + for (std::size_t i = 0; i < y.size(); i++) { x.push_back(i); } + + return bar(x, y, ec, ls, lw, keywords); +} + inline bool subplots_adjust(const std::map& keywords = {}) { + detail::_interpreter::get(); PyObject* kwargs = PyDict_New(); for (std::map::const_iterator it = @@ -722,7 +990,9 @@ inline bool subplots_adjust(const std::map& keywords = {}) template< typename Numeric> bool named_hist(std::string label,const std::vector& y, long bins=10, std::string color="b", double alpha=1.0) { - PyObject* yarray = get_array(y); + detail::_interpreter::get(); + + PyObject* yarray = detail::get_array(y); PyObject* kwargs = PyDict_New(); PyDict_SetItemString(kwargs, "label", PyString_FromString(label.c_str())); @@ -748,8 +1018,10 @@ bool plot(const std::vector& x, const std::vector& y, const { assert(x.size() == y.size()); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + detail::_interpreter::get(); + + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(s.c_str()); @@ -771,10 +1043,12 @@ bool quiver(const std::vector& x, const std::vector& y, cons { assert(x.size() == y.size() && x.size() == u.size() && u.size() == w.size()); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); - PyObject* uarray = get_array(u); - PyObject* warray = get_array(w); + detail::_interpreter::get(); + + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); + PyObject* uarray = detail::get_array(u); + PyObject* warray = detail::get_array(w); PyObject* plot_args = PyTuple_New(4); PyTuple_SetItem(plot_args, 0, xarray); @@ -805,8 +1079,10 @@ bool stem(const std::vector& x, const std::vector& y, const { assert(x.size() == y.size()); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + detail::_interpreter::get(); + + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(s.c_str()); @@ -830,8 +1106,10 @@ bool semilogx(const std::vector& x, const std::vector& y, co { assert(x.size() == y.size()); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + detail::_interpreter::get(); + + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(s.c_str()); @@ -853,8 +1131,10 @@ bool semilogy(const std::vector& x, const std::vector& y, co { assert(x.size() == y.size()); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + detail::_interpreter::get(); + + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(s.c_str()); @@ -876,8 +1156,10 @@ bool loglog(const std::vector& x, const std::vector& y, cons { assert(x.size() == y.size()); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + detail::_interpreter::get(); + + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(s.c_str()); @@ -899,9 +1181,11 @@ bool errorbar(const std::vector &x, const std::vector &y, co { assert(x.size() == y.size()); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); - PyObject* yerrarray = get_array(yerr); + detail::_interpreter::get(); + + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); + PyObject* yerrarray = detail::get_array(yerr); // construct keyword args PyObject* kwargs = PyDict_New(); @@ -932,10 +1216,12 @@ bool errorbar(const std::vector &x, const std::vector &y, co template bool named_plot(const std::string& name, const std::vector& y, const std::string& format = "") { + detail::_interpreter::get(); + PyObject* kwargs = PyDict_New(); PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str())); - PyObject* yarray = get_array(y); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(format.c_str()); @@ -956,11 +1242,13 @@ bool named_plot(const std::string& name, const std::vector& y, const st template bool named_plot(const std::string& name, const std::vector& x, const std::vector& y, const std::string& format = "") { + detail::_interpreter::get(); + PyObject* kwargs = PyDict_New(); PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str())); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(format.c_str()); @@ -981,11 +1269,13 @@ bool named_plot(const std::string& name, const std::vector& x, const st template bool named_semilogx(const std::string& name, const std::vector& x, const std::vector& y, const std::string& format = "") { + detail::_interpreter::get(); + PyObject* kwargs = PyDict_New(); PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str())); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(format.c_str()); @@ -1006,11 +1296,13 @@ bool named_semilogx(const std::string& name, const std::vector& x, cons template bool named_semilogy(const std::string& name, const std::vector& x, const std::vector& y, const std::string& format = "") { + detail::_interpreter::get(); + PyObject* kwargs = PyDict_New(); PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str())); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(format.c_str()); @@ -1031,11 +1323,13 @@ bool named_semilogy(const std::string& name, const std::vector& x, cons template bool named_loglog(const std::string& name, const std::vector& x, const std::vector& y, const std::string& format = "") { + detail::_interpreter::get(); + PyObject* kwargs = PyDict_New(); PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str())); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(format.c_str()); @@ -1043,7 +1337,6 @@ bool named_loglog(const std::string& name, const std::vector& x, const PyTuple_SetItem(plot_args, 0, xarray); PyTuple_SetItem(plot_args, 1, yarray); PyTuple_SetItem(plot_args, 2, pystring); - PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_loglog, plot_args, kwargs); Py_DECREF(kwargs); @@ -1080,6 +1373,8 @@ bool stem(const std::vector& y, const std::string& format = "") template void text(Numeric x, Numeric y, const std::string& s = "") { + detail::_interpreter::get(); + PyObject* args = PyTuple_New(3); PyTuple_SetItem(args, 0, PyFloat_FromDouble(x)); PyTuple_SetItem(args, 1, PyFloat_FromDouble(y)); @@ -1092,9 +1387,35 @@ void text(Numeric x, Numeric y, const std::string& s = "") Py_DECREF(res); } +inline void colorbar(PyObject* mappable = NULL, const std::map& keywords = {}) +{ + if (mappable == NULL) + throw std::runtime_error("Must call colorbar with PyObject* returned from an image, contour, surface, etc."); + + detail::_interpreter::get(); + + PyObject* args = PyTuple_New(1); + PyTuple_SetItem(args, 0, mappable); + + PyObject* kwargs = PyDict_New(); + for(std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) + { + PyDict_SetItemString(kwargs, it->first.c_str(), PyFloat_FromDouble(it->second)); + } + + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_colorbar, args, kwargs); + if(!res) throw std::runtime_error("Call to colorbar() failed."); + + Py_DECREF(args); + Py_DECREF(kwargs); + Py_DECREF(res); +} + inline long figure(long number = -1) { + detail::_interpreter::get(); + PyObject *res; if (number == -1) res = PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, detail::_interpreter::get().s_python_empty_tuple); @@ -1124,7 +1445,6 @@ inline long figure(long number = -1) inline bool fignum_exists(long number) { - // Make sure interpreter is initialised detail::_interpreter::get(); PyObject *args = PyTuple_New(1); @@ -1141,7 +1461,6 @@ inline bool fignum_exists(long number) inline void figure_size(size_t w, size_t h) { - // Make sure interpreter is initialised detail::_interpreter::get(); const size_t dpi = 100; @@ -1164,6 +1483,8 @@ inline void figure_size(size_t w, size_t h) inline void legend() { + detail::_interpreter::get(); + PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_legend, detail::_interpreter::get().s_python_empty_tuple); if(!res) throw std::runtime_error("Call to legend() failed."); @@ -1173,6 +1494,8 @@ inline void legend() template void ylim(Numeric left, Numeric right) { + detail::_interpreter::get(); + PyObject* list = PyList_New(2); PyList_SetItem(list, 0, PyFloat_FromDouble(left)); PyList_SetItem(list, 1, PyFloat_FromDouble(right)); @@ -1190,6 +1513,8 @@ void ylim(Numeric left, Numeric right) template void xlim(Numeric left, Numeric right) { + detail::_interpreter::get(); + PyObject* list = PyList_New(2); PyList_SetItem(list, 0, PyFloat_FromDouble(left)); PyList_SetItem(list, 1, PyFloat_FromDouble(right)); @@ -1207,6 +1532,8 @@ void xlim(Numeric left, Numeric right) inline double* xlim() { + detail::_interpreter::get(); + PyObject* args = PyTuple_New(0); PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_xlim, args); PyObject* left = PyTuple_GetItem(res,0); @@ -1225,6 +1552,8 @@ inline double* xlim() inline double* ylim() { + detail::_interpreter::get(); + PyObject* args = PyTuple_New(0); PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_ylim, args); PyObject* left = PyTuple_GetItem(res,0); @@ -1245,8 +1574,10 @@ inline void xticks(const std::vector &ticks, const std::vector &ticks, const std::vector &ticks, const std::map& keywords, const std::string axis = "both") +{ + detail::_interpreter::get(); + + // construct positional args + PyObject* args; + args = PyTuple_New(1); + PyTuple_SetItem(args, 0, PyString_FromString(axis.c_str())); + + // construct keyword args + PyObject* kwargs = PyDict_New(); + for (std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) + { + PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); + } + + + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_tick_params, args, kwargs); + + Py_DECREF(args); + Py_DECREF(kwargs); + if (!res) throw std::runtime_error("Call to tick_params() failed"); + + Py_DECREF(res); +} + inline void subplot(long nrows, long ncols, long plot_number) { + detail::_interpreter::get(); + // construct positional args PyObject* args = PyTuple_New(3); PyTuple_SetItem(args, 0, PyFloat_FromDouble(nrows)); @@ -1349,8 +1710,37 @@ inline void subplot(long nrows, long ncols, long plot_number) Py_DECREF(res); } +inline void subplot2grid(long nrows, long ncols, long rowid=0, long colid=0, long rowspan=1, long colspan=1) +{ + detail::_interpreter::get(); + + PyObject* shape = PyTuple_New(2); + PyTuple_SetItem(shape, 0, PyLong_FromLong(nrows)); + PyTuple_SetItem(shape, 1, PyLong_FromLong(ncols)); + + PyObject* loc = PyTuple_New(2); + PyTuple_SetItem(loc, 0, PyLong_FromLong(rowid)); + PyTuple_SetItem(loc, 1, PyLong_FromLong(colid)); + + PyObject* args = PyTuple_New(4); + PyTuple_SetItem(args, 0, shape); + PyTuple_SetItem(args, 1, loc); + PyTuple_SetItem(args, 2, PyLong_FromLong(rowspan)); + PyTuple_SetItem(args, 3, PyLong_FromLong(colspan)); + + PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_subplot2grid, args); + if(!res) throw std::runtime_error("Call to subplot2grid() failed."); + + Py_DECREF(shape); + Py_DECREF(loc); + Py_DECREF(args); + Py_DECREF(res); +} + inline void title(const std::string &titlestr, const std::map &keywords = {}) { + detail::_interpreter::get(); + PyObject* pytitlestr = PyString_FromString(titlestr.c_str()); PyObject* args = PyTuple_New(1); PyTuple_SetItem(args, 0, pytitlestr); @@ -1370,6 +1760,8 @@ inline void title(const std::string &titlestr, const std::map &keywords = {}) { + detail::_interpreter::get(); + PyObject* pysuptitlestr = PyString_FromString(suptitlestr.c_str()); PyObject* args = PyTuple_New(1); PyTuple_SetItem(args, 0, pysuptitlestr); @@ -1389,6 +1781,8 @@ inline void suptitle(const std::string &suptitlestr, const std::map& keywords = std::map()) +{ + detail::_interpreter::get(); + + // construct positional args + PyObject* args = PyTuple_New(3); + PyTuple_SetItem(args, 0, PyFloat_FromDouble(x)); + PyTuple_SetItem(args, 1, PyFloat_FromDouble(ymin)); + PyTuple_SetItem(args, 2, PyFloat_FromDouble(ymax)); + + // construct keyword args + PyObject* kwargs = PyDict_New(); + for(std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) + { + PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); + } + + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_axvline, args, kwargs); + + Py_DECREF(args); + Py_DECREF(kwargs); + + if(res) Py_DECREF(res); +} + inline void xlabel(const std::string &str, const std::map &keywords = {}) { + detail::_interpreter::get(); + PyObject* pystr = PyString_FromString(str.c_str()); PyObject* args = PyTuple_New(1); PyTuple_SetItem(args, 0, pystr); @@ -1421,6 +1842,8 @@ inline void xlabel(const std::string &str, const std::map& keywords = {}) { + detail::_interpreter::get(); + PyObject* pystr = PyString_FromString(str.c_str()); PyObject* args = PyTuple_New(1); PyTuple_SetItem(args, 0, pystr); @@ -1438,8 +1861,62 @@ inline void ylabel(const std::string &str, const std::map& keywords = {}) +{ + detail::_interpreter::get(); + + // Same as with plot_surface: We lazily load the modules here the first time + // this function is called because I'm not sure that we can assume "matplotlib + // installed" implies "mpl_toolkits installed" on all platforms, and we don't + // want to require it for people who don't need 3d plots. + static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr; + if (!mpl_toolkitsmod) { + PyObject* mpl_toolkits = PyString_FromString("mpl_toolkits"); + PyObject* axis3d = PyString_FromString("mpl_toolkits.mplot3d"); + if (!mpl_toolkits || !axis3d) { throw std::runtime_error("couldnt create string"); } + + mpl_toolkitsmod = PyImport_Import(mpl_toolkits); + Py_DECREF(mpl_toolkits); + if (!mpl_toolkitsmod) { throw std::runtime_error("Error loading module mpl_toolkits!"); } + + axis3dmod = PyImport_Import(axis3d); + Py_DECREF(axis3d); + if (!axis3dmod) { throw std::runtime_error("Error loading module mpl_toolkits.mplot3d!"); } + } + + PyObject* pystr = PyString_FromString(str.c_str()); + PyObject* args = PyTuple_New(1); + PyTuple_SetItem(args, 0, pystr); + + PyObject* kwargs = PyDict_New(); + for (auto it = keywords.begin(); it != keywords.end(); ++it) { + PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); + } + + PyObject *ax = + PyObject_CallObject(detail::_interpreter::get().s_python_function_gca, + detail::_interpreter::get().s_python_empty_tuple); + if (!ax) throw std::runtime_error("Call to gca() failed."); + Py_INCREF(ax); + + PyObject *zlabel = PyObject_GetAttrString(ax, "set_zlabel"); + if (!zlabel) throw std::runtime_error("Attribute set_zlabel not found."); + Py_INCREF(zlabel); + + PyObject *res = PyObject_Call(zlabel, args, kwargs); + if (!res) throw std::runtime_error("Call to set_zlabel() failed."); + Py_DECREF(zlabel); + + Py_DECREF(ax); + Py_DECREF(args); + Py_DECREF(kwargs); + if (res) Py_DECREF(res); +} + inline void grid(bool flag) { + detail::_interpreter::get(); + PyObject* pyflag = flag ? Py_True : Py_False; Py_INCREF(pyflag); @@ -1455,6 +1932,8 @@ inline void grid(bool flag) inline void show(const bool block = true) { + detail::_interpreter::get(); + PyObject* res; if(block) { @@ -1478,6 +1957,8 @@ inline void show(const bool block = true) inline void close() { + detail::_interpreter::get(); + PyObject* res = PyObject_CallObject( detail::_interpreter::get().s_python_function_close, detail::_interpreter::get().s_python_empty_tuple); @@ -1488,6 +1969,8 @@ inline void close() } inline void xkcd() { + detail::_interpreter::get(); + PyObject* res; PyObject *kwargs = PyDict_New(); @@ -1504,6 +1987,8 @@ inline void xkcd() { inline void draw() { + detail::_interpreter::get(); + PyObject* res = PyObject_CallObject( detail::_interpreter::get().s_python_function_draw, detail::_interpreter::get().s_python_empty_tuple); @@ -1516,6 +2001,8 @@ inline void draw() template inline void pause(Numeric interval) { + detail::_interpreter::get(); + PyObject* args = PyTuple_New(1); PyTuple_SetItem(args, 0, PyFloat_FromDouble(interval)); @@ -1528,6 +2015,8 @@ inline void pause(Numeric interval) inline void save(const std::string& filename) { + detail::_interpreter::get(); + PyObject* pyfilename = PyString_FromString(filename.c_str()); PyObject* args = PyTuple_New(1); @@ -1541,6 +2030,8 @@ inline void save(const std::string& filename) } inline void clf() { + detail::_interpreter::get(); + PyObject *res = PyObject_CallObject( detail::_interpreter::get().s_python_function_clf, detail::_interpreter::get().s_python_empty_tuple); @@ -1550,7 +2041,9 @@ inline void clf() { Py_DECREF(res); } - inline void ion() { +inline void ion() { + detail::_interpreter::get(); + PyObject *res = PyObject_CallObject( detail::_interpreter::get().s_python_function_ion, detail::_interpreter::get().s_python_empty_tuple); @@ -1562,6 +2055,8 @@ inline void clf() { inline std::vector> ginput(const int numClicks = 1, const std::map& keywords = {}) { + detail::_interpreter::get(); + PyObject *args = PyTuple_New(1); PyTuple_SetItem(args, 0, PyLong_FromLong(numClicks)); @@ -1596,6 +2091,8 @@ inline std::vector> ginput(const int numClicks = 1, const // Actually, is there any reason not to call this automatically for every plot? inline void tight_layout() { + detail::_interpreter::get(); + PyObject *res = PyObject_CallObject( detail::_interpreter::get().s_python_function_tight_layout, detail::_interpreter::get().s_python_empty_tuple); @@ -1737,13 +2234,13 @@ inline bool plot(const std::vector& x, const std::vector& y, con /* * This class allows dynamic plots, ie changing the plotted data without clearing and re-plotting */ - class Plot { public: // default initialization with plot label, some data and format template Plot(const std::string& name, const std::vector& x, const std::vector& y, const std::string& format = "") { + detail::_interpreter::get(); assert(x.size() == y.size()); @@ -1751,8 +2248,8 @@ class Plot if(name != "") PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str())); - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* pystring = PyString_FromString(format.c_str()); @@ -1788,8 +2285,8 @@ class Plot assert(x.size() == y.size()); if(set_data_fct) { - PyObject* xarray = get_array(x); - PyObject* yarray = get_array(y); + PyObject* xarray = detail::get_array(x); + PyObject* yarray = detail::get_array(y); PyObject* plot_args = PyTuple_New(2); PyTuple_SetItem(plot_args, 0, xarray); From 6b8473c85e80e1500b40dd0e7b5c25d22bfe4ec7 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 20 May 2020 23:38:04 +0100 Subject: [PATCH 056/274] Updated clang-format and clang-tidy --- .clang-format | 8 ++++---- clang-tidy.sh | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.clang-format b/.clang-format index 065398c..e298ffc 100644 --- a/.clang-format +++ b/.clang-format @@ -120,10 +120,10 @@ PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Right -RawStringFormats: - - Delimiter: pb - Language: TextProto - BasedOnStyle: google +# RawStringFormats: +# - Delimiter: pb +# Language: TextProto +# BasedOnStyle: google ReflowComments: true diff --git a/clang-tidy.sh b/clang-tidy.sh index 08098bf..e05ce6e 100755 --- a/clang-tidy.sh +++ b/clang-tidy.sh @@ -1,5 +1,18 @@ #!/bin/bash -clang-tidy-6.0 src/*.cpp -- -I./src -I/opt/intel/mkl/include -clang-tidy-6.0 examples/perovskite/*.cpp -- -I./src -I./examples/perovskite -I/opt/intel/mkl/include -clang-tidy-6.0 examples/diffusion_2d/*.cpp -- -I./src -I./examples/diffusion_2d -I/opt/intel/mkl/include -clang-tidy-6.0 examples/robertson/*.cpp -- -I./src -I./examples/robertson -I/opt/intel/mkl/include + +# clang-tidy check +echo '==== clang-tidy ====' +clang-tidy-8 src/*.cpp -- -I./src -I/opt/intel/mkl/include +clang-tidy-8 examples/perovskite/*.cpp -- -I./src -I./examples/perovskite -I/opt/intel/mkl/include +clang-tidy-8 examples/diffusion_2d/*.cpp -- -I./src -I./examples/diffusion_2d -I/opt/intel/mkl/include +clang-tidy-8 examples/robertson/*.cpp -- -I./src -I./examples/robertson -I/opt/intel/mkl/include +echo + +# cppcheck +echo '==== cppcheck ====' +echo 'perovskite:' +cppcheck --enable=all --std=c++11 --quiet -I./src/ -I./examples/perovskite -I/opt/intel/mkl/include/ src/*.cpp examples/perovskite/*.cpp +echo 'diffusion_2d:' +cppcheck --enable=all --std=c++11 --quiet -I./src/ -I./examples/diffusion_2d -I/opt/intel/mkl/include/ src/*.cpp examples/diffusion_2d/*.cpp +echo 'robertson:' +cppcheck --enable=all --std=c++11 --quiet -I./src/ -I./examples/robertson -I/opt/intel/mkl/include/ src/*.cpp examples/robertson/*.cpp From 585e93d4e9c2783c56e0922f10df0b65feb48a20 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 21 May 2020 01:25:05 +0100 Subject: [PATCH 057/274] Added RHS vector output to a file --- src/RHS.h | 7 ++++ src/debug_output.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++ src/jacobian.cpp | 52 ------------------------- 3 files changed, 97 insertions(+), 52 deletions(-) create mode 100644 src/debug_output.cpp diff --git a/src/RHS.h b/src/RHS.h index fd40321..15e68e0 100644 --- a/src/RHS.h +++ b/src/RHS.h @@ -12,6 +12,8 @@ namespace daecpp_namespace_name class RHS { + size_t m_dump_file_counter = 0; + public: /* * Takes vector x and time t and returns vector f. @@ -28,6 +30,11 @@ class RHS { return false; } + + /* + * Helper function to write the RHS vector to a file + */ + void dump(const state_type &x, const double t); }; } // namespace daecpp_namespace_name diff --git a/src/debug_output.cpp b/src/debug_output.cpp new file mode 100644 index 0000000..08ba902 --- /dev/null +++ b/src/debug_output.cpp @@ -0,0 +1,90 @@ +/* + * A set of helper functions to print on screen or write to files + * Jacobian matrix, Mass matrix, the RHS for debugging purposes. + */ + +#include // std::cout +#include // std::setw etc. +#include // File output +#include // std::string, std::to_string + +#include "RHS.h" +#include "jacobian.h" + +namespace daecpp_namespace_name +{ + +const char delimiter = '\t'; // Delimiter of columns in output text files + +/* + * Helper function to write the RHS vector to a file + */ +void RHS::dump(const state_type &x, const double t) +{ + const MKL_INT size = x.size(); + + state_type f(size); // the vector to be saved + + this->operator()(x, f, t); // calls the RHS + + std::ofstream outFile; + + outFile.open("dump_RHS_" + std::to_string(m_dump_file_counter++) + ".txt"); + outFile << "t = " << t << '\n'; + outFile << "i" << delimiter << "x[i]" << delimiter << "RHS[i]" << '\n'; + for(MKL_INT i = 0; i < size; i++) + outFile << i << delimiter << x[i] << delimiter << f[i] << '\n'; + outFile.close(); +} + +/* + * Helper function to show Jacobian structure + */ +void Jacobian::print(const state_type &x, const double t) +{ + if(x.size() > 1000) + { + std::cout << "\nJacobian::print -- too much output. Skipped.\n"; + return; + } + + sparse_matrix_holder J; + + this->operator()(J, x, t); + + std::cout << std::right; + std::cout << "\nJacobian matrix at time t = " << t << ':'; + std::cout << "\n-----------------------------------------\n"; + std::cout << std::setw(7) << "i" << std::setw(16) << "J.A |" + << std::setw(10) << "J.ja |" << std::setw(8) << "J.ia"; + std::cout << "\n-----------------------------------------\n"; + + size_t size = (J.A.size() > J.ia.size()) ? J.A.size() : J.ia.size(); + + for(std::size_t i = 0; i < size; i++) + { + std::cout << std::setw(7) << i << ": "; + std::cout << std::setw(12); + + if(i < J.A.size()) + std::cout << J.A[i]; + else + std::cout << ' '; + + std::cout << " | " << std::setw(7); + + if(i < J.ja.size()) + std::cout << J.ja[i]; + else + std::cout << ' '; + + std::cout << " | "; + + if(i < J.ia.size()) + std::cout << std::setw(7) << J.ia[i]; + + std::cout << std::endl; + } +} + +} // namespace daecpp_namespace_name diff --git a/src/jacobian.cpp b/src/jacobian.cpp index 25ba9cb..dd9b8db 100644 --- a/src/jacobian.cpp +++ b/src/jacobian.cpp @@ -3,8 +3,6 @@ * estimate numerical Jacobian matrix */ -#include // std::cout -#include // std::setw etc. #include // std::abs #include // std::copy @@ -176,54 +174,4 @@ void Jacobian::operator()(sparse_matrix_holder &J, const state_type &x, J.ia.push_back(ci); } -/* - * Helper function to show Jacobian structure - */ -void Jacobian::print(const state_type &x, const double t) -{ - if(x.size() > 1000) - { - std::cout << "\nJacobian::print -- too much output. Skipped.\n"; - return; - } - - sparse_matrix_holder J; - - this->operator()(J, x, t); - - std::cout << std::right; - std::cout << "\nJacobian matrix at time t = " << t << ':'; - std::cout << "\n-----------------------------------------\n"; - std::cout << std::setw(7) << "i" << std::setw(16) << "J.A |" - << std::setw(10) << "J.ja |" << std::setw(8) << "J.ia"; - std::cout << "\n-----------------------------------------\n"; - - size_t size = (J.A.size() > J.ia.size()) ? J.A.size() : J.ia.size(); - - for(std::size_t i = 0; i < size; i++) - { - std::cout << std::setw(7) << i << ": "; - std::cout << std::setw(12); - - if(i < J.A.size()) - std::cout << J.A[i] ; - else - std::cout << ' '; - - std::cout << " | " << std::setw(7); - - if(i < J.ja.size()) - std::cout << J.ja[i]; - else - std::cout << ' '; - - std::cout << " | "; - - if(i < J.ia.size()) - std::cout << std::setw(7) << J.ia[i]; - - std::cout << std::endl; - } -} - } // namespace daecpp_namespace_name From 2adf1ccc1ff6d3d29a3ba1a08f88e7d85967f1c3 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 21 May 2020 01:30:29 +0100 Subject: [PATCH 058/274] Added RHS vector output, updated Robertson example, issue #12 --- examples/robertson/robertson.cpp | 3 +++ src/debug_output.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index 735858e..49a1fc0 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -213,6 +213,9 @@ int main() // Class MyRHS inherits abstract RHS class from dae-cpp library. MyRHS rhs; + // We can write the initial RHS to a file for debugging purposes: + rhs.dump(x, 0); + // Set up the Mass Matrix of the problem. // MyMassMatrix inherits abstract MassMatrix class from dae-cpp library. MyMassMatrix mass; diff --git a/src/debug_output.cpp b/src/debug_output.cpp index 08ba902..3f12ef1 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -30,7 +30,7 @@ void RHS::dump(const state_type &x, const double t) std::ofstream outFile; outFile.open("dump_RHS_" + std::to_string(m_dump_file_counter++) + ".txt"); - outFile << "t = " << t << '\n'; + outFile << "t = " << t << ":\n"; outFile << "i" << delimiter << "x[i]" << delimiter << "RHS[i]" << '\n'; for(MKL_INT i = 0; i < size; i++) outFile << i << delimiter << x[i] << delimiter << f[i] << '\n'; From 6541e4d6a3ccde8c22abdede0c07a6c0e0b8398b Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 21 May 2020 13:57:55 +0100 Subject: [PATCH 059/274] Added cstddef to typedefs, fixed size_t --- src/RHS.h | 2 +- src/debug_output.cpp | 2 +- src/solver.cpp | 2 +- src/time_integrator.cpp | 2 +- src/typedefs.h | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/RHS.h b/src/RHS.h index 15e68e0..3293322 100644 --- a/src/RHS.h +++ b/src/RHS.h @@ -12,7 +12,7 @@ namespace daecpp_namespace_name class RHS { - size_t m_dump_file_counter = 0; + std::size_t m_dump_file_counter = 0; public: /* diff --git a/src/debug_output.cpp b/src/debug_output.cpp index 3f12ef1..d5c0a72 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -59,7 +59,7 @@ void Jacobian::print(const state_type &x, const double t) << std::setw(10) << "J.ja |" << std::setw(8) << "J.ia"; std::cout << "\n-----------------------------------------\n"; - size_t size = (J.A.size() > J.ia.size()) ? J.A.size() : J.ia.size(); + std::size_t size = (J.A.size() > J.ia.size()) ? J.A.size() : J.ia.size(); for(std::size_t i = 0; i < size; i++) { diff --git a/src/solver.cpp b/src/solver.cpp index 0ff8265..ebb4360 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -145,7 +145,7 @@ int Solver::operator()(state_type &x, double &t1) using time_unit = std::chrono::microseconds; // Counts linear solver calls - size_t calls = 0; + std::size_t calls = 0; if(m_opt.verbosity == 1) { diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index 54a1a07..23ed7e4 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -166,7 +166,7 @@ void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, J.ia.clear(); J.ja.clear(); - size_t nzmax = m_M.A.size() + m_J.A.size(); + std::size_t nzmax = m_M.A.size() + m_J.A.size(); // If new size is greater than the current capacity, // a reallocation happens diff --git a/src/typedefs.h b/src/typedefs.h index 4e3cf50..736708e 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "cmake_config.h" From 1cac7ec490f8c28c9b6f928592667b2ff2cc8063 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 21 May 2020 15:02:45 +0100 Subject: [PATCH 060/274] Added output of the Mass matrix according to issue #12 --- examples/robertson/robertson.cpp | 15 ++++++---- src/debug_output.cpp | 47 ++++++++++++++++++++++++++++++++ src/mass_matrix.h | 5 ++++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index 49a1fc0..2077ed0 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -220,15 +220,20 @@ int main() // MyMassMatrix inherits abstract MassMatrix class from dae-cpp library. MyMassMatrix mass; + // Write the Mass Matrix to a file for debugging purposes. + // The content of the output file can be copied/pasted into MS Excel or any + // other spreadsheet sofware + mass.dump(); + // Create an instance of the solver options and update some of the solver // parameters defined in solver_options.h SolverOptions opt; - opt.dt_init = 1.0e-6; // Change initial time step - opt.dt_max = t1 / 100; // Set maximum time step - opt.time_stepping = 1; // S-SATS works better here - opt.atol = 1e-6; // Absolute tolerance - opt.bdf_order = 6; // Set BDF-6 + opt.dt_init = 1.0e-6; // Change initial time step + opt.dt_max = t1 / 100; // Set maximum time step + opt.time_stepping = 1; // S-SATS works better here + opt.atol = 1e-6; // Absolute tolerance + opt.bdf_order = 6; // Set BDF-6 // We can override Jacobian class from dae-cpp library and provide // analytical Jacobian. We shall do this for single precision: diff --git a/src/debug_output.cpp b/src/debug_output.cpp index d5c0a72..3ac7fea 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -9,6 +9,7 @@ #include // std::string, std::to_string #include "RHS.h" +#include "mass_matrix.h" #include "jacobian.h" namespace daecpp_namespace_name @@ -37,6 +38,52 @@ void RHS::dump(const state_type &x, const double t) outFile.close(); } +/* + * Helper function to write the Mass matrix to a file + */ +void MassMatrix::dump() +{ + sparse_matrix_holder M; + + this->operator()(M); // calls the Mass matrix operator + + const MKL_INT size = + M.ia.size() - 1; // derive the matrix size from ia index + + std::ofstream outFile; + + MKL_INT ja = 0; + MKL_INT ia = 0; + + outFile.open("dump_Mass_matrix.txt"); // Mass matrix is static - one file + outFile << "i,j"; + for(MKL_INT i = 0; i < size; i++) + { + outFile << delimiter << "i=" << i; + } + outFile << '\n'; + for(MKL_INT j = 0; j < size; j++) + { + MKL_INT ent = M.ia[ia + 1] - M.ia[ia]; // Number of entries in line j + + outFile << "j=" << j << delimiter; + + for(MKL_INT i = 0; i < size; i++) + { + if(M.ja[ja] == i) + { + outFile << M.A[ja++]; + if(!(--ent)) + break; + } + outFile << delimiter; + } + + outFile << '\n'; + } + outFile.close(); +} + /* * Helper function to show Jacobian structure */ diff --git a/src/mass_matrix.h b/src/mass_matrix.h index 90eaa49..c845777 100644 --- a/src/mass_matrix.h +++ b/src/mass_matrix.h @@ -26,6 +26,11 @@ class MassMatrix * This function is pure virtual and must be overriden. */ virtual void operator()(sparse_matrix_holder &M) = 0; + + /* + * Helper function to write the Mass matrix to a file + */ + void dump(); }; /* From 7b75c93ba2df8f634daa86b1e449c4f721965b4d Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 21 May 2020 16:37:52 +0100 Subject: [PATCH 061/274] Added writing the Jacobian matrix (in dense format) for debugging --- examples/robertson/robertson.cpp | 4 ++ src/debug_output.cpp | 69 +++++++++++++++++++++++++++++--- src/jacobian.h | 9 ++++- 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index 2077ed0..c63328c 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -250,6 +250,10 @@ int main() Jacobian jac_est(rhs, 1e-10); // Obviously this tolerance is // inacceptable for single precision + // Similar to the Mass matrix and the RHS, we can write the initial Jacobian + // matrix to a file: + jac_est.dump(x, 0); + // Print Jacobian out for t = 0: // jac_est.print(x, 0); #endif diff --git a/src/debug_output.cpp b/src/debug_output.cpp index 3ac7fea..d545a59 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -50,13 +50,72 @@ void MassMatrix::dump() const MKL_INT size = M.ia.size() - 1; // derive the matrix size from ia index + if(size > 10000) + { + std::cout << "\nMassMatrix::dump() -- Warning: the size of the Mass " + "matrix for writting is bigger than 10000x10000.\n"; + return; + } + std::ofstream outFile; MKL_INT ja = 0; - MKL_INT ia = 0; outFile.open("dump_Mass_matrix.txt"); // Mass matrix is static - one file - outFile << "i,j"; + outFile << "i,j:"; + for(MKL_INT i = 0; i < size; i++) + { + outFile << delimiter << "i=" << i; + } + outFile << '\n'; + for(MKL_INT j = 0; j < size; j++) + { + MKL_INT ent = M.ia[j + 1] - M.ia[j]; // Number of entries in line j + + outFile << "j=" << j << delimiter; + + for(MKL_INT i = 0; i < size; i++) + { + if(M.ja[ja] == i) + { + outFile << M.A[ja++]; + if(!(--ent)) + break; + } + outFile << delimiter; + } + + outFile << '\n'; + } + outFile.close(); +} + +/* + * Helper function to write the Jacbian matrix to a file (in dense format) + */ +void Jacobian::dump(const state_type &x, const double t) +{ + sparse_matrix_holder M; + + this->operator()(M, x, t); // calls the Jacobian matrix operator + + const MKL_INT size = + M.ia.size() - 1; // derive the matrix size from ia index + + if(size > 10000) + { + std::cout << "\nJacobian::dump() -- Warning: the size of the Jacobian " + "matrix for writting is bigger than 10000x10000.\n"; + return; + } + + std::ofstream outFile; + + MKL_INT ja = 0; + + outFile.open("dump_Jacobian_" + std::to_string(m_dump_file_counter++) + + ".txt"); + outFile << "t=" << t; for(MKL_INT i = 0; i < size; i++) { outFile << delimiter << "i=" << i; @@ -64,7 +123,7 @@ void MassMatrix::dump() outFile << '\n'; for(MKL_INT j = 0; j < size; j++) { - MKL_INT ent = M.ia[ia + 1] - M.ia[ia]; // Number of entries in line j + MKL_INT ent = M.ia[j + 1] - M.ia[j]; // Number of entries in line j outFile << "j=" << j << delimiter; @@ -85,13 +144,13 @@ void MassMatrix::dump() } /* - * Helper function to show Jacobian structure + * Helper function to show Jacobian structure (in sparse format) */ void Jacobian::print(const state_type &x, const double t) { if(x.size() > 1000) { - std::cout << "\nJacobian::print -- too much output. Skipped.\n"; + std::cout << "\nJacobian::print() -- too much output. Skipped.\n"; return; } diff --git a/src/jacobian.h b/src/jacobian.h index d835eac..00689f2 100644 --- a/src/jacobian.h +++ b/src/jacobian.h @@ -24,6 +24,8 @@ class Jacobian const double m_eps = 1.0e-13; // The order of the rounding unit #endif + std::size_t m_dump_file_counter = 0; + public: explicit Jacobian(RHS &rhs) : m_rhs(rhs) {} Jacobian(RHS &rhs, const double tol) : m_rhs(rhs), m_tol(tol) @@ -38,9 +40,14 @@ class Jacobian const double t); /* - * Helper function to show Jacobian structure + * Helper function to show Jacobian structure on screen (in sparse format) */ void print(const state_type &x, const double t); + + /* + * Helper function to write Jacobian matrix to a file (in dense format) + */ + void dump(const state_type &x, const double t); }; } // namespace daecpp_namespace_name From 3a713a8dc9007b36ace92479623cfa4c069bd906 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 22 May 2020 00:03:56 +0100 Subject: [PATCH 062/274] Added Jacobian output and comparison between two Jacobians according to issue #12. Updated Robertson example. --- examples/robertson/robertson.cpp | 8 +++ src/debug_output.cpp | 97 ++++++++++++++++++++++++++++++-- src/jacobian.cpp | 2 + src/jacobian.h | 15 ++++- 4 files changed, 117 insertions(+), 5 deletions(-) diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index c63328c..c85b5cc 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -256,6 +256,14 @@ int main() // Print Jacobian out for t = 0: // jac_est.print(x, 0); + + // We can also compare user-defined analytic Jacobian with the reference + // numerical Jacobian matrix: + MyJacobian jac(rhs); // Analytic Jacobian + jac.dump(x, 0); // Write it to file for debugging + jac.compare(jac_est, x, 1.234, 1e-4); // Or compare it with jac_est at time + // t = 1.234 with the tolerance 1e-4 + // and write the difference to a file #endif // Create an instance of the solver with particular RHS, Mass matrix, diff --git a/src/debug_output.cpp b/src/debug_output.cpp index d545a59..ce69b93 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -7,6 +7,7 @@ #include // std::setw etc. #include // File output #include // std::string, std::to_string +#include // std::abs #include "RHS.h" #include "mass_matrix.h" @@ -54,7 +55,6 @@ void MassMatrix::dump() { std::cout << "\nMassMatrix::dump() -- Warning: the size of the Mass " "matrix for writting is bigger than 10000x10000.\n"; - return; } std::ofstream outFile; @@ -106,15 +106,19 @@ void Jacobian::dump(const state_type &x, const double t) { std::cout << "\nJacobian::dump() -- Warning: the size of the Jacobian " "matrix for writting is bigger than 10000x10000.\n"; - return; } std::ofstream outFile; MKL_INT ja = 0; - outFile.open("dump_Jacobian_" + std::to_string(m_dump_file_counter++) + - ".txt"); + if(m_jac_type) + outFile.open("dump_Jacobian_" + std::to_string(m_dump_file_counter++) + + "_numerical.txt"); + else + outFile.open("dump_Jacobian_" + std::to_string(m_dump_file_counter++) + + ".txt"); + outFile << "t=" << t; for(MKL_INT i = 0; i < size; i++) { @@ -193,4 +197,89 @@ void Jacobian::print(const state_type &x, const double t) } } +/* + * Helper function to compare two Jacobians and write the difference + */ +void Jacobian::compare(Jacobian jac, const state_type &x, const double t, + const double tol) +{ + sparse_matrix_holder M, J; + + this->operator()(M, x, t); // calls the Jacobian matrix operator + jac(J, x, t); // external Jacobian to compare with + + const MKL_INT size = + M.ia.size() - 1; // derive the matrix size from ia index + + if((std::size_t)(size) != (J.ia.size() - 1)) + { + std::cout << "\nJacobian::compare() -- ERROR: the sizes of the " + "matrices do not match ('ia' indexes are different)."; + return; + } + + std::ofstream outFile; + + MKL_INT ja_M = 0; + MKL_INT ja_J = 0; + + outFile.open("dump_Jacobians_compare_" + + std::to_string(m_compare_file_counter++) + ".txt"); + + outFile << "List of differences in Jacobians for t = " << t + << " and the tolerance tol = " << tol << ":\n"; + outFile << "i" << delimiter << "j" << delimiter << "Jac_original" + << delimiter << "Jac_reference" << delimiter << "Rel_difference" + << '\n'; + + std::size_t ndiff = 0; // counts differences + + for(MKL_INT j = 0; j < size; j++) + { + MKL_INT ent_M = M.ia[j + 1] - M.ia[j]; + MKL_INT ent_J = J.ia[j + 1] - J.ia[j]; + + for(MKL_INT i = 0; i < size; i++) + { + double MA = 0.0; + double JA = 0.0; + double diff; + + if((!ent_M) && (!ent_J)) + break; + + if((M.ja[ja_M] == i) && ent_M) + { + MA = M.A[ja_M++]; + ent_M--; + } + if((J.ja[ja_J] == i) && ent_J) + { + JA = J.A[ja_J++]; + ent_J--; + } + + if(JA != 0.0) + { + diff = (MA - JA) / std::abs(JA); + } + else + { + diff = (MA - JA); + } + + if(std::abs(diff) > tol) + { + outFile << i << delimiter << j << delimiter << MA << delimiter + << JA << delimiter << diff << '\n'; + ndiff++; + } + } + } + + outFile << "Total number of differences found: " << ndiff << '\n'; + + outFile.close(); +} + } // namespace daecpp_namespace_name diff --git a/src/jacobian.cpp b/src/jacobian.cpp index dd9b8db..a121cf3 100644 --- a/src/jacobian.cpp +++ b/src/jacobian.cpp @@ -27,6 +27,8 @@ namespace daecpp_namespace_name void Jacobian::operator()(sparse_matrix_holder &J, const state_type &x, const double t) { + m_jac_type = 1; + const MKL_INT size = (MKL_INT)(x.size()); const double invtol = 1.0 / m_tol; diff --git a/src/jacobian.h b/src/jacobian.h index 00689f2..75723d1 100644 --- a/src/jacobian.h +++ b/src/jacobian.h @@ -24,10 +24,15 @@ class Jacobian const double m_eps = 1.0e-13; // The order of the rounding unit #endif - std::size_t m_dump_file_counter = 0; + std::size_t m_dump_file_counter = 0; + std::size_t m_compare_file_counter = 0; + + int m_jac_type = 0; // This will be changed to 1 + // if numerical Jacobian is used public: explicit Jacobian(RHS &rhs) : m_rhs(rhs) {} + Jacobian(RHS &rhs, const double tol) : m_rhs(rhs), m_tol(tol) { // TODO: Check user's tol parameter. Too small tol may lead to crash. @@ -48,6 +53,14 @@ class Jacobian * Helper function to write Jacobian matrix to a file (in dense format) */ void dump(const state_type &x, const double t); + + /* + * Helper function to compare two Jacobians and write the differences. + * Comparison will be made with the external Jacobian jac (usually, + * numerical Jacobian) using vector x at time t. + */ + void compare(Jacobian jac, const state_type &x, const double t, + const double tol); }; } // namespace daecpp_namespace_name From 560861dde335101406eb43d4ab7f34d024d3d7db Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 22 May 2020 15:22:08 +0100 Subject: [PATCH 063/274] Added Mass and Jacobian matrix converter from simple format according to issue #12. Updated debug config for VS Code. --- .vscode/launch.json | 7 ++-- .vscode/tasks.json | 30 ++++++++++++++ examples/robertson/robertson.cpp | 31 ++++++++++++--- src/debug_output.cpp | 11 +++++- src/jacobian.h | 10 ++++- src/mass_matrix.h | 8 ++++ src/matrix_converter.cpp | 67 ++++++++++++++++++++++++++++++++ src/time_integrator.cpp | 4 ++ src/time_integrator.h | 8 ++++ 9 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 src/matrix_converter.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json index 152219b..764adb2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "program": "${workspaceFolder}/dbg.exe", "args": [], - "stopAtEntry": false, + "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [ { @@ -18,7 +18,7 @@ "value": "/opt/intel/mkl/lib/intel64/:/opt/intel/lib/intel64/" } ], - "externalConsole": true, + "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { @@ -26,7 +26,8 @@ "text": "-enable-pretty-printing", "ignoreFailures": true } - ] + ], + "miDebuggerPath": "/usr/bin/gdb" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5783670..44cbb01 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -129,6 +129,36 @@ "$gcc" ] }, + { + "label": "debug-robertson", + "type": "shell", + "command": "g++", + "args": [ + "-g", + "-Wall", + "-std=c++11", + "-m64", + "-fopenmp", + "./examples/robertson/*.cpp", + "./src/*.cpp", + "-o", + "dbg.exe", + "-I/opt/intel/mkl/include", + "-I./src/external", + "-L/opt/intel/mkl/lib/intel64", + "-Wl,--no-as-needed", + "-lmkl_intel_lp64", + "-lmkl_gnu_thread", + "-lmkl_core", + "-lgomp", + "-lpthread", + "-lm", + "-ldl" + ], + "problemMatcher": [ + "$gcc" + ] + }, { "label": "debug-diffusion_2d", "type": "shell", diff --git a/examples/robertson/robertson.cpp b/examples/robertson/robertson.cpp index c85b5cc..4afad16 100644 --- a/examples/robertson/robertson.cpp +++ b/examples/robertson/robertson.cpp @@ -56,11 +56,10 @@ class MyMassMatrix : public MassMatrix public: void operator()(sparse_matrix_holder &M) { - M.A.resize(3); // Matrix size - M.ja.resize(3); // Matrix size - M.ia.resize(4); // Matrix size + 1 + M.A.resize(3); // Number of non-zero elements + M.ja.resize(3); // Number of non-zero elements - // Non-zero and/or diagonal elements + // Non-zero and diagonal elements M.A[0] = 1; M.A[1] = 1; M.A[2] = 0; @@ -71,10 +70,18 @@ class MyMassMatrix : public MassMatrix M.ja[2] = 2; // Index of the first element for each row + M.ia.resize(4); // Matrix size + 1 M.ia[0] = 0; M.ia[1] = 1; M.ia[2] = 2; M.ia[3] = 3; + + // Alternatively, for ia, you can specify the row index of each + // non-zero element A: + // M.ia.resize(3); // Number of non-zero elements + // M.ia[0] = 0; + // M.ia[1] = 1; + // M.ia[2] = 2; } }; @@ -156,9 +163,8 @@ class MyJacobian : public Jacobian // Initialize Jacobian in sparse format J.A.resize(9); J.ja.resize(9); - J.ia.resize(4); - // Non-zero elements + // Non-zero and diagonal elements J.A[0] = -0.04; J.A[1] = 1.0e4 * x[2]; J.A[2] = 1.0e4 * x[1]; @@ -181,10 +187,23 @@ class MyJacobian : public Jacobian J.ja[8] = 2; // Index of the first element for each row + J.ia.resize(4); J.ia[0] = 0; J.ia[1] = 3; J.ia[2] = 6; J.ia[3] = 9; + + // Alternatively, for ia, you may specify row index of each element: + // J.ia.resize(9); + // J.ia[0] = 0; + // J.ia[1] = 0; + // J.ia[2] = 0; + // J.ia[3] = 1; + // J.ia[4] = 1; + // J.ia[5] = 1; + // J.ia[6] = 2; + // J.ia[7] = 2; + // J.ia[8] = 2; } }; diff --git a/src/debug_output.cpp b/src/debug_output.cpp index ce69b93..399e804 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -48,6 +48,8 @@ void MassMatrix::dump() this->operator()(M); // calls the Mass matrix operator + m_matrix_converter(M); // converts the matrix if it is in simple form + const MKL_INT size = M.ia.size() - 1; // derive the matrix size from ia index @@ -99,6 +101,8 @@ void Jacobian::dump(const state_type &x, const double t) this->operator()(M, x, t); // calls the Jacobian matrix operator + m_matrix_converter(M); // converts the matrix if it is in simple form + const MKL_INT size = M.ia.size() - 1; // derive the matrix size from ia index @@ -162,6 +166,8 @@ void Jacobian::print(const state_type &x, const double t) this->operator()(J, x, t); + m_matrix_converter(J); // converts the matrix if it is in simple form + std::cout << std::right; std::cout << "\nJacobian matrix at time t = " << t << ':'; std::cout << "\n-----------------------------------------\n"; @@ -208,13 +214,16 @@ void Jacobian::compare(Jacobian jac, const state_type &x, const double t, this->operator()(M, x, t); // calls the Jacobian matrix operator jac(J, x, t); // external Jacobian to compare with + m_matrix_converter(M); // converts the matrix M if it is in simple form + m_matrix_converter(J); // converts the matrix J if it is in simple form + const MKL_INT size = M.ia.size() - 1; // derive the matrix size from ia index if((std::size_t)(size) != (J.ia.size() - 1)) { std::cout << "\nJacobian::compare() -- ERROR: the sizes of the " - "matrices do not match ('ia' indexes are different)."; + "matrices do not match ('ia' indexes are different).\n"; return; } diff --git a/src/jacobian.h b/src/jacobian.h index 75723d1..087ad19 100644 --- a/src/jacobian.h +++ b/src/jacobian.h @@ -30,6 +30,14 @@ class Jacobian int m_jac_type = 0; // This will be changed to 1 // if numerical Jacobian is used + /* + * Sparse matrix converter from simple three-array format to Intel MKL + * three array format. + * Input: matrix holder M with simple three-array format + * Output: matrix holder M with Intel MKL three-array format + */ + void m_matrix_converter(daecpp::sparse_matrix_holder &M); + public: explicit Jacobian(RHS &rhs) : m_rhs(rhs) {} @@ -57,7 +65,7 @@ class Jacobian /* * Helper function to compare two Jacobians and write the differences. * Comparison will be made with the external Jacobian jac (usually, - * numerical Jacobian) using vector x at time t. + * numerical Jacobian) using vector x at time t with the given tolerance. */ void compare(Jacobian jac, const state_type &x, const double t, const double tol); diff --git a/src/mass_matrix.h b/src/mass_matrix.h index c845777..1153572 100644 --- a/src/mass_matrix.h +++ b/src/mass_matrix.h @@ -14,6 +14,14 @@ namespace daecpp_namespace_name */ class MassMatrix { + /* + * Sparse matrix converter from simple three-array format to Intel MKL + * three array format. + * Input: matrix holder M with simple three-array format + * Output: matrix holder M with Intel MKL three-array format + */ + void m_matrix_converter(daecpp::sparse_matrix_holder &M); + public: /* * The matrix should be defined in sparse format, diff --git a/src/matrix_converter.cpp b/src/matrix_converter.cpp new file mode 100644 index 0000000..3b18a96 --- /dev/null +++ b/src/matrix_converter.cpp @@ -0,0 +1,67 @@ +/* + * Converts a matrix from simple three-array format (A, i, j), where A + * is the non-zero element, i is the column index of A, j is the row index of A, + * to Intel MKL sparse three-array format described here: + * https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format + */ + +#include "time_integrator.h" + +namespace daecpp_namespace_name +{ + +/* + * Input: matrix holder M with simple three-array format + * Output: matrix holder M with Intel MKL three-array format + */ +void matrix_converter(daecpp::sparse_matrix_holder &M) +{ + // Check if we need to convert the matrix at all. + // The matrix will be converted if the size of all three arrays (A, ia, ja) + // is the same. That means each non-zero element has its column and row + // index. + const std::size_t size = M.A.size(); + if((size != M.ia.size()) || (size != M.ja.size())) + return; // The sizes are different, do nothing + + // The sizes are equal. Do conversion. Create a temporary matrix holder: + daecpp::sparse_matrix_holder O; + + // We only need to update ia indexes. The first index is 0: + O.ia.push_back(0); + + // Looking for the other ia indexes + double row = 0; // current row + for(std::size_t i = 0; i < size; i++) + { + if(M.ia[i] != row) + { + row++; + O.ia.push_back(i); + } + } + + // Finalise ia + O.ia.push_back(size); + + // Copy ia index to M + M.ia.clear(); + M.ia = O.ia; +} + +void TimeIntegrator::m_matrix_converter(daecpp::sparse_matrix_holder &M) +{ + matrix_converter(M); +} + +void MassMatrix::m_matrix_converter(daecpp::sparse_matrix_holder &M) +{ + matrix_converter(M); +} + +void Jacobian::m_matrix_converter(daecpp::sparse_matrix_holder &M) +{ + matrix_converter(M); +} + +} // namespace daecpp_namespace_name diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index 23ed7e4..7a493ce 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -17,6 +17,9 @@ TimeIntegrator::TimeIntegrator(RHS &rhs, Jacobian &jac, MassMatrix &mass, // Get static mass matrix m_mass(m_M); + // Convert it to Intel MKL three-array format if necessary + m_matrix_converter(m_M); + // Extract the mass matrix size const MKL_INT size = m_M.ia.size() - 1; @@ -148,6 +151,7 @@ void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, // Calculate Jacobian auto tic0 = clock::now(); m_jac(m_J, x, t); + m_matrix_converter(m_J); // Converts Jacobian if necessary auto tic1 = clock::now(); // Update Jacobian timer diff --git a/src/time_integrator.h b/src/time_integrator.h index ba1ba24..605259d 100644 --- a/src/time_integrator.h +++ b/src/time_integrator.h @@ -59,6 +59,14 @@ class TimeIntegrator // Structure with sparse mass matrix stored in CSR format sparse_matrix_t m_csrA; + /* + * Sparse matrix converter from simple three-array format to Intel MKL + * three array format. + * Input: matrix holder M with simple three-array format + * Output: matrix holder M with Intel MKL three-array format + */ + void m_matrix_converter(daecpp::sparse_matrix_holder &M); + /* * Sparse matrix checker */ From 9908d8950515ad65fc2bdedb6af0537e53887727 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 22 May 2020 19:23:01 +0100 Subject: [PATCH 064/274] Updated README. Activated improved two-level factorization algorithm. Get rid of msvc directory. --- README.md | 83 +++++++++++++++++++++++++++++++++++++++---- msvc/msvc15.zip | Bin 11351 -> 0 bytes src/solver_options.h | 2 +- 3 files changed, 77 insertions(+), 8 deletions(-) delete mode 100644 msvc/msvc15.zip diff --git a/README.md b/README.md index 8ef045b..b67068a 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ For the numerical integration the solver uses implicit [BDF](https://en.wikipedi ### How does it work -BDF time stepper reduces the original DAE system to a system of nonlinear equations that the solver resolves using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. +BDF time stepper reduces the original DAE system to a system of nonlinear equations being solved using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. ### The main features of the solver @@ -30,11 +30,18 @@ BDF time stepper reduces the original DAE system to a system of nonlinear equati - Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. On the other hand, this is optional. Default values should work fine in most cases. - A user can get access to the solution at each time step by overriding Observer function (this is optional). - The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. +- The user-defined RHS, Mass matrix and Jacobian can be saved to a file for debugging or visualisation if needed. - Easy-to-follow examples (see, for example, [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp)) to kick-start the user's project. +### Why? + +For my research project (power battery simulation), I was looking for a light-weight, easy to use, but a very powerful, cross-platform and parallel C++ solver able to solve not only simple ODEs, but a mixture of ODEs with algebraic equations. The packages I found were either extremely heavy (SUNDIALS, PETSc) with very high entry barriers, or they could deal with the systems of ODEs only. So I decided to develop my own DAE solver, and it worked amazingly well for my problem. It allows me to tackle 5-D thermo-electro-chemical problems related to batteries. This involves solution of extremely huge systems (about ten million of DAEs), and it works really fast even on a standard laptop. On the other hand, I have a full control on the solution process. It's not like a black box, everything can be adjusted if necessary. + +I hope this work will be useful for other people too. If you have any questions about the software, please, feel free to submit an [issue](https://github.com/ikorotkin/dae-cpp/issues). Do not forget to [cite](https://doi.org/10.5281/zenodo.3241870) the solver if you use it in your research. Thank you! + ## Installation -This is a cross-platform software that should work on Linux (e.g. Ubuntu), Windows and macOS. The main library (DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS, the latest version and Full Package. +This is a cross-platform software that works on Linux (e.g. Ubuntu), Windows and macOS. The main library (DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS, version 2019 (2020 is relatively new and may have some issues) and Full Package. An alternative and probably the most convenient way to download and install Intel MKL on Ubuntu (using APT Repository) is the following. @@ -146,7 +153,7 @@ Note that in order to execute the tests (for example, `perovskite.exe`) from `Re "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64 ``` -An example of default solution file for Microsoft Visual Studio 15 (2017) is given in [msvc](https://github.com/ikorotkin/dae-cpp/tree/master/msvc) folder. Unpack the zip-archive into the current directory and open dae-cpp.sln. Note that you may need to retarget solution and change the paths to Intel MKL library. +Alternatively, you may install [Windows Subsystem for Linux](https://docs.microsoft.com/en-gb/windows/wsl/install-win10?redirectedfrom=MSDN) and your preferred Linux Distribution (e.g. Ubuntu), and then just follow [installation instructions for Linux](#linux). ### Mac @@ -180,10 +187,10 @@ mkdir build cd build ``` -Configure the project. *Make sure `g++` and `gcc` versions (9 in the example below) are correct*: +Configure the project. *Make sure `g++` version (9 in the example below) is correct*: ```bash -cmake .. -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_CC_COMPILER=gcc-9 -DCMAKE_INSTALL_PREFIX=$PWD +cmake .. -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_INSTALL_PREFIX=$PWD ``` In the command above you may change the user-defined path where the package should be installed (type it instead of `$PWD`). By default the package will be installed into the current `build` directory. @@ -244,9 +251,18 @@ MyRHS rhs(p); In the child MyRHS class the user can also override `stop_condition` virtual function. By default (if not overridden) the function always returns `false`. The user may override this behaviour and set up one or several stop conditions for the solver depending on the solution **x** at the current time *t*. As soon as the function returns `true`, the solver will finalise the current time step and return the current solution. A trivial example of the stop condition function can be found in [perovskite_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_RHS.cpp). +For the debugging purposes, the RHS can be saved to a file: + +```cpp +rhs.dump(x, 0); +rhs.dump(x, 0.1); +``` + +In this example we saved two RHS vectors, at time 0 and 0.1. + ### Step 3. Set up the Mass matrix -Create MyMassMatrix class that inherits the abstract `daecpp::MassMatrix` class from dae-cpp library. Similar to the previous step, the parent MassMatrix class contains a pure virtual functor (operator `()`), that must be overridden in the child class. Refer to [perovskite_Mass.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Mass.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) as an example. Note that the matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format). +Create MyMassMatrix class that inherits the abstract `daecpp::MassMatrix` class from dae-cpp library. Similar to the previous step, the parent MassMatrix class contains a pure virtual functor (operator `()`), that must be overridden in the child class. Refer to [perovskite_Mass.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Mass.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) as an example. Note that the matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format). See also [A note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). Create an instance of the child MyMassMatrix class with the given size *N*: @@ -260,9 +276,15 @@ If the Mass matrix is a simple identity matrix, one can use `daecpp::MassMatrixI dae::MassMatrixIdentity mass(N); ``` +For the debugging purposes, you can save the Mass matrix to a file: + +```cpp +mass.dump(); +``` + ### Step 4. Set up Jacobian matrix -We can provide analytical Jacobian by overriding `daecpp::Jacobian` class from the dae-cpp library (see [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite_Jacobian.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Jacobian.cpp)) or just use numerically estimated one (this may significantly slow down the computation for large *N*). If provided, analytical Jacobian matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format) similar to the Mass matrix. +We can provide analytical Jacobian by overriding `daecpp::Jacobian` class from the dae-cpp library (see [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite_Jacobian.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Jacobian.cpp)) or just use numerically estimated one (this may significantly slow down the computation for large *N*). If provided, analytical Jacobian matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format) similar to the Mass matrix. See also [A note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). If we don't provide analytical Jacobian we should estimate it with the given tolerance: @@ -272,6 +294,27 @@ dae::Jacobian jac(rhs, 1.0e-6); Note that we should pass an instance of the user-defined RHS in order to estimate numerical Jacobian. +Again, for the debugging purposes, Jacobian can be saved to a file: + +```cpp +jac.dump(x, 0); +jac.dump(x, 0.1); +``` + +In the example above we saved two Jacobians, at time 0 and 0.1. + +In some cases the derivation and coding of the analytic Jacobian can be a tricky problem itself. So `dae::Jacobian` class provides additional functionality to compare two Jacobians (one of them is numerical) and write the differences: + +```cpp +dae::Jacobian jac(rhs, 1.0e-6); // Numerical Jacobian calculated automatically (slow) +MyJacobian jac_user(rhs); // Analytic Jacobian provided by the user + +// Comparison of jac and jac_user and writing the differences to a file +jac_user.compare(jac, x, 0.1, 1e-4); +``` + +Here we compared two Jacobians at time 0.1 with the relative tolerance 10-4. + ### Step 5. Set the solver options The solver has lots of options related to the solution process. They all have some default values (defined in [solver_options.h](https://github.com/ikorotkin/dae-cpp/blob/master/src/solver_options.h)) but they can be overridden by a user: @@ -339,6 +382,32 @@ The third example, [robertson](https://github.com/ikorotkin/dae-cpp/tree/master/ Note that by default the plotting is switched off in the examples, but the plotting-related code can be activated using `#define PLOTTING` at the very beginning of each example. Activating the plotting refers to `matplotlibcpp.h` header located in `src/external/matplotlib-cpp/` directory. +### A note about Sparse Matrix Format + +It should be noted that you must define all the diagonal elements of the matrix, even if they are zero. This greatly increases performance, and if some rows are skipped, the code will just stop working. Please double check your Mass matrix and Jacobian, they both should have the main diagonal filled in. Even if the given row is empty (all elements are zero), define zero on the main diagonal explicitly. + +If you are struggling with Intel MKL sparse format, you can use simple three-array format instead, where you need to define all non-zero elements and their indexes (coordinates) in the matrix. For example for the identity 3x3 matrix, you only need to define three non-zero elements and their position in the matrix: + +```cpp +M.A.resize(3); // Number of non-zero elements +M.ia.resize(3); // Number of non-zero elements +M.ja.resize(3); // Number of non-zero elements + +M.A[0] = 1; // First non-zero or diagonal element +M.ia[0] = 0; // Column index of the first non-zero element +M.ja[0] = 0; // Raw index of the first non-zero element + +M.A[1] = 1; // Second non-zero or diagonal element +M.ia[1] = 1; // Column index of the second non-zero element +M.ja[1] = 1; // Raw index of the second non-zero element + +M.A[2] = 1; // Third non-zero or diagonal element +M.ia[2] = 2; // Column index of the third non-zero element +M.ja[2] = 2; // Raw index of the third non-zero element +``` + +This form will be automatically converted to three-array sparse format compatible with Intel MKL. Do not forget to define all diagonal elements even if they are zero. Do not mix the elements up (fill in the first row from left to right, then second row, etc.). + ## Contribution and feedback Please feel free to contribute into the project! diff --git a/msvc/msvc15.zip b/msvc/msvc15.zip deleted file mode 100644 index b6e80138b9305f9e9bf78836aa457b768a29909d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11351 zcmZ{K1yJ0}^7SqfEI0&rx5eE;aM#7%-JRePJi*=F-6aGK?hxF92M7eW{Kq%```X&dG{@*j?v?im(GPy zo*}YjXq)b<)zFOXx+N=Qu>=4qT>&WYBwZwL0Nns3qLOl()p0$#Adh-9{ko-5tc$7U zh2>)ml?IoA6s+4uwl@!Zut6I$$?#p=^ogv z>A|7sc#kKBCi|MkqM4LG`V{R+mAg=CbGCs9FfYG^I{7hg`2~HhP1)jldFCro7{R4e zWe9H4!~a4kpu{HIcvd>13bx0o3a_};J_PqvZL~?EOWFSjDM2GRE{>53h}imGI#u*}>PUPKnf6u5=Dx z#G^_@OC}{X-wW~Sk$$6&y{bp|@$0gsk8NomJxMK8x9k`1+3VZHN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^IUoYanKL2qo5B|Sj0s+{7Zu~NkJJl?Zl6RrN zfn*klC%?sH`edI^{^xzB=aavB;@aC4Y8Jp96V5U0?i1>+GqA`WzuQ2gAzj z$v3}kjpu*H&wcf0JMK9`;FIe72g1KNtY(4yFNcjRf~kKw>?>2eCblk zYdycM0G`WV=+=oi1j(#xlJ ND-;0mj_TLw{{T;aMM3}o diff --git a/src/solver_options.h b/src/solver_options.h index 38313cf..16a59b2 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -119,7 +119,7 @@ class SolverOptions // scalability in case of parallel factorization on many OpenMP threads // (more than eight). // 10 - Improved two-level factorization algorithm. - MKL_INT parallel_fact_control = 0; + MKL_INT parallel_fact_control = 10; // iparm[24]: Parallel forward/backward solve control. // 0 - Intel MKL PARDISO uses the sequential forward and backward solve. From d0753639764a38a5752ac451663d93677dd563aa Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 22 May 2020 19:38:11 +0100 Subject: [PATCH 065/274] Updated README (wording) --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b67068a..4f9cca2 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ For the numerical integration the solver uses implicit [BDF](https://en.wikipedi ### How does it work -BDF time stepper reduces the original DAE system to a system of nonlinear equations being solved using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. +BDF time stepper reduces the original DAE system to a system of nonlinear equations which is being solved using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. ### The main features of the solver @@ -35,13 +35,13 @@ BDF time stepper reduces the original DAE system to a system of nonlinear equati ### Why? -For my research project (power battery simulation), I was looking for a light-weight, easy to use, but a very powerful, cross-platform and parallel C++ solver able to solve not only simple ODEs, but a mixture of ODEs with algebraic equations. The packages I found were either extremely heavy (SUNDIALS, PETSc) with very high entry barriers, or they could deal with the systems of ODEs only. So I decided to develop my own DAE solver, and it worked amazingly well for my problem. It allows me to tackle 5-D thermo-electro-chemical problems related to batteries. This involves solution of extremely huge systems (about ten million of DAEs), and it works really fast even on a standard laptop. On the other hand, I have a full control on the solution process. It's not like a black box, everything can be adjusted if necessary. +For my research project (power battery simulation), I was looking for a light-weight, easy to use, but very powerful, cross-platform and parallel C++ solver able to solve not only simple ODEs, but a mixture of ODEs with algebraic equations. The packages I found were either extremely heavy (SUNDIALS, PETSc) with very high entry barriers, or they could deal with the systems of ODEs only. So I decided to develop my own DAE solver, and it turned out it works amazingly well for my problem. It allows me to tackle 5-D thermo-electro-chemical problems related to batteries. This involves solution of extremely huge systems (about ten million of DAEs), and it works really fast even on a standard laptop. On the other hand, I have a full control on the solution process. It's not like a black box, everything can be adjusted if necessary. -I hope this work will be useful for other people too. If you have any questions about the software, please, feel free to submit an [issue](https://github.com/ikorotkin/dae-cpp/issues). Do not forget to [cite](https://doi.org/10.5281/zenodo.3241870) the solver if you use it in your research. Thank you! +I hope this work will be useful for other people too. If you have any questions about the software, please feel free to submit an [issue](https://github.com/ikorotkin/dae-cpp/issues). Do not forget to [cite](https://doi.org/10.5281/zenodo.3241870) the solver if you use it in your research. Thank you! ## Installation -This is a cross-platform software that works on Linux (e.g. Ubuntu), Windows and macOS. The main library (DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS, version 2019 (2020 is relatively new and may have some issues) and Full Package. +This is a cross-platform software that works on Linux (e.g. Ubuntu), Windows and macOS. The main library (the DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS, version 2019 (2020 is relatively new and may have some issues) and Full Package. An alternative and probably the most convenient way to download and install Intel MKL on Ubuntu (using APT Repository) is the following. @@ -153,7 +153,7 @@ Note that in order to execute the tests (for example, `perovskite.exe`) from `Re "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64 ``` -Alternatively, you may install [Windows Subsystem for Linux](https://docs.microsoft.com/en-gb/windows/wsl/install-win10?redirectedfrom=MSDN) and your preferred Linux Distribution (e.g. Ubuntu), and then just follow [installation instructions for Linux](#linux). +**_Alternatively_**, you may install [Windows Subsystem for Linux](https://docs.microsoft.com/en-gb/windows/wsl/install-win10?redirectedfrom=MSDN) and your preferred Linux Distribution (e.g. Ubuntu), and then just follow [installation instructions for Linux](#linux). ### Mac @@ -262,7 +262,7 @@ In this example we saved two RHS vectors, at time 0 and 0.1. ### Step 3. Set up the Mass matrix -Create MyMassMatrix class that inherits the abstract `daecpp::MassMatrix` class from dae-cpp library. Similar to the previous step, the parent MassMatrix class contains a pure virtual functor (operator `()`), that must be overridden in the child class. Refer to [perovskite_Mass.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Mass.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) as an example. Note that the matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format). See also [A note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). +Create MyMassMatrix class that inherits the abstract `daecpp::MassMatrix` class from dae-cpp library. Similar to the previous step, the parent MassMatrix class contains a pure virtual functor (operator `()`), that must be overridden in the child class. Refer to [perovskite_Mass.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Mass.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) as an example. Note that the matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format). See also [a note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). Create an instance of the child MyMassMatrix class with the given size *N*: @@ -284,7 +284,7 @@ mass.dump(); ### Step 4. Set up Jacobian matrix -We can provide analytical Jacobian by overriding `daecpp::Jacobian` class from the dae-cpp library (see [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite_Jacobian.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Jacobian.cpp)) or just use numerically estimated one (this may significantly slow down the computation for large *N*). If provided, analytical Jacobian matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format) similar to the Mass matrix. See also [A note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). +We can provide analytical Jacobian by overriding `daecpp::Jacobian` class from the dae-cpp library (see [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite_Jacobian.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Jacobian.cpp)) or just use numerically estimated one (this may significantly slow down the computation for large *N*). If provided, analytical Jacobian matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format) similar to the Mass matrix. See also [a note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). If we don't provide analytical Jacobian we should estimate it with the given tolerance: @@ -406,7 +406,7 @@ M.ia[2] = 2; // Column index of the third non-zero element M.ja[2] = 2; // Raw index of the third non-zero element ``` -This form will be automatically converted to three-array sparse format compatible with Intel MKL. Do not forget to define all diagonal elements even if they are zero. Do not mix the elements up (fill in the first row from left to right, then second row, etc.). +This form will be automatically converted to the three-array sparse format compatible with Intel MKL. Do not forget to define all diagonal elements even if they are zero. Do not mix the elements up (fill in the first row from left to right, then the second row, etc.). ## Contribution and feedback From 8507f0c5d97cea15e3652f9b338711c1c3a76173 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Fri, 22 May 2020 19:40:27 +0100 Subject: [PATCH 066/274] Updated README (typo) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f9cca2..112cf10 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ For the numerical integration the solver uses implicit [BDF](https://en.wikipedi ### How does it work -BDF time stepper reduces the original DAE system to a system of nonlinear equations which is being solved using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. +BDF time stepper reduces the original DAE system to a system of nonlinear equations that is solved using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. ### The main features of the solver From 42fa0fc9e9f0235f7b9b20c1ac81ae43fb995a5f Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 23 May 2020 22:30:42 +0100 Subject: [PATCH 067/274] Debug dump() and compare() functions print info messages when called --- src/debug_output.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/debug_output.cpp b/src/debug_output.cpp index 399e804..e6d7d82 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -23,6 +23,9 @@ const char delimiter = '\t'; // Delimiter of columns in output text files */ void RHS::dump(const state_type &x, const double t) { + std::cout << "\nRHS::dump() -- INFO: Writing the RHS at time t = " << t + << "...\n"; + const MKL_INT size = x.size(); state_type f(size); // the vector to be saved @@ -44,6 +47,8 @@ void RHS::dump(const state_type &x, const double t) */ void MassMatrix::dump() { + std::cout << "\nMassMatrix::dump() -- INFO: Writing the Mass matrix...\n"; + sparse_matrix_holder M; this->operator()(M); // calls the Mass matrix operator @@ -55,7 +60,7 @@ void MassMatrix::dump() if(size > 10000) { - std::cout << "\nMassMatrix::dump() -- Warning: the size of the Mass " + std::cout << "\nMassMatrix::dump() -- WARNING: the size of the Mass " "matrix for writting is bigger than 10000x10000.\n"; } @@ -97,18 +102,26 @@ void MassMatrix::dump() */ void Jacobian::dump(const state_type &x, const double t) { + std::cout << "\nJacobian::dump() -- INFO: "; + sparse_matrix_holder M; this->operator()(M, x, t); // calls the Jacobian matrix operator m_matrix_converter(M); // converts the matrix if it is in simple form + if(m_jac_type) + std::cout << "Writing numerically estimated "; + else + std::cout << "Writing user-defined "; + std::cout << "Jacobian matrix at time t = " << t << "...\n"; + const MKL_INT size = M.ia.size() - 1; // derive the matrix size from ia index if(size > 10000) { - std::cout << "\nJacobian::dump() -- Warning: the size of the Jacobian " + std::cout << "\nJacobian::dump() -- WARNING: the size of the Jacobian " "matrix for writting is bigger than 10000x10000.\n"; } @@ -209,6 +222,10 @@ void Jacobian::print(const state_type &x, const double t) void Jacobian::compare(Jacobian jac, const state_type &x, const double t, const double tol) { + std::cout << "\nJacobian::compare() -- INFO: Trying to compare two " + "Jacobians at time t = " + << t << "...\n"; + sparse_matrix_holder M, J; this->operator()(M, x, t); // calls the Jacobian matrix operator @@ -287,6 +304,8 @@ void Jacobian::compare(Jacobian jac, const state_type &x, const double t, } outFile << "Total number of differences found: " << ndiff << '\n'; + std::cout << "Jacobian::compare() -- INFO: Found " << ndiff + << " difference(s).\n"; outFile.close(); } From ca4883c58af5af431305af0959ced27d9c14d005 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 23 May 2020 22:51:43 +0100 Subject: [PATCH 068/274] Made debug output to screen a bit more pretty --- src/debug_output.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/debug_output.cpp b/src/debug_output.cpp index e6d7d82..245f786 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -23,8 +23,8 @@ const char delimiter = '\t'; // Delimiter of columns in output text files */ void RHS::dump(const state_type &x, const double t) { - std::cout << "\nRHS::dump() -- INFO: Writing the RHS at time t = " << t - << "...\n"; + std::cout << "RHS::dump() -- INFO: Writing the RHS at time t = " + << t << "...\n"; const MKL_INT size = x.size(); @@ -47,7 +47,7 @@ void RHS::dump(const state_type &x, const double t) */ void MassMatrix::dump() { - std::cout << "\nMassMatrix::dump() -- INFO: Writing the Mass matrix...\n"; + std::cout << "MassMatrix::dump() -- INFO: Writing the Mass matrix...\n"; sparse_matrix_holder M; @@ -60,7 +60,7 @@ void MassMatrix::dump() if(size > 10000) { - std::cout << "\nMassMatrix::dump() -- WARNING: the size of the Mass " + std::cout << "MassMatrix::dump() -- WARNING: the size of the Mass " "matrix for writting is bigger than 10000x10000.\n"; } @@ -102,7 +102,7 @@ void MassMatrix::dump() */ void Jacobian::dump(const state_type &x, const double t) { - std::cout << "\nJacobian::dump() -- INFO: "; + std::cout << "Jacobian::dump() -- INFO: "; sparse_matrix_holder M; @@ -121,7 +121,7 @@ void Jacobian::dump(const state_type &x, const double t) if(size > 10000) { - std::cout << "\nJacobian::dump() -- WARNING: the size of the Jacobian " + std::cout << "Jacobian::dump() -- WARNING: the size of the Jacobian " "matrix for writting is bigger than 10000x10000.\n"; } @@ -222,9 +222,9 @@ void Jacobian::print(const state_type &x, const double t) void Jacobian::compare(Jacobian jac, const state_type &x, const double t, const double tol) { - std::cout << "\nJacobian::compare() -- INFO: Trying to compare two " + std::cout << "Jacobian::compare() -- INFO: Trying to compare two " "Jacobians at time t = " - << t << "...\n"; + << t << " and the tolerance tol = " << tol << "...\n"; sparse_matrix_holder M, J; @@ -239,7 +239,7 @@ void Jacobian::compare(Jacobian jac, const state_type &x, const double t, if((std::size_t)(size) != (J.ia.size() - 1)) { - std::cout << "\nJacobian::compare() -- ERROR: the sizes of the " + std::cout << "Jacobian::compare() -- ERROR: the sizes of the " "matrices do not match ('ia' indexes are different).\n"; return; } From 9b7fe55c45497e76c4147f73de7b4aa345f99fe6 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 3 Jun 2020 12:50:24 +0100 Subject: [PATCH 069/274] Added newton_failed_attempts option --- src/solver.cpp | 24 ++++++++++++++++++++---- src/solver_options.h | 4 ++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index ebb4360..1afa719 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -26,10 +26,10 @@ Solver::Solver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) if(m_opt.verbosity > 1) { std::cout << "Float precision: " << 8 * sizeof(float_type) - << " bit\n"; + << " bit\n"; std::cout << "Integer precision: " << 8 * sizeof(MKL_INT) << " bit\n"; std::cout << "Numerical algorithm: BDF-" << m_opt.bdf_order - << std::endl; + << std::endl; } // Initialises the internal solver memory pointer. This is only @@ -147,6 +147,13 @@ int Solver::operator()(state_type &x, double &t1) // Counts linear solver calls std::size_t calls = 0; + // Counts how many times the Newton iterator failed to converge within + // max_Newton_iter iterations in a row. + int n_iter_failed = 0; + + // Can be set to true by the solver if it fails to converge + bool fact_every_iter = m_opt.fact_every_iter; + if(m_opt.verbosity == 1) { std::cout << "Calculating..."; @@ -191,12 +198,16 @@ int Solver::operator()(state_type &x, double &t1) m_iterator_state.current_scheme++; } - int iter; // We need this value later + fact_every_iter = (n_iter_failed >= m_opt.newton_failed_attempts) + ? true + : m_opt.fact_every_iter; + + int iter; // Loop index. We need this value later for(iter = 0; iter < m_opt.max_Newton_iter; iter++) { // Reordering, Symbolic and Numerical Factorization - if(m_opt.fact_every_iter || iter == 0 || !(iter % m_opt.fact_iter)) + if(fact_every_iter || iter == 0 || !(iter % m_opt.fact_iter)) { // Time Integrator with updated Jacobian m_ti->integrate(J, b, x, m_x_prev, m_iterator_state.t, @@ -369,12 +380,17 @@ int Solver::operator()(state_type &x, double &t1) // Trying to reduce the time step. if(iter == m_opt.max_Newton_iter) { + n_iter_failed++; if(m_opt.verbosity > 1) std::cout << " <- redo"; if(m_reset_ti_state(x, m_x_prev)) return 3; // Newton method failed to converge continue; } + else + { + n_iter_failed = 0; + } // The solver has reached the target time t1 or the stop condition // triggered. diff --git a/src/solver_options.h b/src/solver_options.h index 16a59b2..40aa18c 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -89,6 +89,10 @@ class SolverOptions // Otherwise stop with error message. bool redo_newton = false; + // If Newton method fails to converge within max_Newton_iter iterations in a + // row, the solver will try to update Jacobian every single iteration. + int newton_failed_attempts = 3; + // 1 - V-SATS will use NORM_infinity to estimate solution variability, // 2 - V-SATS will use NORM_2 (default) int vsats_norm = 2; From de3f6461544b9ac397b0e4ea2ccd8ef67f8c2077 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 3 Jun 2020 15:03:10 +0100 Subject: [PATCH 070/274] Typo in the comment --- src/solver_options.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/solver_options.h b/src/solver_options.h index 40aa18c..2e62685 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -89,8 +89,9 @@ class SolverOptions // Otherwise stop with error message. bool redo_newton = false; - // If Newton method fails to converge within max_Newton_iter iterations in a - // row, the solver will try to update Jacobian every single iteration. + // If Newton method fails to converge within 'max_Newton_iter' iterations + // 'newton_failed_attempts' times in a row, the solver will try to update + // Jacobian every single iteration next time step. int newton_failed_attempts = 3; // 1 - V-SATS will use NORM_infinity to estimate solution variability, From a4635df9cb268725f5c766bec3e2a1bab219076c Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 3 Jun 2020 18:06:45 +0100 Subject: [PATCH 071/274] Fixed issue with fact_every_iter initialisation --- src/solver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solver.cpp b/src/solver.cpp index 1afa719..4258fdf 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -152,7 +152,7 @@ int Solver::operator()(state_type &x, double &t1) int n_iter_failed = 0; // Can be set to true by the solver if it fails to converge - bool fact_every_iter = m_opt.fact_every_iter; + bool fact_every_iter; // Equals to m_opt.fact_every_iter usually if(m_opt.verbosity == 1) { From d619b57430192825a65824ed0b59b26bd1757f5c Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 3 Jun 2020 18:19:53 +0100 Subject: [PATCH 072/274] Reduced the scope of fact_every_iter --- src/solver.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 4258fdf..4d2bc45 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -151,9 +151,6 @@ int Solver::operator()(state_type &x, double &t1) // max_Newton_iter iterations in a row. int n_iter_failed = 0; - // Can be set to true by the solver if it fails to converge - bool fact_every_iter; // Equals to m_opt.fact_every_iter usually - if(m_opt.verbosity == 1) { std::cout << "Calculating..."; @@ -198,9 +195,10 @@ int Solver::operator()(state_type &x, double &t1) m_iterator_state.current_scheme++; } - fact_every_iter = (n_iter_failed >= m_opt.newton_failed_attempts) - ? true - : m_opt.fact_every_iter; + // Can be set to true by the solver if it fails to converge + bool fact_every_iter = (n_iter_failed >= m_opt.newton_failed_attempts) + ? true + : m_opt.fact_every_iter; int iter; // Loop index. We need this value later From ba5777a1d49495e6341c8479f8ad3d61ddae6a63 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 6 Feb 2021 14:13:09 +0000 Subject: [PATCH 073/274] Fixed bug when in some rare cases the solver cannot recover after Newton method diverges. --- src/solver.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 4d2bc45..bc5bcdc 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -335,7 +335,7 @@ int Solver::operator()(state_type &x, double &t1) } else { - return 2; + return 2; // Newton iterations diverged } } @@ -376,13 +376,14 @@ int Solver::operator()(state_type &x, double &t1) // Newton iterator failed to converge within max_Newton_iter iterations. // Trying to reduce the time step. - if(iter == m_opt.max_Newton_iter) + if(iter >= m_opt.max_Newton_iter) { n_iter_failed++; if(m_opt.verbosity > 1) std::cout << " <- redo"; - if(m_reset_ti_state(x, m_x_prev)) - return 3; // Newton method failed to converge + if(m_reset_ti_state(x, m_x_prev) == -1) + return 3; // The time step was reduced to dt_min, + // but the solver still cannot converge continue; } else @@ -406,12 +407,12 @@ int Solver::operator()(state_type &x, double &t1) continue; // Re-run the current time step // Looks like the solver has reached the target time t1 - if(m_iterator_state.t + m_iterator_state.dt_eval >= t1) + if((m_iterator_state.t + m_iterator_state.dt_eval) >= (t1 - m_opt.dt_min)) { // Adjust the last time step size double dt_max = t1 - m_iterator_state.t; - if(std::abs(dt_max) < m_opt.dt_eps_m) + if(std::abs(dt_max) < m_opt.dt_eps_m) // Should never happen { break; // The solver has reached t1 } From 7b6539e1469af27a2defd0df9d0c07b81acee084 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 6 Feb 2021 19:53:04 +0000 Subject: [PATCH 074/274] Improved BDF3-6 accuracy when the time step changes according to issue #25 --- src/solver.cpp | 23 +++++++++++++++++++++-- src/time_integrator.cpp | 2 +- src/time_stepper.cpp | 5 +---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index bc5bcdc..f3d4f3e 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -96,6 +96,13 @@ int Solver::operator()(state_type &x, double &t1) : m_iterator_state.dt[0]; m_iterator_state.dt[0] = m_iterator_state.dt_eval; + // Roll back to BDF-2 if the time step has changed + if((m_iterator_state.dt[0] != m_iterator_state.dt[1]) && + (m_iterator_state.current_scheme > 1)) + { + m_iterator_state.current_scheme = 2; + } + // Initialize the time integrator state structure. m_iterator_state.step_counter_local = 0; m_iterator_state.final_time_step = false; @@ -192,7 +199,11 @@ int Solver::operator()(state_type &x, double &t1) if(m_iterator_state.current_scheme < m_opt.bdf_order) { - m_iterator_state.current_scheme++; + if((m_iterator_state.current_scheme == 1) || + (m_iterator_state.dt[0] == m_iterator_state.dt[1])) + { + m_iterator_state.current_scheme++; + } } // Can be set to true by the solver if it fails to converge @@ -407,7 +418,8 @@ int Solver::operator()(state_type &x, double &t1) continue; // Re-run the current time step // Looks like the solver has reached the target time t1 - if((m_iterator_state.t + m_iterator_state.dt_eval) >= (t1 - m_opt.dt_min)) + if((m_iterator_state.t + m_iterator_state.dt_eval) >= + (t1 - m_opt.dt_min)) { // Adjust the last time step size double dt_max = t1 - m_iterator_state.t; @@ -434,6 +446,13 @@ int Solver::operator()(state_type &x, double &t1) m_iterator_state.dt[1] = m_iterator_state.dt[0]; m_iterator_state.dt[0] = m_iterator_state.dt_eval; + // Roll back to BDF-2 if the time step has changed + if((m_iterator_state.dt[0] != m_iterator_state.dt[1]) && + (m_opt.bdf_order > 1)) + { + m_iterator_state.current_scheme = 2; + } + // Call Observer to provide a user with intermediate results observer(x, m_iterator_state.t); diff --git a/src/time_integrator.cpp b/src/time_integrator.cpp index 7a493ce..9836d0c 100644 --- a/src/time_integrator.cpp +++ b/src/time_integrator.cpp @@ -83,7 +83,7 @@ void TimeIntegrator::integrate(sparse_matrix_holder &J, state_type &b, state_type dxdt(size); // Variable time stepper for BDF-2 - if(m_scheme == 2 && m_opt.bdf_order == 2) + if(m_scheme == 2) { for(MKL_INT i = 0; i < size; i++) { diff --git a/src/time_stepper.cpp b/src/time_stepper.cpp index 9ad457c..fd10955 100644 --- a/src/time_stepper.cpp +++ b/src/time_stepper.cpp @@ -123,10 +123,7 @@ int Solver::m_reset_ti_state(state_type &x, const state_type_matrix &x_prev) */ int Solver::m_reset_ti_scheme() { - if(m_iterator_state.step_counter_local && m_opt.bdf_order == 2) - return 2; // BDF-2 - else - return 1; // BDF-1 + return (m_iterator_state.current_scheme == 1) ? 1 : 2; } /* From 9779f84e4a64843b6a2f756d44b1ebc03e5c0ab4 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 6 Feb 2021 20:44:32 +0000 Subject: [PATCH 075/274] Fixed BDF order update, issue #25 --- src/solver.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index f3d4f3e..3348fa8 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -185,7 +185,7 @@ int Solver::operator()(state_type &x, double &t1) std::cout << "\nStep " << std::setw(7) << m_steps << " :: t = " << std::setw(12) << m_iterator_state.t << " :: "; - std::cout.flush(); + // std::cout.flush(); // This degrades performance in some cases } if(m_opt.verbosity > 2) @@ -197,15 +197,6 @@ int Solver::operator()(state_type &x, double &t1) m_ti->set_scheme(m_iterator_state.current_scheme); - if(m_iterator_state.current_scheme < m_opt.bdf_order) - { - if((m_iterator_state.current_scheme == 1) || - (m_iterator_state.dt[0] == m_iterator_state.dt[1])) - { - m_iterator_state.current_scheme++; - } - } - // Can be set to true by the solver if it fails to converge bool fact_every_iter = (n_iter_failed >= m_opt.newton_failed_attempts) ? true @@ -375,7 +366,7 @@ int Solver::operator()(state_type &x, double &t1) if(m_opt.verbosity > 1) { std::cout << "#"; - std::cout.flush(); + // std::cout.flush(); // This degrades performance in some cases } if(is_converged) @@ -442,6 +433,16 @@ int Solver::operator()(state_type &x, double &t1) } m_x_prev[0] = x; + // Update the BDF order + if(m_iterator_state.current_scheme < m_opt.bdf_order) + { + if((m_iterator_state.current_scheme == 1) || + (m_iterator_state.dt[0] == m_iterator_state.dt[1])) + { + m_iterator_state.current_scheme++; + } + } + // Update time step history m_iterator_state.dt[1] = m_iterator_state.dt[0]; m_iterator_state.dt[0] = m_iterator_state.dt_eval; @@ -536,6 +537,7 @@ int Solver::operator()(state_type &x, double &t1) ss << "\n\n"; std::cout << ss.str(); + std::cout.flush(); } // Success From 5db131706ddb0c7f1296caccd66d4127389b859f Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 6 Feb 2021 21:05:12 +0000 Subject: [PATCH 076/274] Updated matplotlib-cpp to the latest version --- src/external/matplotlib-cpp/matplotlibcpp.h | 222 +++++++++++++++++++- 1 file changed, 220 insertions(+), 2 deletions(-) diff --git a/src/external/matplotlib-cpp/matplotlibcpp.h b/src/external/matplotlib-cpp/matplotlibcpp.h index ea2e4fb..93a72be 100644 --- a/src/external/matplotlib-cpp/matplotlibcpp.h +++ b/src/external/matplotlib-cpp/matplotlibcpp.h @@ -45,6 +45,7 @@ namespace detail { static std::string s_backend; struct _interpreter { + PyObject* s_python_function_arrow; PyObject *s_python_function_show; PyObject *s_python_function_close; PyObject *s_python_function_draw; @@ -54,6 +55,7 @@ struct _interpreter { PyObject *s_python_function_fignum_exists; PyObject *s_python_function_plot; PyObject *s_python_function_quiver; + PyObject* s_python_function_contour; PyObject *s_python_function_semilogx; PyObject *s_python_function_semilogy; PyObject *s_python_function_loglog; @@ -73,13 +75,16 @@ struct _interpreter { PyObject *s_python_function_title; PyObject *s_python_function_axis; PyObject *s_python_function_axvline; + PyObject *s_python_function_axvspan; PyObject *s_python_function_xlabel; PyObject *s_python_function_ylabel; PyObject *s_python_function_gca; PyObject *s_python_function_xticks; PyObject *s_python_function_yticks; + PyObject* s_python_function_margins; PyObject *s_python_function_tick_params; PyObject *s_python_function_grid; + PyObject* s_python_function_cla; PyObject *s_python_function_clf; PyObject *s_python_function_errorbar; PyObject *s_python_function_annotate; @@ -91,18 +96,36 @@ struct _interpreter { PyObject *s_python_function_text; PyObject *s_python_function_suptitle; PyObject *s_python_function_bar; + PyObject *s_python_function_barh; PyObject *s_python_function_colorbar; PyObject *s_python_function_subplots_adjust; /* For now, _interpreter is implemented as a singleton since its currently not possible to have multiple independent embedded python interpreters without patching the python source code - or starting a separate process for each. - http://bytes.com/topic/python/answers/793370-multiple-independent-python-interpreters-c-c-program + or starting a separate process for each. [1] + Furthermore, many python objects expect that they are destructed in the same thread as they + were constructed. [2] So for advanced usage, a `kill()` function is provided so that library + users can manually ensure that the interpreter is constructed and destroyed within the + same thread. + + 1: http://bytes.com/topic/python/answers/793370-multiple-independent-python-interpreters-c-c-program + 2: https://github.com/lava/matplotlib-cpp/pull/202#issue-436220256 */ static _interpreter& get() { + return interkeeper(false); + } + + static _interpreter& kill() { + return interkeeper(true); + } + + // Stores the actual singleton object referenced by `get()` and `kill()`. + static _interpreter& interkeeper(bool should_kill) { static _interpreter ctx; + if (should_kill) + ctx.~_interpreter(); return ctx; } @@ -148,6 +171,11 @@ struct _interpreter { Py_SetProgramName(name); Py_Initialize(); + wchar_t const *dummy_args[] = {L"Python", NULL}; // const is needed because literals must not be modified + wchar_t const **argv = dummy_args; + int argc = sizeof(dummy_args)/sizeof(dummy_args[0])-1; + PySys_SetArgv(argc, const_cast(argv)); + #ifndef WITHOUT_NUMPY import_numpy(); // initialize numpy C-API #endif @@ -185,6 +213,7 @@ struct _interpreter { Py_DECREF(pylabname); if (!pylabmod) { throw std::runtime_error("Error loading module pylab!"); } + s_python_function_arrow = safe_import(pymod, "arrow"); s_python_function_show = safe_import(pymod, "show"); s_python_function_close = safe_import(pymod, "close"); s_python_function_draw = safe_import(pymod, "draw"); @@ -193,6 +222,7 @@ struct _interpreter { s_python_function_fignum_exists = safe_import(pymod, "fignum_exists"); s_python_function_plot = safe_import(pymod, "plot"); s_python_function_quiver = safe_import(pymod, "quiver"); + s_python_function_contour = safe_import(pymod, "contour"); s_python_function_semilogx = safe_import(pymod, "semilogx"); s_python_function_semilogy = safe_import(pymod, "semilogy"); s_python_function_loglog = safe_import(pymod, "loglog"); @@ -208,11 +238,13 @@ struct _interpreter { s_python_function_title = safe_import(pymod, "title"); s_python_function_axis = safe_import(pymod, "axis"); s_python_function_axvline = safe_import(pymod, "axvline"); + s_python_function_axvspan = safe_import(pymod, "axvspan"); s_python_function_xlabel = safe_import(pymod, "xlabel"); s_python_function_ylabel = safe_import(pymod, "ylabel"); s_python_function_gca = safe_import(pymod, "gca"); s_python_function_xticks = safe_import(pymod, "xticks"); s_python_function_yticks = safe_import(pymod, "yticks"); + s_python_function_margins = safe_import(pymod, "margins"); s_python_function_tick_params = safe_import(pymod, "tick_params"); s_python_function_grid = safe_import(pymod, "grid"); s_python_function_xlim = safe_import(pymod, "xlim"); @@ -220,6 +252,7 @@ struct _interpreter { s_python_function_ginput = safe_import(pymod, "ginput"); s_python_function_save = safe_import(pylabmod, "savefig"); s_python_function_annotate = safe_import(pymod,"annotate"); + s_python_function_cla = safe_import(pymod, "cla"); s_python_function_clf = safe_import(pymod, "clf"); s_python_function_errorbar = safe_import(pymod, "errorbar"); s_python_function_tight_layout = safe_import(pymod, "tight_layout"); @@ -228,6 +261,7 @@ struct _interpreter { s_python_function_text = safe_import(pymod, "text"); s_python_function_suptitle = safe_import(pymod, "suptitle"); s_python_function_bar = safe_import(pymod,"bar"); + s_python_function_barh = safe_import(pymod, "barh"); s_python_function_colorbar = PyObject_GetAttrString(pymod, "colorbar"); s_python_function_subplots_adjust = safe_import(pymod,"subplots_adjust"); #ifndef WITHOUT_NUMPY @@ -707,6 +741,37 @@ bool fill_between(const std::vector& x, const std::vector& y1, return res; } +template +bool arrow(Numeric x, Numeric y, Numeric end_x, Numeric end_y, const std::string& fc = "r", + const std::string ec = "k", Numeric head_length = 0.25, Numeric head_width = 0.1625) { + PyObject* obj_x = PyFloat_FromDouble(x); + PyObject* obj_y = PyFloat_FromDouble(y); + PyObject* obj_end_x = PyFloat_FromDouble(end_x); + PyObject* obj_end_y = PyFloat_FromDouble(end_y); + + PyObject* kwargs = PyDict_New(); + PyDict_SetItemString(kwargs, "fc", PyString_FromString(fc.c_str())); + PyDict_SetItemString(kwargs, "ec", PyString_FromString(ec.c_str())); + PyDict_SetItemString(kwargs, "head_width", PyFloat_FromDouble(head_width)); + PyDict_SetItemString(kwargs, "head_length", PyFloat_FromDouble(head_length)); + + PyObject* plot_args = PyTuple_New(4); + PyTuple_SetItem(plot_args, 0, obj_x); + PyTuple_SetItem(plot_args, 1, obj_y); + PyTuple_SetItem(plot_args, 2, obj_end_x); + PyTuple_SetItem(plot_args, 3, obj_end_y); + + PyObject* res = + PyObject_Call(detail::_interpreter::get().s_python_function_arrow, plot_args, kwargs); + + Py_DECREF(plot_args); + Py_DECREF(kwargs); + if (res) + Py_DECREF(res); + + return res; +} + template< typename Numeric> bool hist(const std::vector& y, long bins=10,std::string color="b", double alpha=1.0, bool cumulative=false) @@ -964,6 +1029,36 @@ bool bar(const std::vector & y, return bar(x, y, ec, ls, lw, keywords); } + +template +bool barh(const std::vector &x, const std::vector &y, std::string ec = "black", std::string ls = "-", double lw = 1.0, const std::map &keywords = { }) { + PyObject *xarray = detail::get_array(x); + PyObject *yarray = detail::get_array(y); + + PyObject *kwargs = PyDict_New(); + + PyDict_SetItemString(kwargs, "ec", PyString_FromString(ec.c_str())); + PyDict_SetItemString(kwargs, "ls", PyString_FromString(ls.c_str())); + PyDict_SetItemString(kwargs, "lw", PyFloat_FromDouble(lw)); + + for (std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) { + PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); + } + + PyObject *plot_args = PyTuple_New(2); + PyTuple_SetItem(plot_args, 0, xarray); + PyTuple_SetItem(plot_args, 1, yarray); + + PyObject *res = PyObject_Call(detail::_interpreter::get().s_python_function_barh, plot_args, kwargs); + + Py_DECREF(plot_args); + Py_DECREF(kwargs); + if (res) Py_DECREF(res); + + return res; +} + + inline bool subplots_adjust(const std::map& keywords = {}) { detail::_interpreter::get(); @@ -1038,6 +1133,39 @@ bool plot(const std::vector& x, const std::vector& y, const return res; } +template +bool contour(const std::vector& x, const std::vector& y, + const std::vector& z, + const std::map& keywords = {}) { + assert(x.size() == y.size() && x.size() == z.size()); + + PyObject* xarray = get_array(x); + PyObject* yarray = get_array(y); + PyObject* zarray = get_array(z); + + PyObject* plot_args = PyTuple_New(3); + PyTuple_SetItem(plot_args, 0, xarray); + PyTuple_SetItem(plot_args, 1, yarray); + PyTuple_SetItem(plot_args, 2, zarray); + + // construct keyword args + PyObject* kwargs = PyDict_New(); + for (std::map::const_iterator it = keywords.begin(); + it != keywords.end(); ++it) { + PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); + } + + PyObject* res = + PyObject_Call(detail::_interpreter::get().s_python_function_contour, plot_args, kwargs); + + Py_DECREF(kwargs); + Py_DECREF(plot_args); + if (res) + Py_DECREF(res); + + return res; +} + template bool quiver(const std::vector& x, const std::vector& y, const std::vector& u, const std::vector& w, const std::map& keywords = {}) { @@ -1491,6 +1619,24 @@ inline void legend() Py_DECREF(res); } +inline void legend(const std::map& keywords) +{ + detail::_interpreter::get(); + + // construct keyword args + PyObject* kwargs = PyDict_New(); + for(std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) + { + PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); + } + + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_legend, detail::_interpreter::get().s_python_empty_tuple, kwargs); + if(!res) throw std::runtime_error("Call to legend() failed."); + + Py_DECREF(kwargs); + Py_DECREF(res); +} + template void ylim(Numeric left, Numeric right) { @@ -1667,6 +1813,38 @@ inline void yticks(const std::vector &ticks, const std::map inline void margins(Numeric margin) +{ + // construct positional args + PyObject* args = PyTuple_New(1); + PyTuple_SetItem(args, 0, PyFloat_FromDouble(margin)); + + PyObject* res = + PyObject_CallObject(detail::_interpreter::get().s_python_function_margins, args); + if (!res) + throw std::runtime_error("Call to margins() failed."); + + Py_DECREF(args); + Py_DECREF(res); +} + +template inline void margins(Numeric margin_x, Numeric margin_y) +{ + // construct positional args + PyObject* args = PyTuple_New(2); + PyTuple_SetItem(args, 0, PyFloat_FromDouble(margin_x)); + PyTuple_SetItem(args, 1, PyFloat_FromDouble(margin_y)); + + PyObject* res = + PyObject_CallObject(detail::_interpreter::get().s_python_function_margins, args); + if (!res) + throw std::runtime_error("Call to margins() failed."); + + Py_DECREF(args); + Py_DECREF(res); +} + + inline void tick_params(const std::map& keywords, const std::string axis = "both") { detail::_interpreter::get(); @@ -1819,6 +1997,32 @@ inline void axvline(double x, double ymin = 0., double ymax = 1., const std::map if(res) Py_DECREF(res); } +inline void axvspan(double xmin, double xmax, double ymin = 0., double ymax = 1., const std::map& keywords = std::map()) +{ + // construct positional args + PyObject* args = PyTuple_New(4); + PyTuple_SetItem(args, 0, PyFloat_FromDouble(xmin)); + PyTuple_SetItem(args, 1, PyFloat_FromDouble(xmax)); + PyTuple_SetItem(args, 2, PyFloat_FromDouble(ymin)); + PyTuple_SetItem(args, 3, PyFloat_FromDouble(ymax)); + + // construct keyword args + PyObject* kwargs = PyDict_New(); + for(std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) + { + if (it->first == "linewidth" || it->first == "alpha") + PyDict_SetItemString(kwargs, it->first.c_str(), PyFloat_FromDouble(std::stod(it->second))); + else + PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); + } + + PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_axvspan, args, kwargs); + Py_DECREF(args); + Py_DECREF(kwargs); + + if(res) Py_DECREF(res); +} + inline void xlabel(const std::string &str, const std::map &keywords = {}) { detail::_interpreter::get(); @@ -2041,6 +2245,18 @@ inline void clf() { Py_DECREF(res); } +inline void cla() { + detail::_interpreter::get(); + + PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_cla, + detail::_interpreter::get().s_python_empty_tuple); + + if (!res) + throw std::runtime_error("Call to cla() failed."); + + Py_DECREF(res); +} + inline void ion() { detail::_interpreter::get(); @@ -2154,6 +2370,8 @@ struct plot_impl template bool operator()(const IterableX& x, const IterableY& y, const std::string& format) { + detail::_interpreter::get(); + // 2-phase lookup for distance, begin, end using std::distance; using std::begin; From adb03a3ab6d1ad5dfbd1eb898ccff8bdc3e741e6 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 6 Feb 2021 22:16:22 +0000 Subject: [PATCH 077/274] Added a simple sh-script showing how to build dae-cpp static library and then build and run examples without cmake. --- build_static_lib.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 build_static_lib.sh diff --git a/build_static_lib.sh b/build_static_lib.sh new file mode 100755 index 0000000..a6d6a41 --- /dev/null +++ b/build_static_lib.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Build a static library: +mkdir build_static_lib +cd build_static_lib +g++ -c -O3 -Wall -std=c++11 -m64 -fopenmp ../src/*.cpp -I/opt/intel/mkl/include -I../src -I../src/external +ar rcs libdaecpp.a *.o +rm *.o + +# Compile examples +g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/perovskite/*.cpp -o perovskite -I/opt/intel/mkl/include -I../examples/perovskite -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl +g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/diffusion_2d/*.cpp -o diffusion_2d -I/opt/intel/mkl/include -I../examples/diffusion_2d -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl +g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/robertson/*.cpp -o robertson -I/opt/intel/mkl/include -I../examples/robertson -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl + +echo 'How to run an example using 4 cores:' +echo 'cd build_static_lib/' +echo 'source ../set_MKL_env' +echo 'OMP_NUM_THREADS=4 ./perovskite' From f6559a6d5967c4c2ea62b52cc79311495f3509e3 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 6 Feb 2021 23:28:01 +0000 Subject: [PATCH 078/274] Update License year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index adfaaa0..09a9cd5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019-2020 Ivan Korotkin +Copyright (c) 2019-2021 Ivan Korotkin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From f8e1e8de439b10f1e18dc26f181e2c07beb91769 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 30 Mar 2021 16:04:33 +0100 Subject: [PATCH 079/274] Added a simple DAE system example --- CMakeLists.txt | 2 +- examples/simple_dae/simple_dae.cpp | 282 +++++++++++++++++++++++++++++ examples/simple_dae/simple_dae.png | Bin 0 -> 26151 bytes 3 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 examples/simple_dae/simple_dae.cpp create mode 100644 examples/simple_dae/simple_dae.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bebd94..79cb7fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,7 +135,7 @@ add_subdirectory(src) if(DAE_BUILD_EXAMPLES) - set(EXAMPLE_LIST "perovskite" "diffusion_2d" "robertson") + set(EXAMPLE_LIST "perovskite" "diffusion_2d" "robertson" "simple_dae") if(WIN32) if(CMAKE_SIZEOF_VOID_P EQUAL 8) diff --git a/examples/simple_dae/simple_dae.cpp b/examples/simple_dae/simple_dae.cpp new file mode 100644 index 0000000..92f76bb --- /dev/null +++ b/examples/simple_dae/simple_dae.cpp @@ -0,0 +1,282 @@ +/* + * Solves a very simple system of differential algebraic equation as a test: + * + * x' = y + * 0 = x*x + y*y - 1 + * + * Initial conditions are: x = 0, y = 1 for t = 0. + * + * The solution of this system is + * + * x = sin(t), y = cos(t), 0 <= t <= pi/2; + * x = 1, y = 0, t > pi/2. + * + * Each time step we will check that + * (1) x*x + y*y = 1 for any t, and + * (2) x(t) = sin(t) for t <= pi/2, x(t) = 1 for t > pi/2 + * + * with the absolute tolerance at least 1e-6. + */ + +#include +#include +#include // for std::max_element + +#include "../../src/solver.h" // the main header of dae-cpp library solver + +using namespace daecpp; + +// python3 + numpy + matplotlib should be installed in order to enable plotting +// #define PLOTTING + +#ifdef PLOTTING +#include "../../src/external/matplotlib-cpp/matplotlibcpp.h" +namespace plt = matplotlibcpp; +#endif + +/* + * Singular mass matrix in simplified 3-array sparse format + * ============================================================================= + * The matrix has the following form: + * M = |1 0| + * |0 0| + */ +class MyMassMatrix : public MassMatrix +{ +public: + void operator()(sparse_matrix_holder &M) + { + M.A.resize(2); // Number of non-zero and diagonal elements + M.ia.resize(2); // Number of non-zero and diagonal elements + M.ja.resize(2); // Number of non-zero and diagonal elements + + // Non-zero and diagonal elements + M.A[0] = 1; + M.A[1] = 0; + + // Column index of each element given above + M.ja[0] = 0; + M.ja[1] = 1; + + // Row index of each element in M.A: + M.ia[0] = 0; + M.ia[1] = 1; + } +}; + +/* + * RHS of the problem + * ============================================================================= + */ +class MyRHS : public RHS +{ +public: + /* + * Receives current solution vector x and the current time t. + * Defines the RHS f. + */ + void operator()(const state_type &x, state_type &f, const double t) + { + f[0] = x[1]; + f[1] = x[0] * x[0] + x[1] * x[1] - 1.0; + } +}; + +/* + * (Optional) Observer + * ============================================================================= + * Every time step checks that + * (1) x*x + y*y = 1, and + * (2) x(t) - sin(t) = 0 for t <= pi/2, x(t) = 1 for t > pi/2 + * and prints solution and errors to console. + */ +class MySolver : public Solver +{ +public: + MySolver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) + : Solver(rhs, jac, mass, opt) + { + } + +#ifdef PLOTTING + state_type x_axis, x0, x1; // For plotting +#endif + state_type err1, err2; // To check errors + + /* + * Overloaded observer. + * Receives current solution vector and the current time every time step. + */ + void observer(state_type &x, const double t) + { + double e1 = std::abs(x[0] * x[0] + x[1] * x[1] - 1.0); + double e2 = 0; + + if(t <= 1.5707963) + e2 = std::abs(std::sin(t) - x[0]); + else + e2 = std::abs(x[0] - 1.0); + + std::cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << e1 << '\t' + << e2 << '\n'; + + err1.push_back(e1); + err2.push_back(e2); + +#ifdef PLOTTING + // Save data for plotting + x_axis.push_back(t); + x0.push_back(x[0]); + x1.push_back(x[1]); +#endif + } +}; + +/* + * (Optional) Analytical Jacobian in simplified 3-array sparse format + * ============================================================================= + */ +class MyJacobian : public Jacobian +{ +public: + explicit MyJacobian(RHS &rhs) : Jacobian(rhs) {} + + /* + * Receives current solution vector x and the current time t. Defines the + * analytical Jacobian matrix J. + */ + void operator()(sparse_matrix_holder &J, const state_type &x, + const double t) + { + // Initialize Jacobian in simplified sparse format + J.A.resize(4); + J.ia.resize(4); + J.ja.resize(4); + + // Non-zero and diagonal elements + J.A[0] = 0.0; + J.A[1] = 1.0; + J.A[2] = 2.0 * x[0]; + J.A[3] = 2.0 * x[1]; + + // Column index of each element given above + J.ja[0] = 0; + J.ja[1] = 1; + J.ja[2] = 0; + J.ja[3] = 1; + + // Row index of each non-zero or diagonal element of A + J.ia[0] = 0; + J.ia[1] = 0; + J.ia[2] = 1; + J.ia[3] = 1; + } +}; + +/* + * MAIN FUNCTION + * ============================================================================= + * Returns '0' if solution comparison is OK or '1' if solution error is above + * the acceptable tolerances. + */ +int main() +{ + // Solution time 0 <= t <= pi + double t1 = 3.14; + + // Define the state vector + state_type x(2); + + // Initial conditions + x[0] = 0; + x[1] = 1; + + // Set up the RHS of the problem. + // Class MyRHS inherits abstract RHS class from dae-cpp library. + MyRHS rhs; + + // Set up the Mass Matrix of the problem. + // MyMassMatrix inherits abstract MassMatrix class from dae-cpp library. + MyMassMatrix mass; + + // Create an instance of the solver options and update some of the solver + // parameters defined in solver_options.h + SolverOptions opt; + + opt.dt_init = 1.0e-2; // Change the initial time step. + // It should be relatively small, because the first + // step in time is first order accuracy. + // Reducing dt_init decreases the error (2) + opt.time_stepping = 1; // Use simple stability-based adaptive time stepping + // algorithm. + opt.bdf_order = 6; // Use BDF-6 + opt.verbosity = 0; // Suppress output to screen (we have our own output + // defined in Observer function above) + + // We can override Jacobian class from dae-cpp library and provide + // analytical Jacobian. + MyJacobian jac(rhs); + + // Or we can use numerically estimated Jacobian with the given tolerance. + // Jacobian jac_est(rhs, 1e-6); + + // This will decrease the error (1) for x*x + y*y = 1 +#ifdef DAE_SINGLE + opt.atol = 1e-6; // Redefine absolute tolerance for single precision + opt.rtol = 1e-6; // Redefine relative tolerance for single precision +#else + opt.atol = 1e-8; // Redefine absolute tolerance for double precision + opt.rtol = 1e-8; // Redefine relative tolerance for double precision +#endif + + // Create an instance of the solver with particular RHS, Mass matrix, + // Jacobian and solver options + MySolver solve(rhs, jac, mass, opt); + + // Now we are ready to solve the set of DAEs + std::cout << "\nStarting DAE solver...\n"; + std::cout << "time\tx\ty\terror1\terror2\n"; + + // Solve the system + int status = solve(x, t1); + + // Check errors + double max_err1 = *std::max_element(solve.err1.begin(), solve.err1.end()); + double max_err2 = *std::max_element(solve.err2.begin(), solve.err2.end()); + + std::cout << "\nMaximum absoulte error (1) x*x + y*y = 1: " << max_err1 + << '\n'; + std::cout << "Maximum absolute error (2) x(t) - sin(t) = 0 for t <= pi/2 " + "or x(t) = 1 for t > pi/2: " + << max_err2 << '\n'; + + // Plot the solution +#ifdef PLOTTING + plt::figure(); + plt::figure_size(640, 480); + plt::named_semilogx("x", solve.x_axis, solve.x0); + plt::named_semilogx("y", solve.x_axis, solve.x1); + plt::xlabel("time"); + plt::title("Simple 2x2 DAE system"); + plt::grid(true); + plt::legend(); + + // Save figure + const char *filename = "simple_dae.png"; + std::cout << "Saving result to " << filename << "...\n"; + plt::save(filename); +#endif + +#ifdef DAE_SINGLE + const bool check_result = (max_err1 > 1e-6 || max_err2 > 1e-6 || status); +#else + const bool check_result = (max_err1 > 1e-15 || max_err2 > 1e-6 || status); +#endif + + if(check_result) + std::cout << "...Test FAILED\n\n"; + else + std::cout << "...done\n\n"; + + return check_result; +} diff --git a/examples/simple_dae/simple_dae.png b/examples/simple_dae/simple_dae.png new file mode 100644 index 0000000000000000000000000000000000000000..b87529005c796329cb2ca0e0fd1ea21ddb618531 GIT binary patch literal 26151 zcmdSBbySsG^ftO_l@gGUR78;4beBkpl%mqz4blyYgmfrf3W(BOn{G+z?(UMVyWV|% z-*@l0_x^YPx@R25IRn;y-?iqN@yt1&xxc(tl)=46eh&tN;mW?0REEJ&ePJ+^`8$~4 zH#`H=%iuo(j#6rlZ*5H+UG(jZVG8<=c2>5IR^|qeoQ>@r%x!JB;9PJ{mPclej&=@$ zY;4y5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FSM;Byhb0p?HsY5_K7k^3JFFP9(Cg8ha_=cfQYobnfsO@K^xB zaeBQ=4GE<7apE3V=t7P|1@P}y5Lo=Zh8lq{TMO|Q2|07X8HJL$1MoE&4GNo`{3a6j zbAoiH-#S17tm6pInl5I7ZQdi0hMIa67Cl+t6FEL;8`5VFx$RT(|1JXd@YnvZoVxZETIs-(1Hk)#>BXr?1V@^0BJ~qS1%^W3 z-CYK(JJKa^(-37O_AWJ5P%&U{Y5wquVwaE&;f{f~n@FsK#hiFvN9W|d(9mdD`#Awb zf3nCnmiXzfkI+R^i^J4BXzR)Ndv*SYE9^gc3L@;@K8lFeuXR16}?jK9v_wpB@|q@+sJqkPZ(5=?AaB z(XgbL*d*w-;Hw|NgBuVx7Swt>wlhGycNX-Z6a9$%22jGta}c(O>3b0GqYvK{2ZKi) z@PV1Z2(AU|2H1V%5Wv3fi&NJ|tNj*-%AydZBwU1akZ7ZjSSIf>L;%Uzc|AP@FKg*P zms4O=8 z1Iqg0SrvW1g;H=NcGy7xEyw{=d&omL>>S{(kh)2b6!?sWIu56O%F<>A9UC;k5R3p~ zO+T+mw5k=D*n}%!h7VNW;^LZ`o;E6*=+%aRh-mVmV=$Q&qiP2sv%s_j(dHvg9p<&?u5f@g6ENl0`E4s)H8n_8|KATQ`Nh0xY@IMKZ{7$GZ9!eo(nA+&*xvgumRXR@ literal 0 HcmV?d00001 From 4bfe2a8e44f633710d30b1f886920678cb356fcc Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 30 Mar 2021 16:35:33 +0100 Subject: [PATCH 080/274] Added new example (simple_dae) --- CMakeLists.txt | 7 +++++++ build_static_lib.sh | 1 + 2 files changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79cb7fc..76f760c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,13 +72,20 @@ if(PLOTTING) set(PYTHON_INCLUDE "" CACHE STRING "Path to Python include file (Python.h) for plotting") set(PYTHON_LIB "" CACHE STRING "Python library for plotting") endif(PYTHONLIBS_FOUND) + # A very rude attempt to find numpy library (numpy/arrayobject.h) for plotting find_path(PYTHON_NUMPY_INCLUDE numpy/arrayobject.h PATHS /usr/local/lib/python3.5/dist-packages/numpy/core/include /usr/local/lib/python3.6/dist-packages/numpy/core/include /usr/local/lib/python3.7/dist-packages/numpy/core/include + /usr/local/lib/python3.8/dist-packages/numpy/core/include /usr/local/lib/python3.5/site-packages/numpy/core/include /usr/local/lib/python3.6/site-packages/numpy/core/include /usr/local/lib/python3.7/site-packages/numpy/core/include + /usr/local/lib/python3.8/site-packages/numpy/core/include + ~/.local/lib/python3.5/site-packages/numpy/core/include + ~/.local/lib/python3.6/site-packages/numpy/core/include + ~/.local/lib/python3.7/site-packages/numpy/core/include + ~/.local/lib/python3.8/site-packages/numpy/core/include ${PYTHON_INCLUDE}/../Lib/site-packages/numpy/core/include ${PYTHON_LIB}/../Lib/site-packages/numpy/core/include DOC "Path to Python numpy include file (numpy/arrayobject.h) for plotting") diff --git a/build_static_lib.sh b/build_static_lib.sh index a6d6a41..a6fd035 100755 --- a/build_static_lib.sh +++ b/build_static_lib.sh @@ -11,6 +11,7 @@ rm *.o g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/perovskite/*.cpp -o perovskite -I/opt/intel/mkl/include -I../examples/perovskite -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/diffusion_2d/*.cpp -o diffusion_2d -I/opt/intel/mkl/include -I../examples/diffusion_2d -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/robertson/*.cpp -o robertson -I/opt/intel/mkl/include -I../examples/robertson -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl +g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/simple_dae/*.cpp -o simple_dae -I/opt/intel/mkl/include -I../examples/simple_dae -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl echo 'How to run an example using 4 cores:' echo 'cd build_static_lib/' From 34ef437d186b6e9b5af043e4ea139ee1b8878bb9 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 31 Mar 2021 10:36:33 +0100 Subject: [PATCH 081/274] Updated README --- README.md | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 112cf10..e4500ff 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,15 @@ BDF time stepper reduces the original DAE system to a system of nonlinear equati - Can resolve DAE systems of 108 equations and even more (depending on the Jacobian matrix sparsity and machine's RAM). - A user can provide analytical Jacobian matrix for better performance or use built-in parallel function provided by the solver to estimate numerical Jacobian. - Utilises all available cores on the machine for better performance (this can be overridden by a user). -- Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. On the other hand, this is optional. Default values should work fine in most cases. +- Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. - A user can get access to the solution at each time step by overriding Observer function (this is optional). - The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. - The user-defined RHS, Mass matrix and Jacobian can be saved to a file for debugging or visualisation if needed. -- Easy-to-follow examples (see, for example, [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp)) to kick-start the user's project. - -### Why? - -For my research project (power battery simulation), I was looking for a light-weight, easy to use, but very powerful, cross-platform and parallel C++ solver able to solve not only simple ODEs, but a mixture of ODEs with algebraic equations. The packages I found were either extremely heavy (SUNDIALS, PETSc) with very high entry barriers, or they could deal with the systems of ODEs only. So I decided to develop my own DAE solver, and it turned out it works amazingly well for my problem. It allows me to tackle 5-D thermo-electro-chemical problems related to batteries. This involves solution of extremely huge systems (about ten million of DAEs), and it works really fast even on a standard laptop. On the other hand, I have a full control on the solution process. It's not like a black box, everything can be adjusted if necessary. - -I hope this work will be useful for other people too. If you have any questions about the software, please feel free to submit an [issue](https://github.com/ikorotkin/dae-cpp/issues). Do not forget to [cite](https://doi.org/10.5281/zenodo.3241870) the solver if you use it in your research. Thank you! +- Easy-to-follow examples (see, for example, [simple_dae.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/simple_dae/simple_dae.cpp), [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp)) to kick-start the user's project. ## Installation -This is a cross-platform software that works on Linux (e.g. Ubuntu), Windows and macOS. The main library (the DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS, version 2019 (2020 is relatively new and may have some issues) and Full Package. +This is a cross-platform software that works on Linux (e.g. Ubuntu), Windows and macOS. The main library (the DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS and the Full Package. An alternative and probably the most convenient way to download and install Intel MKL on Ubuntu (using APT Repository) is the following. @@ -94,7 +88,7 @@ cd dae-cpp mkdir build cd build cmake .. -DCMAKE_INSTALL_PREFIX=/install_path -make +make -j4 make install ``` @@ -202,14 +196,14 @@ Instead of `cmake ..` you may consider using `ccmake ..`, a UI for `cmake` that Install dae-cpp and perform a quick self test: ```bash -make -j2 +make -j4 make install ctest ``` ## How to use -Please refer to [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. +Please refer to [simple_dae.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/simple_dae/simple_dae.cpp), [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. The main usage algorithm can be the following. Consider we have a system of DAEs written in a matrix-vector form, with some Mass matrix, RHS, and some initial conditions. @@ -324,8 +318,8 @@ The solver has lots of options related to the solution process. They all have so // parameters defined in solver_options.h dae::SolverOptions opt; -// For example, let's change the absolute tolerance -opt.atol = 1.0e-6; +// For example, let's change the initial time step +opt.dt_init = 0.01; ``` ### Step 6. Solve the system From 4856708122793c660a264c70e983a22ac84cb2bd Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 22 Apr 2021 17:32:56 +0100 Subject: [PATCH 082/274] Fixed observer not able to update the state vector, added an example related to issue #27 --- CMakeLists.txt | 2 +- build_static_lib.sh | 1 + examples/two_bodies/two_bodies.cpp | 212 +++++++++++++++++++++++++++++ examples/two_bodies/two_bodies.png | Bin 0 -> 23604 bytes src/solver.cpp | 12 +- 5 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 examples/two_bodies/two_bodies.cpp create mode 100755 examples/two_bodies/two_bodies.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 76f760c..bf14b6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,7 +142,7 @@ add_subdirectory(src) if(DAE_BUILD_EXAMPLES) - set(EXAMPLE_LIST "perovskite" "diffusion_2d" "robertson" "simple_dae") + set(EXAMPLE_LIST "perovskite" "diffusion_2d" "robertson" "simple_dae" "two_bodies") if(WIN32) if(CMAKE_SIZEOF_VOID_P EQUAL 8) diff --git a/build_static_lib.sh b/build_static_lib.sh index a6fd035..f015939 100755 --- a/build_static_lib.sh +++ b/build_static_lib.sh @@ -12,6 +12,7 @@ g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/perovskite/*.cpp -o perovskit g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/diffusion_2d/*.cpp -o diffusion_2d -I/opt/intel/mkl/include -I../examples/diffusion_2d -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/robertson/*.cpp -o robertson -I/opt/intel/mkl/include -I../examples/robertson -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/simple_dae/*.cpp -o simple_dae -I/opt/intel/mkl/include -I../examples/simple_dae -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl +g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/two_bodies/*.cpp -o two_bodies -I/opt/intel/mkl/include -I../examples/two_bodies -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl echo 'How to run an example using 4 cores:' echo 'cd build_static_lib/' diff --git a/examples/two_bodies/two_bodies.cpp b/examples/two_bodies/two_bodies.cpp new file mode 100644 index 0000000..ac3a1bb --- /dev/null +++ b/examples/two_bodies/two_bodies.cpp @@ -0,0 +1,212 @@ +/* + * Two bodies with with masses m and 10*m head to each other. + * The friction force F is constant and depends on the sign of velocity v: + * F = -sign(v) * F0. + * After collision, the body with mass m bounces in the other direction + * (and hence flips the sign of the friction force). + * + * The system of equations is the following: + * + * dv1/dt = -sign(v1) * F0 / m + * dv2/dt = -sign(v2) * F0 / (10 * m) + * dx1/dt = v1 + * dx2/dt = v2 + * + * Here v1 and x1 is the velocity and the coordinate of the first body, + * v2 and x2 is the velocity and the coordinate of the second body. + * + * When x1 reaches x2, the velocity direction of the body with mass m changes to + * the opposite. + * + * As an example, let us consider the following initial conditions: + * v1 = 10, v2 = -2, x1 = 0, x2 = 5 for t = 0. + */ + +#include +#include + +#include "../../src/solver.h" // the main header of dae-cpp library solver + +using namespace daecpp; + +// python3 + numpy + matplotlib should be installed in order to enable plotting +// #define PLOTTING + +#ifdef PLOTTING +#include "../../src/external/matplotlib-cpp/matplotlibcpp.h" +namespace plt = matplotlibcpp; +#endif + +/* + * RHS of the problem + * ============================================================================= + */ +class MyRHS : public RHS +{ + const double f0 = 10.0; + const double m = 1.0; + +public: + /* + * Receives the current solution vector x and the current time t. + * Defines the RHS f. + */ + void operator()(const state_type &x, state_type &f, const double t) + { + double F1 = -std::copysign(1.0, x[0]) * f0; + double F2 = -std::copysign(1.0, x[1]) * f0; + + f[0] = F1 / m; + f[1] = F2 / (10.0 * m); + f[2] = x[0]; + f[3] = x[1]; + } +}; + +/* + * (Optional) Observer + * ============================================================================= + * Every time step checks that + * (1) x*x + y*y = 1, and + * (2) x(t) - sin(t) = 0 for t <= pi/2, x(t) = 1 for t > pi/2 + * and prints solution and errors to console. + */ +class MySolver : public Solver +{ +public: + MySolver(RHS &rhs, Jacobian &jac, MassMatrix &mass, SolverOptions &opt) + : Solver(rhs, jac, mass, opt) + { + } + +#ifdef PLOTTING + state_type x_axis, v1, v2, x1, x2; // For plotting +#endif + + /* + * Overloaded observer. + * Receives current solution vector and the current time every time step. + */ + void observer(state_type &x, const double t) + { + std::cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << '\t' + << x[3] << '\n'; + + // When x1 reaches x2, change v1 velocity sign to negative + if(x[2] > x[3]) + { + x[0] = -std::abs(x[0]); + } + +#ifdef PLOTTING + // Save data for plotting + x_axis.push_back(t); + v1.push_back(x[0]); + v2.push_back(x[1]); + x1.push_back(x[2]); + x2.push_back(x[3]); +#endif + } +}; + +/* + * (Optional) Analytical Jacobian in simplified 3-array sparse format + * ============================================================================= + */ +class MyJacobian : public Jacobian +{ +public: + explicit MyJacobian(RHS &rhs) : Jacobian(rhs) {} + + /* + * Receives the current solution vector x and the current time t. Defines + * the analytical Jacobian matrix J. + */ + void operator()(sparse_matrix_holder &J, const state_type &x, + const double t) + { + } +}; + +/* + * MAIN FUNCTION + * ============================================================================= + * Returns '0' if solution comparison is OK or '1' if solution error is above + * the acceptable tolerances. + */ +int main() +{ + // Solution time 0 <= t <= t1 + double t1 = 1.0; + + // Define the state vector for 4 equations + state_type x(4); + + // Initial conditions + x[0] = 10; // Initial velocity v1 + x[1] = -2; // Initial velocity v2 + x[2] = 0; // Initial coordinate x1 + x[3] = 5; // Initial coordinate x2 + + // Set up the RHS of the problem. + // Class MyRHS inherits abstract RHS class from dae-cpp library. + MyRHS rhs; + + // Set up the Mass Matrix of the problem. In this case this matrix is + // identity, so we can use a helper class provided by the library. + MassMatrixIdentity mass(4); + + // Create an instance of the solver options and update some of the solver + // parameters defined in solver_options.h + SolverOptions opt; + + opt.time_stepping = 1; // Use simple stability-based adaptive time stepping + // algorithm + opt.bdf_order = 1; // Use BDF-1 + opt.verbosity = 0; // Suppress output to screen (we have our own output + // defined in Observer function above) + opt.dt_init = 0.01; // Change the initial time step + opt.dt_max = 0.01; // Restrict the maximum time step + + // We can override Jacobian class from dae-cpp library and provide + // analytical Jacobian. + // MyJacobian jac(rhs); + + // Or we can use numerically estimated Jacobian with the given tolerance. + Jacobian jac(rhs, 1e-8); + + // Create an instance of the solver with particular RHS, Mass matrix, + // Jacobian and solver options + MySolver solve(rhs, jac, mass, opt); + + // Now we are ready to solve the set of DAEs + std::cout << "\nStarting DAE solver...\n"; + std::cout << "time\tv1\tv2\tx1\tx2\n"; + + // Solve the system + int status = solve(x, t1); + + // Plot the solution +#ifdef PLOTTING + // plt::figure(); + // plt::figure_size(640, 480); + // plt::named_semilogx("x", solve.x_axis, solve.x0); + // plt::named_semilogx("y", solve.x_axis, solve.x1); + // plt::xlabel("time"); + // plt::title("Two bodies"); + // plt::grid(true); + // plt::legend(); + + // // Save figure + // const char *filename = "two_bodies.png"; + // std::cout << "Saving result to " << filename << "...\n"; + // plt::save(filename); +#endif + + if(status) + std::cout << "...Test FAILED\n\n"; + else + std::cout << "...done\n\n"; + + return status; +} diff --git a/examples/two_bodies/two_bodies.png b/examples/two_bodies/two_bodies.png new file mode 100755 index 0000000000000000000000000000000000000000..ae3552f5b4ac19383834c30bc77bda9dca7a69cb GIT binary patch literal 23604 zcmb5WbySsYw>`W83F+?c4(XPXZbZ7JyBnk%r6mPHx=R`XK|n&fLAp~)>UW{<^PKmb z@2_vL2RCEKy{}qx&9&BCM5-uBqaYF@LLd+nSs6(+2n0G10)YxdfCkUhNK5X33!I6( zv?S!=@#jNZVIl-V4w01<)9}pPU-Z(`x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@S{>An0#;in!;!isnoR${n+ksfL`po&7w%4iQ z+%IM4MzAHWCBpJEO8Q1(TiGpr!e0x_%>t4nN9KCbIu9yy*@Cjvh5jg)u}t5DKAEJU zRY@yDIGHJ(4GgL`3I}Up*E+4wzc)*VUW(7CtAzqJP`W%AKX+=_RCDl>+g5|M-U7Pn zIUgCUdc1kp&%rpv%G>?~o#e>C*}+YvSk34GvPF$AgM0wiRDW+rrm!v;wT9tr9M-Lp zmm8ak;qsR@t=105$D(zdGf-gz2S2XNwMvedYGZi|^0#jv@}FIB&)I2UKo2QzWP0@B zSbb#gL>t$U?UYVCC3Gp0lsw?Ne4FZE^>j}kqJi9;ph$wMs79yh_pI^1n&|)M#|E69 zrut-R3F07x1Dq-$FT!b93OT^OibUCZ$Z$T&X2Sgm5d`K{Lv!WsQ8=_!9&+xFq~ST7N9v9!gq?$4x;V*)aN}bMV_Z0WZG&D9z>$d~|Mz%F{4W^Uy;c@h R41wnh(Nc%0y;Zdi{|~{Iq>2Cl literal 0 HcmV?d00001 diff --git a/src/solver.cpp b/src/solver.cpp index 3348fa8..e85297a 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -426,6 +426,9 @@ int Solver::operator()(state_type &x, double &t1) } } + // Call Observer to provide a user with intermediate results + observer(x, m_iterator_state.t); + // Rewrite solution history for(int d = m_opt.bdf_order - 1; d > 0; d--) { @@ -454,9 +457,6 @@ int Solver::operator()(state_type &x, double &t1) m_iterator_state.current_scheme = 2; } - // Call Observer to provide a user with intermediate results - observer(x, m_iterator_state.t); - } // while t // Stop timer @@ -465,6 +465,9 @@ int Solver::operator()(state_type &x, double &t1) // Update solution time t1 = m_iterator_state.t; + // Catch up the last time step + observer(x, m_iterator_state.t); + // Update solution history for(int d = m_opt.bdf_order - 1; d > 0; d--) { @@ -472,9 +475,6 @@ int Solver::operator()(state_type &x, double &t1) } m_x_prev[0] = x; - // Catch up the last time step - observer(x, m_iterator_state.t); - // Restore the previous time step size m_iterator_state.dt_eval = m_iterator_state.dt[1]; m_iterator_state.dt[1] = m_iterator_state.dt[0]; From efaadf3cc03101ec87263fa337b86d95baad6051 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 24 Apr 2021 19:57:54 +0100 Subject: [PATCH 083/274] Updated two-body example related to issue #27 --- .vscode/c_cpp_properties.json | 4 +- .vscode/tasks.json | 98 +++++++++++++++++--------- examples/two_bodies/two_bodies.cpp | 109 +++++++++++++---------------- examples/two_bodies/two_bodies.png | Bin 23604 -> 30371 bytes 4 files changed, 116 insertions(+), 95 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index fd09189..2a5a7ee 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,9 +3,9 @@ { "name": "Linux", "includePath": [ - "${workspaceFolder}/**", + "${workspaceFolder}/src", "/opt/intel/mkl/include", - "/usr/include/python3.6m" + "/usr/include/python3.8" ], "defines": [], "compilerPath": "/usr/bin/gcc", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 44cbb01..d6727c3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,14 +13,14 @@ "-std=c++11", "-m64", "-fopenmp", - "./examples/perovskite/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/perovskite/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "perovskite.exe", "-I/opt/intel/mkl/include", - "-I./src/external", - //"-I/usr/include/python3.6m", - //"-lpython3.6m", + "-I${workspaceFolder}/src/external", + // "-I/usr/include/python3.8", + // "-lpython3.8", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -45,14 +45,14 @@ "-std=c++11", "-m64", "-fopenmp", - "./examples/diffusion_2d/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/diffusion_2d/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "diffusion_2d.exe", "-I/opt/intel/mkl/include", - "-I./src/external", - //"-I/usr/include/python3.6m", - //"-lpython3.6m", + "-I${workspaceFolder}/src/external", + "-I/usr/include/python3.8", + "-lpython3.8", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -77,14 +77,46 @@ "-std=c++11", "-m64", "-fopenmp", - "./examples/robertson/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/robertson/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "robertson.exe", "-I/opt/intel/mkl/include", - "-I./src/external", - //"-I/usr/include/python3.6m", - //"-lpython3.6m", + "-I${workspaceFolder}/src/external", + "-I/usr/include/python3.8", + "-lpython3.8", + "-L/opt/intel/mkl/lib/intel64", + "-Wl,--no-as-needed", + "-lmkl_intel_lp64", + "-lmkl_gnu_thread", + "-lmkl_core", + "-lgomp", + "-lpthread", + "-lm", + "-ldl" + ], + "problemMatcher": [ + "$gcc" + ] + }, + { + "label": "build-two-bodies", + "type": "shell", + "command": "g++", + "args": [ + "-O3", + "-Wall", + "-std=c++11", + "-m64", + "-fopenmp", + "${workspaceFolder}/examples/two_bodies/*.cpp", + "${workspaceFolder}/src/*.cpp", + "-o", + "two_bodies.exe", + "-I/opt/intel/mkl/include", + "-I${workspaceFolder}/src/external", + "-I/usr/include/python3.8", + "-lpython3.8", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -108,12 +140,12 @@ "-Wall", "-std=c++11", "-m64", - "./examples/perovskite/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/perovskite/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "a_iomp.exe", "-I/opt/intel/mkl/include", - "-I./src/external", + "-I${workspaceFolder}/src/external", "-L/opt/intel/mkl/lib/intel64", "-L/opt/intel/lib/intel64", "-Wl,--no-as-needed", @@ -139,12 +171,12 @@ "-std=c++11", "-m64", "-fopenmp", - "./examples/robertson/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/robertson/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "dbg.exe", "-I/opt/intel/mkl/include", - "-I./src/external", + "-I${workspaceFolder}/src/external", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -169,12 +201,12 @@ "-std=c++11", "-m64", "-fopenmp", - "./examples/diffusion_2d/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/diffusion_2d/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "dbg.exe", "-I/opt/intel/mkl/include", - "-I./src/external", + "-I${workspaceFolder}/src/external", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -199,12 +231,12 @@ "-std=c++11", "-m64", "-fopenmp", - "./examples/perovskite/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/perovskite/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "dbg.exe", "-I/opt/intel/mkl/include", - "-I./src/external", + "-I${workspaceFolder}/src/external", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_lp64", @@ -230,12 +262,12 @@ "-DMKL_ILP64", "-m64", "-fopenmp", - "./examples/perovskite/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/perovskite/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "a_int64.exe", "-I/opt/intel/mkl/include", - "-I./src/external", + "-I${workspaceFolder}/src/external", "-L/opt/intel/mkl/lib/intel64", "-Wl,--no-as-needed", "-lmkl_intel_ilp64", @@ -260,12 +292,12 @@ "-std=c++11", "-DMKL_ILP64", "-m64", - "./examples/perovskite/*.cpp", - "./src/*.cpp", + "${workspaceFolder}/examples/perovskite/*.cpp", + "${workspaceFolder}/src/*.cpp", "-o", "a_int64_iomp.exe", "-I/opt/intel/mkl/include", - "-I./src/external", + "-I${workspaceFolder}/src/external", "-L/opt/intel/mkl/lib/intel64", "-L/opt/intel/lib/intel64", "-Wl,--no-as-needed", diff --git a/examples/two_bodies/two_bodies.cpp b/examples/two_bodies/two_bodies.cpp index ac3a1bb..369fe60 100644 --- a/examples/two_bodies/two_bodies.cpp +++ b/examples/two_bodies/two_bodies.cpp @@ -1,25 +1,37 @@ /* - * Two bodies with with masses m and 10*m head to each other. - * The friction force F is constant and depends on the sign of velocity v: - * F = -sign(v) * F0. + * Two bodies with masses m and 10*m head to each other. + * The friction force F is proportional to the velocity v and has the opposite + * sign: F = -v * f0, where f0 is a constant. + * * After collision, the body with mass m bounces in the other direction - * (and hence flips the sign of the friction force). + * (and hence the sign of the friction force instantly changes to the opposite). * * The system of equations is the following: * - * dv1/dt = -sign(v1) * F0 / m - * dv2/dt = -sign(v2) * F0 / (10 * m) + * dv1/dt = -v1 * f0 / m + * dv2/dt = -v2 * f0 / (10 * m) * dx1/dt = v1 * dx2/dt = v2 * - * Here v1 and x1 is the velocity and the coordinate of the first body, - * v2 and x2 is the velocity and the coordinate of the second body. + * Here v1 and x1 are the velocity and the coordinate of the first body, + * v2 and x2 are the velocity and the coordinate of the second body. * * When x1 reaches x2, the velocity direction of the body with mass m changes to * the opposite. * * As an example, let us consider the following initial conditions: - * v1 = 10, v2 = -2, x1 = 0, x2 = 5 for t = 0. + * v1 = 10, v2 = -2, x1 = 0, x2 = 4 for t = 0. + * + * Constants f0 = 2, m = 1. + * + * This is a very simplified collision model but the goal is to demostrate how + * the Observer function can be used as the event function, where the user can + * update the state vector (change velocity direction, for example) during the + * time integration. + * + * Note that in the solver options, the time step is restricted (in order to + * better resolve the collision event in time) and we use BDF-1 time integrator + * to avoid oscillations. */ #include @@ -43,7 +55,7 @@ namespace plt = matplotlibcpp; */ class MyRHS : public RHS { - const double f0 = 10.0; + const double f0 = 2.0; const double m = 1.0; public: @@ -53,8 +65,8 @@ class MyRHS : public RHS */ void operator()(const state_type &x, state_type &f, const double t) { - double F1 = -std::copysign(1.0, x[0]) * f0; - double F2 = -std::copysign(1.0, x[1]) * f0; + double F1 = -x[0] * f0; + double F2 = -x[1] * f0; f[0] = F1 / m; f[1] = F2 / (10.0 * m); @@ -64,12 +76,8 @@ class MyRHS : public RHS }; /* - * (Optional) Observer + * Observer (event) function implementation * ============================================================================= - * Every time step checks that - * (1) x*x + y*y = 1, and - * (2) x(t) - sin(t) = 0 for t <= pi/2, x(t) = 1 for t > pi/2 - * and prints solution and errors to console. */ class MySolver : public Solver { @@ -89,6 +97,7 @@ class MySolver : public Solver */ void observer(state_type &x, const double t) { + // Print solution to screen every time step std::cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << '\t' << x[3] << '\n'; @@ -109,25 +118,6 @@ class MySolver : public Solver } }; -/* - * (Optional) Analytical Jacobian in simplified 3-array sparse format - * ============================================================================= - */ -class MyJacobian : public Jacobian -{ -public: - explicit MyJacobian(RHS &rhs) : Jacobian(rhs) {} - - /* - * Receives the current solution vector x and the current time t. Defines - * the analytical Jacobian matrix J. - */ - void operator()(sparse_matrix_holder &J, const state_type &x, - const double t) - { - } -}; - /* * MAIN FUNCTION * ============================================================================= @@ -137,7 +127,7 @@ class MyJacobian : public Jacobian int main() { // Solution time 0 <= t <= t1 - double t1 = 1.0; + double t1 = 1; // Define the state vector for 4 equations state_type x(4); @@ -146,7 +136,7 @@ int main() x[0] = 10; // Initial velocity v1 x[1] = -2; // Initial velocity v2 x[2] = 0; // Initial coordinate x1 - x[3] = 5; // Initial coordinate x2 + x[3] = 4; // Initial coordinate x2 // Set up the RHS of the problem. // Class MyRHS inherits abstract RHS class from dae-cpp library. @@ -165,18 +155,14 @@ int main() opt.bdf_order = 1; // Use BDF-1 opt.verbosity = 0; // Suppress output to screen (we have our own output // defined in Observer function above) - opt.dt_init = 0.01; // Change the initial time step - opt.dt_max = 0.01; // Restrict the maximum time step - - // We can override Jacobian class from dae-cpp library and provide - // analytical Jacobian. - // MyJacobian jac(rhs); + opt.dt_init = 0.001; // Change the initial time step + opt.dt_max = 0.001; // Restrict the maximum time step - // Or we can use numerically estimated Jacobian with the given tolerance. + // We can use numerically estimated Jacobian with the given tolerance Jacobian jac(rhs, 1e-8); - // Create an instance of the solver with particular RHS, Mass matrix, - // Jacobian and solver options + // Create an instance of the solver with the RHS, Mass matrix, Jacobian and + // the solver options MySolver solve(rhs, jac, mass, opt); // Now we are ready to solve the set of DAEs @@ -188,19 +174,22 @@ int main() // Plot the solution #ifdef PLOTTING - // plt::figure(); - // plt::figure_size(640, 480); - // plt::named_semilogx("x", solve.x_axis, solve.x0); - // plt::named_semilogx("y", solve.x_axis, solve.x1); - // plt::xlabel("time"); - // plt::title("Two bodies"); - // plt::grid(true); - // plt::legend(); - - // // Save figure - // const char *filename = "two_bodies.png"; - // std::cout << "Saving result to " << filename << "...\n"; - // plt::save(filename); + plt::figure(); + plt::figure_size(640, 480); + plt::named_plot("x1", solve.x_axis, solve.x1, "b--"); + plt::named_plot("x2", solve.x_axis, solve.x2, "r--"); + plt::named_plot("v1", solve.x_axis, solve.v1, "b-"); + plt::named_plot("v2", solve.x_axis, solve.v2, "r-"); + plt::xlabel("time"); + plt::ylabel("coordinate and velocity"); + plt::title("Two bodies"); + plt::grid(true); + plt::legend(); + + // Save figure + const char *filename = "two_bodies.png"; + std::cout << "Saving result to " << filename << "...\n"; + plt::save(filename); #endif if(status) diff --git a/examples/two_bodies/two_bodies.png b/examples/two_bodies/two_bodies.png index ae3552f5b4ac19383834c30bc77bda9dca7a69cb..291e8d24446838c069b6f11a69744b4a67acd14b 100755 GIT binary patch literal 30371 zcmdqJby$^M^ewsp0cntK1u5xnPyt0+P`Xp4yGx`6M7j+Gm2P3v-KZcT-69Q2$C=yj z`Q3Bx{qy{Jcpkq`d1J44y=%@n#+YO6NDa071h_P~2n2%Qfug)70)ZZcK%mWC#e&}m zf16r@|6Ost`{2=4`0=}H83F&saZ=QCMIeaGP=C-q%H}_XUy8XY=(=e+TDy6gxmY3W z&D@;q9Np}mnqT*@a&dj?=pe|$&m+Kf{fV2KlLRmC|31#+=widm68%;Qfw+!%Ab;nP zSLVjFx9;N~7hSuD;{EKY7!g!a$rX92>B$xEtS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MvedYGZi|^0#jv@}FIB&)I2UKo2QzWP0@B zSbb#gL>t$U?UYVCC3Gp0lsw?Ne4FZE^>j}kqJi9;ph$wMs79yh_pI^1n&|)M#|E69 zrut-R3F07x1Dq-$FT!b93OT^OibUCZ$Z$T&X2Sgm5d`K{Lv!WsQ8=_!9&+xFq~ST7N9v9!gq?$4x;V*)aN}bMV_Z0WZG&D9z>$d~|Mz%F{4W^Uy;c@h R41wnh(Nc%0y;Zdi{|~{Iq>2Cl From 7f1f5efc61a041ba23b56b995f3ba06fe82d3773 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 1 May 2021 19:53:56 +0100 Subject: [PATCH 084/274] Add Observer test --- examples/two_bodies/two_bodies.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/two_bodies/two_bodies.cpp b/examples/two_bodies/two_bodies.cpp index 369fe60..8e4cc12 100644 --- a/examples/two_bodies/two_bodies.cpp +++ b/examples/two_bodies/two_bodies.cpp @@ -192,7 +192,9 @@ int main() plt::save(filename); #endif - if(status) + // x[2] > x[3] would mean that the collision condition defined in Observer + // did not trigger. + if(status || (x[2] > x[3])) std::cout << "...Test FAILED\n\n"; else std::cout << "...done\n\n"; From 61bc86c9fc687530fd4bf482e6ef319a7e062488 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 1 May 2021 20:11:18 +0100 Subject: [PATCH 085/274] Update DOI and installation procedure --- README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e4500ff..8a0efb7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.com/ikorotkin/dae-cpp.svg?branch=master)](https://travis-ci.com/ikorotkin/dae-cpp) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/4aa33eb3a2834808a6cd1b81e0d8cc23)](https://www.codacy.com/app/ikorotkin/dae-cpp?utm_source=github.com&utm_medium=referral&utm_content=ikorotkin/dae-cpp&utm_campaign=Badge_Grade) -[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3241870.svg)](https://doi.org/10.5281/zenodo.3241870) +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3256507.svg)](https://doi.org/10.5281/zenodo.3256507) A simple but powerful C++ solver for Differential Algebraic Equation (DAE) systems. @@ -44,6 +44,7 @@ Install the GPG key for the repository: ```bash wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB +rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB ``` Add the APT Repository: @@ -56,10 +57,17 @@ Update the list of packages and install the library: ```bash sudo apt-get update -sudo apt-get install intel-mkl-2019.3-062 +sudo apt-get install intel-mkl-2019.5-075 ``` -This will install Intel MKL 2019.3. The list of all available versions can be found [here](https://software.intel.com/en-us/articles/installing-intel-free-libs-and-python-apt-repo). +This will install Intel MKL 2019.5. The list of all available versions and more information can be found [here](https://software.intel.com/en-us/articles/installing-intel-free-libs-and-python-apt-repo). + +Note the latest versions of Intel MKL (2020) may produce a lot of run-time warnings. This is a known issue, the only workaround is to suppress them exporting the following variable: + +```bash +# Suppress MKL run-time warnings (to fix a known issue of MKL 2020) +export KMP_WARNINGS=0 +``` ### Linux @@ -72,7 +80,7 @@ sudo apt-get install g++ cmake cmake-curses-gui git In order to enable plotting (optional), `python3`, `matplotlib` and `numpy` should be installed: ```bash -sudo apt-get install python3 python3-numpy python3-matplotlib +sudo apt-get install python3 python3-dev python3-numpy python3-matplotlib ``` Then download dae-cpp library: From 5c4ab29d6247a2b225754b9ca8931ad6ba5ee6bb Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 1 May 2021 20:23:03 +0100 Subject: [PATCH 086/274] Helper function that compares two Jacobians now returns the number of differences found --- src/debug_output.cpp | 8 +++++--- src/jacobian.h | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/debug_output.cpp b/src/debug_output.cpp index 245f786..ff3b6ab 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -219,7 +219,7 @@ void Jacobian::print(const state_type &x, const double t) /* * Helper function to compare two Jacobians and write the difference */ -void Jacobian::compare(Jacobian jac, const state_type &x, const double t, +int Jacobian::compare(Jacobian jac, const state_type &x, const double t, const double tol) { std::cout << "Jacobian::compare() -- INFO: Trying to compare two " @@ -241,7 +241,7 @@ void Jacobian::compare(Jacobian jac, const state_type &x, const double t, { std::cout << "Jacobian::compare() -- ERROR: the sizes of the " "matrices do not match ('ia' indexes are different).\n"; - return; + return -1; } std::ofstream outFile; @@ -258,7 +258,7 @@ void Jacobian::compare(Jacobian jac, const state_type &x, const double t, << delimiter << "Jac_reference" << delimiter << "Rel_difference" << '\n'; - std::size_t ndiff = 0; // counts differences + int ndiff = 0; // counts differences for(MKL_INT j = 0; j < size; j++) { @@ -308,6 +308,8 @@ void Jacobian::compare(Jacobian jac, const state_type &x, const double t, << " difference(s).\n"; outFile.close(); + + return ndiff; } } // namespace daecpp_namespace_name diff --git a/src/jacobian.h b/src/jacobian.h index 087ad19..cab84f1 100644 --- a/src/jacobian.h +++ b/src/jacobian.h @@ -66,9 +66,10 @@ class Jacobian * Helper function to compare two Jacobians and write the differences. * Comparison will be made with the external Jacobian jac (usually, * numerical Jacobian) using vector x at time t with the given tolerance. + * Returns the number of differences found. */ - void compare(Jacobian jac, const state_type &x, const double t, - const double tol); + int compare(Jacobian jac, const state_type &x, const double t, + const double tol); }; } // namespace daecpp_namespace_name From 0184ae9d0a3e7f3f834b35adcaf34b61a6c6a7b6 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 1 May 2021 20:41:30 +0100 Subject: [PATCH 087/274] Added virtual destructors to the base classes --- src/RHS.h | 2 ++ src/jacobian.h | 2 ++ src/mass_matrix.h | 2 ++ src/solver_options.h | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/RHS.h b/src/RHS.h index 3293322..90c295c 100644 --- a/src/RHS.h +++ b/src/RHS.h @@ -15,6 +15,8 @@ class RHS std::size_t m_dump_file_counter = 0; public: + virtual ~RHS() {} + /* * Takes vector x and time t and returns vector f. * This function is pure virtual and must be overriden. diff --git a/src/jacobian.h b/src/jacobian.h index cab84f1..2604d58 100644 --- a/src/jacobian.h +++ b/src/jacobian.h @@ -46,6 +46,8 @@ class Jacobian // TODO: Check user's tol parameter. Too small tol may lead to crash. } + virtual ~Jacobian() {} + /* * Can be overriden to provide analytical Jacobian */ diff --git a/src/mass_matrix.h b/src/mass_matrix.h index 1153572..f52df5f 100644 --- a/src/mass_matrix.h +++ b/src/mass_matrix.h @@ -23,6 +23,8 @@ class MassMatrix void m_matrix_converter(daecpp::sparse_matrix_holder &M); public: + virtual ~MassMatrix() {} + /* * The matrix should be defined in sparse format, * see three array sparse format decription on diff --git a/src/solver_options.h b/src/solver_options.h index 2e62685..e6c06e7 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -136,6 +136,8 @@ class SolverOptions SolverOptions() = default; + virtual ~SolverOptions() = default; + // Initialises Intel MKL PARDISO parameters (iparam) array void set_iparm_for_pardiso(MKL_INT *iparm); From b1f225c9088b5083ff97c9a81eca24cd3bb70c76 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 1 May 2021 23:30:27 +0100 Subject: [PATCH 088/274] Commented out the output to console for Jacobian compare function since the number of differences is returned and saved to a file --- src/debug_output.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/debug_output.cpp b/src/debug_output.cpp index ff3b6ab..dec2253 100644 --- a/src/debug_output.cpp +++ b/src/debug_output.cpp @@ -220,11 +220,11 @@ void Jacobian::print(const state_type &x, const double t) * Helper function to compare two Jacobians and write the difference */ int Jacobian::compare(Jacobian jac, const state_type &x, const double t, - const double tol) + const double tol) { - std::cout << "Jacobian::compare() -- INFO: Trying to compare two " - "Jacobians at time t = " - << t << " and the tolerance tol = " << tol << "...\n"; + // std::cout << "Jacobian::compare() -- INFO: Trying to compare two " + // "Jacobians at time t = " + // << t << " and the tolerance tol = " << tol << "...\n"; sparse_matrix_holder M, J; @@ -304,8 +304,8 @@ int Jacobian::compare(Jacobian jac, const state_type &x, const double t, } outFile << "Total number of differences found: " << ndiff << '\n'; - std::cout << "Jacobian::compare() -- INFO: Found " << ndiff - << " difference(s).\n"; + // std::cout << "Jacobian::compare() -- INFO: Found " << ndiff + // << " difference(s).\n"; outFile.close(); From 48b3f7e7f00f2010f4a7dba10b4203a6f0a982a6 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 3 May 2021 23:15:52 +0100 Subject: [PATCH 089/274] Hide memory info for verbosity level 3, add level 4 --- src/solver.cpp | 2 +- src/solver_options.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index e85297a..06c4c30 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -229,7 +229,7 @@ int Solver::operator()(state_type &x, double &t1) m_mkl_a, m_ia, m_ja, &m_idum, &m_nrhs, m_iparm, &m_msglvl, &m_ddum, &m_ddum, &m_error); - if(m_opt.verbosity > 2) + if(m_opt.verbosity > 3) { if(m_iparm[14] > peak_mem1 || m_iparm[15] > peak_mem2 || m_iparm[16] > peak_mem3) diff --git a/src/solver_options.h b/src/solver_options.h index e6c06e7..9c74d55 100644 --- a/src/solver_options.h +++ b/src/solver_options.h @@ -72,7 +72,8 @@ class SolverOptions double dt_max = 1.0 / dt_eps_m; // Verbosity level of the solver: - // 0 - silent, 1 - basic information, 2 - time stepping info, 3 - all info + // 0 - silent, 1 - basic information, 2 - time stepping info, + // 3 - time integrator info, 4 - all info int verbosity = 2; // Simple Adaptive Time Stepping options From 4478080e9c9f21ae65c023e9b6acd2f4d61aae6f Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Sat, 15 May 2021 22:48:55 +0100 Subject: [PATCH 090/274] Allow the user to adjust the maximum time step during the simulation --- src/solver.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/solver.cpp b/src/solver.cpp index 06c4c30..0e84ec0 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -366,7 +366,7 @@ int Solver::operator()(state_type &x, double &t1) if(m_opt.verbosity > 1) { std::cout << "#"; - // std::cout.flush(); // This degrades performance in some cases + // std::cout.flush(); // This degrades performance } if(is_converged) @@ -408,6 +408,15 @@ int Solver::operator()(state_type &x, double &t1) else if(status > 0) continue; // Re-run the current time step + // Call Observer to provide a user with intermediate results + observer(x, m_iterator_state.t); + + // Check the time step does not exceed dt_max + if(m_iterator_state.dt_eval > m_opt.dt_max) + { + m_iterator_state.dt_eval = m_opt.dt_max; + } + // Looks like the solver has reached the target time t1 if((m_iterator_state.t + m_iterator_state.dt_eval) >= (t1 - m_opt.dt_min)) @@ -426,9 +435,6 @@ int Solver::operator()(state_type &x, double &t1) } } - // Call Observer to provide a user with intermediate results - observer(x, m_iterator_state.t); - // Rewrite solution history for(int d = m_opt.bdf_order - 1; d > 0; d--) { From 199fc2148bd61fe70e06d9249a7fdec78f9062fb Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Tue, 25 May 2021 10:02:47 +0100 Subject: [PATCH 091/274] Switch to central differences for estimated numerical Jacobian --- src/jacobian.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jacobian.cpp b/src/jacobian.cpp index a121cf3..ca7fa02 100644 --- a/src/jacobian.cpp +++ b/src/jacobian.cpp @@ -13,7 +13,7 @@ #include "jacobian.h" // clang-format off -#define JACOBIAN_SCHEME 1 // 0 - Central differences: (f(x+h) - f(x-h)) / (2*h) +#define JACOBIAN_SCHEME 0 // 0 - Central differences: (f(x+h) - f(x-h)) / (2*h) // 1 - Faster but less accurate scheme: (f(x+h) - f(x)) / h // clang-format on From 6562f417494e1a55a6c235289770f23c74441991 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 31 May 2021 14:26:41 +0100 Subject: [PATCH 092/274] Updated CMake file --- CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf14b6a..a1377a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,13 +49,20 @@ if(WIN32) set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../compiler/lib/ia32_win") endif() else(WIN32) + # MKL library if(EXISTS ${DAE_MKL_DIR}/lib/intel64) set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/intel64") - set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib/intel64") - else(EXISTS ${DAE_MKL_DIR}/lib/intel64) + elseif(EXISTS ${DAE_MKL_DIR}/lib/intel64) set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib") - set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib") endif(EXISTS ${DAE_MKL_DIR}/lib/intel64) + # Intel OMP library + if(EXISTS ${DAE_MKL_DIR}/../lib/intel64) + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib/intel64") + elseif(EXISTS ${DAE_MKL_DIR}/../lib) + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib") + elseif(EXISTS ${DAE_MKL_DIR}/../compiler/lib/intel64) + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../compiler/lib/intel64") + endif(EXISTS ${DAE_MKL_DIR}/../lib/intel64) endif(WIN32) From 144aa8e62b2dce50473ddc3acaa9c87abd1a9c15 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 31 May 2021 14:57:32 +0100 Subject: [PATCH 093/274] Fixed cmake file --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1377a5..f5525be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,16 +52,16 @@ else(WIN32) # MKL library if(EXISTS ${DAE_MKL_DIR}/lib/intel64) set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib/intel64") - elseif(EXISTS ${DAE_MKL_DIR}/lib/intel64) + else(EXISTS ${DAE_MKL_DIR}/lib/intel64) set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib") endif(EXISTS ${DAE_MKL_DIR}/lib/intel64) # Intel OMP library if(EXISTS ${DAE_MKL_DIR}/../lib/intel64) set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib/intel64") - elseif(EXISTS ${DAE_MKL_DIR}/../lib) - set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib") elseif(EXISTS ${DAE_MKL_DIR}/../compiler/lib/intel64) set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../compiler/lib/intel64") + else(EXISTS ${DAE_MKL_DIR}/../lib/intel64) + set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib") endif(EXISTS ${DAE_MKL_DIR}/../lib/intel64) endif(WIN32) From b26e62130979f60c87f569f14ec1e4b6a37d9998 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Mon, 31 May 2021 15:33:24 +0100 Subject: [PATCH 094/274] Fix cmake file --- CMakeLists.txt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5525be..a356921 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,13 +56,11 @@ else(WIN32) set(DAE_MKL_LIB "${DAE_MKL_DIR}/lib") endif(EXISTS ${DAE_MKL_DIR}/lib/intel64) # Intel OMP library - if(EXISTS ${DAE_MKL_DIR}/../lib/intel64) - set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib/intel64") - elseif(EXISTS ${DAE_MKL_DIR}/../compiler/lib/intel64) - set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../compiler/lib/intel64") - else(EXISTS ${DAE_MKL_DIR}/../lib/intel64) - set(DAE_INTEL_LIB "${DAE_MKL_DIR}/../lib") - endif(EXISTS ${DAE_MKL_DIR}/../lib/intel64) + find_path(DAE_INTEL_LIB NAMES libiomp5.so libiomp5.a PATHS + ${DAE_MKL_DIR}/../lib/intel64 + ${DAE_MKL_DIR}/../compiler/lib/intel64 + ${DAE_MKL_DIR}/../lib + DOC "Path to libiomp5 (Intel OMP library)") endif(WIN32) From ab78170a3231c1e9f11e5ebeb0449038ac2000b4 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 20 Mar 2024 14:53:48 +0000 Subject: [PATCH 095/274] Add LICENSE and README template --- .clang-format | 149 ------- .gitignore | 12 +- .travis.yml | 20 - LICENSE | 2 +- README.md | 393 +--------------- CMakeLists.txt => archived/CMakeLists.txt | 0 archived/README.md | 422 ++++++++++++++++++ clang-tidy.sh => archived/clang-tidy.sh | 0 .../examples}/diffusion_2d/diffusion_2d.cpp | 0 .../examples}/diffusion_2d/diffusion_2d.png | Bin .../diffusion_2d/diffusion_2d_RHS.cpp | 0 .../examples}/diffusion_2d/diffusion_2d_RHS.h | 0 .../examples}/perovskite/perovskite.cpp | 0 .../examples}/perovskite/perovskite.png | Bin .../perovskite/perovskite_Jacobian.cpp | 0 .../perovskite/perovskite_Jacobian.h | 0 .../examples}/perovskite/perovskite_Mass.cpp | 0 .../examples}/perovskite/perovskite_Mass.h | 0 .../examples}/perovskite/perovskite_RHS.cpp | 0 .../examples}/perovskite/perovskite_RHS.h | 0 .../perovskite/perovskite_observer.h | 0 .../perovskite/perovskite_parameters.h | 0 .../examples}/robertson/robertson.cpp | 0 .../examples}/robertson/robertson.png | Bin .../examples}/simple_dae/simple_dae.cpp | 0 .../examples}/simple_dae/simple_dae.png | Bin .../examples}/two_bodies/two_bodies.cpp | 0 .../examples}/two_bodies/two_bodies.png | Bin {src => archived/src}/CMakeLists.txt | 0 {src => archived/src}/RHS.h | 0 {src => archived/src}/cmake_config.h | 0 {src => archived/src}/cmake_config.h.in | 0 {src => archived/src}/debug_output.cpp | 0 .../src}/external/boost/LICENSE_1_0.txt | 0 .../src}/external/boost/assert.hpp | 0 .../src}/external/matplotlib-cpp/LICENSE | 0 .../matplotlib-cpp/LICENSE.matplotlib | 0 .../external/matplotlib-cpp/matplotlibcpp.h | 0 {src => archived/src}/jacobian.cpp | 0 {src => archived/src}/jacobian.h | 0 {src => archived/src}/mass_matrix.cpp | 0 {src => archived/src}/mass_matrix.h | 0 {src => archived/src}/matrix_add.cpp | 0 {src => archived/src}/matrix_checker.cpp | 0 {src => archived/src}/matrix_converter.cpp | 0 {src => archived/src}/solver.cpp | 0 {src => archived/src}/solver.h | 0 {src => archived/src}/solver_options.cpp | 0 {src => archived/src}/solver_options.h | 0 {src => archived/src}/time_integrator.cpp | 0 {src => archived/src}/time_integrator.h | 0 {src => archived/src}/time_stepper.cpp | 0 {src => archived/src}/typedefs.h | 0 .../vscode_old}/c_cpp_properties.json | 0 {.vscode => archived/vscode_old}/launch.json | 0 .../vscode_old}/settings.json | 0 {.vscode => archived/vscode_old}/tasks.json | 0 build_static_lib.sh | 20 - set_MKL_env | 2 - set_MKL_env_win.bat | 5 - test.sh | 18 - 61 files changed, 430 insertions(+), 613 deletions(-) delete mode 100644 .clang-format delete mode 100644 .travis.yml rename CMakeLists.txt => archived/CMakeLists.txt (100%) create mode 100644 archived/README.md rename clang-tidy.sh => archived/clang-tidy.sh (100%) rename {examples => archived/examples}/diffusion_2d/diffusion_2d.cpp (100%) rename {examples => archived/examples}/diffusion_2d/diffusion_2d.png (100%) rename {examples => archived/examples}/diffusion_2d/diffusion_2d_RHS.cpp (100%) rename {examples => archived/examples}/diffusion_2d/diffusion_2d_RHS.h (100%) rename {examples => archived/examples}/perovskite/perovskite.cpp (100%) rename {examples => archived/examples}/perovskite/perovskite.png (100%) rename {examples => archived/examples}/perovskite/perovskite_Jacobian.cpp (100%) rename {examples => archived/examples}/perovskite/perovskite_Jacobian.h (100%) rename {examples => archived/examples}/perovskite/perovskite_Mass.cpp (100%) rename {examples => archived/examples}/perovskite/perovskite_Mass.h (100%) rename {examples => archived/examples}/perovskite/perovskite_RHS.cpp (100%) rename {examples => archived/examples}/perovskite/perovskite_RHS.h (100%) rename {examples => archived/examples}/perovskite/perovskite_observer.h (100%) rename {examples => archived/examples}/perovskite/perovskite_parameters.h (100%) rename {examples => archived/examples}/robertson/robertson.cpp (100%) rename {examples => archived/examples}/robertson/robertson.png (100%) rename {examples => archived/examples}/simple_dae/simple_dae.cpp (100%) rename {examples => archived/examples}/simple_dae/simple_dae.png (100%) rename {examples => archived/examples}/two_bodies/two_bodies.cpp (100%) rename {examples => archived/examples}/two_bodies/two_bodies.png (100%) rename {src => archived/src}/CMakeLists.txt (100%) rename {src => archived/src}/RHS.h (100%) rename {src => archived/src}/cmake_config.h (100%) rename {src => archived/src}/cmake_config.h.in (100%) rename {src => archived/src}/debug_output.cpp (100%) rename {src => archived/src}/external/boost/LICENSE_1_0.txt (100%) rename {src => archived/src}/external/boost/assert.hpp (100%) rename {src => archived/src}/external/matplotlib-cpp/LICENSE (100%) rename {src => archived/src}/external/matplotlib-cpp/LICENSE.matplotlib (100%) rename {src => archived/src}/external/matplotlib-cpp/matplotlibcpp.h (100%) rename {src => archived/src}/jacobian.cpp (100%) rename {src => archived/src}/jacobian.h (100%) rename {src => archived/src}/mass_matrix.cpp (100%) rename {src => archived/src}/mass_matrix.h (100%) rename {src => archived/src}/matrix_add.cpp (100%) rename {src => archived/src}/matrix_checker.cpp (100%) rename {src => archived/src}/matrix_converter.cpp (100%) rename {src => archived/src}/solver.cpp (100%) rename {src => archived/src}/solver.h (100%) rename {src => archived/src}/solver_options.cpp (100%) rename {src => archived/src}/solver_options.h (100%) rename {src => archived/src}/time_integrator.cpp (100%) rename {src => archived/src}/time_integrator.h (100%) rename {src => archived/src}/time_stepper.cpp (100%) rename {src => archived/src}/typedefs.h (100%) rename {.vscode => archived/vscode_old}/c_cpp_properties.json (100%) rename {.vscode => archived/vscode_old}/launch.json (100%) rename {.vscode => archived/vscode_old}/settings.json (100%) rename {.vscode => archived/vscode_old}/tasks.json (100%) delete mode 100755 build_static_lib.sh delete mode 100644 set_MKL_env delete mode 100644 set_MKL_env_win.bat delete mode 100755 test.sh diff --git a/.clang-format b/.clang-format deleted file mode 100644 index e298ffc..0000000 --- a/.clang-format +++ /dev/null @@ -1,149 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM - -AccessModifierOffset: -4 - -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: true -AlignConsecutiveDeclarations: true -AlignEscapedNewlines: Right -AlignOperands: true -AlignTrailingComments: true - -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false - -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: false - -BinPackArguments: true -BinPackParameters: true - -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true - -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Allman -BreakBeforeInheritanceComma: false -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon -BreakAfterJavaFieldAnnotations: false -BreakStringLiterals: true - -ColumnLimit: 80 - -CommentPragmas: '^ IWYU pragma:' - -CompactNamespaces: false - -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 - -Cpp11BracedListStyle: true - -DerivePointerAlignment: false - -DisableFormat: false - -ExperimentalAutoDetectBinPacking: false - -FixNamespaceComments: true - -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH - -IncludeBlocks: Preserve - -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 - -IncludeIsMainRegex: '(Test)?$' - -IndentCaseLabels: false -IndentPPDirectives: None -IndentWidth: 4 -IndentWrappedFunctionNames: false - -JavaScriptQuotes: Leave -JavaScriptWrapImports: true - -KeepEmptyLinesAtTheStartOfBlocks: true - -MacroBlockBegin: '' -MacroBlockEnd: '' - -MaxEmptyLinesToKeep: 1 - -NamespaceIndentation: None - -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true - -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 - -PointerAlignment: Right - -# RawStringFormats: -# - Delimiter: pb -# Language: TextProto -# BasedOnStyle: google - -ReflowComments: true - -SortIncludes: false -SortUsingDeclarations: false - -SpaceAfterCStyleCast: false -SpaceAfterTemplateKeyword: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: Never -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: false -SpacesInContainerLiterals: false -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false - -Standard: Cpp11 - -TabWidth: 4 -UseTab: Never -... diff --git a/.gitignore b/.gitignore index 90db366..8c9335a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1 @@ -*.exe -.vs/ -.vscode/ipch/ -Debug/ -Release/ -x64/ -*.sln -*.vcxproj -*.vcxproj.filters -*.vcxproj.user -build*/ +# Executables and builds diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3542b7d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: cpp - -before_install: - - wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB - - sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB - - sudo sh -c 'echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list' - - sudo apt-get update - - travis_retry sudo apt-get install intel-mkl-2019.3-062 cmake - -env: - matrix: - - DAE_SINGLE=OFF DAE_LONG_INT=OFF - - DAE_SINGLE=OFF DAE_LONG_INT=ON - - DAE_SINGLE=ON DAE_LONG_INT=OFF - -script: - - mkdir build && pushd build && cmake -DDAE_SINGLE=$DAE_SINGLE -DDAE_LONG_INT=$DAE_LONG_INT .. && make -j4 && ctest -V - -compiler: - - gcc diff --git a/LICENSE b/LICENSE index 09a9cd5..945d017 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019-2021 Ivan Korotkin +Copyright (c) 2024 Ivan Korotkin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8a0efb7..3faa05c 100644 --- a/README.md +++ b/README.md @@ -1,422 +1,41 @@ # dae-cpp -[![Build Status](https://travis-ci.com/ikorotkin/dae-cpp.svg?branch=master)](https://travis-ci.com/ikorotkin/dae-cpp) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4aa33eb3a2834808a6cd1b81e0d8cc23)](https://www.codacy.com/app/ikorotkin/dae-cpp?utm_source=github.com&utm_medium=referral&utm_content=ikorotkin/dae-cpp&utm_campaign=Badge_Grade) -[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3256507.svg)](https://doi.org/10.5281/zenodo.3256507) - -A simple but powerful C++ solver for Differential Algebraic Equation (DAE) systems. +A simple but powerful header-only C++ solver for systems of Differential and Algebraic Equations (DAE). ## What is dae-cpp -A cross-platform, parallel C++ library for solving user-defined, stiff systems of DAEs (an initial value problem). The system may contain both differential and algebraic equations and can be written in the following matrix-vector form: - -

- -

- -where Mass matrix **M** can be singular, and the RHS **f**(**x**) is a nonlinear function of a real vector **x** and time *t*. - -For the numerical integration the solver uses implicit [BDF](https://en.wikipedia.org/wiki/Backward_differentiation_formula) (Backward Differentiation Formula) method of orders 1-6 (can be defined by a user) with adaptive time stepping. - ### How does it work -BDF time stepper reduces the original DAE system to a system of nonlinear equations that is solved using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. - ### The main features of the solver -- Can resolve DAE systems of 108 equations and even more (depending on the Jacobian matrix sparsity and machine's RAM). -- A user can provide analytical Jacobian matrix for better performance or use built-in parallel function provided by the solver to estimate numerical Jacobian. -- Utilises all available cores on the machine for better performance (this can be overridden by a user). -- Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. -- A user can get access to the solution at each time step by overriding Observer function (this is optional). -- The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. -- The user-defined RHS, Mass matrix and Jacobian can be saved to a file for debugging or visualisation if needed. -- Easy-to-follow examples (see, for example, [simple_dae.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/simple_dae/simple_dae.cpp), [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp)) to kick-start the user's project. - ## Installation -This is a cross-platform software that works on Linux (e.g. Ubuntu), Windows and macOS. The main library (the DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS and the Full Package. - -An alternative and probably the most convenient way to download and install Intel MKL on Ubuntu (using APT Repository) is the following. - -Install the GPG key for the repository: - -```bash -wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB -sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB -rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB -``` - -Add the APT Repository: - -```bash -sudo sh -c 'echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list' -``` - -Update the list of packages and install the library: - -```bash -sudo apt-get update -sudo apt-get install intel-mkl-2019.5-075 -``` - -This will install Intel MKL 2019.5. The list of all available versions and more information can be found [here](https://software.intel.com/en-us/articles/installing-intel-free-libs-and-python-apt-repo). - -Note the latest versions of Intel MKL (2020) may produce a lot of run-time warnings. This is a known issue, the only workaround is to suppress them exporting the following variable: - -```bash -# Suppress MKL run-time warnings (to fix a known issue of MKL 2020) -export KMP_WARNINGS=0 -``` - -### Linux - -On Linux make sure you have `git`, `cmake` and `g++` installed: - -```bash -sudo apt-get install g++ cmake cmake-curses-gui git -``` - -In order to enable plotting (optional), `python3`, `matplotlib` and `numpy` should be installed: - -```bash -sudo apt-get install python3 python3-dev python3-numpy python3-matplotlib -``` - -Then download dae-cpp library: - -```bash -git clone https://github.com/ikorotkin/dae-cpp.git -``` - -The easiest way to install the library and compile all examples is just to create the build directory, then execute `cmake` (providing installation path) and `make`: - -```bash -cd dae-cpp -mkdir build -cd build -cmake .. -DCMAKE_INSTALL_PREFIX=/install_path -make -j4 -make install -``` - -where `/install_path` is the user-defined path where the package should be installed. - -Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`. - -Instead of `cmake -DCMAKE_INSTALL_PREFIX=/install_path ..` you might consider using `ccmake ..`, a GUI for `cmake` that will allow you to see all the options available before building the solver. - -#### Test the solver - -The DAE solver can perform a quick self test. To build the test, dae-cpp should be installed with `DAE_TEST=ON` option (it is ON by default). To start the test, from the build directory execute `ctest`: - -```bash -ctest -``` - -During this test the solver will solve DAE systems from [examples](https://github.com/ikorotkin/dae-cpp/tree/master/examples) directory using analytical (if available) and numerical Jacobians, and then compare the results with the reference solutions. - -#### More building options - -- `DAE_LONG_INT` - Use long integer representation for huge systems (more than ~107 equations). This option is OFF by default. For relatively small systems it is recommended to leave it OFF. -- `DAE_FORTRAN_STYLE` - If ON, the matrices will be defined using FORTRAN style (one-based indexing of columns and rows). By default it is OFF (zero-based indexing). -- `DAE_SINGLE` - If ON, the single precision will be used in the solver instead of double. Single precision may ruin the accuracy. It is highly recommended to leave this option OFF. This option exists for the future compatibility with CUDA implementations of the solver. -- `DAE_BUILD_EXAMPLES` - Build all the examples, ON by default. -- `DAE_TEST` - Build automatic solver test, ON by default. The test can be executed by the command `ctest` from the building directory. -- `DAE_MKL_DIR` - Defines a path to Intel MKL root directory (usually `/opt/intel/mkl`). -- `PLOTTING` - Use [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting, `OFF` by default. If `ON`, `cmake` will try to find Python and `numpy` include directories and libraries. -- `PYTHON_INCLUDE` - Only if `PLOTTING=ON`, defines a path to Python include file (`Python.h`) for plotting. -- `PYTHON_NUMPY_INCLUDE` - Only if `PLOTTING=ON`, defines a path to Python `numpy` include file (`numpy/arrayobject.h`) for plotting. -- `PYTHON_LIB` - Only if `PLOTTING=ON`, defines Python library (e.g. `libpython3.6m`) for plotting. - -### Windows - -Download and install compiler (e.g. [Microsoft Visual Studio](https://visualstudio.microsoft.com/downloads/)) and [Python 3](https://www.python.org/downloads/windows/) with `numpy` and `matplotlib` modules (for plotting, optional). - -Download and install [Git](https://git-scm.com/download/win) and [CMake](https://cmake.org/download/) for Windows. - -From `Git Bash` command line clone dae-cpp library (you may need to create a working directory first): - -```bash -git clone https://github.com/ikorotkin/dae-cpp.git -``` - -Start CMake (`cmake-gui`), choose the source code path (`dae-cpp` folder) and empty target directory (it will contain Visual Studio project files). Press "Configure" button. - -If CMake cannot find any of the libraries, it will print an error message. You can modify the paths and other parameters (see [More building options](https://github.com/ikorotkin/dae-cpp#more-building-options) above) and re-configure the project. - -If configuration is successful, press "Configure" again to update the cache and then "Generate". In the target directory you will find Visual Studio project files. - -Double-click on `dae-cpp.sln` to open Visual Studio with the project. Do not forget to change Solution Configuration from `Debug` to `Release`. Build the solution (`F7` by default). After compilation, the executable files can be found in `Release` folder. - -Note that in order to execute the tests (for example, `perovskite.exe`) from `Release` folder, you need to set up Intel MKL environment variables by executing `mklvars.bat intel64` or `mklvars.bat ia32` (depending on the target platform) from `cmd`. By default `mklvars.bat` is located in MKL root folder in `bin` subdirectory, for example: - -```bash -"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64 -``` - -**_Alternatively_**, you may install [Windows Subsystem for Linux](https://docs.microsoft.com/en-gb/windows/wsl/install-win10?redirectedfrom=MSDN) and your preferred Linux Distribution (e.g. Ubuntu), and then just follow [installation instructions for Linux](#linux). - -### Mac - -Make sure you have installed: `git`, `cmake`, `gcc` and, optional, Python 3 with `numpy` and `matplotlib` modules (for plotting). If these packages are not installed yet, you may install [Homebrew](https://brew.sh/) (package manager for macOS), then install all necessary packages: - -```bash -brew install cmake git gcc python -pip3 install numpy matplotlib -``` - -Note if you install `git` for the first time you will need to configure it (change `Your Name` and `your@email` to your full name and email): - -```bash -git config --global user.name "Your Name" -git config --global user.email your@email -``` - -Then from the working directory download dae-cpp library source files: - -```bash -git clone https://github.com/ikorotkin/dae-cpp.git -``` - -Check the version of `gcc` compiler by typing `gcc` and pressing `Tab` key a few times in the terminal, it will show you the version of `gcc` currently installed, for example, `gcc-9` (you could use the command `gcc --version` but it may point to `clang` compiler for Mac that does not support OpenMP out of the box). - -Create `build` directory: - -```bash -cd dae-cpp -mkdir build -cd build -``` - -Configure the project. *Make sure `g++` version (9 in the example below) is correct*: - -```bash -cmake .. -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_INSTALL_PREFIX=$PWD -``` - -In the command above you may change the user-defined path where the package should be installed (type it instead of `$PWD`). By default the package will be installed into the current `build` directory. - -Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`. - -Instead of `cmake ..` you may consider using `ccmake ..`, a UI for `cmake` that will allow you to see and change all the options available before building the solver. - -Install dae-cpp and perform a quick self test: - -```bash -make -j4 -make install -ctest -``` +## Testing ## How to use -Please refer to [simple_dae.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/simple_dae/simple_dae.cpp), [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. - -The main usage algorithm can be the following. Consider we have a system of DAEs written in a matrix-vector form, with some Mass matrix, RHS, and some initial conditions. - ### Step 0. Include dae-cpp into the project -Include the solver's main header to the project. A shortcut to the solver's namespace (`daecpp`) can be added as well: - -```cpp -#include "path/to/dae-cpp/include/solver.h" -namespace dae = daecpp; -``` - -### Step 1. Define the DAE parameters and initial state vector - -For example, for *N* equations we should define the state vector with the size *N* and initialize it in accordance with the initial conditions: - -```cpp -// State vector -dae::state_type x(N); - -// Initial conditions -for(MKL_INT i = 0; i < N; i++) -{ - x[i] = 1.0; -} -``` - -We can get access to each element of the state vector **x** as to `std::vector` from STL. Also note that instead of `int` or any other integer types we should use `MKL_INT` type. This gives us possibility to re-compile the project with `DAE_LONG_INT` option, so the code will work fine even for extremely huge systems (with *N* more than 107). +### Step 1. Define the initial state vector ### Step 2. Set up the RHS -Create MyRHS class that inherits the abstract `daecpp::RHS` class from dae-cpp library. The parent RHS class contains a pure virtual functor (operator `()`), that must be overridden in the child class. See, for example, [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_RHS.cpp) or [diffusion_2d_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d_RHS.cpp). - -Once the RHS class is overridden, we can create an instance of the child class with some user-defined parameter container *p*: - -```cpp -MyRHS rhs(p); -``` - -In the child MyRHS class the user can also override `stop_condition` virtual function. By default (if not overridden) the function always returns `false`. The user may override this behaviour and set up one or several stop conditions for the solver depending on the solution **x** at the current time *t*. As soon as the function returns `true`, the solver will finalise the current time step and return the current solution. A trivial example of the stop condition function can be found in [perovskite_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_RHS.cpp). - -For the debugging purposes, the RHS can be saved to a file: - -```cpp -rhs.dump(x, 0); -rhs.dump(x, 0.1); -``` - -In this example we saved two RHS vectors, at time 0 and 0.1. - ### Step 3. Set up the Mass matrix -Create MyMassMatrix class that inherits the abstract `daecpp::MassMatrix` class from dae-cpp library. Similar to the previous step, the parent MassMatrix class contains a pure virtual functor (operator `()`), that must be overridden in the child class. Refer to [perovskite_Mass.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Mass.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) as an example. Note that the matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format). See also [a note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). - -Create an instance of the child MyMassMatrix class with the given size *N*: - -```cpp -MyMassMatrix mass(N); -``` - -If the Mass matrix is a simple identity matrix, one can use `daecpp::MassMatrixIdentity` class from dae-cpp library instead of inheriting `daecpp::MassMatrix`. This will create identity Mass matrix in sparse format with the given size *N*: - -```cpp -dae::MassMatrixIdentity mass(N); -``` - -For the debugging purposes, you can save the Mass matrix to a file: - -```cpp -mass.dump(); -``` - -### Step 4. Set up Jacobian matrix - -We can provide analytical Jacobian by overriding `daecpp::Jacobian` class from the dae-cpp library (see [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite_Jacobian.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Jacobian.cpp)) or just use numerically estimated one (this may significantly slow down the computation for large *N*). If provided, analytical Jacobian matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format) similar to the Mass matrix. See also [a note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). - -If we don't provide analytical Jacobian we should estimate it with the given tolerance: - -```cpp -dae::Jacobian jac(rhs, 1.0e-6); -``` - -Note that we should pass an instance of the user-defined RHS in order to estimate numerical Jacobian. - -Again, for the debugging purposes, Jacobian can be saved to a file: - -```cpp -jac.dump(x, 0); -jac.dump(x, 0.1); -``` - -In the example above we saved two Jacobians, at time 0 and 0.1. - -In some cases the derivation and coding of the analytic Jacobian can be a tricky problem itself. So `dae::Jacobian` class provides additional functionality to compare two Jacobians (one of them is numerical) and write the differences: - -```cpp -dae::Jacobian jac(rhs, 1.0e-6); // Numerical Jacobian calculated automatically (slow) -MyJacobian jac_user(rhs); // Analytic Jacobian provided by the user - -// Comparison of jac and jac_user and writing the differences to a file -jac_user.compare(jac, x, 0.1, 1e-4); -``` - -Here we compared two Jacobians at time 0.1 with the relative tolerance 10-4. +### Step 4. Set up the Jacobian matrix ### Step 5. Set the solver options -The solver has lots of options related to the solution process. They all have some default values (defined in [solver_options.h](https://github.com/ikorotkin/dae-cpp/blob/master/src/solver_options.h)) but they can be overridden by a user: - -```cpp -// Create an instance of the solver options and update some of the solver -// parameters defined in solver_options.h -dae::SolverOptions opt; - -// For example, let's change the initial time step -opt.dt_init = 0.01; -``` - ### Step 6. Solve the system -Now we are ready to create an instance of the solver with particular RHS, Mass matrix, Jacobian and the solver options, and then start the solver: - -```cpp -dae::Solver solve(rhs, jac, mass, opt); -int status = solve(x, t1); -``` - -Here *t*1 is the integration time (0 < *t* < *t*1), and **x** is the initial condition vector defined above. - -The solver returns 0 if integration is successful or error code otherwise. Solution at time *t*1 will be written into vector **x** (initial conditions will be overwritten). The actual integration time *t*1 will be returned (the solver may terminate integration earlier). That's it! - #### Optional: Set up Observer -In order to get intermediate solutions at times *t*a, *t*b, *t*c, etc. (0 < *t*a < *t*b < *t*c < ... < *t*1), for example, for plotting, one can call the solver at the given times: - -```cpp -solve(x, t_a); // solves the system in the interval [0; t_a] and stores the solution in x -solve(x, t_b); // continues solving in the interval [t_a; t_b], replaces the solution in x -solve(x, t_c); // continues solving in the interval [t_b; t_c], replaces the solution in x - // ... -solve(x, t1); // continues solving in the interval [t_c; t1] and - // stores the final solution at time t1 in x -``` - -Every call the solver will take the previous solution **x** (if available from the previous call) and overwrite it with a new one at the given time. - -But a proper (and more efficient) way to get intermediate results is to override `virtual void observer(...)` function from `daecpp::Solver` class. This observer function receives the current solution vector **x** and the current time *t* every time step and allows a user to get access to the solution at each time layer. An example of a simple observer is given in the file [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), also in [perovskite_observer.h](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_observer.h). - -### Step 7 (optional). Plot results - -Solution can be visualised using a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module. For example, if `python`, `numpy` and `matplotlib` are installed and the solver was built with `PLOTTING=ON`, the [perovskite](https://github.com/ikorotkin/dae-cpp/tree/master/examples/perovskite) example will produce the following plot: - -

- -

- -Here *P(x)* is the ion concentration in a perovskite solar cell, and *Phi(x)* is the corresponding potential distribution. - -The second example, [diffusion_2d](https://github.com/ikorotkin/dae-cpp/tree/master/examples/diffusion_2d), will produce a two-dimensional Gaussian function, a solution of two-dimensional diffusion problem with an instantaneous point source in the middle of the plane: - -

- -

- -The third example, [robertson](https://github.com/ikorotkin/dae-cpp/tree/master/examples/robertson), solves [Robertson stiff DAE problem](https://www.mathworks.com/help/matlab/ref/ode15s.html) with a conservation law. It produces the following figure: - -

- -

- -Note that by default the plotting is switched off in the examples, but the plotting-related code can be activated using `#define PLOTTING` at the very beginning of each example. Activating the plotting refers to `matplotlibcpp.h` header located in `src/external/matplotlib-cpp/` directory. +#### Optional: Set up Event function ### A note about Sparse Matrix Format -It should be noted that you must define all the diagonal elements of the matrix, even if they are zero. This greatly increases performance, and if some rows are skipped, the code will just stop working. Please double check your Mass matrix and Jacobian, they both should have the main diagonal filled in. Even if the given row is empty (all elements are zero), define zero on the main diagonal explicitly. - -If you are struggling with Intel MKL sparse format, you can use simple three-array format instead, where you need to define all non-zero elements and their indexes (coordinates) in the matrix. For example for the identity 3x3 matrix, you only need to define three non-zero elements and their position in the matrix: - -```cpp -M.A.resize(3); // Number of non-zero elements -M.ia.resize(3); // Number of non-zero elements -M.ja.resize(3); // Number of non-zero elements - -M.A[0] = 1; // First non-zero or diagonal element -M.ia[0] = 0; // Column index of the first non-zero element -M.ja[0] = 0; // Raw index of the first non-zero element - -M.A[1] = 1; // Second non-zero or diagonal element -M.ia[1] = 1; // Column index of the second non-zero element -M.ja[1] = 1; // Raw index of the second non-zero element - -M.A[2] = 1; // Third non-zero or diagonal element -M.ia[2] = 2; // Column index of the third non-zero element -M.ja[2] = 2; // Raw index of the third non-zero element -``` - -This form will be automatically converted to the three-array sparse format compatible with Intel MKL. Do not forget to define all diagonal elements even if they are zero. Do not mix the elements up (fill in the first row from left to right, then the second row, etc.). - ## Contribution and feedback -Please feel free to contribute into the project! - -If you have any questions, suggestion, or a feedback, please, submit an [issue](https://github.com/ikorotkin/dae-cpp/issues). - ## Licensing -- dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). -- Intel MKL is free for use and redistribution under [Intel Simplified Software License](https://software.intel.com/en-us/license/intel-simplified-software-license). +- dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). diff --git a/CMakeLists.txt b/archived/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to archived/CMakeLists.txt diff --git a/archived/README.md b/archived/README.md new file mode 100644 index 0000000..8a0efb7 --- /dev/null +++ b/archived/README.md @@ -0,0 +1,422 @@ +# dae-cpp + +[![Build Status](https://travis-ci.com/ikorotkin/dae-cpp.svg?branch=master)](https://travis-ci.com/ikorotkin/dae-cpp) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4aa33eb3a2834808a6cd1b81e0d8cc23)](https://www.codacy.com/app/ikorotkin/dae-cpp?utm_source=github.com&utm_medium=referral&utm_content=ikorotkin/dae-cpp&utm_campaign=Badge_Grade) +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3256507.svg)](https://doi.org/10.5281/zenodo.3256507) + +A simple but powerful C++ solver for Differential Algebraic Equation (DAE) systems. + +## What is dae-cpp + +A cross-platform, parallel C++ library for solving user-defined, stiff systems of DAEs (an initial value problem). The system may contain both differential and algebraic equations and can be written in the following matrix-vector form: + +

+ +

+ +where Mass matrix **M** can be singular, and the RHS **f**(**x**) is a nonlinear function of a real vector **x** and time *t*. + +For the numerical integration the solver uses implicit [BDF](https://en.wikipedia.org/wiki/Backward_differentiation_formula) (Backward Differentiation Formula) method of orders 1-6 (can be defined by a user) with adaptive time stepping. + +### How does it work + +BDF time stepper reduces the original DAE system to a system of nonlinear equations that is solved using iterative [Newton root-finding algorithm](https://en.wikipedia.org/wiki/Newton%27s_method). Each Newton iteration a system of linear algebraic equations is solved using Parallel Direct Sparse Solver ([Intel MKL PARDISO](https://software.intel.com/en-us/mkl-developer-reference-c-intel-mkl-pardiso-parallel-direct-sparse-solver-interface)). The sparse solver performs 3 steps: reordering and symbolic factorization of Jacobian matrix, then numerical factorization, and then back substitution + iterative refinement. Finally, depending on the convergence rate of the Newton method, variability of the solution and user-defined accuracy, the DAE solver may adjust the time step and initiate a new iteration in time. + +### The main features of the solver + +- Can resolve DAE systems of 108 equations and even more (depending on the Jacobian matrix sparsity and machine's RAM). +- A user can provide analytical Jacobian matrix for better performance or use built-in parallel function provided by the solver to estimate numerical Jacobian. +- Utilises all available cores on the machine for better performance (this can be overridden by a user). +- Allows a user to adjust most of the parameters related to the solution process in order to achieve better accuracy and performance. +- A user can get access to the solution at each time step by overriding Observer function (this is optional). +- The library provides a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting. +- The user-defined RHS, Mass matrix and Jacobian can be saved to a file for debugging or visualisation if needed. +- Easy-to-follow examples (see, for example, [simple_dae.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/simple_dae/simple_dae.cpp), [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp)) to kick-start the user's project. + +## Installation + +This is a cross-platform software that works on Linux (e.g. Ubuntu), Windows and macOS. The main library (the DAE solver itself) and all examples have only one external dependency: [Intel Math Kernel Library](https://software.intel.com/en-us/mkl), a fast and very well optimised math library. So the first step in the installation process is to download and install Intel MKL: [Linux](https://software.intel.com/en-us/mkl/choose-download/linux), [Windows](https://software.intel.com/en-us/mkl/choose-download/windows), [macOS](https://software.intel.com/en-us/mkl/choose-download/macos). Note that you may need to register in order to download the library. When asked, choose Intel Math Kernel Library for your OS and the Full Package. + +An alternative and probably the most convenient way to download and install Intel MKL on Ubuntu (using APT Repository) is the following. + +Install the GPG key for the repository: + +```bash +wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB +sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB +rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB +``` + +Add the APT Repository: + +```bash +sudo sh -c 'echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list' +``` + +Update the list of packages and install the library: + +```bash +sudo apt-get update +sudo apt-get install intel-mkl-2019.5-075 +``` + +This will install Intel MKL 2019.5. The list of all available versions and more information can be found [here](https://software.intel.com/en-us/articles/installing-intel-free-libs-and-python-apt-repo). + +Note the latest versions of Intel MKL (2020) may produce a lot of run-time warnings. This is a known issue, the only workaround is to suppress them exporting the following variable: + +```bash +# Suppress MKL run-time warnings (to fix a known issue of MKL 2020) +export KMP_WARNINGS=0 +``` + +### Linux + +On Linux make sure you have `git`, `cmake` and `g++` installed: + +```bash +sudo apt-get install g++ cmake cmake-curses-gui git +``` + +In order to enable plotting (optional), `python3`, `matplotlib` and `numpy` should be installed: + +```bash +sudo apt-get install python3 python3-dev python3-numpy python3-matplotlib +``` + +Then download dae-cpp library: + +```bash +git clone https://github.com/ikorotkin/dae-cpp.git +``` + +The easiest way to install the library and compile all examples is just to create the build directory, then execute `cmake` (providing installation path) and `make`: + +```bash +cd dae-cpp +mkdir build +cd build +cmake .. -DCMAKE_INSTALL_PREFIX=/install_path +make -j4 +make install +``` + +where `/install_path` is the user-defined path where the package should be installed. + +Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`. + +Instead of `cmake -DCMAKE_INSTALL_PREFIX=/install_path ..` you might consider using `ccmake ..`, a GUI for `cmake` that will allow you to see all the options available before building the solver. + +#### Test the solver + +The DAE solver can perform a quick self test. To build the test, dae-cpp should be installed with `DAE_TEST=ON` option (it is ON by default). To start the test, from the build directory execute `ctest`: + +```bash +ctest +``` + +During this test the solver will solve DAE systems from [examples](https://github.com/ikorotkin/dae-cpp/tree/master/examples) directory using analytical (if available) and numerical Jacobians, and then compare the results with the reference solutions. + +#### More building options + +- `DAE_LONG_INT` - Use long integer representation for huge systems (more than ~107 equations). This option is OFF by default. For relatively small systems it is recommended to leave it OFF. +- `DAE_FORTRAN_STYLE` - If ON, the matrices will be defined using FORTRAN style (one-based indexing of columns and rows). By default it is OFF (zero-based indexing). +- `DAE_SINGLE` - If ON, the single precision will be used in the solver instead of double. Single precision may ruin the accuracy. It is highly recommended to leave this option OFF. This option exists for the future compatibility with CUDA implementations of the solver. +- `DAE_BUILD_EXAMPLES` - Build all the examples, ON by default. +- `DAE_TEST` - Build automatic solver test, ON by default. The test can be executed by the command `ctest` from the building directory. +- `DAE_MKL_DIR` - Defines a path to Intel MKL root directory (usually `/opt/intel/mkl`). +- `PLOTTING` - Use [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module for plotting, `OFF` by default. If `ON`, `cmake` will try to find Python and `numpy` include directories and libraries. +- `PYTHON_INCLUDE` - Only if `PLOTTING=ON`, defines a path to Python include file (`Python.h`) for plotting. +- `PYTHON_NUMPY_INCLUDE` - Only if `PLOTTING=ON`, defines a path to Python `numpy` include file (`numpy/arrayobject.h`) for plotting. +- `PYTHON_LIB` - Only if `PLOTTING=ON`, defines Python library (e.g. `libpython3.6m`) for plotting. + +### Windows + +Download and install compiler (e.g. [Microsoft Visual Studio](https://visualstudio.microsoft.com/downloads/)) and [Python 3](https://www.python.org/downloads/windows/) with `numpy` and `matplotlib` modules (for plotting, optional). + +Download and install [Git](https://git-scm.com/download/win) and [CMake](https://cmake.org/download/) for Windows. + +From `Git Bash` command line clone dae-cpp library (you may need to create a working directory first): + +```bash +git clone https://github.com/ikorotkin/dae-cpp.git +``` + +Start CMake (`cmake-gui`), choose the source code path (`dae-cpp` folder) and empty target directory (it will contain Visual Studio project files). Press "Configure" button. + +If CMake cannot find any of the libraries, it will print an error message. You can modify the paths and other parameters (see [More building options](https://github.com/ikorotkin/dae-cpp#more-building-options) above) and re-configure the project. + +If configuration is successful, press "Configure" again to update the cache and then "Generate". In the target directory you will find Visual Studio project files. + +Double-click on `dae-cpp.sln` to open Visual Studio with the project. Do not forget to change Solution Configuration from `Debug` to `Release`. Build the solution (`F7` by default). After compilation, the executable files can be found in `Release` folder. + +Note that in order to execute the tests (for example, `perovskite.exe`) from `Release` folder, you need to set up Intel MKL environment variables by executing `mklvars.bat intel64` or `mklvars.bat ia32` (depending on the target platform) from `cmd`. By default `mklvars.bat` is located in MKL root folder in `bin` subdirectory, for example: + +```bash +"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64 +``` + +**_Alternatively_**, you may install [Windows Subsystem for Linux](https://docs.microsoft.com/en-gb/windows/wsl/install-win10?redirectedfrom=MSDN) and your preferred Linux Distribution (e.g. Ubuntu), and then just follow [installation instructions for Linux](#linux). + +### Mac + +Make sure you have installed: `git`, `cmake`, `gcc` and, optional, Python 3 with `numpy` and `matplotlib` modules (for plotting). If these packages are not installed yet, you may install [Homebrew](https://brew.sh/) (package manager for macOS), then install all necessary packages: + +```bash +brew install cmake git gcc python +pip3 install numpy matplotlib +``` + +Note if you install `git` for the first time you will need to configure it (change `Your Name` and `your@email` to your full name and email): + +```bash +git config --global user.name "Your Name" +git config --global user.email your@email +``` + +Then from the working directory download dae-cpp library source files: + +```bash +git clone https://github.com/ikorotkin/dae-cpp.git +``` + +Check the version of `gcc` compiler by typing `gcc` and pressing `Tab` key a few times in the terminal, it will show you the version of `gcc` currently installed, for example, `gcc-9` (you could use the command `gcc --version` but it may point to `clang` compiler for Mac that does not support OpenMP out of the box). + +Create `build` directory: + +```bash +cd dae-cpp +mkdir build +cd build +``` + +Configure the project. *Make sure `g++` version (9 in the example below) is correct*: + +```bash +cmake .. -DCMAKE_CXX_COMPILER=g++-9 -DCMAKE_INSTALL_PREFIX=$PWD +``` + +In the command above you may change the user-defined path where the package should be installed (type it instead of `$PWD`). By default the package will be installed into the current `build` directory. + +Note that `cmake` will try to find Intel MKL at its default location `/opt/intel/mkl` or according to `MKLROOT` environment variable. If the installation path is different, please provide MKL root path with the following `cmake` option: `-DDAE_MKL_DIR=/path_to_intel_mkl`. + +Instead of `cmake ..` you may consider using `ccmake ..`, a UI for `cmake` that will allow you to see and change all the options available before building the solver. + +Install dae-cpp and perform a quick self test: + +```bash +make -j4 +make install +ctest +``` + +## How to use + +Please refer to [simple_dae.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/simple_dae/simple_dae.cpp), [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite.cpp) or [diffusion_2d.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d.cpp) as an example. + +The main usage algorithm can be the following. Consider we have a system of DAEs written in a matrix-vector form, with some Mass matrix, RHS, and some initial conditions. + +### Step 0. Include dae-cpp into the project + +Include the solver's main header to the project. A shortcut to the solver's namespace (`daecpp`) can be added as well: + +```cpp +#include "path/to/dae-cpp/include/solver.h" +namespace dae = daecpp; +``` + +### Step 1. Define the DAE parameters and initial state vector + +For example, for *N* equations we should define the state vector with the size *N* and initialize it in accordance with the initial conditions: + +```cpp +// State vector +dae::state_type x(N); + +// Initial conditions +for(MKL_INT i = 0; i < N; i++) +{ + x[i] = 1.0; +} +``` + +We can get access to each element of the state vector **x** as to `std::vector` from STL. Also note that instead of `int` or any other integer types we should use `MKL_INT` type. This gives us possibility to re-compile the project with `DAE_LONG_INT` option, so the code will work fine even for extremely huge systems (with *N* more than 107). + +### Step 2. Set up the RHS + +Create MyRHS class that inherits the abstract `daecpp::RHS` class from dae-cpp library. The parent RHS class contains a pure virtual functor (operator `()`), that must be overridden in the child class. See, for example, [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), [perovskite_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_RHS.cpp) or [diffusion_2d_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/diffusion_2d/diffusion_2d_RHS.cpp). + +Once the RHS class is overridden, we can create an instance of the child class with some user-defined parameter container *p*: + +```cpp +MyRHS rhs(p); +``` + +In the child MyRHS class the user can also override `stop_condition` virtual function. By default (if not overridden) the function always returns `false`. The user may override this behaviour and set up one or several stop conditions for the solver depending on the solution **x** at the current time *t*. As soon as the function returns `true`, the solver will finalise the current time step and return the current solution. A trivial example of the stop condition function can be found in [perovskite_RHS.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_RHS.cpp). + +For the debugging purposes, the RHS can be saved to a file: + +```cpp +rhs.dump(x, 0); +rhs.dump(x, 0.1); +``` + +In this example we saved two RHS vectors, at time 0 and 0.1. + +### Step 3. Set up the Mass matrix + +Create MyMassMatrix class that inherits the abstract `daecpp::MassMatrix` class from dae-cpp library. Similar to the previous step, the parent MassMatrix class contains a pure virtual functor (operator `()`), that must be overridden in the child class. Refer to [perovskite_Mass.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Mass.cpp) or [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) as an example. Note that the matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format). See also [a note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). + +Create an instance of the child MyMassMatrix class with the given size *N*: + +```cpp +MyMassMatrix mass(N); +``` + +If the Mass matrix is a simple identity matrix, one can use `daecpp::MassMatrixIdentity` class from dae-cpp library instead of inheriting `daecpp::MassMatrix`. This will create identity Mass matrix in sparse format with the given size *N*: + +```cpp +dae::MassMatrixIdentity mass(N); +``` + +For the debugging purposes, you can save the Mass matrix to a file: + +```cpp +mass.dump(); +``` + +### Step 4. Set up Jacobian matrix + +We can provide analytical Jacobian by overriding `daecpp::Jacobian` class from the dae-cpp library (see [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp) or [perovskite_Jacobian.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_Jacobian.cpp)) or just use numerically estimated one (this may significantly slow down the computation for large *N*). If provided, analytical Jacobian matrix should be defined in [three array sparse format](https://software.intel.com/en-us/mkl-developer-reference-c-sparse-blas-csr-matrix-storage-format) similar to the Mass matrix. See also [a note about Sparse Matrix Format](#a-note-about-Sparse-Matrix-Format). + +If we don't provide analytical Jacobian we should estimate it with the given tolerance: + +```cpp +dae::Jacobian jac(rhs, 1.0e-6); +``` + +Note that we should pass an instance of the user-defined RHS in order to estimate numerical Jacobian. + +Again, for the debugging purposes, Jacobian can be saved to a file: + +```cpp +jac.dump(x, 0); +jac.dump(x, 0.1); +``` + +In the example above we saved two Jacobians, at time 0 and 0.1. + +In some cases the derivation and coding of the analytic Jacobian can be a tricky problem itself. So `dae::Jacobian` class provides additional functionality to compare two Jacobians (one of them is numerical) and write the differences: + +```cpp +dae::Jacobian jac(rhs, 1.0e-6); // Numerical Jacobian calculated automatically (slow) +MyJacobian jac_user(rhs); // Analytic Jacobian provided by the user + +// Comparison of jac and jac_user and writing the differences to a file +jac_user.compare(jac, x, 0.1, 1e-4); +``` + +Here we compared two Jacobians at time 0.1 with the relative tolerance 10-4. + +### Step 5. Set the solver options + +The solver has lots of options related to the solution process. They all have some default values (defined in [solver_options.h](https://github.com/ikorotkin/dae-cpp/blob/master/src/solver_options.h)) but they can be overridden by a user: + +```cpp +// Create an instance of the solver options and update some of the solver +// parameters defined in solver_options.h +dae::SolverOptions opt; + +// For example, let's change the initial time step +opt.dt_init = 0.01; +``` + +### Step 6. Solve the system + +Now we are ready to create an instance of the solver with particular RHS, Mass matrix, Jacobian and the solver options, and then start the solver: + +```cpp +dae::Solver solve(rhs, jac, mass, opt); +int status = solve(x, t1); +``` + +Here *t*1 is the integration time (0 < *t* < *t*1), and **x** is the initial condition vector defined above. + +The solver returns 0 if integration is successful or error code otherwise. Solution at time *t*1 will be written into vector **x** (initial conditions will be overwritten). The actual integration time *t*1 will be returned (the solver may terminate integration earlier). That's it! + +#### Optional: Set up Observer + +In order to get intermediate solutions at times *t*a, *t*b, *t*c, etc. (0 < *t*a < *t*b < *t*c < ... < *t*1), for example, for plotting, one can call the solver at the given times: + +```cpp +solve(x, t_a); // solves the system in the interval [0; t_a] and stores the solution in x +solve(x, t_b); // continues solving in the interval [t_a; t_b], replaces the solution in x +solve(x, t_c); // continues solving in the interval [t_b; t_c], replaces the solution in x + // ... +solve(x, t1); // continues solving in the interval [t_c; t1] and + // stores the final solution at time t1 in x +``` + +Every call the solver will take the previous solution **x** (if available from the previous call) and overwrite it with a new one at the given time. + +But a proper (and more efficient) way to get intermediate results is to override `virtual void observer(...)` function from `daecpp::Solver` class. This observer function receives the current solution vector **x** and the current time *t* every time step and allows a user to get access to the solution at each time layer. An example of a simple observer is given in the file [robertson.cpp](https://github.com/ikorotkin/dae-cpp/blob/master/examples/robertson/robertson.cpp), also in [perovskite_observer.h](https://github.com/ikorotkin/dae-cpp/blob/master/examples/perovskite/perovskite_observer.h). + +### Step 7 (optional). Plot results + +Solution can be visualised using a simple [C++ interface](https://github.com/lava/matplotlib-cpp) to Python [matplotlib](https://matplotlib.org/) module. For example, if `python`, `numpy` and `matplotlib` are installed and the solver was built with `PLOTTING=ON`, the [perovskite](https://github.com/ikorotkin/dae-cpp/tree/master/examples/perovskite) example will produce the following plot: + +

+ +

+ +Here *P(x)* is the ion concentration in a perovskite solar cell, and *Phi(x)* is the corresponding potential distribution. + +The second example, [diffusion_2d](https://github.com/ikorotkin/dae-cpp/tree/master/examples/diffusion_2d), will produce a two-dimensional Gaussian function, a solution of two-dimensional diffusion problem with an instantaneous point source in the middle of the plane: + +

+ +

+ +The third example, [robertson](https://github.com/ikorotkin/dae-cpp/tree/master/examples/robertson), solves [Robertson stiff DAE problem](https://www.mathworks.com/help/matlab/ref/ode15s.html) with a conservation law. It produces the following figure: + +

+ +

+ +Note that by default the plotting is switched off in the examples, but the plotting-related code can be activated using `#define PLOTTING` at the very beginning of each example. Activating the plotting refers to `matplotlibcpp.h` header located in `src/external/matplotlib-cpp/` directory. + +### A note about Sparse Matrix Format + +It should be noted that you must define all the diagonal elements of the matrix, even if they are zero. This greatly increases performance, and if some rows are skipped, the code will just stop working. Please double check your Mass matrix and Jacobian, they both should have the main diagonal filled in. Even if the given row is empty (all elements are zero), define zero on the main diagonal explicitly. + +If you are struggling with Intel MKL sparse format, you can use simple three-array format instead, where you need to define all non-zero elements and their indexes (coordinates) in the matrix. For example for the identity 3x3 matrix, you only need to define three non-zero elements and their position in the matrix: + +```cpp +M.A.resize(3); // Number of non-zero elements +M.ia.resize(3); // Number of non-zero elements +M.ja.resize(3); // Number of non-zero elements + +M.A[0] = 1; // First non-zero or diagonal element +M.ia[0] = 0; // Column index of the first non-zero element +M.ja[0] = 0; // Raw index of the first non-zero element + +M.A[1] = 1; // Second non-zero or diagonal element +M.ia[1] = 1; // Column index of the second non-zero element +M.ja[1] = 1; // Raw index of the second non-zero element + +M.A[2] = 1; // Third non-zero or diagonal element +M.ia[2] = 2; // Column index of the third non-zero element +M.ja[2] = 2; // Raw index of the third non-zero element +``` + +This form will be automatically converted to the three-array sparse format compatible with Intel MKL. Do not forget to define all diagonal elements even if they are zero. Do not mix the elements up (fill in the first row from left to right, then the second row, etc.). + +## Contribution and feedback + +Please feel free to contribute into the project! + +If you have any questions, suggestion, or a feedback, please, submit an [issue](https://github.com/ikorotkin/dae-cpp/issues). + +## Licensing + +- dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). +- Intel MKL is free for use and redistribution under [Intel Simplified Software License](https://software.intel.com/en-us/license/intel-simplified-software-license). diff --git a/clang-tidy.sh b/archived/clang-tidy.sh similarity index 100% rename from clang-tidy.sh rename to archived/clang-tidy.sh diff --git a/examples/diffusion_2d/diffusion_2d.cpp b/archived/examples/diffusion_2d/diffusion_2d.cpp similarity index 100% rename from examples/diffusion_2d/diffusion_2d.cpp rename to archived/examples/diffusion_2d/diffusion_2d.cpp diff --git a/examples/diffusion_2d/diffusion_2d.png b/archived/examples/diffusion_2d/diffusion_2d.png similarity index 100% rename from examples/diffusion_2d/diffusion_2d.png rename to archived/examples/diffusion_2d/diffusion_2d.png diff --git a/examples/diffusion_2d/diffusion_2d_RHS.cpp b/archived/examples/diffusion_2d/diffusion_2d_RHS.cpp similarity index 100% rename from examples/diffusion_2d/diffusion_2d_RHS.cpp rename to archived/examples/diffusion_2d/diffusion_2d_RHS.cpp diff --git a/examples/diffusion_2d/diffusion_2d_RHS.h b/archived/examples/diffusion_2d/diffusion_2d_RHS.h similarity index 100% rename from examples/diffusion_2d/diffusion_2d_RHS.h rename to archived/examples/diffusion_2d/diffusion_2d_RHS.h diff --git a/examples/perovskite/perovskite.cpp b/archived/examples/perovskite/perovskite.cpp similarity index 100% rename from examples/perovskite/perovskite.cpp rename to archived/examples/perovskite/perovskite.cpp diff --git a/examples/perovskite/perovskite.png b/archived/examples/perovskite/perovskite.png similarity index 100% rename from examples/perovskite/perovskite.png rename to archived/examples/perovskite/perovskite.png diff --git a/examples/perovskite/perovskite_Jacobian.cpp b/archived/examples/perovskite/perovskite_Jacobian.cpp similarity index 100% rename from examples/perovskite/perovskite_Jacobian.cpp rename to archived/examples/perovskite/perovskite_Jacobian.cpp diff --git a/examples/perovskite/perovskite_Jacobian.h b/archived/examples/perovskite/perovskite_Jacobian.h similarity index 100% rename from examples/perovskite/perovskite_Jacobian.h rename to archived/examples/perovskite/perovskite_Jacobian.h diff --git a/examples/perovskite/perovskite_Mass.cpp b/archived/examples/perovskite/perovskite_Mass.cpp similarity index 100% rename from examples/perovskite/perovskite_Mass.cpp rename to archived/examples/perovskite/perovskite_Mass.cpp diff --git a/examples/perovskite/perovskite_Mass.h b/archived/examples/perovskite/perovskite_Mass.h similarity index 100% rename from examples/perovskite/perovskite_Mass.h rename to archived/examples/perovskite/perovskite_Mass.h diff --git a/examples/perovskite/perovskite_RHS.cpp b/archived/examples/perovskite/perovskite_RHS.cpp similarity index 100% rename from examples/perovskite/perovskite_RHS.cpp rename to archived/examples/perovskite/perovskite_RHS.cpp diff --git a/examples/perovskite/perovskite_RHS.h b/archived/examples/perovskite/perovskite_RHS.h similarity index 100% rename from examples/perovskite/perovskite_RHS.h rename to archived/examples/perovskite/perovskite_RHS.h diff --git a/examples/perovskite/perovskite_observer.h b/archived/examples/perovskite/perovskite_observer.h similarity index 100% rename from examples/perovskite/perovskite_observer.h rename to archived/examples/perovskite/perovskite_observer.h diff --git a/examples/perovskite/perovskite_parameters.h b/archived/examples/perovskite/perovskite_parameters.h similarity index 100% rename from examples/perovskite/perovskite_parameters.h rename to archived/examples/perovskite/perovskite_parameters.h diff --git a/examples/robertson/robertson.cpp b/archived/examples/robertson/robertson.cpp similarity index 100% rename from examples/robertson/robertson.cpp rename to archived/examples/robertson/robertson.cpp diff --git a/examples/robertson/robertson.png b/archived/examples/robertson/robertson.png similarity index 100% rename from examples/robertson/robertson.png rename to archived/examples/robertson/robertson.png diff --git a/examples/simple_dae/simple_dae.cpp b/archived/examples/simple_dae/simple_dae.cpp similarity index 100% rename from examples/simple_dae/simple_dae.cpp rename to archived/examples/simple_dae/simple_dae.cpp diff --git a/examples/simple_dae/simple_dae.png b/archived/examples/simple_dae/simple_dae.png similarity index 100% rename from examples/simple_dae/simple_dae.png rename to archived/examples/simple_dae/simple_dae.png diff --git a/examples/two_bodies/two_bodies.cpp b/archived/examples/two_bodies/two_bodies.cpp similarity index 100% rename from examples/two_bodies/two_bodies.cpp rename to archived/examples/two_bodies/two_bodies.cpp diff --git a/examples/two_bodies/two_bodies.png b/archived/examples/two_bodies/two_bodies.png similarity index 100% rename from examples/two_bodies/two_bodies.png rename to archived/examples/two_bodies/two_bodies.png diff --git a/src/CMakeLists.txt b/archived/src/CMakeLists.txt similarity index 100% rename from src/CMakeLists.txt rename to archived/src/CMakeLists.txt diff --git a/src/RHS.h b/archived/src/RHS.h similarity index 100% rename from src/RHS.h rename to archived/src/RHS.h diff --git a/src/cmake_config.h b/archived/src/cmake_config.h similarity index 100% rename from src/cmake_config.h rename to archived/src/cmake_config.h diff --git a/src/cmake_config.h.in b/archived/src/cmake_config.h.in similarity index 100% rename from src/cmake_config.h.in rename to archived/src/cmake_config.h.in diff --git a/src/debug_output.cpp b/archived/src/debug_output.cpp similarity index 100% rename from src/debug_output.cpp rename to archived/src/debug_output.cpp diff --git a/src/external/boost/LICENSE_1_0.txt b/archived/src/external/boost/LICENSE_1_0.txt similarity index 100% rename from src/external/boost/LICENSE_1_0.txt rename to archived/src/external/boost/LICENSE_1_0.txt diff --git a/src/external/boost/assert.hpp b/archived/src/external/boost/assert.hpp similarity index 100% rename from src/external/boost/assert.hpp rename to archived/src/external/boost/assert.hpp diff --git a/src/external/matplotlib-cpp/LICENSE b/archived/src/external/matplotlib-cpp/LICENSE similarity index 100% rename from src/external/matplotlib-cpp/LICENSE rename to archived/src/external/matplotlib-cpp/LICENSE diff --git a/src/external/matplotlib-cpp/LICENSE.matplotlib b/archived/src/external/matplotlib-cpp/LICENSE.matplotlib similarity index 100% rename from src/external/matplotlib-cpp/LICENSE.matplotlib rename to archived/src/external/matplotlib-cpp/LICENSE.matplotlib diff --git a/src/external/matplotlib-cpp/matplotlibcpp.h b/archived/src/external/matplotlib-cpp/matplotlibcpp.h similarity index 100% rename from src/external/matplotlib-cpp/matplotlibcpp.h rename to archived/src/external/matplotlib-cpp/matplotlibcpp.h diff --git a/src/jacobian.cpp b/archived/src/jacobian.cpp similarity index 100% rename from src/jacobian.cpp rename to archived/src/jacobian.cpp diff --git a/src/jacobian.h b/archived/src/jacobian.h similarity index 100% rename from src/jacobian.h rename to archived/src/jacobian.h diff --git a/src/mass_matrix.cpp b/archived/src/mass_matrix.cpp similarity index 100% rename from src/mass_matrix.cpp rename to archived/src/mass_matrix.cpp diff --git a/src/mass_matrix.h b/archived/src/mass_matrix.h similarity index 100% rename from src/mass_matrix.h rename to archived/src/mass_matrix.h diff --git a/src/matrix_add.cpp b/archived/src/matrix_add.cpp similarity index 100% rename from src/matrix_add.cpp rename to archived/src/matrix_add.cpp diff --git a/src/matrix_checker.cpp b/archived/src/matrix_checker.cpp similarity index 100% rename from src/matrix_checker.cpp rename to archived/src/matrix_checker.cpp diff --git a/src/matrix_converter.cpp b/archived/src/matrix_converter.cpp similarity index 100% rename from src/matrix_converter.cpp rename to archived/src/matrix_converter.cpp diff --git a/src/solver.cpp b/archived/src/solver.cpp similarity index 100% rename from src/solver.cpp rename to archived/src/solver.cpp diff --git a/src/solver.h b/archived/src/solver.h similarity index 100% rename from src/solver.h rename to archived/src/solver.h diff --git a/src/solver_options.cpp b/archived/src/solver_options.cpp similarity index 100% rename from src/solver_options.cpp rename to archived/src/solver_options.cpp diff --git a/src/solver_options.h b/archived/src/solver_options.h similarity index 100% rename from src/solver_options.h rename to archived/src/solver_options.h diff --git a/src/time_integrator.cpp b/archived/src/time_integrator.cpp similarity index 100% rename from src/time_integrator.cpp rename to archived/src/time_integrator.cpp diff --git a/src/time_integrator.h b/archived/src/time_integrator.h similarity index 100% rename from src/time_integrator.h rename to archived/src/time_integrator.h diff --git a/src/time_stepper.cpp b/archived/src/time_stepper.cpp similarity index 100% rename from src/time_stepper.cpp rename to archived/src/time_stepper.cpp diff --git a/src/typedefs.h b/archived/src/typedefs.h similarity index 100% rename from src/typedefs.h rename to archived/src/typedefs.h diff --git a/.vscode/c_cpp_properties.json b/archived/vscode_old/c_cpp_properties.json similarity index 100% rename from .vscode/c_cpp_properties.json rename to archived/vscode_old/c_cpp_properties.json diff --git a/.vscode/launch.json b/archived/vscode_old/launch.json similarity index 100% rename from .vscode/launch.json rename to archived/vscode_old/launch.json diff --git a/.vscode/settings.json b/archived/vscode_old/settings.json similarity index 100% rename from .vscode/settings.json rename to archived/vscode_old/settings.json diff --git a/.vscode/tasks.json b/archived/vscode_old/tasks.json similarity index 100% rename from .vscode/tasks.json rename to archived/vscode_old/tasks.json diff --git a/build_static_lib.sh b/build_static_lib.sh deleted file mode 100755 index f015939..0000000 --- a/build_static_lib.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Build a static library: -mkdir build_static_lib -cd build_static_lib -g++ -c -O3 -Wall -std=c++11 -m64 -fopenmp ../src/*.cpp -I/opt/intel/mkl/include -I../src -I../src/external -ar rcs libdaecpp.a *.o -rm *.o - -# Compile examples -g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/perovskite/*.cpp -o perovskite -I/opt/intel/mkl/include -I../examples/perovskite -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl -g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/diffusion_2d/*.cpp -o diffusion_2d -I/opt/intel/mkl/include -I../examples/diffusion_2d -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl -g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/robertson/*.cpp -o robertson -I/opt/intel/mkl/include -I../examples/robertson -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl -g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/simple_dae/*.cpp -o simple_dae -I/opt/intel/mkl/include -I../examples/simple_dae -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl -g++ -O3 -Wall -std=c++11 -m64 -fopenmp ../examples/two_bodies/*.cpp -o two_bodies -I/opt/intel/mkl/include -I../examples/two_bodies -I../src -I../src/external -L/opt/intel/mkl/lib/intel64 -L. -ldaecpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl - -echo 'How to run an example using 4 cores:' -echo 'cd build_static_lib/' -echo 'source ../set_MKL_env' -echo 'OMP_NUM_THREADS=4 ./perovskite' diff --git a/set_MKL_env b/set_MKL_env deleted file mode 100644 index 9af3b36..0000000 --- a/set_MKL_env +++ /dev/null @@ -1,2 +0,0 @@ -# Default Intel MKL library path -source /opt/intel/mkl/bin/mklvars.sh intel64 diff --git a/set_MKL_env_win.bat b/set_MKL_env_win.bat deleted file mode 100644 index c30ba4d..0000000 --- a/set_MKL_env_win.bat +++ /dev/null @@ -1,5 +0,0 @@ -REM ==== 64 bit ==== -"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" intel64 - -REM ==== 32 bit ==== -REM "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\mkl\bin\mklvars.bat" ia32 diff --git a/test.sh b/test.sh deleted file mode 100755 index d84d45e..0000000 --- a/test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# Single precision test -rm -r build_single/ -mkdir build_single -cd build_single -cmake -DDAE_SINGLE=ON .. -make -j 4 -ctest -cd .. - -# Double precision test -rm -r build/ -mkdir build -cd build -cmake .. -make -j 4 -ctest From 5f7be188d5de4cd9ea59dcda83890de1302f30db Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 20 Mar 2024 17:32:06 +0000 Subject: [PATCH 096/274] Add autodiff --- README.md | 20 +- dae-cpp/autodiff/LICENSE | 21 + ...t-d66d8f4852146cc41168a31f750f3d09ef8f2e70 | 0 .../autodiff/common/binomialcoefficient.hpp | 113 + dae-cpp/autodiff/common/classtraits.hpp | 106 + dae-cpp/autodiff/common/eigen.hpp | 155 ++ dae-cpp/autodiff/common/meta.hpp | 203 ++ dae-cpp/autodiff/common/numbertraits.hpp | 73 + dae-cpp/autodiff/common/vectortraits.hpp | 84 + dae-cpp/autodiff/forward/dual.hpp | 35 + dae-cpp/autodiff/forward/dual/dual.hpp | 1811 +++++++++++++++++ dae-cpp/autodiff/forward/dual/eigen.hpp | 129 ++ dae-cpp/autodiff/forward/real.hpp | 35 + dae-cpp/autodiff/forward/real/eigen.hpp | 90 + dae-cpp/autodiff/forward/real/real.hpp | 1031 ++++++++++ dae-cpp/autodiff/forward/utils/derivative.hpp | 294 +++ dae-cpp/autodiff/forward/utils/gradient.hpp | 228 +++ .../autodiff/forward/utils/taylorseries.hpp | 97 + dae-cpp/autodiff/pybind11/eigen.hpp | 89 + dae-cpp/autodiff/reverse/var.hpp | 33 + dae-cpp/autodiff/reverse/var/eigen.hpp | 226 ++ dae-cpp/autodiff/reverse/var/var.hpp | 1540 ++++++++++++++ 22 files changed, 6411 insertions(+), 2 deletions(-) create mode 100644 dae-cpp/autodiff/LICENSE create mode 100644 dae-cpp/autodiff/commit-d66d8f4852146cc41168a31f750f3d09ef8f2e70 create mode 100644 dae-cpp/autodiff/common/binomialcoefficient.hpp create mode 100644 dae-cpp/autodiff/common/classtraits.hpp create mode 100644 dae-cpp/autodiff/common/eigen.hpp create mode 100644 dae-cpp/autodiff/common/meta.hpp create mode 100644 dae-cpp/autodiff/common/numbertraits.hpp create mode 100644 dae-cpp/autodiff/common/vectortraits.hpp create mode 100644 dae-cpp/autodiff/forward/dual.hpp create mode 100644 dae-cpp/autodiff/forward/dual/dual.hpp create mode 100644 dae-cpp/autodiff/forward/dual/eigen.hpp create mode 100644 dae-cpp/autodiff/forward/real.hpp create mode 100644 dae-cpp/autodiff/forward/real/eigen.hpp create mode 100644 dae-cpp/autodiff/forward/real/real.hpp create mode 100644 dae-cpp/autodiff/forward/utils/derivative.hpp create mode 100644 dae-cpp/autodiff/forward/utils/gradient.hpp create mode 100644 dae-cpp/autodiff/forward/utils/taylorseries.hpp create mode 100644 dae-cpp/autodiff/pybind11/eigen.hpp create mode 100644 dae-cpp/autodiff/reverse/var.hpp create mode 100644 dae-cpp/autodiff/reverse/var/eigen.hpp create mode 100644 dae-cpp/autodiff/reverse/var/var.hpp diff --git a/README.md b/README.md index 3faa05c..7767818 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,24 @@ A simple but powerful header-only C++ solver for systems of Differential and Alg ### A note about Sparse Matrix Format -## Contribution and feedback +## Contribution and Feedback + +Thank you for considering contributing to the project! Whether you're an experienced developer or just starting out, your ideas and improvements can make this project even better. No contribution is too small! + +### How to contribute + +0. Create a GitHub issue if you want to suggest or discuss your changes. +1. Fork the repository and clone it to your local machine. +2. Create a new branch for your contributions. +3. Make your changes and ensure they adhere to our coding standards. +4. Add tests and examples (if relevant), test your changes thoroughly. +5. Submit a pull request with a clear description of your changes and why they are beneficial. + +### Feedback + +Feel free to create a [GitHub issue](https://github.com/ikorotkin/dae-cpp/issues) for any questions, suggestions, or feedback you may have. ## Licensing -- dae-cpp is fully open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). +- [dae-cpp](https://github.com/ikorotkin/dae-cpp) is open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). +- [autodiff](https://github.com/autodiff/autodiff) is open source under [MIT license](https://github.com/autodiff/autodiff/blob/main/LICENSE). diff --git a/dae-cpp/autodiff/LICENSE b/dae-cpp/autodiff/LICENSE new file mode 100644 index 0000000..728f73b --- /dev/null +++ b/dae-cpp/autodiff/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright © 2018–2024 Allan Leal + +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. diff --git a/dae-cpp/autodiff/commit-d66d8f4852146cc41168a31f750f3d09ef8f2e70 b/dae-cpp/autodiff/commit-d66d8f4852146cc41168a31f750f3d09ef8f2e70 new file mode 100644 index 0000000..e69de29 diff --git a/dae-cpp/autodiff/common/binomialcoefficient.hpp b/dae-cpp/autodiff/common/binomialcoefficient.hpp new file mode 100644 index 0000000..06f43d5 --- /dev/null +++ b/dae-cpp/autodiff/common/binomialcoefficient.hpp @@ -0,0 +1,113 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// C++ includes +#include + +namespace autodiff { +namespace detail { + +/// The array containing pre calculated binomial coefficients up to order 50. +constexpr double binomialcoeffs_data[] = { + 1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1, + 1, 5, 10, 10, 5, 1, + 1, 6, 15, 20, 15, 6, 1, + 1, 7, 21, 35, 35, 21, 7, 1, + 1, 8, 28, 56, 70, 56, 28, 8, 1, + 1, 9, 36, 84, 126, 126, 84, 36, 9, 1, + 1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1, + 1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1, + 1, 12, 66, 220, 495, 792, 924, 792, 495, 220, 66, 12, 1, + 1, 13, 78, 286, 715, 1287, 1716, 1716, 1287, 715, 286, 78, 13, 1, + 1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1, + 1, 15, 105, 455, 1365, 3003, 5005, 6435, 6435, 5005, 3003, 1365, 455, 105, 15, 1, + 1, 16, 120, 560, 1820, 4368, 8008, 11440, 12870, 11440, 8008, 4368, 1820, 560, 120, 16, 1, + 1, 17, 136, 680, 2380, 6188, 12376, 19448, 24310, 24310, 19448, 12376, 6188, 2380, 680, 136, 17, 1, + 1, 18, 153, 816, 3060, 8568, 18564, 31824, 43758, 48620, 43758, 31824, 18564, 8568, 3060, 816, 153, 18, 1, + 1, 19, 171, 969, 3876, 11628, 27132, 50388, 75582, 92378, 92378, 75582, 50388, 27132, 11628, 3876, 969, 171, 19, 1, + 1, 20, 190, 1140, 4845, 15504, 38760, 77520, 125970, 167960, 184756, 167960, 125970, 77520, 38760, 15504, 4845, 1140, 190, 20, 1, + 1, 21, 210, 1330, 5985, 20349, 54264, 116280, 203490, 293930, 352716, 352716, 293930, 203490, 116280, 54264, 20349, 5985, 1330, 210, 21, 1, + 1, 22, 231, 1540, 7315, 26334, 74613, 170544, 319770, 497420, 646646, 705432, 646646, 497420, 319770, 170544, 74613, 26334, 7315, 1540, 231, 22, 1, + 1, 23, 253, 1771, 8855, 33649, 100947, 245157, 490314, 817190, 1144066, 1352078, 1352078, 1144066, 817190, 490314, 245157, 100947, 33649, 8855, 1771, 253, 23, 1, + 1, 24, 276, 2024, 10626, 42504, 134596, 346104, 735471, 1307504, 1961256, 2496144, 2704156, 2496144, 1961256, 1307504, 735471, 346104, 134596, 42504, 10626, 2024, 276, 24, 1, + 1, 25, 300, 2300, 12650, 53130, 177100, 480700, 1081575, 2042975, 3268760, 4457400, 5200300, 5200300, 4457400, 3268760, 2042975, 1081575, 480700, 177100, 53130, 12650, 2300, 300, 25, 1, + 1, 26, 325, 2600, 14950, 65780, 230230, 657800, 1562275, 3124550, 5311735, 7726160, 9657700, 10400600, 9657700, 7726160, 5311735, 3124550, 1562275, 657800, 230230, 65780, 14950, 2600, 325, 26, 1, + 1, 27, 351, 2925, 17550, 80730, 296010, 888030, 2220075, 4686825, 8436285, 13037895, 17383860, 20058300, 20058300, 17383860, 13037895, 8436285, 4686825, 2220075, 888030, 296010, 80730, 17550, 2925, 351, 27, 1, + 1, 28, 378, 3276, 20475, 98280, 376740, 1184040, 3108105, 6906900, 13123110, 21474180, 30421755, 37442160, 40116600, 37442160, 30421755, 21474180, 13123110, 6906900, 3108105, 1184040, 376740, 98280, 20475, 3276, 378, 28, 1, + 1, 29, 406, 3654, 23751, 118755, 475020, 1560780, 4292145, 10015005, 20030010, 34597290, 51895935, 67863915, 77558760, 77558760, 67863915, 51895935, 34597290, 20030010, 10015005, 4292145, 1560780, 475020, 118755, 23751, 3654, 406, 29, 1, + 1, 30, 435, 4060, 27405, 142506, 593775, 2035800, 5852925, 14307150, 30045015, 54627300, 86493225, 119759850, 145422675, 155117520, 145422675, 119759850, 86493225, 54627300, 30045015, 14307150, 5852925, 2035800, 593775, 142506, 27405, 4060, 435, 30, 1, + 1, 31, 465, 4495, 31465, 169911, 736281, 2629575, 7888725, 20160075, 44352165, 84672315, 141120525, 206253075, 265182525, 300540195, 300540195, 265182525, 206253075, 141120525, 84672315, 44352165, 20160075, 7888725, 2629575, 736281, 169911, 31465, 4495, 465, 31, 1, + 1, 32, 496, 4960, 35960, 201376, 906192, 3365856, 10518300, 28048800, 64512240, 129024480, 225792840, 347373600, 471435600, 565722720, 601080390, 565722720, 471435600, 347373600, 225792840, 129024480, 64512240, 28048800, 10518300, 3365856, 906192, 201376, 35960, 4960, 496, 32, 1, + 1, 33, 528, 5456, 40920, 237336, 1107568, 4272048, 13884156, 38567100, 92561040, 193536720, 354817320, 573166440, 818809200, 1037158320, 1166803110, 1166803110, 1037158320, 818809200, 573166440, 354817320, 193536720, 92561040, 38567100, 13884156, 4272048, 1107568, 237336, 40920, 5456, 528, 33, 1, + 1, 34, 561, 5984, 46376, 278256, 1344904, 5379616, 18156204, 52451256, 131128140, 286097760, 548354040, 927983760, 1391975640, 1855967520, 2203961430, 2333606220, 2203961430, 1855967520, 1391975640, 927983760, 548354040, 286097760, 131128140, 52451256, 18156204, 5379616, 1344904, 278256, 46376, 5984, 561, 34, 1, + 1, 35, 595, 6545, 52360, 324632, 1623160, 6724520, 23535820, 70607460, 183579396, 417225900, 834451800, 1476337800, 2319959400, 3247943160, 4059928950, 4537567650, 4537567650, 4059928950, 3247943160, 2319959400, 1476337800, 834451800, 417225900, 183579396, 70607460, 23535820, 6724520, 1623160, 324632, 52360, 6545, 595, 35, 1, + 1, 36, 630, 7140, 58905, 376992, 1947792, 8347680, 30260340, 94143280, 254186856, 600805296, 1251677700, 2310789600, 3796297200, 5567902560, 7307872110, 8597496600, 9075135300, 8597496600, 7307872110, 5567902560, 3796297200, 2310789600, 1251677700, 600805296, 254186856, 94143280, 30260340, 8347680, 1947792, 376992, 58905, 7140, 630, 36, 1, + 1, 37, 666, 7770, 66045, 435897, 2324784, 10295472, 38608020, 124403620, 348330136, 854992152, 1852482996, 3562467300, 6107086800, 9364199760, 12875774670, 15905368710, 17672631900, 17672631900, 15905368710, 12875774670, 9364199760, 6107086800, 3562467300, 1852482996, 854992152, 348330136, 124403620, 38608020, 10295472, 2324784, 435897, 66045, 7770, 666, 37, 1, + 1, 38, 703, 8436, 73815, 501942, 2760681, 12620256, 48903492, 163011640, 472733756, 1203322288, 2707475148, 5414950296, 9669554100, 15471286560, 22239974430, 28781143380, 33578000610, 35345263800, 33578000610, 28781143380, 22239974430, 15471286560, 9669554100, 5414950296, 2707475148, 1203322288, 472733756, 163011640, 48903492, 12620256, 2760681, 501942, 73815, 8436, 703, 38, 1, + 1, 39, 741, 9139, 82251, 575757, 3262623, 15380937, 61523748, 211915132, 635745396, 1676056044, 3910797436, 8122425444, 15084504396, 25140840660, 37711260990, 51021117810, 62359143990, 68923264410, 68923264410, 62359143990, 51021117810, 37711260990, 25140840660, 15084504396, 8122425444, 3910797436, 1676056044, 635745396, 211915132, 61523748, 15380937, 3262623, 575757, 82251, 9139, 741, 39, 1, + 1, 40, 780, 9880, 91390, 658008, 3838380, 18643560, 76904685, 273438880, 847660528, 2311801440, 5586853480, 12033222880, 23206929840, 40225345056, 62852101650, 88732378800, 113380261800, 131282408400, 137846528820, 131282408400, 113380261800, 88732378800, 62852101650, 40225345056, 23206929840, 12033222880, 5586853480, 2311801440, 847660528, 273438880, 76904685, 18643560, 3838380, 658008, 91390, 9880, 780, 40, 1, + 1, 41, 820, 10660, 101270, 749398, 4496388, 22481940, 95548245, 350343565, 1121099408, 3159461968, 7898654920, 17620076360, 35240152720, 63432274896, 103077446706, 151584480450, 202112640600, 244662670200, 269128937220, 269128937220, 244662670200, 202112640600, 151584480450, 103077446706, 63432274896, 35240152720, 17620076360, 7898654920, 3159461968, 1121099408, 350343565, 95548245, 22481940, 4496388, 749398, 101270, 10660, 820, 41, 1, + 1, 42, 861, 11480, 111930, 850668, 5245786, 26978328, 118030185, 445891810, 1471442973, 4280561376, 11058116888, 25518731280, 52860229080, 98672427616, 166509721602, 254661927156, 353697121050, 446775310800, 513791607420, 538257874440, 513791607420, 446775310800, 353697121050, 254661927156, 166509721602, 98672427616, 52860229080, 25518731280, 11058116888, 4280561376, 1471442973, 445891810, 118030185, 26978328, 5245786, 850668, 111930, 11480, 861, 42, 1, + 1, 43, 903, 12341, 123410, 962598, 6096454, 32224114, 145008513, 563921995, 1917334783, 5752004349, 15338678264, 36576848168, 78378960360, 151532656696, 265182149218, 421171648758, 608359048206, 800472431850, 960566918220, 1052049481860, 1052049481860, 960566918220, 800472431850, 608359048206, 421171648758, 265182149218, 151532656696, 78378960360, 36576848168, 15338678264, 5752004349, 1917334783, 563921995, 145008513, 32224114, 6096454, 962598, 123410, 12341, 903, 43, 1, + 1, 44, 946, 13244, 135751, 1086008, 7059052, 38320568, 177232627, 708930508, 2481256778, 7669339132, 21090682613, 51915526432, 114955808528, 229911617056, 416714805914, 686353797976, 1029530696964, 1408831480056, 1761039350070, 2012616400080, 2104098963720, 2012616400080, 1761039350070, 1408831480056, 1029530696964, 686353797976, 416714805914, 229911617056, 114955808528, 51915526432, 21090682613, 7669339132, 2481256778, 708930508, 177232627, 38320568, 7059052, 1086008, 135751, 13244, 946, 44, 1, + 1, 45, 990, 14190, 148995, 1221759, 8145060, 45379620, 215553195, 886163135, 3190187286, 10150595910, 28760021745, 73006209045, 166871334960, 344867425584, 646626422970, 1103068603890, 1715884494940, 2438362177020, 3169870830126, 3773655750150, 4116715363800, 4116715363800, 3773655750150, 3169870830126, 2438362177020, 1715884494940, 1103068603890, 646626422970, 344867425584, 166871334960, 73006209045, 28760021745, 10150595910, 3190187286, 886163135, 215553195, 45379620, 8145060, 1221759, 148995, 14190, 990, 45, 1, + 1, 46, 1035, 15180, 163185, 1370754, 9366819, 53524680, 260932815, 1101716330, 4076350421, 13340783196, 38910617655, 101766230790, 239877544005, 511738760544, 991493848554, 1749695026860, 2818953098830, 4154246671960, 5608233007146, 6943526580276, 7890371113950, 8233430727600, 7890371113950, 6943526580276, 5608233007146, 4154246671960, 2818953098830, 1749695026860, 991493848554, 511738760544, 239877544005, 101766230790, 38910617655, 13340783196, 4076350421, 1101716330, 260932815, 53524680, 9366819, 1370754, 163185, 15180, 1035, 46, 1, + 1, 47, 1081, 16215, 178365, 1533939, 10737573, 62891499, 314457495, 1362649145, 5178066751, 17417133617, 52251400851, 140676848445, 341643774795, 751616304549, 1503232609098, 2741188875414, 4568648125690, 6973199770790, 9762479679106, 12551759587422, 14833897694226, 16123801841550, 16123801841550, 14833897694226, 12551759587422, 9762479679106, 6973199770790, 4568648125690, 2741188875414, 1503232609098, 751616304549, 341643774795, 140676848445, 52251400851, 17417133617, 5178066751, 1362649145, 314457495, 62891499, 10737573, 1533939, 178365, 16215, 1081, 47, 1, + 1, 48, 1128, 17296, 194580, 1712304, 12271512, 73629072, 377348994, 1677106640, 6540715896, 22595200368, 69668534468, 192928249296, 482320623240, 1093260079344, 2254848913647, 4244421484512, 7309837001104, 11541847896480, 16735679449896, 22314239266528, 27385657281648, 30957699535776, 32247603683100, 30957699535776, 27385657281648, 22314239266528, 16735679449896, 11541847896480, 7309837001104, 4244421484512, 2254848913647, 1093260079344, 482320623240, 192928249296, 69668534468, 22595200368, 6540715896, 1677106640, 377348994, 73629072, 12271512, 1712304, 194580, 17296, 1128, 48, 1, + 1, 49, 1176, 18424, 211876, 1906884, 13983816, 85900584, 450978066, 2054455634, 8217822536, 29135916264, 92263734836, 262596783764, 675248872536, 1575580702584, 3348108992991, 6499270398159, 11554258485616, 18851684897584, 28277527346376, 39049918716424, 49699896548176, 58343356817424, 63205303218876, 63205303218876, 58343356817424, 49699896548176, 39049918716424, 28277527346376, 18851684897584, 11554258485616, 6499270398159, 3348108992991, 1575580702584, 675248872536, 262596783764, 92263734836, 29135916264, 8217822536, 2054455634, 450978066, 85900584, 13983816, 1906884, 211876, 18424, 1176, 49, 1, + 1, 50, 1225, 19600, 230300, 2118760, 15890700, 99884400, 536878650, 2505433700, 10272278170, 37353738800, 121399651100, 354860518600, 937845656300, 2250829575120, 4923689695575, 9847379391150, 18053528883775, 30405943383200, 47129212243960, 67327446062800, 88749815264600, 108043253365600, 121548660036300, 126410606437752, 121548660036300, 108043253365600, 88749815264600, 67327446062800, 47129212243960, 30405943383200, 18053528883775, 9847379391150, 4923689695575, 2250829575120, 937845656300, 354860518600, 121399651100, 37353738800, 10272278170, 2505433700, 536878650, 99884400, 15890700, 2118760, 230300, 19600, 1225, 50, 1 +}; + +/// The array containing the offsets for each row in the array binomialcoeffs_data. +constexpr size_t binomialcoeffs_offsets[] = { 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528, 561, 595, 630, 666, 703, 741, 780, 820, 861, 903, 946, 990, 1035, 1081, 1128, 1176, 1225, 1275, 1326 }; + +/// The maximum order for binomial coefficients supported currently (50). +constexpr size_t binomialcoeffs_nmax = 50; + +/// Return the binomial coefficient C(i,j) at compile time. +template +struct AuxBinomialCoefficient +{ + static_assert(i <= binomialcoeffs_nmax, "Violation of maximum order for binomial coefficient retrieval."); + static_assert(j <= i, "Violation of j <= i condition for retrieving binomial coefficient C(i,j)."); + constexpr static double value = binomialcoeffs_data[binomialcoeffs_offsets[i] + j]; +}; + +/// The binomial coefficient C(i,j) at compile time. +template +constexpr double BinomialCoefficient = AuxBinomialCoefficient::value; + +} // namespace detail +} // namespace autodiff diff --git a/dae-cpp/autodiff/common/classtraits.hpp b/dae-cpp/autodiff/common/classtraits.hpp new file mode 100644 index 0000000..61c23c8 --- /dev/null +++ b/dae-cpp/autodiff/common/classtraits.hpp @@ -0,0 +1,106 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// autodiff includes +#include + +namespace autodiff { +namespace detail { + +//========================================================================================================================================================== +// The code below was taken from: https://stackoverflow.com/questions/87372/check-if-a-class-has-a-member-function-of-a-given-signature/16867422#16867422 +// It implements checkers to determine if a type has a member variable, function, etc. +//========================================================================================================================================================== + +template struct ambiguate : public Args... {}; + +template +struct got_type : std::false_type {}; + +template +struct got_type
: std::true_type { typedef A type; }; + +template +struct sig_check : std::true_type {}; + +template +struct has_member { + template static char ((&f(decltype(&C::value))))[1]; + template static char ((&f(...)))[2]; + + //Make sure the member name is consistently spelled the same. + static_assert( + (sizeof(f(0)) == 1) + , "Member name specified in AmbiguitySeed is different from member name specified in Alias, or wrong Alias/AmbiguitySeed has been specified." + ); + + static bool const value = sizeof(f(0)) == 2; +}; + +//Check for any member with given name, whether var, func, class, union, enum. +#define CREATE_MEMBER_CHECK(member) \ + \ +template \ +struct Alias_##member; \ + \ +template \ +struct Alias_##member < \ + T, std::integral_constant::value> \ +> { static const decltype(&T::member) value; }; \ + \ +struct AmbiguitySeed_##member { char member; }; \ + \ +template \ +struct has_member_##member { \ + static const bool value \ + = has_member< \ + Alias_##member> \ + , Alias_##member \ + >::value \ + ; \ +} + +// Create type trait struct `has_member_size`. +CREATE_MEMBER_CHECK(size); + +/// Boolean constant that is true if type T implements `size` method. +template +constexpr bool hasSize = has_member_size>::value; + +// Create type trait struct `has_operator_bracket`. +template struct has_operator_bracket_impl : std::false_type {}; +template struct has_operator_bracket_impl().operator [](0)) ), T> : std::true_type {}; + +/// Boolean type that is true if type T implements `operator[](int)` method. +template struct has_operator_bracket : has_operator_bracket_impl {}; + +} // namespace detail +} // namespace autodiff diff --git a/dae-cpp/autodiff/common/eigen.hpp b/dae-cpp/autodiff/common/eigen.hpp new file mode 100644 index 0000000..d89c06f --- /dev/null +++ b/dae-cpp/autodiff/common/eigen.hpp @@ -0,0 +1,155 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// Eigen includes +#include + +// autodiff includes +#include + +//===================================================================================================================== +// +// EIGEN MACROS FOR CREATING NEW TYPE ALIASES +// +//===================================================================================================================== + +#define AUTODIFF_DEFINE_EIGEN_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ +using Array##SizeSuffix##SizeSuffix##TypeSuffix = Eigen::Array; \ +using Array##SizeSuffix##TypeSuffix = Eigen::Array; \ +using Matrix##SizeSuffix##TypeSuffix = Eigen::Matrix; \ +using Vector##SizeSuffix##TypeSuffix = Eigen::Matrix; \ +using RowVector##SizeSuffix##TypeSuffix = Eigen::Matrix; + +#define AUTODIFF_DEFINE_EIGEN_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \ +using Array##Size##X##TypeSuffix = Eigen::Array; \ +using Array##X##Size##TypeSuffix = Eigen::Array; \ +using Matrix##Size##X##TypeSuffix = Eigen::Matrix; \ +using Matrix##X##Size##TypeSuffix = Eigen::Matrix; + +#define AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ +AUTODIFF_DEFINE_EIGEN_TYPEDEFS(Type, TypeSuffix, 2, 2) \ +AUTODIFF_DEFINE_EIGEN_TYPEDEFS(Type, TypeSuffix, 3, 3) \ +AUTODIFF_DEFINE_EIGEN_TYPEDEFS(Type, TypeSuffix, 4, 4) \ +AUTODIFF_DEFINE_EIGEN_TYPEDEFS(Type, TypeSuffix, -1, X) \ +AUTODIFF_DEFINE_EIGEN_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \ +AUTODIFF_DEFINE_EIGEN_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \ +AUTODIFF_DEFINE_EIGEN_FIXED_TYPEDEFS(Type, TypeSuffix, 4) + +namespace autodiff { +namespace detail { + +//===================================================================================================================== +// +// DEFINE VECTOR TRAITS FOR EIGEN TYPES +// +//===================================================================================================================== + +template +struct VectorTraits> +{ + using ValueType = Scalar; + + template + using ReplaceValueType = Eigen::Matrix; +}; + +template +struct VectorTraits> +{ + using ValueType = Scalar; + + template + using ReplaceValueType = Eigen::Array; +}; + +template +struct VectorTraits> +{ + using ValueType = typename PlainType::Scalar; + + template + using ReplaceValueType = VectorReplaceValueType; +}; + +#if EIGEN_VERSION_AT_LEAST(3, 3, 90) + + template + struct VectorTraits> + { + using ValueType = typename PlainType::Scalar; + + template + using ReplaceValueType = VectorReplaceValueType; + }; + + template + struct VectorTraits> + { + using ValueType = typename PlainType::Scalar; + + template + using ReplaceValueType = VectorReplaceValueType; + }; + +#endif + +template +struct VectorTraits> +{ + using ValueType = VectorValueType; + + template + using ReplaceValueType = VectorReplaceValueType; +}; + +template +struct VectorTraits> +{ + using ValueType = VectorValueType; + + template + using ReplaceValueType = Eigen::Map, MapOptions, StrideType>; +}; + +//===================================================================================================================== +// +// AUXILIARY TEMPLATE TYPE ALIASES +// +//===================================================================================================================== + +template +using VectorX = Eigen::Matrix; + +template +using MatrixX = Eigen::Matrix; + +} // namespace detail +} // namespace autodiff diff --git a/dae-cpp/autodiff/common/meta.hpp b/dae-cpp/autodiff/common/meta.hpp new file mode 100644 index 0000000..7fe7d26 --- /dev/null +++ b/dae-cpp/autodiff/common/meta.hpp @@ -0,0 +1,203 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// C++ includes +#include +#include +#include + +#ifndef AUTODIFF_DEVICE_FUNC +#ifdef EIGEN_CORE_MODULE_H +#include +#else +#define EIGEN_CORE_MODULE_H +#include +#undef EIGEN_CORE_MODULE_H +#endif + +#ifdef EIGEN_DEVICE_FUNC +#define AUTODIFF_DEVICE_FUNC EIGEN_DEVICE_FUNC +#else +#define AUTODIFF_DEVICE_FUNC +#endif + +#endif + +namespace autodiff { +namespace detail { + +template +using EnableIf = std::enable_if_t; + +template +using Requires = std::enable_if_t; + +template +using PlainType = std::remove_cv_t>; + +template +using ConditionalType = std::conditional_t; + +template +using CommonType = std::common_type_t; + +template +using ReturnType = std::invoke_result_t; + +template +constexpr bool isConst = std::is_const_v>; + +template +constexpr bool isConvertible = std::is_convertible, U>::value; + +template +constexpr bool isSame = std::is_same_v; + +template +constexpr auto TupleSize = std::tuple_size_v>; + +template +AUTODIFF_DEVICE_FUNC constexpr auto TupleHead(Tuple&& tuple) +{ + return std::get<0>(std::forward(tuple)); +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto TupleTail(Tuple&& tuple) +{ + auto g = [&](auto&&, auto&&... args) constexpr { + return std::forward_as_tuple(args...); + }; + return std::apply(g, std::forward(tuple)); +} + +template +struct Index +{ + constexpr static size_t index = i; + constexpr operator size_t() const { return index; } + constexpr operator size_t() { return index; } +}; + +template +AUTODIFF_DEVICE_FUNC constexpr auto AuxFor(Function&& f) +{ + if constexpr (i < iend) { + f(Index{}); + AuxFor(std::forward(f)); + } +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto For(Function&& f) +{ + AuxFor(std::forward(f)); +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto For(Function&& f) +{ + For<0, iend>(std::forward(f)); +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto AuxReverseFor(Function&& f) +{ + if constexpr (i < iend) + { + AuxReverseFor(std::forward(f)); + f(Index{}); + } +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto ReverseFor(Function&& f) +{ + AuxReverseFor(std::forward(f)); +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto ReverseFor(Function&& f) +{ + ReverseFor<0, iend>(std::forward(f)); +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto ForEach(Tuple&& tuple, Function&& f) +{ + constexpr auto N = TupleSize; + For([&](auto i) constexpr { + f(std::get(tuple)); + }); + //------------------------------------------------------------ + // ALTERNATIVE IMPLEMENTATION POSSIBLY USEFUL TO KEEP IT HERE + // auto g = [&](auto&&... args) constexpr { + // ( f(std::forward(args)), ...); + // }; + // std::apply(g, std::forward(tuple)); + //------------------------------------------------------------ +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto ForEach(Tuple1&& tuple1, Tuple2&& tuple2, Function&& f) +{ + constexpr auto N1 = TupleSize; + constexpr auto N2 = TupleSize; + static_assert(N1 == N2); + For([&](auto i) constexpr { + f(std::get(tuple1), std::get(tuple2)); + }); +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto Sum(Function&& f) +{ + using ResultType = std::invoke_result_t>; + ResultType res = {}; + For([&](auto i) constexpr { + res += f(Index{}); + }); + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto Reduce(Tuple&& tuple, Function&& f) +{ + using ResultType = std::invoke_result_t(tuple))>; + ResultType res = {}; + ForEach(tuple, [&](auto&& item) constexpr { + res += f(item); + }); + return res; +} + +} // namespace detail +} // namespace autodiff diff --git a/dae-cpp/autodiff/common/numbertraits.hpp b/dae-cpp/autodiff/common/numbertraits.hpp new file mode 100644 index 0000000..2126e02 --- /dev/null +++ b/dae-cpp/autodiff/common/numbertraits.hpp @@ -0,0 +1,73 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// C++ includes +#include + +namespace autodiff { +namespace detail { + +/// A trait class used to specify whether a type is arithmetic. +template +struct ArithmeticTraits +{ + static constexpr bool isArithmetic = std::is_arithmetic_v; +}; + +/// A compile-time constant that indicates whether a type is arithmetic. +template +constexpr bool isArithmetic = ArithmeticTraits>::isArithmetic; + +/// An auxiliary template type to indicate NumberTraits has not been defined for a type. +template +struct NumericTypeInfoNotDefinedFor { using type = T; }; + +/// A trait class used to specify whether a type is an autodiff number. +template +struct NumberTraits +{ + /// The underlying floating point type of the autodiff number type. + using NumericType = std::conditional_t, T, NumericTypeInfoNotDefinedFor>; + + /// The order of the autodiff number type. + static constexpr auto Order = 0; +}; + +/// A template alias to get the underlying floating point type of an autodiff number. +template +using NumericType = typename NumberTraits>::NumericType; + +/// A compile-time constant with the order of an autodiff number. +template +constexpr auto Order = NumberTraits>::Order; + +} // namespace detail +} // namespace autodiff diff --git a/dae-cpp/autodiff/common/vectortraits.hpp b/dae-cpp/autodiff/common/vectortraits.hpp new file mode 100644 index 0000000..634b576 --- /dev/null +++ b/dae-cpp/autodiff/common/vectortraits.hpp @@ -0,0 +1,84 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// C++ includes +#include + +// autodiff includes +#include + +namespace autodiff { +namespace detail { + +/// An auxiliary template type to indicate VectorTraits has not been defined for a type. +template +struct VectorTraitsNotDefinedFor {}; + +/// An auxiliary template type to indicate VectorTraits::ReplaceValueType is not supported for a type. +template +struct VectorReplaceValueTypeNotSupportedFor {}; + +/// A vector traits to be defined for each autodiff number. +template +struct VectorTraits +{ + /// The value type of each entry in the vector. + using ValueType = VectorTraitsNotDefinedFor; + + /// The template alias to replace the value type of a vector type with another value type. + using ReplaceValueType = VectorReplaceValueTypeNotSupportedFor; +}; + +/// A template alias used to get the type of the values in a vector type. +template +using VectorValueType = typename VectorTraits>::ValueType; + +/// A template alias used to get the type of a vector that is equivalent to another but with a different value type. +template +using VectorReplaceValueType = typename VectorTraits>::template ReplaceValueType; + +/// A compile-time constant that indicates with a type is a vector type. +template +constexpr bool isVector = !std::is_same_v>, VectorTraitsNotDefinedFor>>; + + +/// Implementation of VectorTraits for std::vector. +template typename Allocator> +struct VectorTraits>> +{ + using ValueType = T; + + template + using ReplaceValueType = std::vector>; +}; + +} // namespace detail +} // namespace autodiff diff --git a/dae-cpp/autodiff/forward/dual.hpp b/dae-cpp/autodiff/forward/dual.hpp new file mode 100644 index 0000000..ba11962 --- /dev/null +++ b/dae-cpp/autodiff/forward/dual.hpp @@ -0,0 +1,35 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// autodiff includes +#include +#include +#include diff --git a/dae-cpp/autodiff/forward/dual/dual.hpp b/dae-cpp/autodiff/forward/dual/dual.hpp new file mode 100644 index 0000000..2177507 --- /dev/null +++ b/dae-cpp/autodiff/forward/dual/dual.hpp @@ -0,0 +1,1811 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// C++ includes +#include +#include +#include +#include +#include +#include +#include + +// autodiff includes +#include +#include + +namespace autodiff { +namespace detail { + +//===================================================================================================================== +// +// STANDARD TEMPLATE LIBRARY MATH FUNCTIONS +// +//===================================================================================================================== + +using std::abs; +using std::acos; +using std::asin; +using std::atan; +using std::atan2; +using std::cos; +using std::exp; +using std::log10; +using std::log; +using std::pow; +using std::sin; +using std::sqrt; +using std::tan; +using std::cosh; +using std::sinh; +using std::tanh; +using std::erf; +using std::hypot; + +//===================================================================================================================== +// +// OPERATOR TYPES +// +//===================================================================================================================== + +//----------------------------------------------------------------------------- +// ARITHMETIC OPERATORS +//----------------------------------------------------------------------------- +struct AddOp {}; // ADDITION OPERATOR +struct SubOp {}; // SUBTRACTION OPERATOR +struct MulOp {}; // MULTIPLICATION OPERATOR +struct DivOp {}; // DIVISION OPERATOR + +//----------------------------------------------------------------------------- +// MATHEMATICAL OPERATORS +//----------------------------------------------------------------------------- +struct NegOp {}; // NEGATIVE OPERATOR +struct InvOp {}; // INVERSE OPERATOR +struct SinOp {}; // SINE OPERATOR +struct CosOp {}; // COSINE OPERATOR +struct TanOp {}; // TANGENT OPERATOR +struct SinhOp {}; // HYPERBOLIC SINE OPERATOR +struct CoshOp {}; // HYPERBOLIC COSINE OPERATOR +struct TanhOp {}; // HYPERBOLIC TANGENT OPERATOR +struct ArcSinOp {}; // ARC SINE OPERATOR +struct ArcCosOp {}; // ARC COSINE OPERATOR +struct ArcTanOp {}; // ARC TANGENT OPERATOR +struct ArcTan2Op {}; // 2-ARGUMENT ARC TANGENT OPERATOR +struct ExpOp {}; // EXPONENTIAL OPERATOR +struct LogOp {}; // NATURAL LOGARITHM OPERATOR +struct Log10Op {}; // BASE-10 LOGARITHM OPERATOR +struct SqrtOp {}; // SQUARE ROOT OPERATOR +struct PowOp {}; // POWER OPERATOR +struct AbsOp {}; // ABSOLUTE OPERATOR +struct ErfOp {}; // ERROR FUNCTION OPERATOR +struct Hypot2Op {}; // 2D HYPOT OPERATOR +struct Hypot3Op {}; // 3D HYPOT OPERATOR + +//----------------------------------------------------------------------------- +// OTHER OPERATORS +//----------------------------------------------------------------------------- +struct NumberDualMulOp {}; // NUMBER-DUAL MULTIPLICATION OPERATOR +struct NumberDualDualMulOp {}; // NUMBER-DUAL-DUAL MULTIPLICATION OPERATOR + +//===================================================================================================================== +// +// BASE EXPRESSION TYPES (DECLARATION) +// +//===================================================================================================================== + +template +struct Dual; + +template +struct UnaryExpr; + +template +struct BinaryExpr; + +template +struct TernaryExpr; + +//===================================================================================================================== +// +// DERIVED EXPRESSION TYPES +// +//===================================================================================================================== + +//----------------------------------------------------------------------------- +// DERIVED MATHEMATICAL EXPRESSIONS +//----------------------------------------------------------------------------- +template +using NegExpr = UnaryExpr; + +template +using InvExpr = UnaryExpr; + +template +using SinExpr = UnaryExpr; + +template +using CosExpr = UnaryExpr; + +template +using TanExpr = UnaryExpr; + +template +using SinhExpr = UnaryExpr; + +template +using CoshExpr = UnaryExpr; + +template +using TanhExpr = UnaryExpr; + +template +using ArcSinExpr = UnaryExpr; + +template +using ArcCosExpr = UnaryExpr; + +template +using ArcTanExpr = UnaryExpr; + +template +using ArcTan2Expr = BinaryExpr; + +template +using ExpExpr = UnaryExpr; + +template +using LogExpr = UnaryExpr; + +template +using Log10Expr = UnaryExpr; + +template +using SqrtExpr = UnaryExpr; + +template +using PowExpr = BinaryExpr; + +template +using AbsExpr = UnaryExpr; + +template +using ErfExpr = UnaryExpr; + +template +using Hypot2Expr = BinaryExpr; + +template +using Hypot3Expr = TernaryExpr; + +//----------------------------------------------------------------------------- +// DERIVED ARITHMETIC EXPRESSIONS +//----------------------------------------------------------------------------- +template +using AddExpr = BinaryExpr; + +template +using MulExpr = BinaryExpr; + +//----------------------------------------------------------------------------- +// DERIVED OTHER EXPRESSIONS +//----------------------------------------------------------------------------- +template +using NumberDualMulExpr = BinaryExpr; + +template +using NumberDualDualMulExpr = TernaryExpr; + +//===================================================================================================================== +// +// TYPE TRAITS UTILITIES +// +//===================================================================================================================== + +namespace traits { + +//----------------------------------------------------------------------------- +// IS TYPE T AN EXPRESSION NODE? +//----------------------------------------------------------------------------- +template +struct isExpr { constexpr static bool value = false; }; + +template +struct isExpr> { constexpr static bool value = true; }; + +template +struct isExpr> { constexpr static bool value = true; }; + +template +struct isExpr> { constexpr static bool value = true; }; + +template +struct isExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A DUAL INSTANCE? +//----------------------------------------------------------------------------- +template +struct isDual { constexpr static bool value = false; }; + +template +struct isDual> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T AN UNARY EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isUnaryExpr { constexpr static bool value = false; }; + +template +struct isUnaryExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A BINARY EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isBinaryExpr { constexpr static bool value = false; }; + +template +struct isBinaryExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A TERNARY EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isTernaryExpr { constexpr static bool value = false; }; + +template +struct isTernaryExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A NEGATIVE EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isNegExpr { constexpr static bool value = false; }; + +template +struct isNegExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T AN INVERSE EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isInvExpr { constexpr static bool value = false; }; + +template +struct isInvExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A GENERAL ADDITION EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isAddExpr { constexpr static bool value = false; }; + +template +struct isAddExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A GENERAL MULTIPLICATION EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isMulExpr { constexpr static bool value = false; }; + +template +struct isMulExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A POWER EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isPowExpr { constexpr static bool value = false; }; + +template +struct isPowExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A ARCTAN2 EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isArcTan2Expr { constexpr static bool value = false; }; + +template +struct isArcTan2Expr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A NUMBER-DUAL MULTIPLICATION EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isNumberDualMulExpr { constexpr static bool value = false; }; + +template +struct isNumberDualMulExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A NUMBER-DUAL-DUAL MULTIPLICATION EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isNumberDualDualMulExpr { constexpr static bool value = false; }; + +template +struct isNumberDualDualMulExpr> { constexpr static bool value = true; }; + +//----------------------------------------------------------------------------- +// IS TYPE T A HYPOT EXPRESSION? +//----------------------------------------------------------------------------- +template +struct isHypot2Expr { constexpr static bool value = false; }; + +template +struct isHypot2Expr> { constexpr static bool value = true; }; + +template +struct isHypot3Expr { constexpr static bool value = false; }; + +template +struct isHypot3Expr> { constexpr static bool value = true; }; + +} // namespace traits + +template +constexpr bool isExpr = traits::isExpr>::value; + +template +constexpr bool isDual = traits::isDual>::value; + +template +constexpr bool isUnaryExpr = traits::isUnaryExpr>::value; + +template +constexpr bool isBinaryExpr = traits::isBinaryExpr>::value; + +template +constexpr bool isTernaryExpr = traits::isTernaryExpr>::value; + +template +constexpr bool isNegExpr = traits::isNegExpr>::value; + +template +constexpr bool isInvExpr = traits::isInvExpr>::value; + +template +constexpr bool isAddExpr = traits::isAddExpr>::value; + +template +constexpr bool isMulExpr = traits::isMulExpr>::value; + +template +constexpr bool isPowExpr = traits::isPowExpr>::value; + +template +constexpr bool isArcTan2Expr = traits::isArcTan2Expr>::value; + +template +constexpr bool isHypot2Expr = traits::isHypot2Expr>::value; + +template +constexpr bool isHypot3Expr = traits::isHypot3Expr>::value; + +template +constexpr bool isNumberDualMulExpr = traits::isNumberDualMulExpr>::value; + +template +constexpr bool isNumberDualDualMulExpr = traits::isNumberDualDualMulExpr>::value; + +template +constexpr bool areDual = (... && isDual); + +//----------------------------------------------------------------------------- +// ARE TYPES L AND R EXPRESSION NODES OR NUMBERS, BUT NOT BOTH NUMBERS? +//----------------------------------------------------------------------------- +template +constexpr bool isOperable = (isExpr && isExpr) || (isArithmetic && isExpr) || (isExpr && isArithmetic); + +template +constexpr bool isOperable3 = (isOperable && isOperable) || (isOperable && isOperable) || (isOperable && isOperable); + +//----------------------------------------------------------------------------- +// VALUE, GRAD, AND OP TYPES IN DUAL EXPRESSIONS +//----------------------------------------------------------------------------- + +template struct AuxDualType; +template struct AuxDualOpType; +template struct AuxCommonDualType; + + +template struct DualTypeNotDefinedFor {}; +template struct DualOpTypeNotDefinedFor {}; +template struct CommonDualTypeNotDefinedFor {}; + + +template using DualType = typename AuxDualType>::type; +template using DualOpType = typename AuxDualOpType>::type; +template using CommonDualType = typename AuxCommonDualType, PlainType>::type; + + +template +struct AuxDualType { using type = ConditionalType, T, DualTypeNotDefinedFor>; }; + +template +struct AuxDualType> { using type = Dual; }; + +template +struct AuxDualType> { using type = DualType; }; + +template +struct AuxDualType> { using type = CommonDualType; }; + +template +struct AuxDualType> { using type = CommonDualType>; }; + + +template +struct AuxDualOpType { using type = DualOpTypeNotDefinedFor; }; + +template +struct AuxDualOpType> { using type = Op; }; + +template +struct AuxDualOpType> { using type = Op; }; + +template +struct AuxDualOpType> { using type = Op; }; + +template +AUTODIFF_DEVICE_FUNC constexpr auto auxCommonDualType() +{ + if constexpr (isArithmetic && isArithmetic) + return CommonType(); + else if constexpr (isExpr && isArithmetic) + return DualType(); + else if constexpr (isArithmetic && isExpr) + return DualType(); + else if constexpr (isExpr && isExpr) { + using DualTypeL = DualType; + using DualTypeR = DualType; + static_assert(isSame); + return DualTypeL(); + } + else return CommonDualTypeNotDefinedFor(); +} + +template +struct AuxCommonDualType { using type = decltype(auxCommonDualType()); }; + +//===================================================================================================================== +// +// EXPRESSION TYPES DEFINITION +// +//===================================================================================================================== + +template +struct Dual +{ + T val = {}; + + G grad = {}; + + AUTODIFF_DEVICE_FUNC Dual() + {} + + template || isArithmetic> = true> + AUTODIFF_DEVICE_FUNC Dual(U&& other) + { + assign(*this, std::forward(other)); + } + + template || isArithmetic> = true> + AUTODIFF_DEVICE_FUNC Dual& operator=(U&& other) + { + Dual tmp; + assign(tmp, std::forward(other)); + assign(*this, tmp); + return *this; + } + + template || isArithmetic> = true> + AUTODIFF_DEVICE_FUNC Dual& operator+=(U&& other) + { + Dual tmp; + assign(tmp, std::forward(other)); + assignAdd(*this, tmp); + return *this; + } + + template || isArithmetic> = true> + AUTODIFF_DEVICE_FUNC Dual& operator-=(U&& other) + { + Dual tmp; + assign(tmp, std::forward(other)); + assignSub(*this, tmp); + return *this; + } + + template || isArithmetic> = true> + AUTODIFF_DEVICE_FUNC Dual& operator*=(U&& other) + { + Dual tmp; + assign(tmp, std::forward(other)); + assignMul(*this, tmp); + return *this; + } + + template || isArithmetic> = true> + AUTODIFF_DEVICE_FUNC Dual& operator/=(U&& other) + { + Dual tmp; + assign(tmp, std::forward(other)); + assignDiv(*this, tmp); + return *this; + } + + /// Convert this Dual number into a value of type @p U. +#if defined(AUTODIFF_ENABLE_IMPLICIT_CONVERSION_DUAL) || defined(AUTODIFF_ENABLE_IMPLICIT_CONVERSION) + AUTODIFF_DEVICE_FUNC operator T() const { return val; } + + template + AUTODIFF_DEVICE_FUNC operator U() const { return static_cast(val); } +#else + AUTODIFF_DEVICE_FUNC explicit operator T() const { return val; } + + template + AUTODIFF_DEVICE_FUNC explicit operator U() const { return static_cast(val); } +#endif +}; + +template +struct UnaryExpr +{ + R r; +}; + +template +struct BinaryExpr +{ + L l; + R r; +}; + +template +struct TernaryExpr +{ + L l; + C c; + R r; +}; + +template +AUTODIFF_DEVICE_FUNC auto inner(const UnaryExpr& expr) -> const R +{ + return expr.r; +} + +template +AUTODIFF_DEVICE_FUNC auto left(const BinaryExpr& expr) -> const L +{ + return expr.l; +} + +template +AUTODIFF_DEVICE_FUNC auto right(const BinaryExpr& expr) -> const R +{ + return expr.r; +} + +//===================================================================================================================== +// +// UTILITY FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr auto eval(T&& expr) +{ + static_assert(isDual || isExpr || isArithmetic); + if constexpr (isDual) + return std::forward(expr); + else if constexpr (isExpr) + return DualType(std::forward(expr)); + else return std::forward(expr); +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto val(T&& expr) +{ + static_assert(isDual || isExpr || isArithmetic); + if constexpr (isDual) + return val(expr.val); + else if constexpr (isExpr) + return val(eval(std::forward(expr))); + else return std::forward(expr); +} + +//===================================================================================================================== +// +// DERIVATIVE FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC auto derivative(const Dual& dual) +{ + if constexpr (order == 0) + return val(dual.val); + else if constexpr (order == 1) + return val(dual.grad); + else return derivative(dual.grad); +} + +//===================================================================================================================== +// +// SEED FUNCTION +// +//===================================================================================================================== + +/// Traverse down along the `val` branch until depth `order` is reached, then return the `grad` node. +template +AUTODIFF_DEVICE_FUNC auto& gradnode(Dual& dual) +{ + constexpr auto N = Order>; + static_assert(order <= N); + if constexpr (order == 0) return dual.val; + else if constexpr (order == 1) return dual.grad; + else return gradnode(dual.val); +} + +/// Set the `grad` node of a dual number along the `val` branch at a depth `order`. +template +AUTODIFF_DEVICE_FUNC auto seed(Dual& dual, U&& seedval) +{ + gradnode(dual) = static_cast(dual))>>(seedval); +} + +//===================================================================================================================== +// +// CONVENIENT FUNCTIONS +// +//===================================================================================================================== + +/// Alias template used to prevent expression nodes to be stored as references. +/// For example, the following should not exist `BinaryExpr&>>`. +/// It should be instead `BinaryExpr>`. +/// This alias template allows only dual numbers to have their original type. +/// All other types become plain, without reference and const attributes. +template +using PreventExprRef = ConditionalType, T, PlainType>; + +//----------------------------------------------------------------------------- +// NEGATIVE EXPRESSION GENERATOR FUNCTION +//----------------------------------------------------------------------------- +template +AUTODIFF_DEVICE_FUNC constexpr auto negative(U&& expr) +{ + static_assert(isExpr || isArithmetic); + if constexpr (isNegExpr) + return inner(expr); + else return NegExpr>{ expr }; +} + +//----------------------------------------------------------------------------- +// INVERSE EXPRESSION GENERATOR FUNCTION +//----------------------------------------------------------------------------- +template +AUTODIFF_DEVICE_FUNC constexpr auto inverse(U&& expr) +{ + static_assert(isExpr); + if constexpr (isInvExpr) + return inner(expr); + else return InvExpr>{ expr }; +} + +//----------------------------------------------------------------------------- +// AUXILIARY CONSTEXPR CONSTANTS +//----------------------------------------------------------------------------- +template +AUTODIFF_DEVICE_FUNC constexpr auto Zero() { return static_cast>(0); } + +template +AUTODIFF_DEVICE_FUNC constexpr auto One() { return static_cast>(1); } + +//===================================================================================================================== +// +// POSITIVE ARITHMETIC OPERATOR OVERLOADING +// +//===================================================================================================================== + +//----------------------------------------------------------------------------- +// POSITIVE OPERATOR: +x +//----------------------------------------------------------------------------- +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto operator+(R&& expr) +{ + return std::forward(expr); // expression optimization: +(expr) => expr +} + +//===================================================================================================================== +// +// NEGATIVE ARITHMETIC OPERATOR OVERLOADING +// +//===================================================================================================================== + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto operator-(R&& expr) +{ + // NEGATIVE EXPRESSION CASE: -(-x) => x when expr is (-x) + if constexpr (isNegExpr) + return inner(expr); + // NEGATIVE EXPRESSION CASE: -(number * dual) => (-number) * dual + else if constexpr (isNumberDualMulExpr) + return (-left(expr)) * right(expr); + // default expression + else return NegExpr>{ expr }; +} + +//===================================================================================================================== +// +// ADDITION ARITHMETIC OPERATOR OVERLOADING +// +//===================================================================================================================== + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto operator+(L&& l, R&& r) +{ + // ADDITION EXPRESSION CASE: (-x) + (-y) => -(x + y) + if constexpr (isNegExpr && isNegExpr) + return -( inner(l) + inner(r) ); + // ADDITION EXPRESSION CASE: expr + number => number + expr (number always on the left) + else if constexpr (isExpr && isArithmetic) + return std::forward(r) + std::forward(l); + // DEFAULT ADDITION EXPRESSION + else return AddExpr, PreventExprRef>{ l, r }; +} + +//===================================================================================================================== +// +// MULTIPLICATION ARITHMETIC OPERATOR OVERLOADING +// +//===================================================================================================================== + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto operator*(L&& l, R&& r) +{ + // MULTIPLICATION EXPRESSION CASE: (-expr) * (-expr) => expr * expr + if constexpr (isNegExpr && isNegExpr) + return inner(l) * inner(r); + // // MULTIPLICATION EXPRESSION CASE: (1 / expr) * (1 / expr) => 1 / (expr * expr) + else if constexpr (isInvExpr && isInvExpr) + return inverse(inner(l) * inner(r)); + // // MULTIPLICATION EXPRESSION CASE: expr * number => number * expr + else if constexpr (isExpr && isArithmetic) + return std::forward(r) * std::forward(l); + // // MULTIPLICATION EXPRESSION CASE: number * (-expr) => (-number) * expr + else if constexpr (isArithmetic && isNegExpr) + return (-l) * inner(r); + // // MULTIPLICATION EXPRESSION CASE: number * (number * expr) => (number * number) * expr + else if constexpr (isArithmetic && isNumberDualMulExpr) + return (l * left(r)) * right(r); + // MULTIPLICATION EXPRESSION CASE: number * dual => NumberDualMulExpr + else if constexpr (isArithmetic && isDual) + return NumberDualMulExpr, PreventExprRef>{ l, r }; + // DEFAULT MULTIPLICATION EXPRESSION: expr * expr => MulExpr + else return MulExpr, PreventExprRef>{ l, r }; +} + +//===================================================================================================================== +// +// SUBTRACTION ARITHMETIC OPERATOR OVERLOADING +// +//===================================================================================================================== + +//----------------------------------------------------------------------------- +// SUBTRACTION OPERATOR: expr - expr, scalar - expr, expr - scalar +//----------------------------------------------------------------------------- +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto operator-(L&& l, R&& r) +{ + return std::forward(l) + ( -std::forward(r) ); +} + +//===================================================================================================================== +// +// DIVISION ARITHMETIC OPERATOR OVERLOADING +// +//===================================================================================================================== + +//----------------------------------------------------------------------------- +// DIVISION OPERATOR: expr / expr +//----------------------------------------------------------------------------- +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto operator/(L&& l, R&& r) +{ + if constexpr (isArithmetic) + return std::forward(l) * (One() / std::forward(r)); + else return std::forward(l) * inverse(std::forward(r)); +} + +//===================================================================================================================== +// +// TRIGONOMETRIC FUNCTIONS OVERLOADING +// +//===================================================================================================================== + +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto sin(R&& r) -> SinExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto cos(R&& r) -> CosExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto tan(R&& r) -> TanExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto asin(R&& r) -> ArcSinExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto acos(R&& r) -> ArcCosExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto atan(R&& r) -> ArcTanExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto atan2(L&& l, R&& r) -> ArcTan2Expr { return { l, r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto hypot(L&& l, R&& r) -> Hypot2Expr { return { l, r }; } +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto hypot(L&& l, C&& c, R&& r) -> Hypot3Expr { return { l, c, r }; } + +//===================================================================================================================== +// +// HYPERBOLIC FUNCTIONS OVERLOADING +// +//===================================================================================================================== + +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto sinh(R&& r) -> SinhExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto cosh(R&& r) -> CoshExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto tanh(R&& r) -> TanhExpr { return { r }; } + +//===================================================================================================================== +// +// EXPONENTIAL AND LOGARITHMIC FUNCTIONS OVERLOADING +// +//===================================================================================================================== + +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto exp(R&& r) -> ExpExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto log(R&& r) -> LogExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto log10(R&& r) -> Log10Expr { return { r }; } + +//===================================================================================================================== +// +// POWER FUNCTIONS OVERLOADING +// +//===================================================================================================================== + +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto pow(L&& l, R&& r) -> PowExpr { return { l, r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto sqrt(R&& r) -> SqrtExpr { return { r }; } + +//===================================================================================================================== +// +// OTHER FUNCTIONS OVERLOADING +// +//===================================================================================================================== + +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto abs(R&& r) -> AbsExpr { return { r }; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto abs2(R&& r) { return std::forward(r) * std::forward(r); } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto conj(R&& r) { return std::forward(r); } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto real(R&& r) { return std::forward(r); } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto imag(R&&) { return 0.0; } +template> = true> AUTODIFF_DEVICE_FUNC constexpr auto erf(R&& r) -> ErfExpr { return { r }; } + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto min(L&& l, R&& r) +{ + const auto x = eval(l); + const auto y = eval(r); + return (x <= y) ? x : y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto max(L&& l, R&& r) +{ + const auto x = eval(l); + const auto y = eval(r); + return (x >= y) ? x : y; +} + +//===================================================================================================================== +// +// COMPARISON OPERATORS OVERLOADING +// +//===================================================================================================================== + +template> = true> AUTODIFF_DEVICE_FUNC bool operator==(L&& l, R&& r) { return val(l) == val(r); } +template> = true> AUTODIFF_DEVICE_FUNC bool operator!=(L&& l, R&& r) { return val(l) != val(r); } +template> = true> AUTODIFF_DEVICE_FUNC bool operator<=(L&& l, R&& r) { return val(l) <= val(r); } +template> = true> AUTODIFF_DEVICE_FUNC bool operator>=(L&& l, R&& r) { return val(l) >= val(r); } +template> = true> AUTODIFF_DEVICE_FUNC bool operator<(L&& l, R&& r) { return val(l) < val(r); } +template> = true> AUTODIFF_DEVICE_FUNC bool operator>(L&& l, R&& r) { return val(l) > val(r); } + +//===================================================================================================================== +// +// AUXILIARY FUNCTIONS +// +//===================================================================================================================== +template +AUTODIFF_DEVICE_FUNC constexpr void negate(Dual& self) +{ + self.val = -self.val; + self.grad = -self.grad; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void scale(Dual& self, const U& scalar) +{ + self.val *= scalar; + self.grad *= scalar; +} + +//===================================================================================================================== +// +// FORWARD DECLARATIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self); + +//===================================================================================================================== +// +// ASSIGNMENT FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void assign(Dual& self, U&& other) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN A NUMBER: self = number + if constexpr (isArithmetic) { + self.val = other; + self.grad = Zero(); + } + // ASSIGN A DUAL NUMBER: self = dual + else if constexpr (isDual) { + self.val = other.val; + self.grad = other.grad; + } + // ASSIGN A NUMBER-DUAL MULTIPLICATION EXPRESSION: self = number * dual + else if constexpr (isNumberDualMulExpr) { + assign(self, other.r); + scale(self, other.l); + } + // ASSIGN A UNARY EXPRESSION: self = unaryexpr + else if constexpr (isUnaryExpr) { + using Op = DualOpType; + assign(self, other.r); + apply(self); + } + // ASSIGN AN ADDITION EXPRESSION: self = expr + expr + else if constexpr (isAddExpr) { + assign(self, other.r); + assignAdd(self, other.l); + } + // ASSIGN A MULTIPLICATION EXPRESSION: self = expr * expr + else if constexpr (isMulExpr) { + assign(self, other.r); + assignMul(self, other.l); + } + // ASSIGN A POWER EXPRESSION: self = pow(expr) + else if constexpr (isPowExpr) { + assign(self, other.l); + assignPow(self, other.r); + } + // ASSIGN A ATAN2 EXPRESSION: self = atan2(expr, expr) + else if constexpr (isArcTan2Expr) { + assignArcTan2(self, other.l, other.r); + } + + // ASSIGN A HYPOT2 EXPRESSION: self = hypot(expr, expr) + else if constexpr (isHypot2Expr) { + assignHypot2(self, other.l, other.r); + } + + // ASSIGN A HYPOT3 EXPRESSION: self = hypot(expr, expr) + else if constexpr (isHypot3Expr) { + assignHypot3(self, other.l, other.c, other.r); + } +} + +template +AUTODIFF_DEVICE_FUNC constexpr void assign(Dual& self, U&& other, Dual& tmp) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN AN UNARY EXPRESSION: self = func(expr) + if constexpr (isUnaryExpr) { + using Op = DualOpType; + assign(self, other.r, tmp); + apply(self); + } + // ASSIGN AN ADDITION EXPRESSION: self = expr + expr + else if constexpr (isAddExpr) { + assign(self, other.r, tmp); + assignAdd(self, other.l, tmp); + } + // ASSIGN A MULTIPLICATION EXPRESSION: self = expr * expr + else if constexpr (isMulExpr) { + assign(self, other.r, tmp); + assignMul(self, other.l, tmp); + } + // ASSIGN A POWER EXPRESSION: self = pow(expr, expr) + else if constexpr (isPowExpr) { + assign(self, other.l, tmp); + assignPow(self, other.r, tmp); + } + // ALL OTHER EXPRESSIONS + else { + assign(tmp, other); + assign(self, tmp); + } +} + +//===================================================================================================================== +// +// ASSIGNMENT-ADDITION FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void assignAdd(Dual& self, U&& other) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN-ADD A NUMBER: self += number + if constexpr (isArithmetic) { + self.val += other; + } + // ASSIGN-ADD A DUAL NUMBER: self += dual + else if constexpr (isDual) { + self.val += other.val; + self.grad += other.grad; + } + // ASSIGN-ADD A NEGATIVE EXPRESSION: self += -expr => self -= expr + else if constexpr (isNegExpr) { + assignSub(self, other.r); + } + // ASSIGN-ADD A NUMBER-DUAL MULTIPLICATION EXPRESSION: self += number * dual + else if constexpr (isNumberDualMulExpr) { + self.val += other.l * other.r.val; + self.grad += other.l * other.r.grad; + } + // ASSIGN-ADD AN ADDITION EXPRESSION: self += expr + expr + else if constexpr (isAddExpr) { + assignAdd(self, other.l); + assignAdd(self, other.r); + } + // ASSIGN-ADD ALL OTHER EXPRESSIONS + else { + Dual tmp; + assignAdd(self, std::forward(other), tmp); + } +} + +template +AUTODIFF_DEVICE_FUNC constexpr void assignAdd(Dual& self, U&& other, Dual& tmp) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN-ADD A NEGATIVE EXPRESSION: self += -expr => self -= expr + if constexpr (isNegExpr) { + assignSub(self, other.r, tmp); + } + // ASSIGN-ADD AN ADDITION EXPRESSION: self += expr + expr + else if constexpr (isAddExpr) { + assignAdd(self, other.l, tmp); + assignAdd(self, other.r, tmp); + } + // ASSIGN-ADD ALL OTHER EXPRESSIONS + else { + assign(tmp, other); + assignAdd(self, tmp); + } +} + +//===================================================================================================================== +// +// ASSIGNMENT-SUBTRACTION FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void assignSub(Dual& self, U&& other) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN-SUBTRACT A NUMBER: self -= number + if constexpr (isArithmetic) { + self.val -= other; + } + // ASSIGN-SUBTRACT A DUAL NUMBER: self -= dual + else if constexpr (isDual) { + self.val -= other.val; + self.grad -= other.grad; + } + // ASSIGN-SUBTRACT A NEGATIVE EXPRESSION: self -= -expr => self += expr + else if constexpr (isNegExpr) { + assignAdd(self, other.r); + } + // ASSIGN-SUBTRACT A NUMBER-DUAL MULTIPLICATION EXPRESSION: self -= number * dual + else if constexpr (isNumberDualMulExpr) { + self.val -= other.l * other.r.val; + self.grad -= other.l * other.r.grad; + } + // ASSIGN-SUBTRACT AN ADDITION EXPRESSION: self -= expr + expr + else if constexpr (isAddExpr) { + assignSub(self, other.l); + assignSub(self, other.r); + } + // ASSIGN-SUBTRACT ALL OTHER EXPRESSIONS + else { + Dual tmp; + assignSub(self, std::forward(other), tmp); + } +} + +template +AUTODIFF_DEVICE_FUNC constexpr void assignSub(Dual& self, U&& other, Dual& tmp) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN-SUBTRACT A NEGATIVE EXPRESSION: self -= -expr => self += expr + if constexpr (isNegExpr) { + assignAdd(self, other.r, tmp); + } + // ASSIGN-SUBTRACT AN ADDITION EXPRESSION: self -= expr + expr + else if constexpr (isAddExpr) { + assignSub(self, other.l, tmp); + assignSub(self, other.r, tmp); + } + // ASSIGN-SUBTRACT ALL OTHER EXPRESSIONS + else { + assign(tmp, other); + assignSub(self, tmp); + } +} + +//===================================================================================================================== +// +// ASSIGNMENT-MULTIPLICATION FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void assignMul(Dual& self, U&& other) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN-MULTIPLY A NUMBER: self *= number + if constexpr (isArithmetic) { + self.val *= other; + self.grad *= other; + } + // ASSIGN-MULTIPLY A DUAL NUMBER: self *= dual + else if constexpr (isDual) { + const G aux = other.grad; // to avoid aliasing when self === other + self.grad *= other.val; + self.grad += self.val * aux; + self.val *= other.val; + } + // ASSIGN-MULTIPLY A NEGATIVE EXPRESSION: self *= (-expr) + else if constexpr (isNegExpr) { + assignMul(self, other.r); + negate(self); + } + // ASSIGN-MULTIPLY A NUMBER-DUAL MULTIPLICATION EXPRESSION: self *= number * dual + else if constexpr (isNumberDualMulExpr) { + assignMul(self, other.r); + scale(self, other.l); + } + // ASSIGN-MULTIPLY A MULTIPLICATION EXPRESSION: self *= expr * expr + else if constexpr (isMulExpr) { + assignMul(self, other.l); + assignMul(self, other.r); + } + // ASSIGN-MULTIPLY ALL OTHER EXPRESSIONS + else { + Dual tmp; + assignMul(self, std::forward(other), tmp); + } +} + +template +AUTODIFF_DEVICE_FUNC constexpr void assignMul(Dual& self, U&& other, Dual& tmp) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN-MULTIPLY A NEGATIVE EXPRESSION: self *= (-expr) + if constexpr (isNegExpr) { + assignMul(self, other.r, tmp); + negate(self); + } + // ASSIGN-MULTIPLY A MULTIPLICATION EXPRESSION: self *= expr * expr + else if constexpr (isMulExpr) { + assignMul(self, other.l, tmp); + assignMul(self, other.r, tmp); + } + // ASSIGN-MULTIPLY ALL OTHER EXPRESSIONS + else { + assign(tmp, other); + assignMul(self, tmp); + } +} + +//===================================================================================================================== +// +// ASSIGNMENT-DIVISION FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void assignDiv(Dual& self, U&& other) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN-DIVIDE A NUMBER: self /= number + if constexpr (isArithmetic) { + self.val /= other; + self.grad /= other; + } + // ASSIGN-DIVIDE A DUAL NUMBER: self /= dual + else if constexpr (isDual) { + const T aux = One() / other.val; // to avoid aliasing when self === other + self.val *= aux; + self.grad -= self.val * other.grad; + self.grad *= aux; + } + // ASSIGN-DIVIDE A NEGATIVE EXPRESSION: self /= (-expr) + else if constexpr (isNegExpr) { + assignDiv(self, other.r); + negate(self); + } + // ASSIGN-DIVIDE AN INVERSE EXPRESSION: self /= 1/expr + else if constexpr (isInvExpr) { + assignMul(self, other.r); + } + // ASSIGN-DIVIDE A NUMBER-DUAL MULTIPLICATION EXPRESSION: self /= number * dual + else if constexpr (isNumberDualMulExpr) { + assignDiv(self, other.r); + assignDiv(self, other.l); + } + // ASSIGN-DIVIDE A MULTIPLICATION EXPRESSION: self /= expr * expr + else if constexpr (isMulExpr) { + assignDiv(self, other.l); + assignDiv(self, other.r); + } + // ASSIGN-DIVIDE ALL OTHER EXPRESSIONS + else { + Dual tmp; + assignDiv(self, std::forward(other), tmp); + } +} + +template +AUTODIFF_DEVICE_FUNC constexpr void assignDiv(Dual& self, U&& other, Dual& tmp) +{ + static_assert(isExpr || isArithmetic); + + // ASSIGN-DIVIDE A NEGATIVE EXPRESSION: self /= (-expr) + if constexpr (isNegExpr) { + assignDiv(self, other.r, tmp); + negate(self); + } + // ASSIGN-DIVIDE AN INVERSE EXPRESSION: self /= 1/expr + else if constexpr (isInvExpr) { + assignMul(self, other.r, tmp); + } + // ASSIGN-DIVIDE A MULTIPLICATION EXPRESSION: self /= expr * expr + else if constexpr (isMulExpr) { + assignDiv(self, other.l, tmp); + assignDiv(self, other.r, tmp); + } + // ASSIGN-DIVIDE ALL OTHER EXPRESSIONS + else { + assign(tmp, other); + assignDiv(self, tmp); + } +} + +//===================================================================================================================== +// +// ASSIGNMENT-POWER FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void assignPow(Dual& self, U&& other) +{ + // ASSIGN-POW A NUMBER: self = pow(self, number) + if constexpr (isArithmetic) { + const T aux = pow(self.val, other - 1); + self.grad *= other * aux; + self.val = aux * self.val; + } + // ASSIGN-POW A DUAL NUMBER: self = pow(self, dual) + else if constexpr (isDual) { + const T aux1 = pow(self.val, other.val); + const T aux2 = log(self.val); + self.grad *= other.val/self.val; + self.grad += aux2 * other.grad; + self.grad *= aux1; + self.val = aux1; + } + // ASSIGN-POW ALL OTHER EXPRESSIONS: self = pow(self, expr) + else { + Dual tmp; + assignPow(self, std::forward(other), tmp); + } +} + +template +AUTODIFF_DEVICE_FUNC constexpr void assignPow(Dual& self, U&& other, Dual& tmp) +{ + assign(tmp, other); + assignPow(self, tmp); +} + +//===================================================================================================================== +// +// ASSIGNMENT-ARCTAN2 FUNCTION +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void assignArcTan2(Dual& self, Y&&y, X&&x) +{ + static_assert(isArithmetic || isExpr); + static_assert(isArithmetic || isExpr); + + // self = atan2(number, dual) + if constexpr (isArithmetic && isDual) { + self.val = atan2(y, x.val); + self.grad = -y/(y*y + x.val * x.val) * x.grad; + } + + // self = atan2(dual, number) + else if constexpr (isDual && isArithmetic) { + self.val = atan2(y.val, x); + self.grad = x/(y.val * y.val + x * x) * y.grad; + } + + // self = atan2(dual, dual) + else if constexpr (isDual && isDual) { + self.val = atan2(y.val, x.val); + self.grad = (x.val * y.grad - y.val * x.grad)/(y.val * y.val + x.val * x.val); + } + + // self = atan2(expr, .) + else if constexpr (!isDual && !isArithmetic) { + Dual y_tmp; + assign(y_tmp, std::forward(y)); + assignArcTan2(self, std::move(y_tmp), std::forward(x)); + } + + // self = atan2(., expr) + else { + Dual x_tmp; + assign(x_tmp, std::forward(x)); + assignArcTan2(self, std::forward(y), std::move(x_tmp)); + } +} + +//===================================================================================================================== +// +// ASSIGNMENT-HYPOT FUNCTION +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr void assignHypot2(Dual& self, X&& x, Y&& y) +{ + static_assert(isArithmetic || isExpr); + static_assert(isArithmetic || isExpr); + + // self = hypot(number, dual) + if constexpr (isDual && isArithmetic) { + self.val = hypot(x.val, y); + self.grad = x.val / self.val * x.grad; + } + + // self = hypot(dual, number) + else if constexpr (isArithmetic && isDual) { + self.val = hypot(x, y.val); + self.grad = y.val / self.val * y.grad; + } + + // self = hypot(dual, dual) + else if constexpr (isDual && isDual) { + self.val = hypot(x.val, y.val); + self.grad = (x.grad * x.val + y.grad * y.val) / self.val; + } + + // self = hypot(expr, .) + else if constexpr (!isDual && !isArithmetic) { + Dual x_tmp; + assign(x_tmp, std::forward(x)); + assignHypot2(self, std::move(x_tmp), std::forward(y)); + } + + // self = hypot(., expr) + else { + Dual y_tmp; + assign(y_tmp, std::forward(y)); + assignHypot2(self, std::forward(x), std::move(y_tmp)); + } +} + +template +AUTODIFF_DEVICE_FUNC inline T hypot_device_func(T x, T y, T z) +{ +#ifdef __CUDA_ARCH__ + x = std::abs(x); + y = std::abs(y); + z = std::abs(z); + if(T a = x < y ? y < z ? z : y : x < z ? z + : x) + return a * std::sqrt((x / a) * (x / a) + (y / a) * (y / a) + (z / a) * (z / a)); + else + return {}; +#else + return hypot(x, y, z); +#endif +} + +template +AUTODIFF_DEVICE_FUNC constexpr void assignHypot3(Dual& self, X&& x, Y&& y, Z&& z) +{ + static_assert(isArithmetic || isExpr); + static_assert(isArithmetic || isExpr); + static_assert(isArithmetic || isExpr); + + // self = hypot(dual, number, number) + if constexpr (isDual && isArithmetic && isArithmetic) { + self.val = hypot_device_func(x.val, y, z); + self.grad = x.val / self.val * x.grad; + } + + // self = hypot(number, dual, number) + else if constexpr (isArithmetic && isDual && isArithmetic) { + self.val = hypot_device_func(x, y.val, z); + self.grad = y.val / self.val * y.grad; + } + + // self = hypot(number, number, dual) + else if constexpr (isArithmetic && isArithmetic && isDual) { + self.val = hypot_device_func(x, y, z.val); + self.grad = z.val / self.val * z.grad; + } + + // self = hypot(dual, dual, number) + else if constexpr (isDual && isDual && isArithmetic) { + self.val = hypot_device_func(x.val, y.val, z); + self.grad = (x.grad * x.val + y.grad * y.val ) / self.val; + } + + // self = hypot(number, dual, dual) + else if constexpr (isArithmetic && isDual && isDual) { + self.val = hypot_device_func(x, y.val, z.val); + self.grad = (y.grad * y.val + z.grad * z.val) / self.val; + } + + // self = hypot(dual, number, dual) + else if constexpr (isDual && isArithmetic && isDual) { + self.val = hypot_device_func(x.val, y, z.val); + self.grad = (x.grad * x.val + z.grad * z.val) / self.val; + } + + // self = hypot(dual, dual, dual) + else if constexpr (isDual && isDual && isDual) { + self.val = hypot_device_func(x.val, y.val, z.val); + self.grad = (x.grad * x.val + y.grad * y.val + z.grad * z.val) / self.val; + } + + // self = hypot(expr, ., .) + else if constexpr (!isDual && !isArithmetic) { + Dual tmp; + assign(tmp, std::forward(x)); + assignHypot3(self, std::move(tmp), std::forward(y), std::forward(z)); + } + + // self = hypot(., expr, .) + else if constexpr (!isDual && !isArithmetic) { + Dual tmp; + assign(tmp, std::forward(y)); + assignHypot3(self, std::forward(x), std::move(tmp), std::forward(z)); + } + + // self = hypot(., ., expr) + else { + Dual tmp; + assign(tmp, std::forward(z)); + assignHypot3(self, std::forward(x), std::forward(y), std::move(tmp)); + } +} + +//===================================================================================================================== +// +// APPLY-OPERATOR FUNCTIONS +// +//===================================================================================================================== +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, NegOp) +{ + self.val = -self.val; + self.grad = -self.grad; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, InvOp) +{ + self.val = One() / self.val; + self.grad *= - self.val * self.val; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, SinOp) +{ + self.grad *= cos(self.val); + self.val = sin(self.val); +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, CosOp) +{ + self.grad *= -sin(self.val); + self.val = cos(self.val); +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, TanOp) +{ + const T aux = One() / cos(self.val); + self.val = tan(self.val); + self.grad *= aux * aux; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, SinhOp) +{ + self.grad *= cosh(self.val); + self.val = sinh(self.val); +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, CoshOp) +{ + self.grad *= sinh(self.val); + self.val = cosh(self.val); +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, TanhOp) +{ + const T aux = One() / cosh(self.val); + self.val = tanh(self.val); + self.grad *= aux * aux; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, ArcSinOp) +{ + const T aux = One() / sqrt(1.0 - self.val * self.val); + self.val = asin(self.val); + self.grad *= aux; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, ArcCosOp) +{ + const T aux = -One() / sqrt(1.0 - self.val * self.val); + self.val = acos(self.val); + self.grad *= aux; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, ArcTanOp) +{ + const T aux = One() / (1.0 + self.val * self.val); + self.val = atan(self.val); + self.grad *= aux; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, ExpOp) +{ + self.val = exp(self.val); + self.grad *= self.val; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, LogOp) +{ + const T aux = One() / self.val; + self.val = log(self.val); + self.grad *= aux; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, Log10Op) +{ + constexpr NumericType ln10 = 2.3025850929940456840179914546843; + const T aux = One() / (ln10 * self.val); + self.val = log10(self.val); + self.grad *= aux; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, SqrtOp) +{ + self.val = sqrt(self.val); + self.grad *= 0.5 / self.val; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, AbsOp) +{ + self.grad *= self.val < T(0) ? G(-1) : (self.val > T(0) ? G(1) : G(0)); + self.val = abs(self.val); +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self, ErfOp) +{ + constexpr NumericType sqrt_pi = 1.7724538509055160272981674833411451872554456638435; + const T aux = self.val; + self.val = erf(aux); + self.grad *= 2.0 * exp(-aux*aux)/sqrt_pi; +} + +template +AUTODIFF_DEVICE_FUNC constexpr void apply(Dual& self) +{ + apply(self, Op{}); +} + +template +std::ostream& operator<<(std::ostream& out, const Dual& x) +{ + out << x.val; + return out; +} + +template> = true> +auto reprAux(const T& x) +{ + std::stringstream ss; ss << x; + return ss.str(); +} + +template +auto reprAux(const Dual& x) +{ + return "(" + reprAux(x.val) + ", " + reprAux(x.grad) + ")"; +} + +template +auto repr(const Dual& x) +{ + return "autodiff.dual" + reprAux(x); +} + +//===================================================================================================================== +// +// NUMBER TRAITS DEFINITION +// +//===================================================================================================================== + +template +struct NumberTraits> +{ + /// The dual type resulting from the evaluation of the expression (in case T is not double but an expression!). + using ResultDualType = DualType; + + /// The underlying floating point type of Dual. + using NumericType = typename NumberTraits::NumericType; + + /// The order of Dual. + static constexpr auto Order = 1 + NumberTraits::Order; +}; + +template +struct NumberTraits> +{ + /// The dual type resulting from the evaluation of the expression. + using ResultDualType = DualType>; + + /// The underlying floating point type of UnaryExpr. + using NumericType = typename NumberTraits::NumericType; + + /// The order of the expression UnaryExpr as the order of the evaluated dual type. + static constexpr auto Order = NumberTraits::Order; +}; + +template +struct NumberTraits> +{ + /// The dual type resulting from the evaluation of the expression. + using ResultDualType = DualType>; + + /// The underlying floating point type of BinaryExpr. + using NumericType = typename NumberTraits::NumericType; + + /// The order of the expression BinaryExpr as the order of the evaluated dual type. + static constexpr auto Order = NumberTraits::Order; +}; + +template +struct NumberTraits> +{ + /// The dual type resulting from the evaluation of the expression. + using ResultDualType = DualType>; + + /// The underlying floating point type of TernaryExpr. + using NumericType = typename NumberTraits::NumericType; + + /// The order of the expression TernaryExpr as the order of the evaluated dual type. + static constexpr auto Order = NumberTraits::Order; +}; + +//===================================================================================================================== +// +// HIGHER-ORDER DUAL NUMBERS +// +//===================================================================================================================== + +template +struct AuxHigherOrderDual; + +template +struct AuxHigherOrderDual<0, T> +{ + using type = T; +}; + +template +struct AuxHigherOrderDual +{ + using type = Dual::type, typename AuxHigherOrderDual::type>; +}; + +template +using HigherOrderDual = typename AuxHigherOrderDual::type; + +} // namespace detail + +using detail::val; +using detail::eval; +using detail::repr; +using detail::Dual; +using detail::HigherOrderDual; + +using dual0th = HigherOrderDual<0, double>; +using dual1st = HigherOrderDual<1, double>; +using dual2nd = HigherOrderDual<2, double>; +using dual3rd = HigherOrderDual<3, double>; +using dual4th = HigherOrderDual<4, double>; + +using dual = dual1st; + +} // namespace autodiff diff --git a/dae-cpp/autodiff/forward/dual/eigen.hpp b/dae-cpp/autodiff/forward/dual/eigen.hpp new file mode 100644 index 0000000..3b8e579 --- /dev/null +++ b/dae-cpp/autodiff/forward/dual/eigen.hpp @@ -0,0 +1,129 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// Eigen includes +#include + +// autodiff includes +#include +#include +#include + +//------------------------------------------------------------------------------ +// SUPPORT FOR EIGEN MATRICES AND VECTORS OF DUAL +//------------------------------------------------------------------------------ +namespace Eigen { + +using namespace autodiff; +using namespace autodiff::detail; + +template +struct NumTraits; + +template +struct NumTraits> : NumTraits // permits to get the epsilon, dummy_precision, lowest, highest functions +{ + typedef autodiff::Dual Real; + typedef autodiff::Dual NonInteger; + typedef autodiff::Dual Nested; + enum + { + IsComplex = 0, + IsInteger = 0, + IsSigned = 1, + RequireInitialization = 1, + ReadCost = 1, + AddCost = 3, + MulCost = 3 + }; +}; + +template +struct ScalarBinaryOpTraits, NumericType, BinOp> +{ + typedef DualType> ReturnType; +}; + +template +struct ScalarBinaryOpTraits, NumericType>, BinOp> +{ + typedef DualType> ReturnType; +}; + +template +struct ScalarBinaryOpTraits, NumericType>, BinOp> +{ + typedef DualType> ReturnType; +}; + +template +struct ScalarBinaryOpTraits, NumericType>, BinOp> +{ + typedef DualType> ReturnType; +}; + +template +struct ScalarBinaryOpTraits, Dual, BinOp> +{ + typedef DualType> ReturnType; +}; + +template +struct ScalarBinaryOpTraits>, UnaryExpr, BinOp> +{ + typedef DualType> ReturnType; +}; + +template +struct ScalarBinaryOpTraits>, BinaryExpr, BinOp> +{ + typedef DualType> ReturnType; +}; + +template +struct ScalarBinaryOpTraits>, TernaryExpr, BinOp> +{ + typedef DualType> ReturnType; +}; + +} // namespace Eigen + +namespace autodiff { + +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(dual0th, dual0th); +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(dual1st, dual1st); +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(dual2nd, dual2nd); +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(dual3rd, dual3rd); +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(dual4th, dual4th); + +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(dual, dual) + +} // namespace autodiff diff --git a/dae-cpp/autodiff/forward/real.hpp b/dae-cpp/autodiff/forward/real.hpp new file mode 100644 index 0000000..9e24b45 --- /dev/null +++ b/dae-cpp/autodiff/forward/real.hpp @@ -0,0 +1,35 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// autodiff includes +#include +#include +#include diff --git a/dae-cpp/autodiff/forward/real/eigen.hpp b/dae-cpp/autodiff/forward/real/eigen.hpp new file mode 100644 index 0000000..a01b36c --- /dev/null +++ b/dae-cpp/autodiff/forward/real/eigen.hpp @@ -0,0 +1,90 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// Eigen includes +#include + +// autodiff includes +#include +#include +#include + +//------------------------------------------------------------------------------ +// SUPPORT FOR EIGEN MATRICES AND VECTORS OF REAL +//------------------------------------------------------------------------------ +namespace Eigen { + +template +struct NumTraits; + +template +struct NumTraits> : NumTraits // permits to get the epsilon, dummy_precision, lowest, highest functions +{ + typedef autodiff::Real Real; + typedef autodiff::Real NonInteger; + typedef autodiff::Real Nested; + enum + { + IsComplex = 0, + IsInteger = 0, + IsSigned = 1, + RequireInitialization = 1, + ReadCost = 1, + AddCost = 3, + MulCost = 3 + }; +}; + +template +struct ScalarBinaryOpTraits, T, BinOp> +{ + typedef autodiff::Real ReturnType; +}; + +template +struct ScalarBinaryOpTraits, BinOp> +{ + typedef autodiff::Real ReturnType; +}; + +} // namespace Eigen + +namespace autodiff { + +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(real0th, real0th); +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(real1st, real1st); +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(real2nd, real2nd); +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(real3rd, real3rd); +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(real4th, real4th); + +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(real, real) + +} // namespace autodiff diff --git a/dae-cpp/autodiff/forward/real/real.hpp b/dae-cpp/autodiff/forward/real/real.hpp new file mode 100644 index 0000000..d283f61 --- /dev/null +++ b/dae-cpp/autodiff/forward/real/real.hpp @@ -0,0 +1,1031 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// C++ includes +#include +#include +#include +#include +#include +#include +#include + +// autodiff includes +#include +#include +#include + +namespace autodiff { +namespace detail { + +/// The type used to represent a real number that supports up to *N*-th order derivative calculation. +template +class Real +{ +private: + // Ensure type T is a numeric type + static_assert(isArithmetic); + + /// The value and derivatives of the number up to order *N*. + std::array m_data = {}; + +public: + /// Construct a default Real number of order *N* and type *T*. + AUTODIFF_DEVICE_FUNC constexpr Real() + {} + + /// Construct a Real number with given data. + AUTODIFF_DEVICE_FUNC constexpr Real(const T& value) + { + m_data[0] = value; + } + + /// Construct a Real number with given data. + AUTODIFF_DEVICE_FUNC constexpr Real(const std::array& data) + : m_data(data) + {} + + /// Construct a Real number with given data. + template> = true> + AUTODIFF_DEVICE_FUNC constexpr explicit Real(const Real& other) + { + static_assert(N <= M); + For<0, N + 1>([&](auto i) constexpr { + m_data[i] = static_cast(other[i]); + }); + } + + /// Return the value of the Real number. + AUTODIFF_DEVICE_FUNC constexpr auto val() -> T& + { + return m_data[0]; + } + + /// Return the value of the Real number. + AUTODIFF_DEVICE_FUNC constexpr auto val() const -> const T& + { + return m_data[0]; + } + + AUTODIFF_DEVICE_FUNC constexpr auto operator[](size_t i) -> T& + { + return m_data[i]; + } + + AUTODIFF_DEVICE_FUNC constexpr auto operator[](size_t i) const -> const T& + { + return m_data[i]; + } + + template> = true> + AUTODIFF_DEVICE_FUNC constexpr auto operator=(const U& value) -> Real& + { + m_data[0] = value; + For<1, N + 1>([&](auto i) constexpr { m_data[i] = T{}; }); + return *this; + } + + AUTODIFF_DEVICE_FUNC constexpr auto operator=(const std::array& data) + { + m_data = data; + return *this; + } + + template> = true> + AUTODIFF_DEVICE_FUNC constexpr auto operator+=(const U& value) -> Real& + { + m_data[0] += static_cast(value); + return *this; + } + + template> = true> + AUTODIFF_DEVICE_FUNC constexpr auto operator-=(const U& value) -> Real& + { + m_data[0] -= static_cast(value); + return *this; + } + + template> = true> + AUTODIFF_DEVICE_FUNC constexpr auto operator*=(const U& value) -> Real& + { + For<0, N + 1>([&](auto i) constexpr { m_data[i] *= static_cast(value); }); + return *this; + } + + template> = true> + AUTODIFF_DEVICE_FUNC constexpr auto operator/=(const U& value) -> Real& + { + For<0, N + 1>([&](auto i) constexpr { m_data[i] /= static_cast(value); }); + return *this; + } + + AUTODIFF_DEVICE_FUNC constexpr auto operator+=(const Real& y) + { + auto& x = *this; + For<0, N + 1>([&](auto i) constexpr { x[i] += y[i]; }); + return *this; + } + + AUTODIFF_DEVICE_FUNC constexpr auto operator-=(const Real& y) + { + auto& x = *this; + For<0, N + 1>([&](auto i) constexpr { x[i] -= y[i]; }); + return *this; + } + + AUTODIFF_DEVICE_FUNC constexpr auto operator*=(const Real& y) + { + auto& x = *this; + ReverseFor([&](auto i) constexpr { + x[i] = Sum<0, i + 1>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * y[j]; + }); + }); + return *this; + } + + AUTODIFF_DEVICE_FUNC constexpr auto operator/=(const Real& y) + { + auto& x = *this; + For([&](auto i) constexpr { + x[i] -= Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[j] * y[i - j]; + }); + x[i] /= y[0]; + }); + return *this; + } + +#if defined(AUTODIFF_ENABLE_IMPLICIT_CONVERSION_REAL) || defined(AUTODIFF_ENABLE_IMPLICIT_CONVERSION) + AUTODIFF_DEVICE_FUNC constexpr operator T() const { return static_cast(m_data[0]); } + + template> = true> + AUTODIFF_DEVICE_FUNC constexpr operator U() const { return static_cast(m_data[0]); } +#else + AUTODIFF_DEVICE_FUNC constexpr explicit operator T() const { return static_cast(m_data[0]); } + + template> = true> + AUTODIFF_DEVICE_FUNC constexpr explicit operator U() const { return static_cast(m_data[0]); } +#endif +}; + +//===================================================================================================================== +// +// STANDARD TEMPLATE LIBRARY MATH FUNCTIONS +// +//===================================================================================================================== + +using std::abs; +using std::acos; +using std::acosh; +using std::asin; +using std::asinh; +using std::atan2; +using std::atan; +using std::atanh; +using std::cbrt; +using std::cos; +using std::cosh; +using std::exp; +using std::log; +using std::log10; +using std::max; +using std::min; +using std::pow; +using std::sin; +using std::sinh; +using std::sqrt; +using std::tan; +using std::tanh; + +//===================================================================================================================== +// +// TYPE TRAITS +// +//===================================================================================================================== + +template +struct isRealAux { constexpr static bool value = false; }; + +template +struct isRealAux> { constexpr static bool value = true; }; + +template +constexpr bool isReal = isRealAux>::value; + +template +constexpr bool areReal = (... && isReal); + +//===================================================================================================================== +// +// UNARY OPERATORS +(Real) AND -(Real) +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC auto operator+(const Real& x) +{ + return x; +} + +template +AUTODIFF_DEVICE_FUNC auto operator-(const Real& x) +{ + Real res; + For<0, N + 1>([&](auto i) constexpr { res[i] = -x[i]; }); + return res; +} + +//===================================================================================================================== +// +// BINARY OPERATOR +(Real, Real), +(Real, Number), +(Number, Real) +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC auto operator+(Real x, const Real& y) +{ + return x += y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto operator+(Real x, const U& y) +{ + return x += y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto operator+(const U& x, Real y) +{ + return y += x; +} + +//===================================================================================================================== +// +// BINARY OPERATOR -(Real, Real), -(Real, Number), -(Number, Real) +// +//===================================================================================================================== +template +AUTODIFF_DEVICE_FUNC auto operator-(Real x, const Real& y) +{ + return x -= y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto operator-(Real x, const U& y) +{ + return x -= y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto operator-(const U& x, Real y) +{ + y -= x; + y *= -static_cast(1.0); + return y; +} + +//===================================================================================================================== +// +// BINARY OPERATOR *(Real, Real), *(Real, Number), *(Number, Real) +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC auto operator*(Real x, const Real& y) +{ + return x *= y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto operator*(Real x, const U& y) +{ + return x *= y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto operator*(const U& x, Real y) +{ + return y *= x; +} + +//===================================================================================================================== +// +// BINARY OPERATOR /(Real, Real), /(Real, Number), /(Number, Real) +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC auto operator/(Real x, const Real& y) +{ + return x /= y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto operator/(Real x, const U& y) +{ + return x /= y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto operator/(const U& x, Real y) +{ + Real z = x; + return z /= y; +} + +//===================================================================================================================== +// +// EXPONENTIAL AND LOGARITHMIC FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr auto exp(const Real& x) +{ + Real expx; + expx[0] = exp(x[0]); + For<1, N + 1>([&](auto i) constexpr { + expx[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * expx[j]; + }); + }); + return expx; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto log(const Real& x) +{ + assert(x[0] != 0 && "autodiff::log(x) has undefined value and derivatives when x = 0"); + Real logx; + logx[0] = log(x[0]); + For<1, N + 1>([&](auto i) constexpr { + logx[i] = x[i] - Sum<1, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * logx[j]; + }); + logx[i] /= x[0]; + }); + return logx; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto log10(const Real& x) +{ + assert(x[0] != 0 && "autodiff::log10(x) has undefined value and derivatives when x = 0"); + const auto ln10 = 2.302585092994046; + Real res = log(x); + return res /= ln10; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto sqrt(const Real& x) +{ + Real res; + res[0] = sqrt(x[0]); + + if constexpr (N > 0) + { + // assert(x[0] != 0 && "autodiff::sqrt(x) has undefined derivatives when x = 0"); + if(x[0] == 0) return res; + Real a; + For<1, N + 1>([&](auto i) constexpr { + a[i] = x[i] - Sum<1, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * a[j]; + }); + a[i] /= x[0]; + + res[i] = 0.5 * Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * a[i - j] * res[j]; + }); + }); + } + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto cbrt(const Real& x) +{ + Real res; + res[0] = cbrt(x[0]); + + if constexpr (N > 0) + { + // assert(x[0] != 0 && "autodiff::cbrt(x) has undefined derivatives when x = 0"); + if(x[0] == 0) return res; + Real a; + For<1, N + 1>([&](auto i) constexpr { + a[i] = x[i] - Sum<1, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * a[j]; + }); + a[i] /= x[0]; + + res[i] = (1.0/3.0) * Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * a[i - j] * res[j]; + }); + }); + } + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto pow(const Real& x, const Real& y) +{ + Real res; + res[0] = pow(x[0], y[0]); + if constexpr (N > 0) + { + // assert(x[0] != 0 && "autodiff::pow(x, y) has undefined derivatives when x = 0"); + if(x[0] == 0) return res; + Real lnx = log(x); + Real a; + For<1, N + 1>([&](auto i) constexpr { + a[i] = Sum<0, i + 1>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * y[i - j] * lnx[j]; + }); + + res[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * a[i - j] * res[j]; + }); + }); + } + return res; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto pow(const Real& x, const U& c) +{ + Real res; + res[0] = pow(x[0], static_cast(c)); + if constexpr (N > 0) + { + // assert(x[0] != 0 && "autodiff::pow(x, y) has undefined derivatives when x = 0"); + if(x[0] == 0) return res; + Real a = c * log(x); + For<1, N + 1>([&](auto i) constexpr { + res[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * a[i - j] * res[j]; + }); + }); + } + return res; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto pow(const U& c, const Real& y) +{ + Real res; + res[0] = pow(static_cast(c), y[0]); + if constexpr (N > 0) + { + // assert(c != 0 && "autodiff::pow(x, y) has undefined derivatives when x = 0"); + if(c == 0) return res; + Real a = y * log(c); + For<1, N + 1>([&](auto i) constexpr { + res[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * a[i - j] * res[j]; + }); + }); + } + return res; +} + +//===================================================================================================================== +// +// TRIGONOMETRIC FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC auto sincos(const Real& x) -> std::tuple, Real> +{ + Real sinx; + Real cosx; + + cosx[0] = cos(x[0]); + sinx[0] = sin(x[0]); + + For<1, N + 1>([&](auto i) constexpr { + cosx[i] = -Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * sinx[j]; + }); + + sinx[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * cosx[j]; + }); + }); + + return {sinx, cosx}; +} + +template +AUTODIFF_DEVICE_FUNC auto sin(const Real& x) +{ + return std::get<0>(sincos(x)); +} + +template +AUTODIFF_DEVICE_FUNC auto cos(const Real& x) +{ + return std::get<1>(sincos(x)); +} + +template +AUTODIFF_DEVICE_FUNC auto tan(const Real& x) +{ + Real tanx; + tanx[0] = tan(x[0]); + + if constexpr (N > 0) + { + Real aux; + aux[0] = 1 + tanx[0]*tanx[0]; + + For<1, N + 1>([&](auto i) constexpr { + tanx[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * aux[j]; + }); + + aux[i] = 2*Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * tanx[i - j] * tanx[j]; + }); + }); + } + + return tanx; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto asin(const Real& x) +{ + Real res; + res[0] = asin(x[0]); + if constexpr (N > 0) + { + assert(x[0] < 1.0 && "autodiff::asin(x) has undefined derivative when |x| >= 1"); + Real xprime; + For<1, N + 1>([&](auto i) constexpr { + xprime[i - 1] = x[i]; + }); + Real aux(x); + aux = xprime/sqrt(1 - aux*aux); + For<1, N + 1>([&](auto i) constexpr { + res[i] = aux[i - 1]; + }); + } + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto acos(const Real& x) +{ + Real res; + res[0] = acos(x[0]); + if constexpr (N > 0) + { + assert(x[0] < 1.0 && "autodiff::acos(x) has undefined derivative when |x| >= 1"); + Real xprime; + For<1, N + 1>([&](auto i) constexpr { + xprime[i - 1] = x[i]; + }); + Real aux(x); + aux = -xprime/sqrt(1 - aux*aux); + For<1, N + 1>([&](auto i) constexpr { + res[i] = aux[i - 1]; + }); + } + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto atan(const Real& x) +{ + Real res; + res[0] = atan(x[0]); + if constexpr (N > 0) + { + Real xprime; + For<1, N + 1>([&](auto i) constexpr { + xprime[i - 1] = x[i]; + }); + Real aux(x); + aux = xprime/(1 + aux*aux); + For<1, N + 1>([&](auto i) constexpr { + res[i] = aux[i - 1]; + }); + } + return res; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto atan2(const U& c, const Real& x) +{ + // d[atan2(c,x)]/dx = -c / (c^2 + x^2) + Real res; + res[0] = atan2(c, x[0]); + if constexpr(N > 0) { + Real xprime; + For<1, N + 1>([&](auto i) constexpr { + xprime[i - 1] = x[i]; + }); + Real aux(x); + aux = xprime * (-c / (c * c + aux * aux)); + For<1, N + 1>([&](auto i) constexpr { + res[i] = aux[i - 1]; + }); + } + return res; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto atan2(const Real& y, const U& c) +{ + // d[atan2(y,c)]/dy = c / (c^2 + y^2) + Real res; + res[0] = atan2(y[0], c); + if constexpr(N > 0) { + Real yprime; + For<1, N + 1>([&](auto i) constexpr { + yprime[i - 1] = y[i]; + }); + Real aux(y); + aux = yprime * (c / (c * c + aux * aux)); + For<1, N + 1>([&](auto i) constexpr { + res[i] = aux[i - 1]; + }); + } + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto atan2(const Real& y, const Real& x) +{ + Real res; + res[0] = atan2(y[0], x[0]); + if constexpr(N > 0) { + const T denom = x[0] * x[0] + y[0] * y[0]; + For<1, N + 1>([&](auto i) constexpr { + res[i] = (x[0] * y[i] - x[i] * y[0]) / denom; + }); + } + return res; +} + +//===================================================================================================================== +// +// HYPERBOLIC FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC auto sinhcosh(const Real& x) -> std::tuple, Real> +{ + Real sinhx; + Real coshx; + + coshx[0] = cosh(x[0]); + sinhx[0] = sinh(x[0]); + + For<1, N + 1>([&](auto i) constexpr { + coshx[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * sinhx[j]; + }); + + sinhx[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * coshx[j]; + }); + }); + + return {sinhx, coshx}; +} + +template +AUTODIFF_DEVICE_FUNC auto sinh(const Real& x) +{ + return std::get<0>(sinhcosh(x)); +} + +template +AUTODIFF_DEVICE_FUNC auto cosh(const Real& x) +{ + return std::get<1>(sinhcosh(x)); +} + + +template +AUTODIFF_DEVICE_FUNC auto tanh(const Real& x) +{ + Real tanhx; + tanhx[0] = tanh(x[0]); + + if constexpr (N > 0) + { + Real aux; + + aux[0] = 1 - tanhx[0]*tanhx[0]; + + For<1, N + 1>([&](auto i) constexpr { + tanhx[i] = Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * x[i - j] * aux[j]; + }); + + aux[i] = -2*Sum<0, i>([&](auto j) constexpr { + constexpr auto c = BinomialCoefficient; + return c * tanhx[i - j] * tanhx[j]; + }); + }); + } + + return tanhx; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto asinh(const Real& x) +{ + Real res; + res[0] = asinh(x[0]); + if constexpr (N > 0) + { + Real aux(x); + aux = 1/sqrt(aux*aux + 1); + For<1, N + 1>([&](auto i) constexpr { + res[i] = aux[i - 1]; + }); + } + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto acosh(const Real& x) +{ + Real res; + res[0] = acosh(x[0]); + if constexpr (N > 0) + { + assert(x[0] > 1.0 && "autodiff::acosh(x) has undefined derivative when |x| <= 1"); + Real aux(x); + aux = 1/sqrt(aux*aux - 1); + For<1, N + 1>([&](auto i) constexpr { + res[i] = aux[i - 1]; + }); + } + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto atanh(const Real& x) +{ + Real res; + res[0] = atanh(x[0]); + if constexpr (N > 0) + { + assert(x[0] < 1.0 && "autodiff::atanh(x) has undefined derivative when |x| >= 1"); + Real aux(x); + aux = 1/(1 - aux*aux); + For<1, N + 1>([&](auto i) constexpr { + res[i] = aux[i - 1]; + }); + } + return res; +} + +//===================================================================================================================== +// +// OTHER FUNCTIONS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC constexpr auto abs(const Real& x) +{ + Real res; + res[0] = std::abs(x[0]); + if constexpr (N > 0) + { + // assert(x[0] != 0 && "autodiff::abs(x) has undefined derivatives when x = 0"); + if(x[0] == 0) return res; + const T s = std::copysign(1.0, x[0]); + For<1, N + 1>([&](auto i) constexpr { + res[i] = s * x[i]; + }); + } + return res; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto min(const Real& x, const Real& y) +{ + return (x[0] <= y[0]) ? x : y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto min(const Real& x, const U& y) +{ + return (x[0] <= y) ? x : Real{y}; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto min(const U& x, const Real& y) +{ + return (x < y[0]) ? Real{x} : y; +} + +template +AUTODIFF_DEVICE_FUNC constexpr auto max(const Real& x, const Real& y) +{ + return (x[0] >= y[0]) ? x : y; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto max(const Real& x, const U& y) +{ + return (x[0] >= y) ? x : Real{y}; +} + +template> = true> +AUTODIFF_DEVICE_FUNC constexpr auto max(const U& x, const Real& y) +{ + return (x > y[0]) ? Real{x} : y; +} + +//===================================================================================================================== +// +// PRINTING FUNCTIONS +// +//===================================================================================================================== + +template +std::ostream& operator<<(std::ostream& out, const Real& x) +{ + out << x[0]; + return out; +} + +template +auto repr(const Real& x) +{ + std::stringstream ss; + ss << "autodiff.real("; + for(auto i = 0; i <= N; ++i) + ss << (i == 0 ? "" : ", ") << x[i]; + ss << ")"; + return ss.str(); +}; + +//===================================================================================================================== +// +// COMPARISON OPERATORS +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC bool operator==(const Real& x, const Real& y) +{ + bool res = true; + For<0, N + 1>([&](auto i) constexpr { + res = res && x[i] == y[i]; + }); + return res; +} + +template AUTODIFF_DEVICE_FUNC bool operator!=(const Real& x, const Real& y) { return !(x == y); } +template AUTODIFF_DEVICE_FUNC bool operator< (const Real& x, const Real& y) { return x[0] < y[0]; } +template AUTODIFF_DEVICE_FUNC bool operator> (const Real& x, const Real& y) { return x[0] > y[0]; } +template AUTODIFF_DEVICE_FUNC bool operator<=(const Real& x, const Real& y) { return x[0] <= y[0]; } +template AUTODIFF_DEVICE_FUNC bool operator>=(const Real& x, const Real& y) { return x[0] >= y[0]; } + +template> = true> AUTODIFF_DEVICE_FUNC bool operator==(const Real& x, const U& y) { return x[0] == y; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator!=(const Real& x, const U& y) { return x[0] != y; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator< (const Real& x, const U& y) { return x[0] < y; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator> (const Real& x, const U& y) { return x[0] > y; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator<=(const Real& x, const U& y) { return x[0] <= y; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator>=(const Real& x, const U& y) { return x[0] >= y; } + +template> = true> AUTODIFF_DEVICE_FUNC bool operator==(const U& x, const Real& y) { return x == y[0]; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator!=(const U& x, const Real& y) { return x != y[0]; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator< (const U& x, const Real& y) { return x < y[0]; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator> (const U& x, const Real& y) { return x > y[0]; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator<=(const U& x, const Real& y) { return x <= y[0]; } +template> = true> AUTODIFF_DEVICE_FUNC bool operator>=(const U& x, const Real& y) { return x >= y[0]; } + +//===================================================================================================================== +// +// SEED FUNCTION +// +//===================================================================================================================== + +template +AUTODIFF_DEVICE_FUNC auto seed(Real& real, U&& seedval) +{ + static_assert(order == 1, + "Real is optimized for higher-order **directional** derivatives. " + "You're possibly trying to use it for computing higher-order **cross** derivatives " + "(e.g., `derivative(f, wrt(x, x, y), at(x, y))`) which is not supported by Real. " + "Use Dual instead (e.g., `using dual4th = HigherOrderDual<4>;`)"); + real[order] = static_cast(seedval); +} + +//===================================================================================================================== +// +// DERIVATIVE FUNCTIONS +// +//===================================================================================================================== + +/// Return the value of a Real number. +template +AUTODIFF_DEVICE_FUNC constexpr auto val(const Real& x) +{ + return x[0]; +} + +/// Return the derivative of a Real number with given order. +template +AUTODIFF_DEVICE_FUNC constexpr auto derivative(const Real& x) +{ + return x[order]; +} + +//===================================================================================================================== +// +// NUMBER TRAITS DEFINITION +// +//===================================================================================================================== + +template +struct NumberTraits> +{ + /// The underlying floating point type of Real. + using NumericType = T; + + /// The order of Real. + static constexpr auto Order = N; +}; + +} // namespace detail + +//===================================================================================================================== +// +// CONVENIENT TYPE ALIASES +// +//===================================================================================================================== + +using detail::Real; +using detail::val; +using detail::derivative; +using detail::repr; + +using real0th = Real<0, double>; +using real1st = Real<1, double>; +using real2nd = Real<2, double>; +using real3rd = Real<3, double>; +using real4th = Real<4, double>; + +using real = real1st; + +} // namespace autodiff diff --git a/dae-cpp/autodiff/forward/utils/derivative.hpp b/dae-cpp/autodiff/forward/utils/derivative.hpp new file mode 100644 index 0000000..8bdae02 --- /dev/null +++ b/dae-cpp/autodiff/forward/utils/derivative.hpp @@ -0,0 +1,294 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +// C++ includes +#include +#include + +// autodiff includes +#include +#include + +#pragma once + +namespace autodiff { +namespace detail { + +template +struct At +{ + std::tuple args; +}; + +template +struct Wrt +{ + std::tuple args; +}; + +template +struct Along +{ + std::tuple args; +}; + +/// The keyword used to denote the variables *with respect to* the derivative is calculated. +template +AUTODIFF_DEVICE_FUNC auto wrt(Args&&... args) +{ + return Wrt{ std::forward_as_tuple(std::forward(args)...) }; +} + +/// The keyword used to denote the variables *at* which the derivatives are calculated. +template +AUTODIFF_DEVICE_FUNC auto at(Args&&... args) +{ + return At{ std::forward_as_tuple(std::forward(args)...) }; +} + +/// The keyword used to denote the direction vector *along* which the derivatives are calculated. +template +AUTODIFF_DEVICE_FUNC auto along(Args&&... args) +{ + return Along{ std::forward_as_tuple(std::forward(args)...) }; +} + +/// Seed each dual number in the **wrt** list using its position as the derivative order to be seeded. +/// Using `seed(wrt(x, y, z), 1)` will set the 1st order derivative of `x`, the +/// 2nd order derivative of `y`, and the 3rd order derivative of `z` to 1. If +/// these dual numbers have order greater than 3, then the last dual number will +/// be used for the remaining higher-order derivatives. For example, if these +/// numbers are 5th order, than the 4th and 5th order derivatives of `z` will be +/// set to 1 as well. In this example, `wrt(x, y, z)` is equivalent to `wrt(x, +/// y, z, z, z)`. This automatic seeding permits derivatives `fx`, `fxy`, +/// `fxyz`, `fxyzz`, and `fxyzzz` to be computed in a more convenient way. +template +AUTODIFF_DEVICE_FUNC auto seed(const Wrt& wrt, T&& seedval) +{ + constexpr static auto N = Order; + constexpr static auto size = 1 + sizeof...(Vars); + static_assert(size <= N, "It is not possible to compute higher-order derivatives with order greater than that of the autodiff number (e.g., using wrt(x, x, y, z) will fail if the autodiff numbers in use have order below 4)."); + For([&](auto i) constexpr { + if constexpr (i.index < size) + seed(std::get(wrt.args), seedval); + else + seed(std::get(wrt.args), seedval); // use the last variable in the wrt list as the variable for which the remaining higher-order derivatives are calculated (e.g., derivatives(f, wrt(x), at(x)) will produce [f0, fx, fxx, fxxx, fxxxx] when x is a 4th order dual number). + }); +} + +template +AUTODIFF_DEVICE_FUNC auto seed(const Wrt& wrt) +{ + seed(wrt, 1.0); +} + +template +AUTODIFF_DEVICE_FUNC auto unseed(const Wrt& wrt) +{ + seed(wrt, 0.0); +} + +template +AUTODIFF_DEVICE_FUNC auto seed(const At& at, const Along& along) +{ + static_assert(sizeof...(Args) == sizeof...(Vecs)); + + ForEach(at.args, along.args, [&](auto& arg, auto&& dir) constexpr { + if constexpr (isVector) { + static_assert(isVector); + assert(arg.size() == dir.size()); + for(auto i = 0; i < dir.size(); ++i) + seed<1>(arg[i], dir[i]); + } + else seed<1>(arg, dir); + }); +} + +template +AUTODIFF_DEVICE_FUNC auto unseed(const At& at) +{ + ForEach(at.args, [&](auto& arg) constexpr { + if constexpr (isVector) { + for(auto i = 0; i < arg.size(); ++i) + seed<1>(arg[i], 0.0); + } + else seed<1>(arg, 0.0); + }); +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto seed(T& x) +{ + seed(x, 1.0); +} + +template> = true> +AUTODIFF_DEVICE_FUNC auto unseed(T& x) +{ + seed(x, 0.0); +} + +#ifdef __CUDA_ARCH__ +template +AUTODIFF_DEVICE_FUNC constexpr decltype(auto) device_apply_impl(F&& f, Tuple&& t, std::index_sequence) { + return std::forward(f)(std::get(std::forward(t))...); +} + +template +AUTODIFF_DEVICE_FUNC constexpr decltype(auto) device_apply(F&& f, Tuple&& t) { + return device_apply_impl( + std::forward(f), + std::forward(t), + std::make_index_sequence>>{} + ); +} +#endif + +template +AUTODIFF_DEVICE_FUNC auto eval(const Fun& f, const At& at, const Wrt& wrt) +{ + seed(wrt); +#ifdef __CUDA_ARCH__ + auto u = device_apply(f, at.args); +#else + auto u = std::apply(f, at.args); +#endif + unseed(wrt); + return u; +} + +template +AUTODIFF_DEVICE_FUNC auto eval(const Fun& f, const At& at, const Along& along) +{ + seed(at, along); +#ifdef __CUDA_ARCH__ + auto u = device_apply(f, at.args); +#else + auto u = std::apply(f, at.args); +#endif + unseed(at); + return u; +} + +/// Extract the derivative of given order from a vector of dual/real numbers. +template> = true> +AUTODIFF_DEVICE_FUNC auto derivative(const Vec& u) +{ + size_t len = u.size(); // the length of the vector containing dual/real numbers + using NumType = decltype(u[0]); // get the type of the dual/real number + using T = NumericType; // get the numeric/floating point type of the dual/real number + using Res = VectorReplaceValueType; // get the type of the vector containing numeric values instead of dual/real numbers (e.g., vector becomes vector, VectorXdual becomes VectorXd, etc.) + Res res(len); // create an array to store the derivatives stored inside the dual/real number + for(auto i = 0; i < len; ++i) + res[i] = derivative(u[i]); // get the derivative of given order from i-th dual/real number + return res; +} + +/// Alias method to `derivative(x)` where `x` is either a dual/real number or vector/array of such numbers. +template +AUTODIFF_DEVICE_FUNC auto grad(const T& x) +{ + return derivative(x); +} + +/// Unpack the derivatives from the result of an @ref eval call into an array. +template +AUTODIFF_DEVICE_FUNC auto derivatives(const Result& result) +{ +#ifndef __CUDA_ARCH__ + if constexpr (isVector) // check if the argument is a vector container of dual/real numbers + { + size_t len = result.size(); // the length of the vector containing dual/real numbers + using NumType = decltype(result[0]); // get the type of the dual/real number + using T = NumericType; // get the numeric/floating point type of the dual/real number + using Vec = VectorReplaceValueType; // get the type of the vector containing numeric values instead of dual/real numbers (e.g., vector becomes vector, VectorXdual becomes VectorXd, etc.) + constexpr auto N = Order; // the order of the dual/real number + std::array values; // create an array to store the derivatives stored inside the dual/real number + For([&](auto i) constexpr { + values[i].resize(len); + for(auto j = 0U; j < len; ++j) + values[i][j] = derivative(result[j]); // get the ith derivative of the jth dual/real number + }); + return values; + } + else // result is then just a dual/real number +#endif + { + using T = NumericType; // get the numeric/floating point type of the dual/real result number + constexpr auto N = Order; // the order of the dual/real result number + std::array values; // create an array to store the derivatives stored inside the dual/real number + For([&](auto i) constexpr { + values[i] = derivative(result); + }); + return values; + } +} + +template +AUTODIFF_DEVICE_FUNC auto derivatives(const Fun& f, const Wrt& wrt, const At& at) +{ + return derivatives(eval(f, at, wrt)); +} + +template +AUTODIFF_DEVICE_FUNC auto derivative(const Fun& f, const Wrt& wrt, const At& at, Result& u) +{ + u = derivatives(f, wrt, at); + return derivative(u); +} + +template +AUTODIFF_DEVICE_FUNC auto derivative(const Fun& f, const Wrt& wrt, const At& at) +{ + auto u = eval(f, at, wrt); + return derivative(u); +} + +template +AUTODIFF_DEVICE_FUNC auto derivatives(const Fun& f, const Along& along, const At& at) +{ + return derivatives(eval(f, at, along)); +} + +} // namespace detail + +using detail::derivatives; +using detail::derivative; +using detail::grad; +using detail::along; +using detail::wrt; +using detail::at; +using detail::seed; +using detail::unseed; + +using detail::Along; +using detail::At; +using detail::Wrt; + +} // namespace autodiff diff --git a/dae-cpp/autodiff/forward/utils/gradient.hpp b/dae-cpp/autodiff/forward/utils/gradient.hpp new file mode 100644 index 0000000..d060806 --- /dev/null +++ b/dae-cpp/autodiff/forward/utils/gradient.hpp @@ -0,0 +1,228 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// autodiff includes +#include +#include +#include +#include + +namespace autodiff { +namespace detail { + +/// Return the length of an item in a `wrt(...)` list. +template +auto wrt_item_length(const Item& item) -> size_t +{ + if constexpr (isVector) + return item.size(); // if item is a vector, return its size + else return 1; // if not a vector, say, a number, return 1 for its length +} + + +/// Return the sum of lengths of all itens in a `wrt(...)` list. +template +auto wrt_total_length(const Wrt& wrt) -> size_t +{ + return Reduce(wrt.args, [&](auto&& item) constexpr { + return wrt_item_length(item); + }); +} + +// Loop through each variable in a wrt list and apply a function f(i, x) that +// accepts an index i and the variable x[i], where i is the global index of the +// variable in the list. +template +constexpr auto ForEachWrtVar(const Wrt& wrt, Function&& f) +{ + auto i = 0; // the current index of the variable in the wrt list + ForEach(wrt.args, [&](auto& item) constexpr + { + using T = decltype(item); + static_assert(isVector || Order > 0, "Expecting a wrt list with either vectors or individual autodiff numbers."); + if constexpr (isVector) { + for(auto j = 0; j < item.size(); ++j) + // call given f with current index and variable from item (a vector) + if constexpr (detail::has_operator_bracket()) { + f(i++, item[j]); + } else { + f(i++, item(j)); + } + } + else f(i++, item); // call given f with current index and variable from item (a number, not a vector) + }); +} + +/// Return the gradient of scalar function *f* with respect to some or all variables *x*. +template +void gradient(const Fun& f, const Wrt& wrt, const At& at, Y& u, G& g) +{ + static_assert(sizeof...(Vars) >= 1); + static_assert(sizeof...(Args) >= 1); + + const size_t n = wrt_total_length(wrt); + + g.resize(n); + + if(n == 0) return; + + ForEachWrtVar(wrt, [&](auto&& i, auto&& xi) constexpr + { + static_assert(!isConst, "Expecting non-const autodiff numbers in wrt list because these need to be seeded, and thus altered!"); + u = eval(f, at, detail::wrt(xi)); // evaluate u with xi seeded so that du/dxi is also computed + g[i] = derivative<1>(u); + }); + +} + +/// Return the gradient of scalar function *f* with respect to some or all variables *x*. +template +auto gradient(const Fun& f, const Wrt& wrt, const At& at, Y& u) +{ + using T = NumericType; // the underlying numeric floating point type in the autodiff number u + using Vec = VectorX; // the gradient vector type with floating point values (not autodiff numbers!) + + Vec g; + gradient(f, wrt, at, u, g); + return g; +} + +/// Return the gradient of scalar function *f* with respect to some or all variables *x*. +template +auto gradient(const Fun& f, const Wrt& wrt, const At& at) +{ + ReturnType u; + return gradient(f, wrt, at, u); +} + +/// Return the Jacobian matrix of a function *f* with respect to some or all variables. +template +void jacobian(const Fun& f, const Wrt& wrt, const At& at, Y& F, Jac& J) +{ + static_assert(sizeof...(Vars) >= 1); + static_assert(sizeof...(Args) >= 1); + + size_t n = wrt_total_length(wrt); /// using const size_t produces an error in GCC 7.3 because of the capture in the constexpr lambda in the ForEach block + size_t m = 0; + + ForEachWrtVar(wrt, [&](auto&& i, auto&& xi) constexpr { + static_assert(!isConst, "Expecting non-const autodiff numbers in wrt list because these need to be seeded, and thus altered!"); + F = eval(f, at, detail::wrt(xi)); // evaluate F with xi seeded so that dF/dxi is also computed + if(m == 0) { m = F.size(); J.resize(m, n); }; + for(size_t row = 0; row < m; ++row) + J(row, i) = derivative<1>(F[row]); + }); +} + +/// Return the Jacobian matrix of a function *f* with respect to some or all variables. +template +auto jacobian(const Fun& f, const Wrt& wrt, const At& at, Y& F) +{ + using U = VectorValueType; // the type of the autodiff numbers in vector F + using T = NumericType; // the underlying numeric floating point type in the autodiff number U + using Mat = MatrixX; // the jacobian matrix type with floating point values (not autodiff numbers!) + + Mat J; + jacobian(f, wrt, at, F, J); + return J; +} + +/// Return the Jacobian matrix of a function *f* with respect to some or all variables. +template +auto jacobian(const Fun& f, const Wrt& wrt, const At& at) +{ + using Y = ReturnType; + static_assert(!std::is_same_v, + "In jacobian(f, wrt(x), at(x)), the type of x " + "might not be the same as in the definition of f. " + "For example, x is Eigen::VectorXdual but the " + "definition of f uses Eigen::Ref."); + Y F; + return jacobian(f, wrt, at, F); +} + +/// Return the hessian matrix of scalar function *f* with respect to some or all variables *x*. +template +void hessian(const Fun& f, const Wrt& wrt, const At& at, U& u, G& g, H& h) +{ + static_assert(sizeof...(Vars) >= 1); + static_assert(sizeof...(Args) >= 1); + + size_t n = wrt_total_length(wrt); + + g.resize(n); + h.resize(n, n); + + ForEachWrtVar(wrt, [&](auto&& i, auto&& xi) constexpr { + ForEachWrtVar(wrt, [&](auto&& j, auto&& xj) constexpr + { + static_assert(!isConst && !isConst, "Expecting non-const autodiff numbers in wrt list because these need to be seeded, and thus altered!"); + if(j >= i) { // this take advantage of the fact the Hessian matrix is symmetric + u = eval(f, at, detail::wrt(xi, xj)); // evaluate u with xi and xj seeded to produce u0, du/dxi, d2u/dxidxj + g[i] = derivative<1>(u); // get du/dxi from u + h(i, j) = h(j, i) = derivative<2>(u); // get d2u/dxidxj from u + } + }); + }); +} + +/// Return the hessian matrix of scalar function *f* with respect to some or all variables *x*. +template +auto hessian(const Fun& f, const Wrt& wrt, const At& at, U& u, G& g) +{ + using T = NumericType; // the underlying numeric floating point type in the autodiff number u + using Mat = MatrixX; // the Hessian matrix type with floating point values (not autodiff numbers!) + + Mat H; + hessian(f, wrt, at, u, g, H); + return H; +} + +/// Return the hessian matrix of scalar function *f* with respect to some or all variables *x*. +template +auto hessian(const Fun& f, const Wrt& wrt, const At& at) +{ + using U = ReturnType; + using T = NumericType; + using Vec = VectorX; + U u; + Vec g; + return hessian(f, wrt, at, u, g); +} + +} // namespace detail + +using detail::gradient; +using detail::jacobian; +using detail::hessian; + +} // namespace autodiff + diff --git a/dae-cpp/autodiff/forward/utils/taylorseries.hpp b/dae-cpp/autodiff/forward/utils/taylorseries.hpp new file mode 100644 index 0000000..b312f6b --- /dev/null +++ b/dae-cpp/autodiff/forward/utils/taylorseries.hpp @@ -0,0 +1,97 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// C++ includes +#include + +// autodiff includes +#include +#include +#include + +namespace autodiff { +namespace detail { + +/// Represents a Taylor series along a direction for either a scalar or vector function. +/// @see taylorseries +template +class TaylorSeries +{ +public: + /// The numeric floating point type of the derivatives, which can be a vector of values or just one. + using T = std::conditional_t, VectorValueType, V>; + + /// Construct a default TaylorSeries object. + TaylorSeries() = default; + + /// Construct a TaylorSeries object with given directional derivatives. + explicit TaylorSeries(const std::array& derivatives) + : _derivatives(derivatives) + {} + + /// Evaluate the Taylor series object with given directional derivatives. + auto operator()(const T& t) + { + auto res = _derivatives[0]; + auto factor = t; + For<1, N + 1>([&](auto&& i) constexpr { + res += factor * _derivatives[i]; + factor *= t / static_cast(i + 1); + }); + return res; + } + + /// Return the directional derivatives of this TaylorSeries. + auto derivatives() + { + return _derivatives; + } + +private: + /// The directional derivatives of the function up to Nth order. + std::array _derivatives; +}; + +/// Return a TaylorSeries of a scalar or vector function *f* along a direction *v* at *x*. +template +auto taylorseries(const Fun& f, const Along& along, const At& at) +{ + auto data = derivatives(f, along, at); + constexpr auto N = data.size() - 1; + using V = typename decltype(data)::value_type; + return TaylorSeries(data); +} + +} // namespace detail + +using detail::taylorseries; + +} // namespace autodiff diff --git a/dae-cpp/autodiff/pybind11/eigen.hpp b/dae-cpp/autodiff/pybind11/eigen.hpp new file mode 100644 index 0000000..15fdff1 --- /dev/null +++ b/dae-cpp/autodiff/pybind11/eigen.hpp @@ -0,0 +1,89 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// pybind11 includes +#include "pybind11.hxx" + +// autodiff includes +#include +#include +#include +#include + +#define PYBIND11_MAKE_OPAQUE_EIGEN_TYPES(scalar) \ + PYBIND11_MAKE_OPAQUE(autodiff::VectorX##scalar##0th); \ + PYBIND11_MAKE_OPAQUE(autodiff::VectorX##scalar##1st); \ + PYBIND11_MAKE_OPAQUE(autodiff::VectorX##scalar##2nd); \ + PYBIND11_MAKE_OPAQUE(autodiff::VectorX##scalar##3rd); \ + PYBIND11_MAKE_OPAQUE(autodiff::VectorX##scalar##4th); \ + PYBIND11_MAKE_OPAQUE(autodiff::MatrixX##scalar##0th); \ + PYBIND11_MAKE_OPAQUE(autodiff::MatrixX##scalar##1st); \ + PYBIND11_MAKE_OPAQUE(autodiff::MatrixX##scalar##2nd); \ + PYBIND11_MAKE_OPAQUE(autodiff::MatrixX##scalar##3rd); \ + PYBIND11_MAKE_OPAQUE(autodiff::MatrixX##scalar##4th); \ + PYBIND11_MAKE_OPAQUE(autodiff::ArrayX##scalar##0th); \ + PYBIND11_MAKE_OPAQUE(autodiff::ArrayX##scalar##1st); \ + PYBIND11_MAKE_OPAQUE(autodiff::ArrayX##scalar##2nd); \ + PYBIND11_MAKE_OPAQUE(autodiff::ArrayX##scalar##3rd); \ + PYBIND11_MAKE_OPAQUE(autodiff::ArrayX##scalar##4th); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); \ + PYBIND11_MAKE_OPAQUE(Eigen::Ref); + +PYBIND11_MAKE_OPAQUE_EIGEN_TYPES(real); +PYBIND11_MAKE_OPAQUE_EIGEN_TYPES(dual); diff --git a/dae-cpp/autodiff/reverse/var.hpp b/dae-cpp/autodiff/reverse/var.hpp new file mode 100644 index 0000000..40bd97c --- /dev/null +++ b/dae-cpp/autodiff/reverse/var.hpp @@ -0,0 +1,33 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// autodiff includes +#include diff --git a/dae-cpp/autodiff/reverse/var/eigen.hpp b/dae-cpp/autodiff/reverse/var/eigen.hpp new file mode 100644 index 0000000..2543626 --- /dev/null +++ b/dae-cpp/autodiff/reverse/var/eigen.hpp @@ -0,0 +1,226 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// Eigen includes +#include + +// autodiff includes +#include +#include +#include + +//------------------------------------------------------------------------------ +// SUPPORT FOR EIGEN MATRICES AND VECTORS OF VAR +//------------------------------------------------------------------------------ +namespace Eigen { + +template +struct NumTraits; + +template +struct NumTraits> : NumTraits // permits to get the epsilon, dummy_precision, lowest, highest functions +{ + typedef autodiff::Variable Real; + typedef autodiff::Variable NonInteger; + typedef autodiff::Variable Nested; + enum + { + IsComplex = 0, + IsInteger = 0, + IsSigned = 1, + RequireInitialization = 1, + ReadCost = 1, + AddCost = 3, + MulCost = 3 + }; +}; + +template +struct ScalarBinaryOpTraits, T, BinOp> +{ + typedef autodiff::Variable ReturnType; +}; + +template +struct ScalarBinaryOpTraits, BinOp> +{ + typedef autodiff::Variable ReturnType; +}; + +template +struct NumTraits> : NumTraits // permits to get the epsilon, dummy_precision, lowest, highest functions +{ + typedef autodiff::Variable Real; + typedef autodiff::Variable NonInteger; + typedef autodiff::Variable Nested; + enum + { + IsComplex = 0, + IsInteger = 0, + IsSigned = 1, + RequireInitialization = 1, + ReadCost = 1, + AddCost = 3, + MulCost = 3 + }; +}; + +template +struct ScalarBinaryOpTraits, T, BinOp> +{ + typedef autodiff::Variable ReturnType; +}; + +template +struct ScalarBinaryOpTraits, BinOp> +{ + typedef autodiff::Variable ReturnType; +}; + +} // namespace Eigen + +namespace autodiff { +namespace reverse { +namespace detail { + +template +using Vec = Eigen::Matrix; + +template +using Mat = Eigen::Matrix; + +/// Return the gradient vector of variable y with respect to variables x. +template +auto gradient(const Variable& y, Eigen::DenseBase& x) +{ + using U = VariableValueType; + + using ScalarX = typename X::Scalar; + static_assert(isVariable, "Argument x is not a vector with Variable (aka var) objects.."); + + constexpr auto isVec = X::IsVectorAtCompileTime; + static_assert(isVec, "Argument x is not a vector."); + + constexpr auto Rows = X::RowsAtCompileTime; + constexpr auto MaxRows = X::MaxRowsAtCompileTime; + + const auto n = x.size(); + using Gradient = Vec; + Gradient g = Gradient::Zero(n); + + for(auto i = 0; i < n; ++i) + x[i].expr->bind_value(&g[i]); + + y.expr->propagate(1.0); + + for(auto i = 0; i < n; ++i) + x[i].expr->bind_value(nullptr); + + return g; +} + +/// Return the Hessian matrix of variable y with respect to variables x. +template +auto hessian(const Variable& y, Eigen::DenseBase& x, GradientVec& g) +{ + using U = VariableValueType; + + using ScalarX = typename X::Scalar; + static_assert(isVariable, "Argument x is not a vector with Variable (aka var) objects."); + + using ScalarG = typename GradientVec::Scalar; + static_assert(std::is_same_v, "Argument g does not have the same arithmetic type as y."); + + constexpr auto Rows = X::RowsAtCompileTime; + constexpr auto MaxRows = X::MaxRowsAtCompileTime; + + const auto n = x.size(); + + // Form a vector containing gradient expressions for each variable + using ExpressionGradient = Vec; + ExpressionGradient G(n); + + for(auto k = 0; k < n; ++k) + x[k].expr->bind_expr(&G(k).expr); + + /* Build a full gradient expression in DFS tree traversal, updating + * gradient expressions when encountering variables + */ + y.expr->propagatex(constant(1.0)); + + for(auto k = 0; k < n; ++k) { + x[k].expr->bind_expr(nullptr); + } + + // Read the gradient value from gradient expressions' cached values + g.resize(n); + for(auto i = 0; i < n; ++i) + g[i] = val(G[i]); + + // Form a numeric hessian using the gradient expressions + using Hessian = Mat; + Hessian H = Hessian::Zero(n, n); + for(auto i = 0; i < n; ++i) + { + for(auto k = 0; k < n; ++k) + x[k].expr->bind_value(&H(i, k)); + + // Propagate a second derivative value calculation down the gradient expression tree for variable i + G[i].expr->propagate(1.0); + + for(auto k = 0; k < n; ++k) + x[k].expr->bind_value(nullptr); + } + + return H; +} + +/// Return the Hessian matrix of variable y with respect to variables x. +template +auto hessian(const Variable& y, Eigen::DenseBase& x) +{ + using U = VariableValueType; + constexpr auto Rows = X::RowsAtCompileTime; + constexpr auto MaxRows = X::MaxRowsAtCompileTime; + Vec g; + return hessian(y, x, g); +} + +} // namespace detail + // +} // namespace reverse + +AUTODIFF_DEFINE_EIGEN_TYPEDEFS_ALL_SIZES(autodiff::var, var) + +using reverse::detail::gradient; +using reverse::detail::hessian; + +} // namespace autodiff diff --git a/dae-cpp/autodiff/reverse/var/var.hpp b/dae-cpp/autodiff/reverse/var/var.hpp new file mode 100644 index 0000000..1389112 --- /dev/null +++ b/dae-cpp/autodiff/reverse/var/var.hpp @@ -0,0 +1,1540 @@ +// _ _ +// _ _|_ _ _|o_|__|_ +// (_||_||_(_)(_|| | | +// +// automatic differentiation made easier in C++ +// https://github.com/autodiff/autodiff +// +// Licensed under the MIT License . +// +// Copyright © 2018–2024 Allan Leal +// +// 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. + +#pragma once + +// C++ includes +#include +#include +#include +#include +#include +#include +#include + +// autodiff includes +#include +#include + +/// autodiff namespace where @ref Variable and @ref grad are defined. +namespace autodiff {} + +namespace autodiff { +// avoid clash with autodiff::detail in autodiff/forward/dual/dual.hpp +namespace reverse { +using detail::Requires; +using detail::For; +using detail::isArithmetic; +namespace detail { + + +using std::abs; +using std::acos; +using std::asin; +using std::atan; +using std::atan2; +using std::cos; +using std::cosh; +using std::erf; +using std::exp; +using std::hypot; +using std::log; +using std::log10; +using std::pow; +using std::sin; +using std::sinh; +using std::sqrt; +using std::tan; +using std::tanh; + +template struct Expr; +template struct VariableExpr; +template struct IndependentVariableExpr; +template struct DependentVariableExpr; +template struct ConstantExpr; +template struct UnaryExpr; +template struct NegativeExpr; +template struct BinaryExpr; +template struct TernaryExpr; +template struct AddExpr; +template struct SubExpr; +template struct MulExpr; +template struct DivExpr; +template struct SinExpr; +template struct CosExpr; +template struct TanExpr; +template struct SinhExpr; +template struct CoshExpr; +template struct TanhExpr; +template struct ArcSinExpr; +template struct ArcCosExpr; +template struct ArcTanExpr; +template struct ArcTan2Expr; +template struct ExpExpr; +template struct LogExpr; +template struct Log10Expr; +template struct PowExpr; +template struct SqrtExpr; +template struct AbsExpr; +template struct ErfExpr; +template struct Hypot2Expr; +template struct Hypot3Expr; +template struct Variable; + +template using ExprPtr = std::shared_ptr>; + +namespace traits { + +template +struct VariableValueTypeNotDefinedFor {}; + +template +struct VariableValueType; + +template +struct VariableValueType { using type = std::conditional_t, T, VariableValueTypeNotDefinedFor>; }; + +template +struct VariableValueType> { using type = typename VariableValueType::type; }; + +template +struct VariableValueType> { using type = typename VariableValueType::type; }; + +template +struct VariableOrder { constexpr static auto value = 0; }; + +template +struct VariableOrder> { constexpr static auto value = 1 + VariableOrder::value; }; + +template +struct isVariable { constexpr static bool value = false; }; + +template +struct isVariable> { constexpr static bool value = true; }; + +} // namespace traits + +template +using VariableValueType = typename traits::VariableValueType::type; + +template +constexpr auto VariableOrder = traits::VariableOrder::value; + +template +constexpr auto isVariable = traits::isVariable::value; + +/// The abstract type of any node type in the expression tree. +template +struct Expr +{ + /// The value of this expression node. + T val = {}; + + /// Construct an Expr object with given value. + explicit Expr(const T& v) : val(v) {} + + /// Destructor (to avoid warning) + virtual ~Expr() {} + + /// Bind a value pointer for writing the derivative during propagation + virtual void bind_value(T* /* grad */) {} + + /// Bind an expression pointer for writing the derivative expression during propagation + virtual void bind_expr(ExprPtr* /* gradx */) {} + + /// Update the contribution of this expression in the derivative of the root node of the expression tree. + /// @param wprime The derivative of the root expression node w.r.t. the child expression of this expression node. + virtual void propagate(const T& wprime) = 0; + + /// Update the contribution of this expression in the derivative of the root node of the expression tree. + /// @param wprime The derivative of the root expression node w.r.t. the child expression of this expression node (as an expression). + virtual void propagatex(const ExprPtr& wprime) = 0; + + /// Update the value of this expression + virtual void update() = 0; +}; + +/// The node in the expression tree representing either an independent or dependent variable. +template +struct VariableExpr : Expr +{ + /// The derivative value of the root expression node w.r.t. this variable. + T* gradPtr = {}; + + /// The derivative expression of the root expression node w.r.t. this variable (reusable for higher-order derivatives). + ExprPtr* gradxPtr = {}; + + /// Construct a VariableExpr object with given value. + VariableExpr(const T& v) : Expr(v) {} + + virtual void bind_value(T* grad) { gradPtr = grad; } + virtual void bind_expr(ExprPtr* gradx) { gradxPtr = gradx; } +}; + +/// The node in the expression tree representing an independent variable. +template +struct IndependentVariableExpr : VariableExpr +{ + using VariableExpr::gradPtr; + using VariableExpr::gradxPtr; + + /// Construct an IndependentVariableExpr object with given value. + IndependentVariableExpr(const T& v) : VariableExpr(v) {} + + void propagate(const T& wprime) override { + if(gradPtr) { *gradPtr += wprime; } + } + + void propagatex(const ExprPtr& wprime) override + { + if(gradxPtr) { *gradxPtr = *gradxPtr + wprime; } + } + + void update() override {} +}; + +/// The node in the expression tree representing a dependent variable. +template +struct DependentVariableExpr : VariableExpr +{ + using VariableExpr::gradPtr; + using VariableExpr::gradxPtr; + + /// The expression tree that defines how the dependent variable is calculated. + ExprPtr expr; + + /// Construct an DependentVariableExpr object with given value. + DependentVariableExpr(const ExprPtr& e) : VariableExpr(e->val), expr(e) {} + + void propagate(const T& wprime) override + { + if(gradPtr) { *gradPtr += wprime; } + expr->propagate(wprime); + } + + void propagatex(const ExprPtr& wprime) override + { + if(gradxPtr) { *gradxPtr = *gradxPtr + wprime; } + expr->propagatex(wprime); + } + + void update() override + { + expr->update(); + this->val = expr->val; + } +}; + +template +struct ConstantExpr : Expr +{ + using Expr::Expr; + + void propagate([[maybe_unused]] const T& wprime) override + {} + + void propagatex([[maybe_unused]] const ExprPtr& wprime) override + {} + + void update() override {} +}; + +template ExprPtr constant(const T& val) { return std::make_shared>(val); } + +template +struct UnaryExpr : Expr +{ + ExprPtr x; + + UnaryExpr(const T& v, const ExprPtr& e) : Expr(v), x(e) {} +}; + +template +struct NegativeExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + using UnaryExpr::UnaryExpr; + + void propagate(const T& wprime) override + { + x->propagate(-wprime); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(-wprime); + } + + void update() override + { + x->update(); + this->val = -x->val; + } +}; + +template +struct BinaryExpr : Expr +{ + ExprPtr l, r; + + BinaryExpr(const T& v, const ExprPtr& ll, const ExprPtr& rr) : Expr(v), l(ll), r(rr) {} +}; + +template +struct TernaryExpr : Expr +{ + ExprPtr l, c, r; + + TernaryExpr(const T& v, const ExprPtr& ll, const ExprPtr& cc, const ExprPtr& rr) : Expr(v), l(ll), c(cc), r(rr) {} +}; + +template +struct AddExpr : BinaryExpr +{ + // Using declarations for data members of base class + using BinaryExpr::l; + using BinaryExpr::r; + + using BinaryExpr::BinaryExpr; + + void propagate(const T& wprime) override + { + l->propagate(wprime); + r->propagate(wprime); + } + + void propagatex(const ExprPtr& wprime) override + { + l->propagatex(wprime); + r->propagatex(wprime); + } + + void update() override + { + l->update(); + r->update(); + this->val = l->val + r->val; + } +}; + +template +struct SubExpr : BinaryExpr +{ + // Using declarations for data members of base class + using BinaryExpr::l; + using BinaryExpr::r; + using BinaryExpr::BinaryExpr; + + void propagate(const T& wprime) override + { + l->propagate(wprime); + r->propagate(-wprime); + } + + void propagatex(const ExprPtr& wprime) override + { + l->propagatex(wprime); // (l - r)'l = l' + r->propagatex(-wprime); // (l - r)'r = -r' + } + + void update() override + { + l->update(); + r->update(); + this->val = l->val - r->val; + } +}; + +template +struct MulExpr : BinaryExpr +{ + // Using declarations for data members of base class + using BinaryExpr::l; + using BinaryExpr::r; + using BinaryExpr::BinaryExpr; + + void propagate(const T& wprime) override + { + l->propagate(wprime * r->val); // (l * r)'l = w' * r + r->propagate(wprime * l->val); // (l * r)'r = l * w' + } + + void propagatex(const ExprPtr& wprime) override + { + l->propagatex(wprime * r); + r->propagatex(wprime * l); + } + + void update() override + { + l->update(); + r->update(); + this->val = l->val * r->val; + } +}; + +template +struct DivExpr : BinaryExpr +{ + // Using declarations for data members of base class + using BinaryExpr::l; + using BinaryExpr::r; + using BinaryExpr::BinaryExpr; + + void propagate(const T& wprime) override + { + const auto aux1 = 1.0 / r->val; + const auto aux2 = -l->val * aux1 * aux1; + l->propagate(wprime * aux1); + r->propagate(wprime * aux2); + } + + void propagatex(const ExprPtr& wprime) override + { + const auto aux1 = 1.0 / r; + const auto aux2 = -l * aux1 * aux1; + l->propagatex(wprime * aux1); + r->propagatex(wprime * aux2); + } + + void update() override + { + l->update(); + r->update(); + this->val = l->val / r->val; + } +}; + +template +struct SinExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + SinExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(wprime * cos(x->val)); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime * cos(x)); + } + + void update() override + { + x->update(); + this->val = sin(x->val); + } +}; + +template +struct CosExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + CosExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(-wprime * sin(x->val)); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(-wprime * sin(x)); + } + + void update() override + { + x->update(); + this->val = cos(x->val); + } +}; + +template +struct TanExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + TanExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + const auto aux = 1.0 / cos(x->val); + x->propagate(wprime * aux * aux); + } + + void propagatex(const ExprPtr& wprime) override + { + const auto aux = 1.0 / cos(x); + x->propagatex(wprime * aux * aux); + } + + void update() override + { + x->update(); + this->val = tan(x->val); + } +}; + +template +struct SinhExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + SinhExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(wprime * cosh(x->val)); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime * cosh(x)); + } + + void update() override + { + x->update(); + this->val = sinh(x->val); + } +}; + +template +struct CoshExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + CoshExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(wprime * sinh(x->val)); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime * sinh(x)); + } + + void update() override + { + x->update(); + this->val = cosh(x->val); + } +}; + +template +struct TanhExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + TanhExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + const auto aux = 1.0 / cosh(x->val); + x->propagate(wprime * aux * aux); + } + + void propagatex(const ExprPtr& wprime) override + { + const auto aux = 1.0 / cosh(x); + x->propagatex(wprime * aux * aux); + } + + void update() override + { + x->update(); + this->val = tanh(x->val); + } +}; + +template +struct ArcSinExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + ArcSinExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(wprime / sqrt(1.0 - x->val * x->val)); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime / sqrt(1.0 - x * x)); + } + + void update() override + { + x->update(); + this->val = asin(x->val); + } +}; + +template +struct ArcCosExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + ArcCosExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(-wprime / sqrt(1.0 - x->val * x->val)); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(-wprime / sqrt(1.0 - x * x)); + } + + void update() override + { + x->update(); + this->val = acos(x->val); + } +}; + +template +struct ArcTanExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + ArcTanExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(wprime / (1.0 + x->val * x->val)); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime / (1.0 + x * x)); + } + + void update() override + { + x->update(); + this->val = atan(x->val); + } +}; + +template +struct ArcTan2Expr : BinaryExpr +{ + using BinaryExpr::val; + using BinaryExpr::l; + using BinaryExpr::r; + + ArcTan2Expr(const T& v, const ExprPtr& ll, const ExprPtr& rr) : BinaryExpr(v, ll, rr) {} + + void propagate(const T& wprime) override + { + const auto aux = wprime / (l->val * l->val + r->val * r->val); + l->propagate(r->val * aux); + r->propagate(-l->val * aux); + } + + void propagatex(const ExprPtr& wprime) override + { + const auto aux = wprime / (l * l + r * r); + l->propagatex(r * aux); + r->propagatex(-l * aux); + } + + void update() override + { + l->update(); + r->update(); + this->val = atan2(l->val, r->val); + } +}; + +template +struct ExpExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::UnaryExpr; + using UnaryExpr::val; + using UnaryExpr::x; + + void propagate(const T& wprime) override + { + x->propagate(wprime * val); // exp(x)' = exp(x) * x' + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime * exp(x)); + } + + void update() override + { + x->update(); + this->val = exp(x->val); + } +}; + +template +struct LogExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + using UnaryExpr::UnaryExpr; + + void propagate(const T& wprime) override + { + x->propagate(wprime / x->val); // log(x)' = x'/x + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime / x); + } + + void update() override + { + x->update(); + this->val = log(x->val); + } +}; + +template +struct Log10Expr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + constexpr static auto ln10 = static_cast>(2.3025850929940456840179914546843); + + Log10Expr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(wprime / (ln10 * x->val)); + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime / (ln10 * x)); + } + + void update() override + { + x->update(); + this->val = log10(x->val); + } +}; + +template +struct PowExpr : BinaryExpr +{ + // Using declarations for data members of base class + using BinaryExpr::val; + using BinaryExpr::l; + using BinaryExpr::r; + + T log_l; + + PowExpr(const T& v, const ExprPtr& ll, const ExprPtr& rr) : BinaryExpr(v, ll, rr), log_l(log(ll->val)) {} + + void propagate(const T& wprime) override + { + using U = VariableValueType; + constexpr auto zero = U(0.0); + const auto lval = l->val; + const auto rval = r->val; + const auto aux = wprime * pow(lval, rval - 1); + l->propagate(aux * rval); + const auto auxr = lval == zero ? 0.0 : lval * log(lval); // since x*log(x) -> 0 as x -> 0 + r->propagate(aux * auxr); + } + + void propagatex(const ExprPtr& wprime) override + { + using U = VariableValueType; + constexpr auto zero = U(0.0); + const auto aux = wprime * pow(l, r - 1); + l->propagatex(aux * r); + const auto auxr = l == zero ? 0.0*l : l * log(l); // since x*log(x) -> 0 as x -> 0 + r->propagatex(aux * auxr); + } + + void update() override + { + l->update(); + r->update(); + this->val = pow(l->val, r->val); + } +}; + +template +struct PowConstantLeftExpr : BinaryExpr +{ + // Using declarations for data members of base class + using BinaryExpr::val; + using BinaryExpr::l; + using BinaryExpr::r; + + PowConstantLeftExpr(const T& v, const ExprPtr& ll, const ExprPtr& rr) : BinaryExpr(v, ll, rr) {} + + void propagate(const T& wprime) override + { + const auto lval = l->val; + const auto rval = r->val; + const auto aux = wprime * pow(lval, rval - 1); + const auto auxr = lval == 0.0 ? 0.0 : lval * log(lval); // since x*log(x) -> 0 as x -> 0 + r->propagate(aux * auxr); + } + + void propagatex(const ExprPtr& wprime) override + { + const auto aux = wprime * pow(l, r - 1); + const auto auxr = l == 0.0 ? 0.0*l : l * log(l); // since x*log(x) -> 0 as x -> 0 + r->propagatex(aux * auxr); + } + + void update() override + { + r->update(); + this->val = pow(l->val, r->val); + } +}; + +template +struct PowConstantRightExpr : BinaryExpr +{ + // Using declarations for data members of base class + using BinaryExpr::val; + using BinaryExpr::l; + using BinaryExpr::r; + + PowConstantRightExpr(const T& v, const ExprPtr& ll, const ExprPtr& rr) : BinaryExpr(v, ll, rr) {} + + void propagate(const T& wprime) override + { + l->propagate(wprime * pow(l->val, r->val - 1) * r->val); // pow(l, r)'l = r * pow(l, r - 1) * l' + } + + void propagatex(const ExprPtr& wprime) override + { + l->propagatex(wprime * pow(l, r - 1) * r); + } + + void update() override + { + l->update(); + this->val = pow(l->val, r->val); + } +}; + +template +struct SqrtExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + SqrtExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + x->propagate(wprime / (2.0 * sqrt(x->val))); // sqrt(x)' = 1/2 * 1/sqrt(x) * x' + } + + void propagatex(const ExprPtr& wprime) override + { + x->propagatex(wprime / (2.0 * sqrt(x))); + } + + void update() override + { + x->update(); + this->val = sqrt(x->val); + } +}; + +template +struct AbsExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + using U = VariableValueType; + + AbsExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + if(x->val < 0.0) x->propagate(-wprime); + else if(x->val > 0.0) x->propagate(wprime); + else x->propagate(T(0)); + } + + void propagatex(const ExprPtr& wprime) override + { + if(x->val < 0.0) x->propagatex(-wprime); + else if(x->val > 0.0) x->propagatex(wprime); + else x->propagate(T(0)); + } + + void update() override + { + x->update(); + this->val = abs(x->val); + } +}; + +template +struct ErfExpr : UnaryExpr +{ + // Using declarations for data members of base class + using UnaryExpr::x; + + constexpr static auto sqrt_pi = static_cast>(1.7724538509055160272981674833411451872554456638435); + + ErfExpr(const T& v, const ExprPtr& e) : UnaryExpr(v, e) {} + + void propagate(const T& wprime) override + { + const auto aux = 2.0 / sqrt_pi * exp(-(x->val) * (x->val)); // erf(x)' = 2/sqrt(pi) * exp(-x * x) * x' + x->propagate(wprime * aux); + } + + void propagatex(const ExprPtr& wprime) override + { + const auto aux = 2.0 / sqrt_pi * exp(-x * x); + x->propagatex(wprime * aux); + } + + void update() override + { + x->update(); + this->val = erf(x->val); + } +}; + +template +struct Hypot2Expr : BinaryExpr +{ + // Using declarations for data members of base class + using BinaryExpr::val; + using BinaryExpr::l; + using BinaryExpr::r; + + Hypot2Expr(const T& v, const ExprPtr& ll, const ExprPtr& rr) : BinaryExpr(v, ll, rr) {} + + void propagate(const T& wprime) override + { + l->propagate(wprime * l->val / val); // sqrt(l*l + r*r)'l = 1/2 * 1/sqrt(l*l + r*r) * (2*l*l') = (l*l')/sqrt(l*l + r*r) + r->propagate(wprime * r->val / val); // sqrt(l*l + r*r)'r = 1/2 * 1/sqrt(l*l + r*r) * (2*r*r') = (r*r')/sqrt(l*l + r*r) + } + + void propagatex(const ExprPtr& wprime) override + { + l->propagatex(wprime * l / hypot(l, r)); + r->propagatex(wprime * r / hypot(l, r)); + } + + void update() override + { + l->update(); + r->update(); + this->val = hypot(l->val, r->val); + } +}; + +template +struct Hypot3Expr : TernaryExpr +{ + // Using declarations for data members of base class + using TernaryExpr::val; + using TernaryExpr::l; + using TernaryExpr::c; + using TernaryExpr::r; + + Hypot3Expr(const T& v, const ExprPtr& ll, const ExprPtr& cc, const ExprPtr& rr) : TernaryExpr(v, ll, cc, rr) {} + + void propagate(const T& wprime) override + { + l->propagate(wprime * l->val / val); + c->propagate(wprime * c->val / val); + r->propagate(wprime * r->val / val); + } + + void propagatex(const ExprPtr& wprime) override + { + l->propagatex(wprime * l / hypot(l, c, r)); + c->propagatex(wprime * c / hypot(l, c, r)); + r->propagatex(wprime * r / hypot(l, c, r)); + } + + void update() override + { + l->update(); + c->update(); + r->update(); + this->val = hypot(l->val, c->val, r->val); + } +}; + +// Any expression yielding a boolean depending on arithmetic subexpressions +struct BooleanExpr +{ + std::function expr; + bool val = {}; + + explicit BooleanExpr(std::function expression) : expr(std::move(expression)) { update(); } + operator bool() const { return val; } + + void update() { val = expr(); } + + auto operator! () const { return BooleanExpr([=]() { return !(expr()); }); } +}; + +/// Capture numeric comparison between two expression trees +template +auto expr_comparison(const ExprPtr& l, const ExprPtr& r, Comparator&& compare) { + return BooleanExpr([=]() mutable -> bool { + l->update(); + r->update(); + return compare(l->val, r->val); + }); +} + +template auto bool_expr_op(BooleanExpr& l, BooleanExpr& r, Op op) { + return BooleanExpr([=]() mutable -> bool { + l.update(); + r.update(); + return op(l, r); + }); +} + +inline auto operator && (BooleanExpr&& l, BooleanExpr&& r) { return bool_expr_op(l, r, std::logical_and<> {}); } +inline auto operator || (BooleanExpr&& l, BooleanExpr&& r) { return bool_expr_op(l, r, std::logical_or<> {}); } + +/// Select between expression branches depending on a boolean expression +template +struct ConditionalExpr : Expr +{ + // Using declarations for data members of base class + BooleanExpr predicate; + using Expr::val; + ExprPtr l, r; + + ConditionalExpr(const BooleanExpr& wrappedPred, const ExprPtr& ll, const ExprPtr& rr) : Expr(wrappedPred ? ll->val : rr->val), predicate(wrappedPred), l(ll), r(rr) {} + + void propagate(const T& wprime) override + { + if(predicate.val) l->propagate(wprime); + else r->propagate(wprime); + } + + void propagatex(const ExprPtr& wprime) override + { + l->propagatex(derive(wprime, constant(0.0))); + r->propagatex(derive(constant(0.0), wprime)); + } + + void update() override + { + predicate.update(); + if(predicate.val) { + l->update(); + this->val = l->val; + } else { + r->update(); + this->val = r->val; + } + } + + ExprPtr derive(const ExprPtr& left, const ExprPtr& right) const { + return std::make_shared(predicate, left, right); + } +}; + +//------------------------------------------------------------------------------ +// CONVENIENT FUNCTIONS +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// ARITHMETIC OPERATORS +//------------------------------------------------------------------------------ +template ExprPtr operator+(const ExprPtr& r) { return r; } +template ExprPtr operator-(const ExprPtr& r) { return std::make_shared>(-r->val, r); } + +template ExprPtr operator+(const ExprPtr& l, const ExprPtr& r) { return std::make_shared>(l->val + r->val, l, r); } +template ExprPtr operator-(const ExprPtr& l, const ExprPtr& r) { return std::make_shared>(l->val - r->val, l, r); } +template ExprPtr operator*(const ExprPtr& l, const ExprPtr& r) { return std::make_shared>(l->val * r->val, l, r); } +template ExprPtr operator/(const ExprPtr& l, const ExprPtr& r) { return std::make_shared>(l->val / r->val, l, r); } + +template> = true> ExprPtr operator+(const U& l, const ExprPtr& r) { return constant(l) + r; } +template> = true> ExprPtr operator-(const U& l, const ExprPtr& r) { return constant(l) - r; } +template> = true> ExprPtr operator*(const U& l, const ExprPtr& r) { return constant(l) * r; } +template> = true> ExprPtr operator/(const U& l, const ExprPtr& r) { return constant(l) / r; } + +template> = true> ExprPtr operator+(const ExprPtr& l, const U& r) { return l + constant(r); } +template> = true> ExprPtr operator-(const ExprPtr& l, const U& r) { return l - constant(r); } +template> = true> ExprPtr operator*(const ExprPtr& l, const U& r) { return l * constant(r); } +template> = true> ExprPtr operator/(const ExprPtr& l, const U& r) { return l / constant(r); } + +//------------------------------------------------------------------------------ +// TRIGONOMETRIC FUNCTIONS +//------------------------------------------------------------------------------ +template ExprPtr sin(const ExprPtr& x) { return std::make_shared>(sin(x->val), x); } +template ExprPtr cos(const ExprPtr& x) { return std::make_shared>(cos(x->val), x); } +template ExprPtr tan(const ExprPtr& x) { return std::make_shared>(tan(x->val), x); } +template ExprPtr asin(const ExprPtr& x) { return std::make_shared>(asin(x->val), x); } +template ExprPtr acos(const ExprPtr& x) { return std::make_shared>(acos(x->val), x); } +template ExprPtr atan(const ExprPtr& x) { return std::make_shared>(atan(x->val), x); } +template ExprPtr atan2(const ExprPtr& l, const ExprPtr& r) { return std::make_shared>(atan2(l->val, r->val), l, r); } +template> = true> ExprPtr atan2(const U& l, const ExprPtr& r) { return std::make_shared>(atan2(l, r->val), constant(l), r); } +template> = true> ExprPtr atan2(const ExprPtr& l, const U& r) { return std::make_shared>(atan2(l->val, r), l, constant(r)); } + + +//------------------------------------------------------------------------------ +// HYPOT2 FUNCTIONS +//------------------------------------------------------------------------------ +template ExprPtr hypot(const ExprPtr& l, const ExprPtr& r) { return std::make_shared>(hypot(l->val, r->val), l, r); } +template> = true> ExprPtr hypot(const U& l, const ExprPtr& r) { return std::make_shared>(hypot(l, r->val), constant(l), r); } +template> = true> ExprPtr hypot(const ExprPtr& l, const U& r) { return std::make_shared>(hypot(l->val, r), l, constant(r)); } + +//------------------------------------------------------------------------------ +// HYPOT3 FUNCTIONS +//------------------------------------------------------------------------------ +template ExprPtr hypot(const ExprPtr& l, const ExprPtr& c, const ExprPtr& r) { return std::make_shared>(hypot(l->val,c->val, r->val), l, c, r); } +template> = true> ExprPtr hypot(const ExprPtr& l, const ExprPtr& c, const U& r) { return std::make_shared>(hypot(l->val, c->val, r), l, c, constant(r)); } +template> = true> ExprPtr hypot(const U& l, const ExprPtr& c, const ExprPtr& r) { return std::make_shared>(hypot(l, c->val, r->val), constant(l), c, r); } +template> = true> ExprPtr hypot(const ExprPtr& l,const U& c, const ExprPtr& r) { return std::make_shared>(hypot(l->val, c, r->val), l, constant(c), r); } +template && isArithmetic> = true> ExprPtr hypot(const ExprPtr& l, const U& c, const V& r) { return std::make_shared>(hypot(l->val, c, r), l, constant(c), constant(r)); } +template && isArithmetic> = true> ExprPtr hypot(const U& l, const ExprPtr& c, const V& r) { return std::make_shared>(hypot(l, c->val, r), constant(l), c, constant(r)); } +template && isArithmetic> = true> ExprPtr hypot(const V& l, const U& c, const ExprPtr& r) { return std::make_shared>(hypot(l, c, r->val), constant(l), constant(c), r); } + +//------------------------------------------------------------------------------ +// HYPERBOLIC FUNCTIONS +//------------------------------------------------------------------------------ +template ExprPtr sinh(const ExprPtr& x) { return std::make_shared>(sinh(x->val), x); } +template ExprPtr cosh(const ExprPtr& x) { return std::make_shared>(cosh(x->val), x); } +template ExprPtr tanh(const ExprPtr& x) { return std::make_shared>(tanh(x->val), x); } + +//------------------------------------------------------------------------------ +// EXPONENTIAL AND LOGARITHMIC FUNCTIONS +//------------------------------------------------------------------------------ +template ExprPtr exp(const ExprPtr& x) { return std::make_shared>(exp(x->val), x); } +template ExprPtr log(const ExprPtr& x) { return std::make_shared>(log(x->val), x); } +template ExprPtr log10(const ExprPtr& x) { return std::make_shared>(log10(x->val), x); } + +//------------------------------------------------------------------------------ +// POWER FUNCTIONS +//------------------------------------------------------------------------------ +template ExprPtr sqrt(const ExprPtr& x) { return std::make_shared>(sqrt(x->val), x); } +template ExprPtr pow(const ExprPtr& l, const ExprPtr& r) { return std::make_shared>(pow(l->val, r->val), l, r); } +template> = true> ExprPtr pow(const U& l, const ExprPtr& r) { return std::make_shared>(pow(l, r->val), constant(l), r); } +template> = true> ExprPtr pow(const ExprPtr& l, const U& r) { return std::make_shared>(pow(l->val, r), l, constant(r)); } + +//------------------------------------------------------------------------------ +// OTHER FUNCTIONS +//------------------------------------------------------------------------------ +template ExprPtr abs(const ExprPtr& x) { return std::make_shared>(abs(x->val), x); } +template ExprPtr abs2(const ExprPtr& x) { return x * x; } +template ExprPtr conj(const ExprPtr& x) { return x; } +template ExprPtr real(const ExprPtr& x) { return x; } +template ExprPtr imag(const ExprPtr&) { return constant(0.0); } +template ExprPtr erf(const ExprPtr& x) { return std::make_shared>(erf(x->val), x); } + +/// The autodiff variable type used for detail mode automatic differentiation. +template +struct Variable +{ + /// The pointer to the expression tree of variable operations + ExprPtr expr; + + /// Construct a default Variable object + Variable() : Variable(0.0) {} + + /// Construct a copy of a Variable object + Variable(const Variable& other) : Variable(other.expr) {} + + /// Construct a Variable object with given arithmetic value + template> = true> + Variable(const U& val) : expr(std::make_shared>(val)) {} + + /// Construct a Variable object with given expression + Variable(const ExprPtr& e) : expr(std::make_shared>(e)) {} + + /// Default copy assignment + Variable& operator=(const Variable&) = default; + + /// Update the value of this variable with changes in its expression tree + void update() { expr->update(); } + + void update(T value) { + if(auto independentExpr = std::dynamic_pointer_cast>(expr)) { + independentExpr->val = value; + independentExpr->update(); + } else { + throw std::logic_error("Cannot update the value of a dependent expression stored in a variable"); + } + } + + /// Implicitly convert this Variable object into an expression pointer. + operator const ExprPtr&() const { return expr; } + + /// Assign an arithmetic value to this variable. + template> = true> + auto operator=(const U& val) -> Variable& { *this = Variable(val); return *this; } + + /// Assign an expression to this variable. + auto operator=(const ExprPtr& x) -> Variable& { *this = Variable(x); return *this; } + + // Assignment operators + Variable& operator+=(const ExprPtr& x) { *this = Variable(expr + x); return *this; } + Variable& operator-=(const ExprPtr& x) { *this = Variable(expr - x); return *this; } + Variable& operator*=(const ExprPtr& x) { *this = Variable(expr * x); return *this; } + Variable& operator/=(const ExprPtr& x) { *this = Variable(expr / x); return *this; } + + // Assignment operators with arithmetic values + template> = true> Variable& operator+=(const U& x) { *this = Variable(expr + x); return *this; } + template> = true> Variable& operator-=(const U& x) { *this = Variable(expr - x); return *this; } + template> = true> Variable& operator*=(const U& x) { *this = Variable(expr * x); return *this; } + template> = true> Variable& operator/=(const U& x) { *this = Variable(expr / x); return *this; } + +#if defined(AUTODIFF_ENABLE_IMPLICIT_CONVERSION_VAR) || defined(AUTODIFF_ENABLE_IMPLICIT_CONVERSION) + operator T() const { return expr->val; } + + template + operator U() const { return static_cast(expr->val); } +#else + explicit operator T() const { return expr->val; } + + template + explicit operator U() const { return static_cast(expr->val); } +#endif +}; + +//------------------------------------------------------------------------------ +// EXPRESSION TRAITS +//------------------------------------------------------------------------------ + +template> = true> T expr_value(const T& t) { return t; } +template T expr_value(const ExprPtr& t) { return t->val; } +template T expr_value(const Variable& t) { return t.expr->val; } + +template +using expr_common_t = std::common_type_t())), decltype(expr_value(std::declval()))>; + +template struct sfinae_true : std::true_type {}; +template static auto is_expr_test(int) -> sfinae_true()))>; +template static auto is_expr_test(long) -> std::false_type; +template struct is_expr : decltype(is_expr_test(0)) {}; +template constexpr bool is_expr_v = is_expr::value; + +template> = true> ExprPtr coerce_expr(const U& u) { return constant(u); } +template ExprPtr coerce_expr(const ExprPtr& t) { return t; } +template ExprPtr coerce_expr(const Variable& t) { return t.expr; } + +template struct is_binary_expr : std::conditional_t && isArithmetic) && is_expr_v && is_expr_v, std::true_type, std::false_type> {}; +template constexpr bool is_binary_expr_v = is_binary_expr::value; + + +//------------------------------------------------------------------------------ +// COMPARISON OPERATORS +//------------------------------------------------------------------------------ + +template +auto comparison_operator(const T& t, const U& u) { + using C = expr_common_t; + return expr_comparison(coerce_expr(t), coerce_expr(u), Comparator {}); +} + +template> = true> +auto operator == (const T& t, const U& u) { return comparison_operator>(t, u); } +template> = true> +auto operator != (const T& t, const U& u) { return comparison_operator>(t, u); } +template> = true> +auto operator <= (const T& t, const U& u) { return comparison_operator>(t, u); } +template> = true> +auto operator >= (const T& t, const U& u) { return comparison_operator>(t, u); } +template> = true> +auto operator < (const T& t, const U& u) { return comparison_operator>(t, u); } +template> = true> +auto operator > (const T& t, const U& u) { return comparison_operator>(t, u); } + +//------------------------------------------------------------------------------ +// CONDITION AND RELATED FUNCTIONS +//------------------------------------------------------------------------------ + +template && is_expr_v> = true> +auto condition(BooleanExpr&& p, const T& t, const U& u) { + using C = expr_common_t; + ExprPtr expr = std::make_shared>(std::forward(p), coerce_expr(t), coerce_expr(u)); + return expr; +} + +template> = true> auto min(const T& x, const U& y) { return condition(x < y, x, y); } +template> = true> auto max(const T& x, const U& y) { return condition(x > y, x, y); } +template ExprPtr sgn(const ExprPtr& x) { return condition(x < 0, -1.0, condition(x > 0, 1.0, 0.0)); } +template ExprPtr sgn(const Variable& x) { return condition(x.expr < 0, -1.0, condition(x.expr > 0, 1.0, 0.0)); } + +//------------------------------------------------------------------------------ +// ARITHMETIC OPERATORS (DEFINED FOR ARGUMENTS OF TYPE Variable) +//------------------------------------------------------------------------------ +template const ExprPtr& operator+(const Variable& r) { return r.expr; } +template ExprPtr operator-(const Variable& r) { return -r.expr; } + +template ExprPtr operator+(const Variable& l, const Variable& r) { return l.expr + r.expr; } +template ExprPtr operator-(const Variable& l, const Variable& r) { return l.expr - r.expr; } +template ExprPtr operator*(const Variable& l, const Variable& r) { return l.expr * r.expr; } +template ExprPtr operator/(const Variable& l, const Variable& r) { return l.expr / r.expr; } + +template ExprPtr operator+(const ExprPtr& l, const Variable& r) { return l + r.expr; } +template ExprPtr operator-(const ExprPtr& l, const Variable& r) { return l - r.expr; } +template ExprPtr operator*(const ExprPtr& l, const Variable& r) { return l * r.expr; } +template ExprPtr operator/(const ExprPtr& l, const Variable& r) { return l / r.expr; } + +template ExprPtr operator+(const Variable& l, const ExprPtr& r) { return l.expr + r; } +template ExprPtr operator-(const Variable& l, const ExprPtr& r) { return l.expr - r; } +template ExprPtr operator*(const Variable& l, const ExprPtr& r) { return l.expr * r; } +template ExprPtr operator/(const Variable& l, const ExprPtr& r) { return l.expr / r; } + +template> = true> ExprPtr operator+(const U& l, const Variable& r) { return l + r.expr; } +template> = true> ExprPtr operator-(const U& l, const Variable& r) { return l - r.expr; } +template> = true> ExprPtr operator*(const U& l, const Variable& r) { return l * r.expr; } +template> = true> ExprPtr operator/(const U& l, const Variable& r) { return l / r.expr; } + +template> = true> ExprPtr operator+(const Variable& l, const U& r) { return l.expr + r; } +template> = true> ExprPtr operator-(const Variable& l, const U& r) { return l.expr - r; } +template> = true> ExprPtr operator*(const Variable& l, const U& r) { return l.expr * r; } +template> = true> ExprPtr operator/(const Variable& l, const U& r) { return l.expr / r; } + +//------------------------------------------------------------------------------ +// TRIGONOMETRIC FUNCTIONS (DEFINED FOR ARGUMENTS OF TYPE Variable) +//------------------------------------------------------------------------------ +template ExprPtr sin(const Variable& x) { return sin(x.expr); } +template ExprPtr cos(const Variable& x) { return cos(x.expr); } +template ExprPtr tan(const Variable& x) { return tan(x.expr); } +template ExprPtr asin(const Variable& x) { return asin(x.expr); } +template ExprPtr acos(const Variable& x) { return acos(x.expr); } +template ExprPtr atan(const Variable& x) { return atan(x.expr); } +template ExprPtr atan2(const Variable & l, const Variable & r) { return atan2(l.expr, r.expr); } +template> = true> ExprPtr atan2(const U& l, const Variable& r) { return atan2(l, r.expr); } +template> = true> ExprPtr atan2(const Variable& l, const U& r) { return atan2(l.expr, r); } + +//------------------------------------------------------------------------------ +// HYPOT2 FUNCTIONS (DEFINED FOR ARGUMENTS OF TYPE Variable) +//------------------------------------------------------------------------------ +template ExprPtr hypot(const Variable& l, const Variable& r) { return hypot(l.expr, r.expr); } +template> = true> ExprPtr hypot(const U& l, const Variable& r) { return hypot(l, r.expr); } +template> = true> ExprPtr hypot(const Variable& l, const U& r) { return hypot(l.expr, r); } + +//------------------------------------------------------------------------------ +// HYPOT3 FUNCTIONS (DEFINED FOR ARGUMENTS OF TYPE Variable) +//------------------------------------------------------------------------------ +template ExprPtr hypot(const Variable &l, const Variable &c, const Variable &r) { return hypot(l.expr, c.expr, r.expr); } +template && isArithmetic> = true> ExprPtr hypot(const Variable& l, const U& c, const V& r) { return hypot(l.expr, c, r); } +template && isArithmetic> = true> ExprPtr hypot(const U& l, const Variable& c, const V& r) { return hypot(l, c.expr, r); } +template && isArithmetic> = true> ExprPtr hypot(const U& l, const V& c, const Variable& r) { return hypot(l, c, r.expr); } +template> = true> ExprPtr hypot(const Variable &l, const Variable &c, const U& r) { return hypot(l.expr, c.expr, r); } +template> = true> ExprPtr hypot(const U &l, const Variable &c, const Variable& r) { return hypot(l, c.expr, r.expr); } +template> = true> ExprPtr hypot(const Variable &l, const U &c, const Variable& r) { return hypot(l.expr, c, r.expr); } + +//------------------------------------------------------------------------------ +// HYPERBOLIC FUNCTIONS (DEFINED FOR ARGUMENTS OF TYPE Variable) +//------------------------------------------------------------------------------ +template ExprPtr sinh(const Variable& x) { return sinh(x.expr); } +template ExprPtr cosh(const Variable& x) { return cosh(x.expr); } +template ExprPtr tanh(const Variable& x) { return tanh(x.expr); } + +//------------------------------------------------------------------------------ +// EXPONENTIAL AND LOGARITHMIC FUNCTIONS (DEFINED FOR ARGUMENTS OF TYPE Variable) +//------------------------------------------------------------------------------ +template ExprPtr exp(const Variable& x) { return exp(x.expr); } +template ExprPtr log(const Variable& x) { return log(x.expr); } +template ExprPtr log10(const Variable& x) { return log10(x.expr); } + +//------------------------------------------------------------------------------ +// POWER FUNCTIONS (DEFINED FOR ARGUMENTS OF TYPE Variable) +//------------------------------------------------------------------------------ +template ExprPtr sqrt(const Variable& x) { return sqrt(x.expr); } +template ExprPtr pow(const Variable& l, const Variable& r) { return pow(l.expr, r.expr); } +template> = true> ExprPtr pow(const U& l, const Variable& r) { return pow(l, r.expr); } +template> = true> ExprPtr pow(const Variable& l, const U& r) { return pow(l.expr, r); } + +//------------------------------------------------------------------------------ +// OTHER FUNCTIONS (DEFINED FOR ARGUMENTS OF TYPE Variable) +//------------------------------------------------------------------------------ +template ExprPtr abs(const Variable& x) { return abs(x.expr); } +template ExprPtr abs2(const Variable& x) { return abs2(x.expr); } +template ExprPtr conj(const Variable& x) { return conj(x.expr); } +template ExprPtr real(const Variable& x) { return real(x.expr); } +template ExprPtr imag(const Variable& x) { return imag(x.expr); } +template ExprPtr erf(const Variable& x) { return erf(x.expr); } + +template> = true> +auto val(const T& t) { return expr_value(t); } + +/// Return the derivatives of a variable y with respect to all independent variables. +template +[[deprecated("Use method `derivatives(y, wrt(a, b, c,...)` instead.")]] +auto derivatives(const T&) +{ + static_assert(!std::is_same_v, "Method derivatives(const var&) has been deprecated. Use method derivatives(y, wrt(a, b, c,...) instead."); +} + +/// Return the derivatives of a variable y with respect to all independent variables. +template +[[deprecated("Use method derivativesx(y, wrt(a, b, c,...) instead.")]] +auto derivativesx(const T&) +{ + static_assert(!std::is_same_v, "Method derivativesx(const var&) has been deprecated. Use method derivativesx(y, wrt(a, b, c,...) instead."); +} + +template +struct Wrt +{ + std::tuple args; +}; + +/// The keyword used to denote the variables *with respect to* the derivative is calculated. +template +auto wrt(Args&&... args) +{ + return Wrt{ std::forward_as_tuple(std::forward(args)...) }; +} + +/// Return the derivatives of a dependent variable y with respect given independent variables. +template +auto derivatives(const Variable& y, const Wrt& wrt) +{ + constexpr auto N = sizeof...(Vars); + std::array values; + values.fill(0.0); + + For([&](auto i) constexpr { + std::get(wrt.args).expr->bind_value(&values.at(i)); + }); + + y.expr->propagate(1.0); + + For([&](auto i) constexpr { + std::get(wrt.args).expr->bind_value(nullptr); + }); + + return values; +} + +/// Return the derivatives of a dependent variable y with respect given independent variables. +template +auto derivativesx(const Variable& y, const Wrt& wrt) +{ + constexpr auto N = sizeof...(Vars); + std::array, N> values; + + For([&](auto i) constexpr { + std::get(wrt.args).expr->bind_expr(&values.at(i).expr); + }); + + y.expr->propagatex(constant(1.0)); + + For([&](auto i) constexpr { + std::get(wrt.args).expr->bind_expr(nullptr); + }); + + return values; +} + +/// Output a Variable object to the output stream. +template +std::ostream& operator<<(std::ostream& out, const Variable& x) +{ + out << val(x); + return out; +} + +/// Output an ExprPrt object to the output stream. +template +std::ostream& operator<<(std::ostream& out, const ExprPtr& x) +{ + out << val(x); + return out; +} + +//===================================================================================================================== +// +// HIGHER-ORDER VAR NUMBERS +// +//===================================================================================================================== + +template +struct AuxHigherOrderVariable; + +template +struct AuxHigherOrderVariable<0, T> +{ + using type = T; +}; + +template +struct AuxHigherOrderVariable +{ + using type = Variable::type>; +}; + +template +using HigherOrderVariable = typename AuxHigherOrderVariable::type; + +} // namespace detail + +} // namespace reverse + +using reverse::detail::wrt; +using reverse::detail::derivatives; +using reverse::detail::Variable; +using reverse::detail::val; + +using var = Variable; + +inline reverse::detail::BooleanExpr boolref(const bool& v) { return reverse::detail::BooleanExpr([&]() { return v; }); } + +} // namespace autodiff From 78773b499c4f6b1cc0fa730679d11f2f390a5a53 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Wed, 20 Mar 2024 19:23:40 +0000 Subject: [PATCH 097/274] Add assert-custom, typedefs, and timer --- .vscode/settings.json | 4 ++ README.md | 4 +- dae-cpp/assert-custom.hpp | 147 ++++++++++++++++++++++++++++++++++++++ dae-cpp/timer.hpp | 75 +++++++++++++++++++ dae-cpp/typedefs.hpp | 43 +++++++++++ 5 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 dae-cpp/assert-custom.hpp create mode 100644 dae-cpp/timer.hpp create mode 100644 dae-cpp/typedefs.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fe140d8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "C_Cpp.formatting": "clangFormat", + "C_Cpp.clang_format_style": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: None, FixNamespaceComments: true }", +} \ No newline at end of file diff --git a/README.md b/README.md index 7767818..6f3c1b3 100644 --- a/README.md +++ b/README.md @@ -53,5 +53,5 @@ Feel free to create a [GitHub issue](https://github.com/ikorotkin/dae-cpp/issues ## Licensing -- [dae-cpp](https://github.com/ikorotkin/dae-cpp) is open source under [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). -- [autodiff](https://github.com/autodiff/autodiff) is open source under [MIT license](https://github.com/autodiff/autodiff/blob/main/LICENSE). +- [dae-cpp](https://github.com/ikorotkin/dae-cpp) is licensed under the [MIT license](https://github.com/ikorotkin/dae-cpp/blob/master/LICENSE). +- [autodiff](https://github.com/autodiff/autodiff) is licensed under the [MIT license](https://github.com/autodiff/autodiff/blob/main/LICENSE). diff --git a/dae-cpp/assert-custom.hpp b/dae-cpp/assert-custom.hpp new file mode 100644 index 0000000..654509e --- /dev/null +++ b/dae-cpp/assert-custom.hpp @@ -0,0 +1,147 @@ +/* + * Custom header-only run-time testing and printing. + * + * This file is part of dae-cpp. + * + * dae-cpp is licensed under the MIT license. + * A copy of the license can be found in the LICENSE file. + * + * Copyright (c) 2024 Ivan Korotkin + */ + +#pragma once + +#include + +#include "typedefs.hpp" + +namespace daecpp_namespace_name +{ + +/* + * ERROR(error message) + * + * Prints error message and aborts with error code -1. + * + * Example: + * ERROR("v = " << v); + */ +#define ERROR(msg) \ + std::cerr << "\nERROR: " << msg << "\nThis error is fatal." << std::endl; \ + exit(-1); + +/* + * WARNING(warning message) + * + * Prints warning message. + * + * Example: + * WARNING("v = " << v); + */ +#ifdef TESTING +#define WARNING(msg) +#else +#define WARNING(msg) \ + std::cerr << "WARNING: " << msg << std::endl; +#endif + +/* + * NOTE(note message) + * + * Prints a note. + * + * Example: + * NOTE("v = " << v); + */ +#ifdef TESTING +#define NOTE(msg) +#else +#define NOTE(msg) \ + std::cerr << "NOTE: " << msg << std::endl; +#endif + +/* + * ASSERT(expression, error message) + * + * Prints error message and aborts with error code -1 if expression is false. + * + * Example: + * ASSERT(v > 0, "Variable v is negative or zero: v = " << v); + */ +#define ASSERT(expression, msg) \ + if (!(expression)) \ + { \ + ERROR(msg); \ + } + +/* + * CHECK(expression, warning message) + * + * Prints a warning message if expression is false. + * + * Example: + * CHECK(v > 0, "Variable v is negative or zero: v = " << v); + */ +#define CHECK(expression, msg) \ + if (!(expression)) \ + { \ + WARNING(msg); \ + } + +#ifdef DEBUG + +/* + * Same as ERROR(message) but works only if DEBUG is defined. + */ +#define DEBUG_ERROR(msg) ERROR(msg) + +/* + * Same as WARNING(message) but works only if DEBUG is defined. + */ +#define DEBUG_WARNING(msg) WARNING(msg) + +/* + * Same as NOTE(message) but works only if DEBUG is defined. + */ +#define DEBUG_NOTE(msg) NOTE(msg) + +/* + * Same as ASSERT(expression, error message) but works only if DEBUG is defined. + */ +#define DEBUG_ASSERT(expression, msg) ASSERT(expression, msg) + +/* + * Same as CHECK(expression, warning message) but works only if DEBUG is defined. + */ +#define DEBUG_CHECK(expression, msg) CHECK(expression, msg) + +#else // #ifdef DEBUG + +/* + * DEBUG is not defined. This macro does nothing. + */ +#define DEBUG_ERROR(msg) + +/* + * DEBUG is not defined. This macro does nothing. + */ +#define DEBUG_WARNING(msg) + +/* + * DEBUG is not defined. This macro does nothing. + */ +#define DEBUG_NOTE(msg) + +/* + * DEBUG is not defined. This macro does nothing. + */ +#define DEBUG_ASSERT(expression, msg) + +/* + * DEBUG is not defined. This macro does nothing. + */ +#define DEBUG_CHECK(expression, msg) + +#endif // #ifdef DEBUG + +} // namespace daecpp_namespace_name diff --git a/dae-cpp/timer.hpp b/dae-cpp/timer.hpp new file mode 100644 index 0000000..1a6115d --- /dev/null +++ b/dae-cpp/timer.hpp @@ -0,0 +1,75 @@ +/* + * Timer class -- measures time in ms. + * + * Usage example: + * + * double time = 0.0; + * { + * Timer timer(&time); + * << TASK >> + * } + * + * This file is part of dae-cpp. + * + * dae-cpp is licensed under the MIT license. + * A copy of the license can be found in the LICENSE file. + * + * Copyright (c) 2024 Ivan Korotkin + */ + +#pragma once + +#include + +#include "typedefs.hpp" + +namespace daecpp_namespace_name +{ + +/* + * Specific timers (a singleton) + */ +class Timers +{ + static Timers *_instance; + + Timers() {} + +public: + double total{0.0}; // Total time + + static Timers *getInstance() + { + if (_instance == nullptr) + { + _instance = new Timers(); + } + return _instance; + } +}; + +/* + * Main timer class + */ +class Timer +{ + // Sets up clock + using clock = std::chrono::steady_clock; + using time_unit = std::chrono::microseconds; + + // Starts timer + std::chrono::time_point tic = clock::now(); + + // Stores time + double *_t; + +public: + Timer(double *t) : _t(t) {} + + ~Timer() + { + *_t += std::chrono::duration_cast(clock::now() - tic).count() * 1e-3; // ms + } +}; + +} // namespace daecpp_namespace_name diff --git a/dae-cpp/typedefs.hpp b/dae-cpp/typedefs.hpp new file mode 100644 index 0000000..3d8bc3d --- /dev/null +++ b/dae-cpp/typedefs.hpp @@ -0,0 +1,43 @@ +/* + * Defines custom types and shortcuts used in the project. + * + * This file is part of dae-cpp. + * + * dae-cpp is licensed under the MIT license. + * A copy of the license can be found in the LICENSE file. + * + * Copyright (c) 2024 Ivan Korotkin + */ + +#pragma once + +#include + +#define daecpp_namespace_name daecpp + +namespace daecpp_namespace_name +{ + +#ifdef DAECPP_SINGLE +typedef float float_type; +#else +typedef double float_type; +#endif + +// Integer vector +typedef std::vector ivec; + +// Floating point (double or single precision) vector +typedef std::vector fvec; + +// Matrix structure in 3-array format +struct sparse_matrix_holder +{ + fvec A; // Non-zero element A + ivec i; // Row index of the element A + ivec j; // Column index of the element A + + void check(); // Checks the matrix structure +}; + +} // namespace daecpp_namespace_name From a2730146aa9eed2a3913a5fc1a7ee73312ad4497 Mon Sep 17 00:00:00 2001 From: Ivan Korotkin Date: Thu, 21 Mar 2024 16:05:47 +0000 Subject: [PATCH 098/274] Add Eigen --- .vscode/c_cpp_properties.json | 16 + dae-cpp/Eigen/AccelerateSupport | 52 + dae-cpp/Eigen/COPYING.APACHE | 203 + dae-cpp/Eigen/COPYING.BSD | 26 + dae-cpp/Eigen/COPYING.MINPACK | 51 + dae-cpp/Eigen/COPYING.MPL2 | 373 + dae-cpp/Eigen/COPYING.README | 6 + dae-cpp/Eigen/Cholesky | 43 + dae-cpp/Eigen/CholmodSupport | 50 + dae-cpp/Eigen/Core | 410 + dae-cpp/Eigen/Dense | 7 + dae-cpp/Eigen/Eigen | 2 + dae-cpp/Eigen/Eigenvalues | 63 + dae-cpp/Eigen/Geometry | 61 + dae-cpp/Eigen/Householder | 31 + dae-cpp/Eigen/IterativeLinearSolvers | 52 + dae-cpp/Eigen/Jacobi | 33 + dae-cpp/Eigen/KLUSupport | 43 + dae-cpp/Eigen/LU | 46 + dae-cpp/Eigen/MetisSupport | 35 + dae-cpp/Eigen/OrderingMethods | 73 + dae-cpp/Eigen/PaStiXSupport | 51 + dae-cpp/Eigen/PardisoSupport | 38 + dae-cpp/Eigen/QR | 48 + dae-cpp/Eigen/QtAlignedMalloc | 32 + dae-cpp/Eigen/SPQRSupport | 41 + dae-cpp/Eigen/SVD | 56 + dae-cpp/Eigen/Sparse | 33 + dae-cpp/Eigen/SparseCholesky | 40 + dae-cpp/Eigen/SparseCore | 70 + dae-cpp/Eigen/SparseLU | 50 + dae-cpp/Eigen/SparseQR | 38 + dae-cpp/Eigen/StdDeque | 30 + dae-cpp/Eigen/StdList | 29 + dae-cpp/Eigen/StdVector | 30 + dae-cpp/Eigen/SuperLUSupport | 70 + dae-cpp/Eigen/ThreadPool | 78 + dae-cpp/Eigen/UmfPackSupport | 42 + ...t-d3cd3126520f1e81aeb2abb5e5ae77bd322f8193 | 0 .../src/AccelerateSupport/AccelerateSupport.h | 423 + .../AccelerateSupport/InternalHeaderCheck.h | 3 + .../Eigen/src/Cholesky/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/Cholesky/LDLT.h | 649 + dae-cpp/Eigen/src/Cholesky/LLT.h | 514 + dae-cpp/Eigen/src/Cholesky/LLT_LAPACKE.h | 124 + .../Eigen/src/CholmodSupport/CholmodSupport.h | 738 ++ .../src/CholmodSupport/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/Core/ArithmeticSequence.h | 269 + dae-cpp/Eigen/src/Core/Array.h | 369 + dae-cpp/Eigen/src/Core/ArrayBase.h | 222 + dae-cpp/Eigen/src/Core/ArrayWrapper.h | 173 + dae-cpp/Eigen/src/Core/Assign.h | 80 + dae-cpp/Eigen/src/Core/AssignEvaluator.h | 951 ++ dae-cpp/Eigen/src/Core/Assign_MKL.h | 183 + dae-cpp/Eigen/src/Core/BandMatrix.h | 338 + dae-cpp/Eigen/src/Core/Block.h | 439 + dae-cpp/Eigen/src/Core/CommaInitializer.h | 149 + dae-cpp/Eigen/src/Core/ConditionEstimator.h | 173 + dae-cpp/Eigen/src/Core/CoreEvaluators.h | 1666 +++ dae-cpp/Eigen/src/Core/CoreIterators.h | 141 + dae-cpp/Eigen/src/Core/CwiseBinaryOp.h | 166 + dae-cpp/Eigen/src/Core/CwiseNullaryOp.h | 971 ++ dae-cpp/Eigen/src/Core/CwiseTernaryOp.h | 171 + dae-cpp/Eigen/src/Core/CwiseUnaryOp.h | 91 + dae-cpp/Eigen/src/Core/CwiseUnaryView.h | 167 + dae-cpp/Eigen/src/Core/DenseBase.h | 645 + dae-cpp/Eigen/src/Core/DenseCoeffsBase.h | 568 + dae-cpp/Eigen/src/Core/DenseStorage.h | 650 + dae-cpp/Eigen/src/Core/Diagonal.h | 221 + dae-cpp/Eigen/src/Core/DiagonalMatrix.h | 414 + dae-cpp/Eigen/src/Core/DiagonalProduct.h | 30 + dae-cpp/Eigen/src/Core/Dot.h | 289 + dae-cpp/Eigen/src/Core/EigenBase.h | 144 + dae-cpp/Eigen/src/Core/ForceAlignedAccess.h | 131 + dae-cpp/Eigen/src/Core/Fuzzy.h | 132 + dae-cpp/Eigen/src/Core/GeneralProduct.h | 519 + dae-cpp/Eigen/src/Core/GenericPacketMath.h | 1515 +++ dae-cpp/Eigen/src/Core/GlobalFunctions.h | 226 + dae-cpp/Eigen/src/Core/IO.h | 233 + dae-cpp/Eigen/src/Core/IndexedView.h | 316 + dae-cpp/Eigen/src/Core/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/Core/Inverse.h | 108 + dae-cpp/Eigen/src/Core/Map.h | 153 + dae-cpp/Eigen/src/Core/MapBase.h | 283 + dae-cpp/Eigen/src/Core/MathFunctions.h | 2047 ++++ dae-cpp/Eigen/src/Core/MathFunctionsImpl.h | 262 + dae-cpp/Eigen/src/Core/Matrix.h | 527 + dae-cpp/Eigen/src/Core/MatrixBase.h | 542 + dae-cpp/Eigen/src/Core/NestByValue.h | 91 + dae-cpp/Eigen/src/Core/NoAlias.h | 102 + dae-cpp/Eigen/src/Core/NumTraits.h | 327 + .../Eigen/src/Core/PartialReduxEvaluator.h | 209 + dae-cpp/Eigen/src/Core/PermutationMatrix.h | 552 + dae-cpp/Eigen/src/Core/PlainObjectBase.h | 1049 ++ dae-cpp/Eigen/src/Core/Product.h | 174 + dae-cpp/Eigen/src/Core/ProductEvaluators.h | 1155 ++ dae-cpp/Eigen/src/Core/Random.h | 207 + dae-cpp/Eigen/src/Core/Redux.h | 528 + dae-cpp/Eigen/src/Core/Ref.h | 383 + dae-cpp/Eigen/src/Core/Replicate.h | 133 + dae-cpp/Eigen/src/Core/Reshaped.h | 398 + dae-cpp/Eigen/src/Core/ReturnByValue.h | 115 + dae-cpp/Eigen/src/Core/Reverse.h | 196 + dae-cpp/Eigen/src/Core/Select.h | 156 + dae-cpp/Eigen/src/Core/SelfAdjointView.h | 329 + dae-cpp/Eigen/src/Core/SelfCwiseBinaryOp.h | 50 + dae-cpp/Eigen/src/Core/SkewSymmetricMatrix3.h | 382 + dae-cpp/Eigen/src/Core/Solve.h | 174 + dae-cpp/Eigen/src/Core/SolveTriangular.h | 237 + dae-cpp/Eigen/src/Core/SolverBase.h | 159 + dae-cpp/Eigen/src/Core/StableNorm.h | 236 + dae-cpp/Eigen/src/Core/StlIterators.h | 614 + dae-cpp/Eigen/src/Core/Stride.h | 107 + dae-cpp/Eigen/src/Core/Swap.h | 74 + dae-cpp/Eigen/src/Core/Transpose.h | 425 + dae-cpp/Eigen/src/Core/Transpositions.h | 323 + dae-cpp/Eigen/src/Core/TriangularMatrix.h | 900 ++ dae-cpp/Eigen/src/Core/VectorBlock.h | 83 + dae-cpp/Eigen/src/Core/VectorwiseOp.h | 713 ++ dae-cpp/Eigen/src/Core/Visitor.h | 789 ++ dae-cpp/Eigen/src/Core/arch/AVX/Complex.h | 456 + .../Eigen/src/Core/arch/AVX/MathFunctions.h | 113 + dae-cpp/Eigen/src/Core/arch/AVX/PacketMath.h | 2856 +++++ dae-cpp/Eigen/src/Core/arch/AVX/TypeCasting.h | 227 + dae-cpp/Eigen/src/Core/arch/AVX512/Complex.h | 472 + .../Eigen/src/Core/arch/AVX512/GemmKernel.h | 1245 ++ .../src/Core/arch/AVX512/MathFunctions.h | 136 + .../Eigen/src/Core/arch/AVX512/PacketMath.h | 2762 +++++ .../src/Core/arch/AVX512/PacketMathFP16.h | 870 ++ .../Eigen/src/Core/arch/AVX512/TrsmKernel.h | 1167 ++ .../src/Core/arch/AVX512/TrsmUnrolls.inc | 1218 ++ .../Eigen/src/Core/arch/AVX512/TypeCasting.h | 281 + dae-cpp/Eigen/src/Core/arch/AltiVec/Complex.h | 644 + .../src/Core/arch/AltiVec/MathFunctions.h | 81 + .../src/Core/arch/AltiVec/MatrixProduct.h | 3686 ++++++ .../Core/arch/AltiVec/MatrixProductCommon.h | 205 + .../src/Core/arch/AltiVec/MatrixProductMMA.h | 901 ++ .../arch/AltiVec/MatrixProductMMAbfloat16.h | 742 ++ .../Core/arch/AltiVec/MatrixVectorProduct.h | 2818 +++++ .../Eigen/src/Core/arch/AltiVec/PacketMath.h | 3712 ++++++ .../Eigen/src/Core/arch/AltiVec/TypeCasting.h | 163 + .../Eigen/src/Core/arch/Default/BFloat16.h | 822 ++ .../Eigen/src/Core/arch/Default/ConjHelper.h | 128 + .../arch/Default/GenericPacketMathFunctions.h | 2307 ++++ .../Default/GenericPacketMathFunctionsFwd.h | 167 + dae-cpp/Eigen/src/Core/arch/Default/Half.h | 974 ++ .../Eigen/src/Core/arch/Default/Settings.h | 47 + dae-cpp/Eigen/src/Core/arch/GPU/Complex.h | 244 + .../Eigen/src/Core/arch/GPU/MathFunctions.h | 93 + dae-cpp/Eigen/src/Core/arch/GPU/PacketMath.h | 1681 +++ dae-cpp/Eigen/src/Core/arch/GPU/Tuple.h | 273 + dae-cpp/Eigen/src/Core/arch/GPU/TypeCasting.h | 77 + .../src/Core/arch/HIP/hcc/math_constants.h | 23 + dae-cpp/Eigen/src/Core/arch/HVX/PacketMath.h | 1074 ++ dae-cpp/Eigen/src/Core/arch/MSA/Complex.h | 620 + .../Eigen/src/Core/arch/MSA/MathFunctions.h | 379 + dae-cpp/Eigen/src/Core/arch/MSA/PacketMath.h | 1243 ++ dae-cpp/Eigen/src/Core/arch/NEON/Complex.h | 694 ++ .../Core/arch/NEON/GeneralBlockPanelKernel.h | 243 + .../Eigen/src/Core/arch/NEON/MathFunctions.h | 67 + dae-cpp/Eigen/src/Core/arch/NEON/PacketMath.h | 6185 ++++++++++ .../Eigen/src/Core/arch/NEON/TypeCasting.h | 1642 +++ .../Eigen/src/Core/arch/NEON/UnaryFunctors.h | 57 + dae-cpp/Eigen/src/Core/arch/SSE/Complex.h | 436 + .../Eigen/src/Core/arch/SSE/MathFunctions.h | 88 + dae-cpp/Eigen/src/Core/arch/SSE/PacketMath.h | 2617 ++++ dae-cpp/Eigen/src/Core/arch/SSE/TypeCasting.h | 197 + .../Eigen/src/Core/arch/SVE/MathFunctions.h | 48 + dae-cpp/Eigen/src/Core/arch/SVE/PacketMath.h | 667 + dae-cpp/Eigen/src/Core/arch/SVE/TypeCasting.h | 52 + .../Eigen/src/Core/arch/SYCL/InteropHeaders.h | 227 + .../Eigen/src/Core/arch/SYCL/MathFunctions.h | 303 + dae-cpp/Eigen/src/Core/arch/SYCL/PacketMath.h | 576 + .../Eigen/src/Core/arch/SYCL/TypeCasting.h | 83 + dae-cpp/Eigen/src/Core/arch/ZVector/Complex.h | 556 + .../src/Core/arch/ZVector/MathFunctions.h | 230 + .../Eigen/src/Core/arch/ZVector/PacketMath.h | 1292 ++ .../src/Core/functors/AssignmentFunctors.h | 181 + .../Eigen/src/Core/functors/BinaryFunctors.h | 763 ++ .../Eigen/src/Core/functors/NullaryFunctors.h | 263 + dae-cpp/Eigen/src/Core/functors/StlFunctors.h | 149 + .../Eigen/src/Core/functors/TernaryFunctors.h | 52 + .../Eigen/src/Core/functors/UnaryFunctors.h | 1326 ++ .../Core/products/GeneralBlockPanelKernel.h | 3153 +++++ .../src/Core/products/GeneralMatrixMatrix.h | 457 + .../products/GeneralMatrixMatrixTriangular.h | 322 + .../GeneralMatrixMatrixTriangular_BLAS.h | 148 + .../Core/products/GeneralMatrixMatrix_BLAS.h | 123 + .../src/Core/products/GeneralMatrixVector.h | 473 + .../Core/products/GeneralMatrixVector_BLAS.h | 139 + .../Eigen/src/Core/products/Parallelizer.h | 276 + .../Core/products/SelfadjointMatrixMatrix.h | 483 + .../products/SelfadjointMatrixMatrix_BLAS.h | 277 + .../Core/products/SelfadjointMatrixVector.h | 246 + .../products/SelfadjointMatrixVector_BLAS.h | 115 + .../src/Core/products/SelfadjointProduct.h | 133 + .../Core/products/SelfadjointRank2Update.h | 95 + .../Core/products/TriangularMatrixMatrix.h | 404 + .../products/TriangularMatrixMatrix_BLAS.h | 325 + .../Core/products/TriangularMatrixVector.h | 341 + .../products/TriangularMatrixVector_BLAS.h | 275 + .../Core/products/TriangularSolverMatrix.h | 388 + .../products/TriangularSolverMatrix_BLAS.h | 166 + .../Core/products/TriangularSolverVector.h | 122 + dae-cpp/Eigen/src/Core/util/Assert.h | 158 + dae-cpp/Eigen/src/Core/util/BlasUtil.h | 622 + .../src/Core/util/ConfigureVectorization.h | 517 + dae-cpp/Eigen/src/Core/util/Constants.h | 595 + .../src/Core/util/DisableStupidWarnings.h | 146 + dae-cpp/Eigen/src/Core/util/EmulateArray.h | 270 + .../Eigen/src/Core/util/ForwardDeclarations.h | 505 + .../Eigen/src/Core/util/IndexedViewHelper.h | 213 + .../Eigen/src/Core/util/IntegralConstant.h | 284 + dae-cpp/Eigen/src/Core/util/MKL_support.h | 139 + dae-cpp/Eigen/src/Core/util/Macros.h | 1301 ++ dae-cpp/Eigen/src/Core/util/MaxSizeVector.h | 139 + dae-cpp/Eigen/src/Core/util/Memory.h | 1326 ++ dae-cpp/Eigen/src/Core/util/Meta.h | 717 ++ dae-cpp/Eigen/src/Core/util/MoreMeta.h | 630 + .../src/Core/util/ReenableStupidWarnings.h | 44 + dae-cpp/Eigen/src/Core/util/ReshapedHelper.h | 51 + dae-cpp/Eigen/src/Core/util/Serializer.h | 208 + dae-cpp/Eigen/src/Core/util/StaticAssert.h | 105 + dae-cpp/Eigen/src/Core/util/SymbolicIndex.h | 301 + dae-cpp/Eigen/src/Core/util/XprHelper.h | 1025 ++ .../src/Eigenvalues/ComplexEigenSolver.h | 315 + dae-cpp/Eigen/src/Eigenvalues/ComplexSchur.h | 442 + .../src/Eigenvalues/ComplexSchur_LAPACKE.h | 95 + dae-cpp/Eigen/src/Eigenvalues/EigenSolver.h | 572 + .../src/Eigenvalues/GeneralizedEigenSolver.h | 402 + .../GeneralizedSelfAdjointEigenSolver.h | 212 + .../src/Eigenvalues/HessenbergDecomposition.h | 356 + .../src/Eigenvalues/InternalHeaderCheck.h | 3 + .../src/Eigenvalues/MatrixBaseEigenvalues.h | 142 + dae-cpp/Eigen/src/Eigenvalues/RealQZ.h | 587 + dae-cpp/Eigen/src/Eigenvalues/RealSchur.h | 519 + .../Eigen/src/Eigenvalues/RealSchur_LAPACKE.h | 83 + .../src/Eigenvalues/SelfAdjointEigenSolver.h | 850 ++ .../SelfAdjointEigenSolver_LAPACKE.h | 90 + .../src/Eigenvalues/Tridiagonalization.h | 527 + dae-cpp/Eigen/src/Geometry/AlignedBox.h | 485 + dae-cpp/Eigen/src/Geometry/AngleAxis.h | 245 + dae-cpp/Eigen/src/Geometry/EulerAngles.h | 203 + dae-cpp/Eigen/src/Geometry/Homogeneous.h | 455 + dae-cpp/Eigen/src/Geometry/Hyperplane.h | 273 + .../Eigen/src/Geometry/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/Geometry/OrthoMethods.h | 259 + dae-cpp/Eigen/src/Geometry/ParametrizedLine.h | 232 + dae-cpp/Eigen/src/Geometry/Quaternion.h | 857 ++ dae-cpp/Eigen/src/Geometry/Rotation2D.h | 201 + dae-cpp/Eigen/src/Geometry/RotationBase.h | 209 + dae-cpp/Eigen/src/Geometry/Scaling.h | 195 + dae-cpp/Eigen/src/Geometry/Transform.h | 1484 +++ dae-cpp/Eigen/src/Geometry/Translation.h | 204 + dae-cpp/Eigen/src/Geometry/Umeyama.h | 165 + .../Eigen/src/Geometry/arch/Geometry_SIMD.h | 149 + .../Eigen/src/Householder/BlockHouseholder.h | 115 + dae-cpp/Eigen/src/Householder/Householder.h | 155 + .../src/Householder/HouseholderSequence.h | 502 + .../src/Householder/InternalHeaderCheck.h | 3 + .../BasicPreconditioners.h | 213 + .../src/IterativeLinearSolvers/BiCGSTAB.h | 202 + .../ConjugateGradient.h | 217 + .../IncompleteCholesky.h | 402 + .../IterativeLinearSolvers/IncompleteLUT.h | 421 + .../InternalHeaderCheck.h | 3 + .../IterativeSolverBase.h | 395 + .../LeastSquareConjugateGradient.h | 193 + .../IterativeLinearSolvers/SolveWithGuess.h | 111 + .../Eigen/src/Jacobi/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/Jacobi/Jacobi.h | 427 + .../src/KLUSupport/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/KLUSupport/KLUSupport.h | 339 + dae-cpp/Eigen/src/LU/Determinant.h | 98 + dae-cpp/Eigen/src/LU/FullPivLU.h | 812 ++ dae-cpp/Eigen/src/LU/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/LU/InverseImpl.h | 353 + dae-cpp/Eigen/src/LU/PartialPivLU.h | 575 + dae-cpp/Eigen/src/LU/PartialPivLU_LAPACKE.h | 97 + dae-cpp/Eigen/src/LU/arch/InverseSize4.h | 353 + .../src/MetisSupport/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/MetisSupport/MetisSupport.h | 125 + dae-cpp/Eigen/src/OrderingMethods/Amd.h | 413 + .../Eigen/src/OrderingMethods/Eigen_Colamd.h | 1690 +++ .../src/OrderingMethods/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/OrderingMethods/Ordering.h | 148 + .../src/PaStiXSupport/InternalHeaderCheck.h | 3 + .../Eigen/src/PaStiXSupport/PaStiXSupport.h | 632 + .../src/PardisoSupport/InternalHeaderCheck.h | 3 + .../Eigen/src/PardisoSupport/PardisoSupport.h | 499 + dae-cpp/Eigen/src/QR/ColPivHouseholderQR.h | 674 ++ .../src/QR/ColPivHouseholderQR_LAPACKE.h | 161 + .../src/QR/CompleteOrthogonalDecomposition.h | 648 + dae-cpp/Eigen/src/QR/FullPivHouseholderQR.h | 722 ++ dae-cpp/Eigen/src/QR/HouseholderQR.h | 532 + dae-cpp/Eigen/src/QR/HouseholderQR_LAPACKE.h | 77 + dae-cpp/Eigen/src/QR/InternalHeaderCheck.h | 3 + .../src/SPQRSupport/InternalHeaderCheck.h | 3 + .../src/SPQRSupport/SuiteSparseQRSupport.h | 315 + dae-cpp/Eigen/src/SVD/BDCSVD.h | 1474 +++ dae-cpp/Eigen/src/SVD/BDCSVD_LAPACKE.h | 172 + dae-cpp/Eigen/src/SVD/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/SVD/JacobiSVD.h | 807 ++ dae-cpp/Eigen/src/SVD/JacobiSVD_LAPACKE.h | 127 + dae-cpp/Eigen/src/SVD/SVDBase.h | 436 + .../Eigen/src/SVD/UpperBidiagonalization.h | 379 + .../src/SparseCholesky/InternalHeaderCheck.h | 3 + .../src/SparseCholesky/SimplicialCholesky.h | 632 + .../SparseCholesky/SimplicialCholesky_impl.h | 158 + dae-cpp/Eigen/src/SparseCore/AmbiVector.h | 329 + .../Eigen/src/SparseCore/CompressedStorage.h | 206 + .../ConservativeSparseSparseProduct.h | 308 + .../src/SparseCore/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/SparseCore/SparseAssign.h | 279 + dae-cpp/Eigen/src/SparseCore/SparseBlock.h | 534 + dae-cpp/Eigen/src/SparseCore/SparseColEtree.h | 194 + .../src/SparseCore/SparseCompressedBase.h | 591 + .../src/SparseCore/SparseCwiseBinaryOp.h | 938 ++ .../Eigen/src/SparseCore/SparseCwiseUnaryOp.h | 142 + .../Eigen/src/SparseCore/SparseDenseProduct.h | 316 + .../src/SparseCore/SparseDiagonalProduct.h | 138 + dae-cpp/Eigen/src/SparseCore/SparseDot.h | 100 + dae-cpp/Eigen/src/SparseCore/SparseFuzzy.h | 31 + dae-cpp/Eigen/src/SparseCore/SparseMap.h | 295 + dae-cpp/Eigen/src/SparseCore/SparseMatrix.h | 1852 +++ .../Eigen/src/SparseCore/SparseMatrixBase.h | 400 + .../Eigen/src/SparseCore/SparsePermutation.h | 249 + dae-cpp/Eigen/src/SparseCore/SparseProduct.h | 178 + dae-cpp/Eigen/src/SparseCore/SparseRedux.h | 47 + dae-cpp/Eigen/src/SparseCore/SparseRef.h | 370 + .../src/SparseCore/SparseSelfAdjointView.h | 613 + .../Eigen/src/SparseCore/SparseSolverBase.h | 115 + .../SparseSparseProductWithPruning.h | 184 + .../Eigen/src/SparseCore/SparseTranspose.h | 83 + .../src/SparseCore/SparseTriangularView.h | 177 + dae-cpp/Eigen/src/SparseCore/SparseUtil.h | 209 + dae-cpp/Eigen/src/SparseCore/SparseVector.h | 505 + dae-cpp/Eigen/src/SparseCore/SparseView.h | 225 + .../Eigen/src/SparseCore/TriangularSolver.h | 266 + .../Eigen/src/SparseLU/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/SparseLU/SparseLU.h | 969 ++ dae-cpp/Eigen/src/SparseLU/SparseLUImpl.h | 79 + dae-cpp/Eigen/src/SparseLU/SparseLU_Memory.h | 210 + dae-cpp/Eigen/src/SparseLU/SparseLU_Structs.h | 113 + .../src/SparseLU/SparseLU_SupernodalMatrix.h | 319 + dae-cpp/Eigen/src/SparseLU/SparseLU_Utils.h | 75 + .../Eigen/src/SparseLU/SparseLU_column_bmod.h | 177 + .../Eigen/src/SparseLU/SparseLU_column_dfs.h | 168 + .../src/SparseLU/SparseLU_copy_to_ucol.h | 106 + .../src/SparseLU/SparseLU_heap_relax_snode.h | 114 + .../Eigen/src/SparseLU/SparseLU_kernel_bmod.h | 133 + .../Eigen/src/SparseLU/SparseLU_panel_bmod.h | 215 + .../Eigen/src/SparseLU/SparseLU_panel_dfs.h | 235 + dae-cpp/Eigen/src/SparseLU/SparseLU_pivotL.h | 136 + dae-cpp/Eigen/src/SparseLU/SparseLU_pruneL.h | 130 + .../Eigen/src/SparseLU/SparseLU_relax_snode.h | 81 + .../Eigen/src/SparseQR/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/SparseQR/SparseQR.h | 704 ++ dae-cpp/Eigen/src/StlSupport/StdDeque.h | 51 + dae-cpp/Eigen/src/StlSupport/StdList.h | 50 + dae-cpp/Eigen/src/StlSupport/StdVector.h | 51 + dae-cpp/Eigen/src/StlSupport/details.h | 82 + .../src/SuperLUSupport/InternalHeaderCheck.h | 3 + .../Eigen/src/SuperLUSupport/SuperLUSupport.h | 908 ++ dae-cpp/Eigen/src/ThreadPool/Barrier.h | 70 + dae-cpp/Eigen/src/ThreadPool/EventCount.h | 238 + .../src/ThreadPool/InternalHeaderCheck.h | 4 + .../src/ThreadPool/NonBlockingThreadPool.h | 473 + dae-cpp/Eigen/src/ThreadPool/RunQueue.h | 226 + dae-cpp/Eigen/src/ThreadPool/ThreadCancel.h | 21 + .../Eigen/src/ThreadPool/ThreadEnvironment.h | 43 + dae-cpp/Eigen/src/ThreadPool/ThreadLocal.h | 294 + .../src/ThreadPool/ThreadPoolInterface.h | 50 + dae-cpp/Eigen/src/ThreadPool/ThreadYield.h | 16 + .../src/UmfPackSupport/InternalHeaderCheck.h | 3 + .../Eigen/src/UmfPackSupport/UmfPackSupport.h | 606 + dae-cpp/Eigen/src/misc/Image.h | 80 + dae-cpp/Eigen/src/misc/InternalHeaderCheck.h | 3 + dae-cpp/Eigen/src/misc/Kernel.h | 77 + dae-cpp/Eigen/src/misc/RealSvd2x2.h | 53 + dae-cpp/Eigen/src/misc/blas.h | 97 + dae-cpp/Eigen/src/misc/lapacke.h | 10085 ++++++++++++++++ dae-cpp/Eigen/src/misc/lapacke_helpers.h | 163 + dae-cpp/Eigen/src/misc/lapacke_mangling.h | 16 + .../Eigen/src/plugins/ArrayCwiseBinaryOps.inc | 347 + .../Eigen/src/plugins/ArrayCwiseUnaryOps.inc | 525 + dae-cpp/Eigen/src/plugins/BlockMethods.inc | 1370 +++ .../src/plugins/CommonCwiseBinaryOps.inc | 133 + .../Eigen/src/plugins/CommonCwiseUnaryOps.inc | 167 + .../Eigen/src/plugins/IndexedViewMethods.inc | 351 + .../Eigen/src/plugins/InternalHeaderCheck.inc | 3 + .../src/plugins/MatrixCwiseBinaryOps.inc | 331 + .../Eigen/src/plugins/MatrixCwiseUnaryOps.inc | 112 + dae-cpp/Eigen/src/plugins/ReshapedMethods.inc | 133 + dae-cpp/RHS.hpp | 57 + dae-cpp/assert-custom.hpp | 7 +- dae-cpp/jacobian.hpp | 76 + dae-cpp/mass-matrix.hpp | 79 + dae-cpp/solver.hpp | 128 + dae-cpp/timer.hpp | 7 +- dae-cpp/typedefs.hpp | 40 +- examples/simple_dae/simple_dae.cpp | 284 + 402 files changed, 164015 insertions(+), 13 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 dae-cpp/Eigen/AccelerateSupport create mode 100644 dae-cpp/Eigen/COPYING.APACHE create mode 100644 dae-cpp/Eigen/COPYING.BSD create mode 100644 dae-cpp/Eigen/COPYING.MINPACK create mode 100644 dae-cpp/Eigen/COPYING.MPL2 create mode 100644 dae-cpp/Eigen/COPYING.README create mode 100644 dae-cpp/Eigen/Cholesky create mode 100644 dae-cpp/Eigen/CholmodSupport create mode 100644 dae-cpp/Eigen/Core create mode 100644 dae-cpp/Eigen/Dense create mode 100644 dae-cpp/Eigen/Eigen create mode 100644 dae-cpp/Eigen/Eigenvalues create mode 100644 dae-cpp/Eigen/Geometry create mode 100644 dae-cpp/Eigen/Householder create mode 100644 dae-cpp/Eigen/IterativeLinearSolvers create mode 100644 dae-cpp/Eigen/Jacobi create mode 100644 dae-cpp/Eigen/KLUSupport create mode 100644 dae-cpp/Eigen/LU create mode 100644 dae-cpp/Eigen/MetisSupport create mode 100644 dae-cpp/Eigen/OrderingMethods create mode 100644 dae-cpp/Eigen/PaStiXSupport create mode 100644 dae-cpp/Eigen/PardisoSupport create mode 100644 dae-cpp/Eigen/QR create mode 100644 dae-cpp/Eigen/QtAlignedMalloc create mode 100644 dae-cpp/Eigen/SPQRSupport create mode 100644 dae-cpp/Eigen/SVD create mode 100644 dae-cpp/Eigen/Sparse create mode 100644 dae-cpp/Eigen/SparseCholesky create mode 100644 dae-cpp/Eigen/SparseCore create mode 100644 dae-cpp/Eigen/SparseLU create mode 100644 dae-cpp/Eigen/SparseQR create mode 100644 dae-cpp/Eigen/StdDeque create mode 100644 dae-cpp/Eigen/StdList create mode 100644 dae-cpp/Eigen/StdVector create mode 100644 dae-cpp/Eigen/SuperLUSupport create mode 100644 dae-cpp/Eigen/ThreadPool create mode 100644 dae-cpp/Eigen/UmfPackSupport create mode 100644 dae-cpp/Eigen/commit-d3cd3126520f1e81aeb2abb5e5ae77bd322f8193 create mode 100644 dae-cpp/Eigen/src/AccelerateSupport/AccelerateSupport.h create mode 100644 dae-cpp/Eigen/src/AccelerateSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/Cholesky/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/Cholesky/LDLT.h create mode 100644 dae-cpp/Eigen/src/Cholesky/LLT.h create mode 100644 dae-cpp/Eigen/src/Cholesky/LLT_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/CholmodSupport/CholmodSupport.h create mode 100644 dae-cpp/Eigen/src/CholmodSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/Core/ArithmeticSequence.h create mode 100644 dae-cpp/Eigen/src/Core/Array.h create mode 100644 dae-cpp/Eigen/src/Core/ArrayBase.h create mode 100644 dae-cpp/Eigen/src/Core/ArrayWrapper.h create mode 100644 dae-cpp/Eigen/src/Core/Assign.h create mode 100644 dae-cpp/Eigen/src/Core/AssignEvaluator.h create mode 100644 dae-cpp/Eigen/src/Core/Assign_MKL.h create mode 100644 dae-cpp/Eigen/src/Core/BandMatrix.h create mode 100644 dae-cpp/Eigen/src/Core/Block.h create mode 100644 dae-cpp/Eigen/src/Core/CommaInitializer.h create mode 100644 dae-cpp/Eigen/src/Core/ConditionEstimator.h create mode 100644 dae-cpp/Eigen/src/Core/CoreEvaluators.h create mode 100644 dae-cpp/Eigen/src/Core/CoreIterators.h create mode 100644 dae-cpp/Eigen/src/Core/CwiseBinaryOp.h create mode 100644 dae-cpp/Eigen/src/Core/CwiseNullaryOp.h create mode 100644 dae-cpp/Eigen/src/Core/CwiseTernaryOp.h create mode 100644 dae-cpp/Eigen/src/Core/CwiseUnaryOp.h create mode 100644 dae-cpp/Eigen/src/Core/CwiseUnaryView.h create mode 100644 dae-cpp/Eigen/src/Core/DenseBase.h create mode 100644 dae-cpp/Eigen/src/Core/DenseCoeffsBase.h create mode 100644 dae-cpp/Eigen/src/Core/DenseStorage.h create mode 100644 dae-cpp/Eigen/src/Core/Diagonal.h create mode 100644 dae-cpp/Eigen/src/Core/DiagonalMatrix.h create mode 100644 dae-cpp/Eigen/src/Core/DiagonalProduct.h create mode 100644 dae-cpp/Eigen/src/Core/Dot.h create mode 100644 dae-cpp/Eigen/src/Core/EigenBase.h create mode 100644 dae-cpp/Eigen/src/Core/ForceAlignedAccess.h create mode 100644 dae-cpp/Eigen/src/Core/Fuzzy.h create mode 100644 dae-cpp/Eigen/src/Core/GeneralProduct.h create mode 100644 dae-cpp/Eigen/src/Core/GenericPacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/GlobalFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/IO.h create mode 100644 dae-cpp/Eigen/src/Core/IndexedView.h create mode 100644 dae-cpp/Eigen/src/Core/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/Core/Inverse.h create mode 100644 dae-cpp/Eigen/src/Core/Map.h create mode 100644 dae-cpp/Eigen/src/Core/MapBase.h create mode 100644 dae-cpp/Eigen/src/Core/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/MathFunctionsImpl.h create mode 100644 dae-cpp/Eigen/src/Core/Matrix.h create mode 100644 dae-cpp/Eigen/src/Core/MatrixBase.h create mode 100644 dae-cpp/Eigen/src/Core/NestByValue.h create mode 100644 dae-cpp/Eigen/src/Core/NoAlias.h create mode 100644 dae-cpp/Eigen/src/Core/NumTraits.h create mode 100644 dae-cpp/Eigen/src/Core/PartialReduxEvaluator.h create mode 100644 dae-cpp/Eigen/src/Core/PermutationMatrix.h create mode 100644 dae-cpp/Eigen/src/Core/PlainObjectBase.h create mode 100644 dae-cpp/Eigen/src/Core/Product.h create mode 100644 dae-cpp/Eigen/src/Core/ProductEvaluators.h create mode 100644 dae-cpp/Eigen/src/Core/Random.h create mode 100644 dae-cpp/Eigen/src/Core/Redux.h create mode 100644 dae-cpp/Eigen/src/Core/Ref.h create mode 100644 dae-cpp/Eigen/src/Core/Replicate.h create mode 100644 dae-cpp/Eigen/src/Core/Reshaped.h create mode 100644 dae-cpp/Eigen/src/Core/ReturnByValue.h create mode 100644 dae-cpp/Eigen/src/Core/Reverse.h create mode 100644 dae-cpp/Eigen/src/Core/Select.h create mode 100644 dae-cpp/Eigen/src/Core/SelfAdjointView.h create mode 100644 dae-cpp/Eigen/src/Core/SelfCwiseBinaryOp.h create mode 100644 dae-cpp/Eigen/src/Core/SkewSymmetricMatrix3.h create mode 100644 dae-cpp/Eigen/src/Core/Solve.h create mode 100644 dae-cpp/Eigen/src/Core/SolveTriangular.h create mode 100644 dae-cpp/Eigen/src/Core/SolverBase.h create mode 100644 dae-cpp/Eigen/src/Core/StableNorm.h create mode 100644 dae-cpp/Eigen/src/Core/StlIterators.h create mode 100644 dae-cpp/Eigen/src/Core/Stride.h create mode 100644 dae-cpp/Eigen/src/Core/Swap.h create mode 100644 dae-cpp/Eigen/src/Core/Transpose.h create mode 100644 dae-cpp/Eigen/src/Core/Transpositions.h create mode 100644 dae-cpp/Eigen/src/Core/TriangularMatrix.h create mode 100644 dae-cpp/Eigen/src/Core/VectorBlock.h create mode 100644 dae-cpp/Eigen/src/Core/VectorwiseOp.h create mode 100644 dae-cpp/Eigen/src/Core/Visitor.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX/Complex.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX/TypeCasting.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX512/Complex.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX512/GemmKernel.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX512/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX512/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX512/PacketMathFP16.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX512/TrsmKernel.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX512/TrsmUnrolls.inc create mode 100644 dae-cpp/Eigen/src/Core/arch/AVX512/TypeCasting.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/Complex.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/MatrixProduct.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/MatrixProductMMAbfloat16.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/MatrixVectorProduct.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/AltiVec/TypeCasting.h create mode 100644 dae-cpp/Eigen/src/Core/arch/Default/BFloat16.h create mode 100644 dae-cpp/Eigen/src/Core/arch/Default/ConjHelper.h create mode 100644 dae-cpp/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h create mode 100644 dae-cpp/Eigen/src/Core/arch/Default/Half.h create mode 100644 dae-cpp/Eigen/src/Core/arch/Default/Settings.h create mode 100644 dae-cpp/Eigen/src/Core/arch/GPU/Complex.h create mode 100644 dae-cpp/Eigen/src/Core/arch/GPU/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/GPU/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/GPU/Tuple.h create mode 100644 dae-cpp/Eigen/src/Core/arch/GPU/TypeCasting.h create mode 100644 dae-cpp/Eigen/src/Core/arch/HIP/hcc/math_constants.h create mode 100644 dae-cpp/Eigen/src/Core/arch/HVX/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/MSA/Complex.h create mode 100644 dae-cpp/Eigen/src/Core/arch/MSA/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/MSA/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/NEON/Complex.h create mode 100644 dae-cpp/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h create mode 100644 dae-cpp/Eigen/src/Core/arch/NEON/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/NEON/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/NEON/TypeCasting.h create mode 100644 dae-cpp/Eigen/src/Core/arch/NEON/UnaryFunctors.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SSE/Complex.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SSE/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SSE/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SSE/TypeCasting.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SVE/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SVE/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SVE/TypeCasting.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SYCL/InteropHeaders.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SYCL/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SYCL/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/arch/SYCL/TypeCasting.h create mode 100644 dae-cpp/Eigen/src/Core/arch/ZVector/Complex.h create mode 100644 dae-cpp/Eigen/src/Core/arch/ZVector/MathFunctions.h create mode 100644 dae-cpp/Eigen/src/Core/arch/ZVector/PacketMath.h create mode 100644 dae-cpp/Eigen/src/Core/functors/AssignmentFunctors.h create mode 100644 dae-cpp/Eigen/src/Core/functors/BinaryFunctors.h create mode 100644 dae-cpp/Eigen/src/Core/functors/NullaryFunctors.h create mode 100644 dae-cpp/Eigen/src/Core/functors/StlFunctors.h create mode 100644 dae-cpp/Eigen/src/Core/functors/TernaryFunctors.h create mode 100644 dae-cpp/Eigen/src/Core/functors/UnaryFunctors.h create mode 100644 dae-cpp/Eigen/src/Core/products/GeneralBlockPanelKernel.h create mode 100644 dae-cpp/Eigen/src/Core/products/GeneralMatrixMatrix.h create mode 100644 dae-cpp/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h create mode 100644 dae-cpp/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h create mode 100644 dae-cpp/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h create mode 100644 dae-cpp/Eigen/src/Core/products/GeneralMatrixVector.h create mode 100644 dae-cpp/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h create mode 100644 dae-cpp/Eigen/src/Core/products/Parallelizer.h create mode 100644 dae-cpp/Eigen/src/Core/products/SelfadjointMatrixMatrix.h create mode 100644 dae-cpp/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h create mode 100644 dae-cpp/Eigen/src/Core/products/SelfadjointMatrixVector.h create mode 100644 dae-cpp/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h create mode 100644 dae-cpp/Eigen/src/Core/products/SelfadjointProduct.h create mode 100644 dae-cpp/Eigen/src/Core/products/SelfadjointRank2Update.h create mode 100644 dae-cpp/Eigen/src/Core/products/TriangularMatrixMatrix.h create mode 100644 dae-cpp/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h create mode 100644 dae-cpp/Eigen/src/Core/products/TriangularMatrixVector.h create mode 100644 dae-cpp/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h create mode 100644 dae-cpp/Eigen/src/Core/products/TriangularSolverMatrix.h create mode 100644 dae-cpp/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h create mode 100644 dae-cpp/Eigen/src/Core/products/TriangularSolverVector.h create mode 100644 dae-cpp/Eigen/src/Core/util/Assert.h create mode 100644 dae-cpp/Eigen/src/Core/util/BlasUtil.h create mode 100644 dae-cpp/Eigen/src/Core/util/ConfigureVectorization.h create mode 100644 dae-cpp/Eigen/src/Core/util/Constants.h create mode 100644 dae-cpp/Eigen/src/Core/util/DisableStupidWarnings.h create mode 100644 dae-cpp/Eigen/src/Core/util/EmulateArray.h create mode 100644 dae-cpp/Eigen/src/Core/util/ForwardDeclarations.h create mode 100644 dae-cpp/Eigen/src/Core/util/IndexedViewHelper.h create mode 100644 dae-cpp/Eigen/src/Core/util/IntegralConstant.h create mode 100644 dae-cpp/Eigen/src/Core/util/MKL_support.h create mode 100644 dae-cpp/Eigen/src/Core/util/Macros.h create mode 100644 dae-cpp/Eigen/src/Core/util/MaxSizeVector.h create mode 100644 dae-cpp/Eigen/src/Core/util/Memory.h create mode 100644 dae-cpp/Eigen/src/Core/util/Meta.h create mode 100644 dae-cpp/Eigen/src/Core/util/MoreMeta.h create mode 100644 dae-cpp/Eigen/src/Core/util/ReenableStupidWarnings.h create mode 100644 dae-cpp/Eigen/src/Core/util/ReshapedHelper.h create mode 100644 dae-cpp/Eigen/src/Core/util/Serializer.h create mode 100644 dae-cpp/Eigen/src/Core/util/StaticAssert.h create mode 100644 dae-cpp/Eigen/src/Core/util/SymbolicIndex.h create mode 100644 dae-cpp/Eigen/src/Core/util/XprHelper.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/ComplexEigenSolver.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/ComplexSchur.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/EigenSolver.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/HessenbergDecomposition.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/RealQZ.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/RealSchur.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/Eigenvalues/Tridiagonalization.h create mode 100644 dae-cpp/Eigen/src/Geometry/AlignedBox.h create mode 100644 dae-cpp/Eigen/src/Geometry/AngleAxis.h create mode 100644 dae-cpp/Eigen/src/Geometry/EulerAngles.h create mode 100644 dae-cpp/Eigen/src/Geometry/Homogeneous.h create mode 100644 dae-cpp/Eigen/src/Geometry/Hyperplane.h create mode 100644 dae-cpp/Eigen/src/Geometry/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/Geometry/OrthoMethods.h create mode 100644 dae-cpp/Eigen/src/Geometry/ParametrizedLine.h create mode 100644 dae-cpp/Eigen/src/Geometry/Quaternion.h create mode 100644 dae-cpp/Eigen/src/Geometry/Rotation2D.h create mode 100644 dae-cpp/Eigen/src/Geometry/RotationBase.h create mode 100644 dae-cpp/Eigen/src/Geometry/Scaling.h create mode 100644 dae-cpp/Eigen/src/Geometry/Transform.h create mode 100644 dae-cpp/Eigen/src/Geometry/Translation.h create mode 100644 dae-cpp/Eigen/src/Geometry/Umeyama.h create mode 100644 dae-cpp/Eigen/src/Geometry/arch/Geometry_SIMD.h create mode 100644 dae-cpp/Eigen/src/Householder/BlockHouseholder.h create mode 100644 dae-cpp/Eigen/src/Householder/Householder.h create mode 100644 dae-cpp/Eigen/src/Householder/HouseholderSequence.h create mode 100644 dae-cpp/Eigen/src/Householder/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h create mode 100644 dae-cpp/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h create mode 100644 dae-cpp/Eigen/src/Jacobi/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/Jacobi/Jacobi.h create mode 100644 dae-cpp/Eigen/src/KLUSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/KLUSupport/KLUSupport.h create mode 100644 dae-cpp/Eigen/src/LU/Determinant.h create mode 100644 dae-cpp/Eigen/src/LU/FullPivLU.h create mode 100644 dae-cpp/Eigen/src/LU/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/LU/InverseImpl.h create mode 100644 dae-cpp/Eigen/src/LU/PartialPivLU.h create mode 100644 dae-cpp/Eigen/src/LU/PartialPivLU_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/LU/arch/InverseSize4.h create mode 100644 dae-cpp/Eigen/src/MetisSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/MetisSupport/MetisSupport.h create mode 100644 dae-cpp/Eigen/src/OrderingMethods/Amd.h create mode 100644 dae-cpp/Eigen/src/OrderingMethods/Eigen_Colamd.h create mode 100644 dae-cpp/Eigen/src/OrderingMethods/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/OrderingMethods/Ordering.h create mode 100644 dae-cpp/Eigen/src/PaStiXSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/PaStiXSupport/PaStiXSupport.h create mode 100644 dae-cpp/Eigen/src/PardisoSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/PardisoSupport/PardisoSupport.h create mode 100644 dae-cpp/Eigen/src/QR/ColPivHouseholderQR.h create mode 100644 dae-cpp/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/QR/CompleteOrthogonalDecomposition.h create mode 100644 dae-cpp/Eigen/src/QR/FullPivHouseholderQR.h create mode 100644 dae-cpp/Eigen/src/QR/HouseholderQR.h create mode 100644 dae-cpp/Eigen/src/QR/HouseholderQR_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/QR/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/SPQRSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h create mode 100644 dae-cpp/Eigen/src/SVD/BDCSVD.h create mode 100644 dae-cpp/Eigen/src/SVD/BDCSVD_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/SVD/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/SVD/JacobiSVD.h create mode 100644 dae-cpp/Eigen/src/SVD/JacobiSVD_LAPACKE.h create mode 100644 dae-cpp/Eigen/src/SVD/SVDBase.h create mode 100644 dae-cpp/Eigen/src/SVD/UpperBidiagonalization.h create mode 100644 dae-cpp/Eigen/src/SparseCholesky/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/SparseCholesky/SimplicialCholesky.h create mode 100644 dae-cpp/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h create mode 100644 dae-cpp/Eigen/src/SparseCore/AmbiVector.h create mode 100644 dae-cpp/Eigen/src/SparseCore/CompressedStorage.h create mode 100644 dae-cpp/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h create mode 100644 dae-cpp/Eigen/src/SparseCore/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseAssign.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseBlock.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseColEtree.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseCompressedBase.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseCwiseBinaryOp.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseCwiseUnaryOp.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseDenseProduct.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseDiagonalProduct.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseDot.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseFuzzy.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseMap.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseMatrix.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseMatrixBase.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparsePermutation.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseProduct.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseRedux.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseRef.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseSelfAdjointView.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseSolverBase.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseSparseProductWithPruning.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseTranspose.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseTriangularView.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseUtil.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseVector.h create mode 100644 dae-cpp/Eigen/src/SparseCore/SparseView.h create mode 100644 dae-cpp/Eigen/src/SparseCore/TriangularSolver.h create mode 100644 dae-cpp/Eigen/src/SparseLU/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLUImpl.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_Memory.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_Structs.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_Utils.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_column_bmod.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_column_dfs.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_kernel_bmod.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_panel_bmod.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_panel_dfs.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_pivotL.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_pruneL.h create mode 100644 dae-cpp/Eigen/src/SparseLU/SparseLU_relax_snode.h create mode 100644 dae-cpp/Eigen/src/SparseQR/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/SparseQR/SparseQR.h create mode 100644 dae-cpp/Eigen/src/StlSupport/StdDeque.h create mode 100644 dae-cpp/Eigen/src/StlSupport/StdList.h create mode 100644 dae-cpp/Eigen/src/StlSupport/StdVector.h create mode 100644 dae-cpp/Eigen/src/StlSupport/details.h create mode 100644 dae-cpp/Eigen/src/SuperLUSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/SuperLUSupport/SuperLUSupport.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/Barrier.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/EventCount.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/NonBlockingThreadPool.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/RunQueue.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/ThreadCancel.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/ThreadEnvironment.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/ThreadLocal.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/ThreadPoolInterface.h create mode 100644 dae-cpp/Eigen/src/ThreadPool/ThreadYield.h create mode 100644 dae-cpp/Eigen/src/UmfPackSupport/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/UmfPackSupport/UmfPackSupport.h create mode 100644 dae-cpp/Eigen/src/misc/Image.h create mode 100644 dae-cpp/Eigen/src/misc/InternalHeaderCheck.h create mode 100644 dae-cpp/Eigen/src/misc/Kernel.h create mode 100644 dae-cpp/Eigen/src/misc/RealSvd2x2.h create mode 100644 dae-cpp/Eigen/src/misc/blas.h create mode 100644 dae-cpp/Eigen/src/misc/lapacke.h create mode 100644 dae-cpp/Eigen/src/misc/lapacke_helpers.h create mode 100644 dae-cpp/Eigen/src/misc/lapacke_mangling.h create mode 100644 dae-cpp/Eigen/src/plugins/ArrayCwiseBinaryOps.inc create mode 100644 dae-cpp/Eigen/src/plugins/ArrayCwiseUnaryOps.inc create mode 100644 dae-cpp/Eigen/src/plugins/BlockMethods.inc create mode 100644 dae-cpp/Eigen/src/plugins/CommonCwiseBinaryOps.inc create mode 100644 dae-cpp/Eigen/src/plugins/CommonCwiseUnaryOps.inc create mode 100644 dae-cpp/Eigen/src/plugins/IndexedViewMethods.inc create mode 100644 dae-cpp/Eigen/src/plugins/InternalHeaderCheck.inc create mode 100644 dae-cpp/Eigen/src/plugins/MatrixCwiseBinaryOps.inc create mode 100644 dae-cpp/Eigen/src/plugins/MatrixCwiseUnaryOps.inc create mode 100644 dae-cpp/Eigen/src/plugins/ReshapedMethods.inc create mode 100644 dae-cpp/RHS.hpp create mode 100644 dae-cpp/jacobian.hpp create mode 100644 dae-cpp/mass-matrix.hpp create mode 100644 dae-cpp/solver.hpp create mode 100644 examples/simple_dae/simple_dae.cpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..d80741d --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/dae-cpp/Eigen/AccelerateSupport b/dae-cpp/Eigen/AccelerateSupport new file mode 100644 index 0000000..533be68 --- /dev/null +++ b/dae-cpp/Eigen/AccelerateSupport @@ -0,0 +1,52 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ACCELERATESUPPORT_MODULE_H +#define EIGEN_ACCELERATESUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \ingroup Support_modules + * \defgroup AccelerateSupport_Module AccelerateSupport module + * + * This module provides an interface to the Apple Accelerate library. + * It provides the seven following main factorization classes: + * - class AccelerateLLT: a Cholesky (LL^T) factorization. + * - class AccelerateLDLT: the default LDL^T factorization. + * - class AccelerateLDLTUnpivoted: a Cholesky-like LDL^T factorization with only 1x1 pivots and no pivoting + * - class AccelerateLDLTSBK: an LDL^T factorization with Supernode Bunch-Kaufman and static pivoting + * - class AccelerateLDLTTPP: an LDL^T factorization with full threshold partial pivoting + * - class AccelerateQR: a QR factorization + * - class AccelerateCholeskyAtA: a QR factorization without storing Q (equivalent to A^TA = R^T R) + * + * \code + * #include + * \endcode + * + * In order to use this module, the Accelerate headers must be accessible from + * the include paths, and your binary must be linked to the Accelerate framework. + * The Accelerate library is only available on Apple hardware. + * + * Note that many of the algorithms can be influenced by the UpLo template + * argument. All matrices are assumed to be symmetric. For example, the following + * creates an LDLT factorization where your matrix is symmetric (implicit) and + * uses the lower triangle: + * + * \code + * AccelerateLDLT, Lower> ldlt; + * \endcode + */ + +// IWYU pragma: begin_exports +#include "src/AccelerateSupport/AccelerateSupport.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_ACCELERATESUPPORT_MODULE_H diff --git a/dae-cpp/Eigen/COPYING.APACHE b/dae-cpp/Eigen/COPYING.APACHE new file mode 100644 index 0000000..61e948d --- /dev/null +++ b/dae-cpp/Eigen/COPYING.APACHE @@ -0,0 +1,203 @@ +/* + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ \ No newline at end of file diff --git a/dae-cpp/Eigen/COPYING.BSD b/dae-cpp/Eigen/COPYING.BSD new file mode 100644 index 0000000..8964ddf --- /dev/null +++ b/dae-cpp/Eigen/COPYING.BSD @@ -0,0 +1,26 @@ +/* + Copyright (c) 2011, Intel Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ diff --git a/dae-cpp/Eigen/COPYING.MINPACK b/dae-cpp/Eigen/COPYING.MINPACK new file mode 100644 index 0000000..132cc3f --- /dev/null +++ b/dae-cpp/Eigen/COPYING.MINPACK @@ -0,0 +1,51 @@ +Minpack Copyright Notice (1999) University of Chicago. All rights reserved + +Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the +following conditions are met: + +1. Redistributions of source code must retain the above +copyright notice, this list of conditions and the following +disclaimer. + +2. Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials +provided with the distribution. + +3. The end-user documentation included with the +redistribution, if any, must include the following +acknowledgment: + + "This product includes software developed by the + University of Chicago, as Operator of Argonne National + Laboratory. + +Alternately, this acknowledgment may appear in the software +itself, if and wherever such third-party acknowledgments +normally appear. + +4. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" +WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDER, THE +UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND +THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE +OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY +OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR +USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF +THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) +DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION +UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL +BE CORRECTED. + +5. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT +HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF +ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, +INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF +ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF +PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER +SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT +(INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, +EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE +POSSIBILITY OF SUCH LOSS OR DAMAGES. diff --git a/dae-cpp/Eigen/COPYING.MPL2 b/dae-cpp/Eigen/COPYING.MPL2 new file mode 100644 index 0000000..ee6256c --- /dev/null +++ b/dae-cpp/Eigen/COPYING.MPL2 @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + 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/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/dae-cpp/Eigen/COPYING.README b/dae-cpp/Eigen/COPYING.README new file mode 100644 index 0000000..11af93c --- /dev/null +++ b/dae-cpp/Eigen/COPYING.README @@ -0,0 +1,6 @@ +Eigen is primarily MPL2 licensed. See COPYING.MPL2 and these links: + http://www.mozilla.org/MPL/2.0/ + http://www.mozilla.org/MPL/2.0/FAQ.html + +Some files contain third-party code under BSD or other MPL2-compatible licenses, +whence the other COPYING.* files here. \ No newline at end of file diff --git a/dae-cpp/Eigen/Cholesky b/dae-cpp/Eigen/Cholesky new file mode 100644 index 0000000..b05ed82 --- /dev/null +++ b/dae-cpp/Eigen/Cholesky @@ -0,0 +1,43 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CHOLESKY_MODULE_H +#define EIGEN_CHOLESKY_MODULE_H + +#include "Core" +#include "Jacobi" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup Cholesky_Module Cholesky module + * + * + * + * This module provides two variants of the Cholesky decomposition for selfadjoint (hermitian) matrices. + * Those decompositions are also accessible via the following methods: + * - MatrixBase::llt() + * - MatrixBase::ldlt() + * - SelfAdjointView::llt() + * - SelfAdjointView::ldlt() + * + * \code + * #include + * \endcode + */ + +// IWYU pragma: begin_exports +#include "src/Cholesky/LLT.h" +#include "src/Cholesky/LDLT.h" +#ifdef EIGEN_USE_LAPACKE +#include "src/misc/lapacke_helpers.h" +#include "src/Cholesky/LLT_LAPACKE.h" +#endif +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_CHOLESKY_MODULE_H diff --git a/dae-cpp/Eigen/CholmodSupport b/dae-cpp/Eigen/CholmodSupport new file mode 100644 index 0000000..2961863 --- /dev/null +++ b/dae-cpp/Eigen/CholmodSupport @@ -0,0 +1,50 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CHOLMODSUPPORT_MODULE_H +#define EIGEN_CHOLMODSUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +extern "C" { +#include +} + +/** \ingroup Support_modules + * \defgroup CholmodSupport_Module CholmodSupport module + * + * This module provides an interface to the Cholmod library which is part of the suitesparse package. It provides the two following main factorization classes: + * - class CholmodSupernodalLLT: a supernodal LLT Cholesky factorization. + * - class CholmodDecomposition: a general L(D)LT Cholesky factorization with automatic or explicit runtime selection of + * the underlying factorization method (supernodal or simplicial). + * + * For the sake of completeness, this module also propose the two following classes: + * - class CholmodSimplicialLLT + * - class CholmodSimplicialLDLT + * Note that these classes does not bring any particular advantage compared to the built-in + * SimplicialLLT and SimplicialLDLT factorization classes. + * + * \code + * #include + * \endcode + * + * In order to use this module, the cholmod headers must be accessible from the include paths, and your binary must be + * linked to the cholmod library and its dependencies. The dependencies depend on how cholmod has been compiled. For a + * cmake based project, you can use our FindCholmod.cmake module to help you in this task. + * + */ + +// IWYU pragma: begin_exports +#include "src/CholmodSupport/CholmodSupport.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_CHOLMODSUPPORT_MODULE_H diff --git a/dae-cpp/Eigen/Core b/dae-cpp/Eigen/Core new file mode 100644 index 0000000..f9d9974 --- /dev/null +++ b/dae-cpp/Eigen/Core @@ -0,0 +1,410 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2007-2011 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CORE_MODULE_H +#define EIGEN_CORE_MODULE_H + +// first thing Eigen does: stop the compiler from reporting useless warnings. +#include "src/Core/util/DisableStupidWarnings.h" + +// then include this file where all our macros are defined. It's really important to do it first because +// it's where we do all the compiler/OS/arch detections and define most defaults. +#include "src/Core/util/Macros.h" + +// This detects SSE/AVX/NEON/etc. and configure alignment settings +#include "src/Core/util/ConfigureVectorization.h" + +// We need cuda_runtime.h/hip_runtime.h to ensure that +// the EIGEN_USING_STD macro works properly on the device side +#if defined(EIGEN_CUDACC) +#include +#elif defined(EIGEN_HIPCC) +#include +#endif + +#ifdef EIGEN_EXCEPTIONS +#include +#endif + +// Disable the ipa-cp-clone optimization flag with MinGW 6.x or older (enabled by default with -O3) +// See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=556 for details. +#if EIGEN_COMP_MINGW && EIGEN_GNUC_STRICT_LESS_THAN(6, 0, 0) +#pragma GCC optimize("-fno-ipa-cp-clone") +#endif + +// Prevent ICC from specializing std::complex operators that silently fail +// on device. This allows us to use our own device-compatible specializations +// instead. +#if EIGEN_COMP_ICC && defined(EIGEN_GPU_COMPILE_PHASE) && !defined(_OVERRIDE_COMPLEX_SPECIALIZATION_) +#define _OVERRIDE_COMPLEX_SPECIALIZATION_ 1 +#endif +#include + +// this include file manages BLAS and MKL related macros +// and inclusion of their respective header files +#include "src/Core/util/MKL_support.h" + +#if defined(EIGEN_HAS_CUDA_FP16) || defined(EIGEN_HAS_HIP_FP16) +#define EIGEN_HAS_GPU_FP16 +#endif + +#if defined(EIGEN_HAS_CUDA_BF16) || defined(EIGEN_HAS_HIP_BF16) +#define EIGEN_HAS_GPU_BF16 +#endif + +#if (defined _OPENMP) && (!defined EIGEN_DONT_PARALLELIZE) +#define EIGEN_HAS_OPENMP +#endif + +#ifdef EIGEN_HAS_OPENMP +#include +#include +#endif + +// MSVC for windows mobile does not have the errno.h file +#if !(EIGEN_COMP_MSVC && EIGEN_OS_WINCE) && !EIGEN_COMP_ARM +#define EIGEN_HAS_ERRNO +#endif + +#ifdef EIGEN_HAS_ERRNO +#include +#endif +#include +#include +#include +#include +#ifndef EIGEN_NO_IO +#include +#include +#endif +#include +#include +#include +#include // for CHAR_BIT +// for min/max: +#include + +#include +#include + +// for std::is_nothrow_move_assignable +#include + +// for outputting debug info +#ifdef EIGEN_DEBUG_ASSIGN +#include +#endif + +// required for __cpuid, needs to be included after cmath +// also required for _BitScanReverse on Windows on ARM +#if EIGEN_COMP_MSVC && (EIGEN_ARCH_i386_OR_x86_64 || EIGEN_ARCH_ARM64) && !EIGEN_OS_WINCE +#include +#endif + +#if defined(EIGEN_USE_SYCL) +#undef min +#undef max +#undef isnan +#undef isinf +#undef isfinite +#include +#include +#include +#include +#include +#ifndef EIGEN_SYCL_LOCAL_THREAD_DIM0 +#define EIGEN_SYCL_LOCAL_THREAD_DIM0 16 +#endif +#ifndef EIGEN_SYCL_LOCAL_THREAD_DIM1 +#define EIGEN_SYCL_LOCAL_THREAD_DIM1 16 +#endif +#endif + +#if defined EIGEN2_SUPPORT_STAGE40_FULL_EIGEN3_STRICTNESS || defined EIGEN2_SUPPORT_STAGE30_FULL_EIGEN3_API || \ + defined EIGEN2_SUPPORT_STAGE20_RESOLVE_API_CONFLICTS || defined EIGEN2_SUPPORT_STAGE10_FULL_EIGEN2_API || \ + defined EIGEN2_SUPPORT +// This will generate an error message: +#error Eigen2-support is only available up to version 3.2. Please go to "http://eigen.tuxfamily.org/index.php?title=Eigen2" for further information +#endif + +namespace Eigen { + +// we use size_t frequently and we'll never remember to prepend it with std:: every time just to +// ensure QNX/QCC support +using std::size_t; +// gcc 4.6.0 wants std:: for ptrdiff_t +using std::ptrdiff_t; + +} // namespace Eigen + +/** \defgroup Core_Module Core module + * This is the main module of Eigen providing dense matrix and vector support + * (both fixed and dynamic size) with all the features corresponding to a BLAS library + * and much more... + * + * \code + * #include + * \endcode + */ + +#ifdef EIGEN_USE_LAPACKE +#ifdef EIGEN_USE_MKL +#include "mkl_lapacke.h" +#else +#include "src/misc/lapacke.h" +#endif +#endif + +// IWYU pragma: begin_exports +#include "src/Core/util/Constants.h" +#include "src/Core/util/Meta.h" +#include "src/Core/util/Assert.h" +#include "src/Core/util/ForwardDeclarations.h" +#include "src/Core/util/StaticAssert.h" +#include "src/Core/util/XprHelper.h" +#include "src/Core/util/Memory.h" +#include "src/Core/util/IntegralConstant.h" +#include "src/Core/util/Serializer.h" +#include "src/Core/util/SymbolicIndex.h" +#include "src/Core/util/EmulateArray.h" +#include "src/Core/util/MoreMeta.h" + +#include "src/Core/NumTraits.h" +#include "src/Core/MathFunctions.h" +#include "src/Core/GenericPacketMath.h" +#include "src/Core/MathFunctionsImpl.h" +#include "src/Core/arch/Default/ConjHelper.h" +// Generic half float support +#include "src/Core/arch/Default/Half.h" +#include "src/Core/arch/Default/BFloat16.h" +#include "src/Core/arch/Default/GenericPacketMathFunctionsFwd.h" + +#if defined EIGEN_VECTORIZE_AVX512 +#if defined EIGEN_VECTORIZE_AVX512FP16 +#include "src/Core/arch/AVX512/PacketMathFP16.h" +#endif +#include "src/Core/arch/SSE/PacketMath.h" +#include "src/Core/arch/SSE/TypeCasting.h" +#include "src/Core/arch/SSE/Complex.h" +#include "src/Core/arch/AVX/PacketMath.h" +#include "src/Core/arch/AVX/TypeCasting.h" +#include "src/Core/arch/AVX/Complex.h" +#include "src/Core/arch/AVX512/PacketMath.h" +#include "src/Core/arch/AVX512/TypeCasting.h" +#include "src/Core/arch/AVX512/Complex.h" +#include "src/Core/arch/SSE/MathFunctions.h" +#include "src/Core/arch/AVX/MathFunctions.h" +#include "src/Core/arch/AVX512/MathFunctions.h" +#include "src/Core/arch/AVX512/TrsmKernel.h" +#elif defined EIGEN_VECTORIZE_AVX + // Use AVX for floats and doubles, SSE for integers +#include "src/Core/arch/SSE/PacketMath.h" +#include "src/Core/arch/SSE/TypeCasting.h" +#include "src/Core/arch/SSE/Complex.h" +#include "src/Core/arch/AVX/PacketMath.h" +#include "src/Core/arch/AVX/TypeCasting.h" +#include "src/Core/arch/AVX/Complex.h" +#include "src/Core/arch/SSE/MathFunctions.h" +#include "src/Core/arch/AVX/MathFunctions.h" +#elif defined EIGEN_VECTORIZE_SSE +#include "src/Core/arch/SSE/PacketMath.h" +#include "src/Core/arch/SSE/TypeCasting.h" +#include "src/Core/arch/SSE/MathFunctions.h" +#include "src/Core/arch/SSE/Complex.h" +#elif defined(EIGEN_VECTORIZE_ALTIVEC) || defined(EIGEN_VECTORIZE_VSX) +#include "src/Core/arch/AltiVec/PacketMath.h" +#include "src/Core/arch/AltiVec/TypeCasting.h" +#include "src/Core/arch/AltiVec/MathFunctions.h" +#include "src/Core/arch/AltiVec/Complex.h" +#elif defined EIGEN_VECTORIZE_NEON +#include "src/Core/arch/NEON/PacketMath.h" +#include "src/Core/arch/NEON/TypeCasting.h" +#include "src/Core/arch/NEON/MathFunctions.h" +#include "src/Core/arch/NEON/Complex.h" +#elif defined EIGEN_VECTORIZE_SVE +#include "src/Core/arch/SVE/PacketMath.h" +#include "src/Core/arch/SVE/TypeCasting.h" +#include "src/Core/arch/SVE/MathFunctions.h" +#elif defined EIGEN_VECTORIZE_ZVECTOR +#include "src/Core/arch/ZVector/PacketMath.h" +#include "src/Core/arch/ZVector/MathFunctions.h" +#include "src/Core/arch/ZVector/Complex.h" +#elif defined EIGEN_VECTORIZE_MSA +#include "src/Core/arch/MSA/PacketMath.h" +#include "src/Core/arch/MSA/MathFunctions.h" +#include "src/Core/arch/MSA/Complex.h" +#elif defined EIGEN_VECTORIZE_HVX +#include "src/Core/arch/HVX/PacketMath.h" +#endif + +#if defined EIGEN_VECTORIZE_GPU +#include "src/Core/arch/GPU/PacketMath.h" +#include "src/Core/arch/GPU/MathFunctions.h" +#include "src/Core/arch/GPU/TypeCasting.h" +#endif + +#if defined(EIGEN_USE_SYCL) +#include "src/Core/arch/SYCL/InteropHeaders.h" +#if !defined(EIGEN_DONT_VECTORIZE_SYCL) +#include "src/Core/arch/SYCL/PacketMath.h" +#include "src/Core/arch/SYCL/MathFunctions.h" +#include "src/Core/arch/SYCL/TypeCasting.h" +#endif +#endif + +#include "src/Core/arch/Default/Settings.h" +// This file provides generic implementations valid for scalar as well +#include "src/Core/arch/Default/GenericPacketMathFunctions.h" + +#include "src/Core/functors/TernaryFunctors.h" +#include "src/Core/functors/BinaryFunctors.h" +#include "src/Core/functors/UnaryFunctors.h" +#include "src/Core/functors/NullaryFunctors.h" +#include "src/Core/functors/StlFunctors.h" +#include "src/Core/functors/AssignmentFunctors.h" + +// Specialized functors for GPU. +#ifdef EIGEN_GPUCC +#include "src/Core/arch/GPU/Complex.h" +#endif + +// Specializations of vectorized activation functions for NEON. +#ifdef EIGEN_VECTORIZE_NEON +#include "src/Core/arch/NEON/UnaryFunctors.h" +#endif + +#include "src/Core/util/IndexedViewHelper.h" +#include "src/Core/util/ReshapedHelper.h" +#include "src/Core/ArithmeticSequence.h" +#ifndef EIGEN_NO_IO +#include "src/Core/IO.h" +#endif +#include "src/Core/DenseCoeffsBase.h" +#include "src/Core/DenseBase.h" +#include "src/Core/MatrixBase.h" +#include "src/Core/EigenBase.h" + +#include "src/Core/Product.h" +#include "src/Core/CoreEvaluators.h" +#include "src/Core/AssignEvaluator.h" + +#ifndef EIGEN_PARSED_BY_DOXYGEN // work around Doxygen bug triggered by Assign.h r814874 + // at least confirmed with Doxygen 1.5.5 and 1.5.6 +#include "src/Core/Assign.h" +#endif + +#include "src/Core/ArrayBase.h" +#include "src/Core/util/BlasUtil.h" +#include "src/Core/DenseStorage.h" +#include "src/Core/NestByValue.h" + +// #include "src/Core/ForceAlignedAccess.h" + +#include "src/Core/ReturnByValue.h" +#include "src/Core/NoAlias.h" +#include "src/Core/PlainObjectBase.h" +#include "src/Core/Matrix.h" +#include "src/Core/Array.h" +#include "src/Core/CwiseTernaryOp.h" +#include "src/Core/CwiseBinaryOp.h" +#include "src/Core/CwiseUnaryOp.h" +#include "src/Core/CwiseNullaryOp.h" +#include "src/Core/CwiseUnaryView.h" +#include "src/Core/SelfCwiseBinaryOp.h" +#include "src/Core/Dot.h" +#include "src/Core/StableNorm.h" +#include "src/Core/Stride.h" +#include "src/Core/MapBase.h" +#include "src/Core/Map.h" +#include "src/Core/Ref.h" +#include "src/Core/Block.h" +#include "src/Core/VectorBlock.h" +#include "src/Core/IndexedView.h" +#include "src/Core/Reshaped.h" +#include "src/Core/Transpose.h" +#include "src/Core/DiagonalMatrix.h" +#include "src/Core/Diagonal.h" +#include "src/Core/DiagonalProduct.h" +#include "src/Core/SkewSymmetricMatrix3.h" +#include "src/Core/Redux.h" +#include "src/Core/Visitor.h" +#include "src/Core/Fuzzy.h" +#include "src/Core/Swap.h" +#include "src/Core/CommaInitializer.h" +#include "src/Core/GeneralProduct.h" +#include "src/Core/Solve.h" +#include "src/Core/Inverse.h" +#include "src/Core/SolverBase.h" +#include "src/Core/PermutationMatrix.h" +#include "src/Core/Transpositions.h" +#include "src/Core/TriangularMatrix.h" +#include "src/Core/SelfAdjointView.h" +#include "src/Core/products/GeneralBlockPanelKernel.h" +#ifdef EIGEN_GEMM_THREADPOOL +#include "ThreadPool" +#endif +#include "src/Core/products/Parallelizer.h" +#include "src/Core/ProductEvaluators.h" +#include "src/Core/products/GeneralMatrixVector.h" +#include "src/Core/products/GeneralMatrixMatrix.h" +#include "src/Core/SolveTriangular.h" +#include "src/Core/products/GeneralMatrixMatrixTriangular.h" +#include "src/Core/products/SelfadjointMatrixVector.h" +#include "src/Core/products/SelfadjointMatrixMatrix.h" +#include "src/Core/products/SelfadjointProduct.h" +#include "src/Core/products/SelfadjointRank2Update.h" +#include "src/Core/products/TriangularMatrixVector.h" +#include "src/Core/products/TriangularMatrixMatrix.h" +#include "src/Core/products/TriangularSolverMatrix.h" +#include "src/Core/products/TriangularSolverVector.h" +#include "src/Core/BandMatrix.h" +#include "src/Core/CoreIterators.h" +#include "src/Core/ConditionEstimator.h" + +#if defined(EIGEN_VECTORIZE_VSX) +#include "src/Core/arch/AltiVec/MatrixProduct.h" +#elif defined EIGEN_VECTORIZE_NEON +#include "src/Core/arch/NEON/GeneralBlockPanelKernel.h" +#endif + +#if defined(EIGEN_VECTORIZE_AVX512) +#include "src/Core/arch/AVX512/GemmKernel.h" +#endif + +#include "src/Core/Select.h" +#include "src/Core/VectorwiseOp.h" +#include "src/Core/PartialReduxEvaluator.h" +#include "src/Core/Random.h" +#include "src/Core/Replicate.h" +#include "src/Core/Reverse.h" +#include "src/Core/ArrayWrapper.h" +#include "src/Core/StlIterators.h" + +#ifdef EIGEN_USE_BLAS +#include "src/Core/products/GeneralMatrixMatrix_BLAS.h" +#include "src/Core/products/GeneralMatrixVector_BLAS.h" +#include "src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h" +#include "src/Core/products/SelfadjointMatrixMatrix_BLAS.h" +#include "src/Core/products/SelfadjointMatrixVector_BLAS.h" +#include "src/Core/products/TriangularMatrixMatrix_BLAS.h" +#include "src/Core/products/TriangularMatrixVector_BLAS.h" +#include "src/Core/products/TriangularSolverMatrix_BLAS.h" +#endif // EIGEN_USE_BLAS + +#ifdef EIGEN_USE_MKL_VML +#include "src/Core/Assign_MKL.h" +#endif + +#include "src/Core/GlobalFunctions.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_CORE_MODULE_H diff --git a/dae-cpp/Eigen/Dense b/dae-cpp/Eigen/Dense new file mode 100644 index 0000000..5768910 --- /dev/null +++ b/dae-cpp/Eigen/Dense @@ -0,0 +1,7 @@ +#include "Core" +#include "LU" +#include "Cholesky" +#include "QR" +#include "SVD" +#include "Geometry" +#include "Eigenvalues" diff --git a/dae-cpp/Eigen/Eigen b/dae-cpp/Eigen/Eigen new file mode 100644 index 0000000..654c8dc --- /dev/null +++ b/dae-cpp/Eigen/Eigen @@ -0,0 +1,2 @@ +#include "Dense" +#include "Sparse" diff --git a/dae-cpp/Eigen/Eigenvalues b/dae-cpp/Eigen/Eigenvalues new file mode 100644 index 0000000..3b0bdee --- /dev/null +++ b/dae-cpp/Eigen/Eigenvalues @@ -0,0 +1,63 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_EIGENVALUES_MODULE_H +#define EIGEN_EIGENVALUES_MODULE_H + +#include "Core" + +#include "Cholesky" +#include "Jacobi" +#include "Householder" +#include "LU" +#include "Geometry" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup Eigenvalues_Module Eigenvalues module + * + * + * + * This module mainly provides various eigenvalue solvers. + * This module also provides some MatrixBase methods, including: + * - MatrixBase::eigenvalues(), + * - MatrixBase::operatorNorm() + * + * \code + * #include + * \endcode + */ + +#include "src/misc/RealSvd2x2.h" + +// IWYU pragma: begin_exports +#include "src/Eigenvalues/Tridiagonalization.h" +#include "src/Eigenvalues/RealSchur.h" +#include "src/Eigenvalues/EigenSolver.h" +#include "src/Eigenvalues/SelfAdjointEigenSolver.h" +#include "src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h" +#include "src/Eigenvalues/HessenbergDecomposition.h" +#include "src/Eigenvalues/ComplexSchur.h" +#include "src/Eigenvalues/ComplexEigenSolver.h" +#include "src/Eigenvalues/RealQZ.h" +#include "src/Eigenvalues/GeneralizedEigenSolver.h" +#include "src/Eigenvalues/MatrixBaseEigenvalues.h" +#ifdef EIGEN_USE_LAPACKE +#ifdef EIGEN_USE_MKL +#include "mkl_lapacke.h" +#else +#include "src/misc/lapacke.h" +#endif +#include "src/Eigenvalues/RealSchur_LAPACKE.h" +#include "src/Eigenvalues/ComplexSchur_LAPACKE.h" +#include "src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h" +#endif +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_EIGENVALUES_MODULE_H diff --git a/dae-cpp/Eigen/Geometry b/dae-cpp/Eigen/Geometry new file mode 100644 index 0000000..3334874 --- /dev/null +++ b/dae-cpp/Eigen/Geometry @@ -0,0 +1,61 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_GEOMETRY_MODULE_H +#define EIGEN_GEOMETRY_MODULE_H + +#include "Core" + +#include "SVD" +#include "LU" +#include + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup Geometry_Module Geometry module + * + * This module provides support for: + * - fixed-size homogeneous transformations + * - translation, scaling, 2D and 3D rotations + * - \link Quaternion quaternions \endlink + * - cross products (\ref MatrixBase::cross, \ref MatrixBase::cross3) + * - orthognal vector generation (\ref MatrixBase::unitOrthogonal) + * - some linear components: \link ParametrizedLine parametrized-lines \endlink and \link Hyperplane hyperplanes + * \endlink + * - \link AlignedBox axis aligned bounding boxes \endlink + * - \link umeyama least-square transformation fitting \endlink + * + * \code + * #include + * \endcode + */ + +// IWYU pragma: begin_exports +#include "src/Geometry/OrthoMethods.h" +#include "src/Geometry/EulerAngles.h" +#include "src/Geometry/Homogeneous.h" +#include "src/Geometry/RotationBase.h" +#include "src/Geometry/Rotation2D.h" +#include "src/Geometry/Quaternion.h" +#include "src/Geometry/AngleAxis.h" +#include "src/Geometry/Transform.h" +#include "src/Geometry/Translation.h" +#include "src/Geometry/Scaling.h" +#include "src/Geometry/Hyperplane.h" +#include "src/Geometry/ParametrizedLine.h" +#include "src/Geometry/AlignedBox.h" +#include "src/Geometry/Umeyama.h" + +// Use the SSE optimized version whenever possible. +#if (defined EIGEN_VECTORIZE_SSE) || (defined EIGEN_VECTORIZE_NEON) +#include "src/Geometry/arch/Geometry_SIMD.h" +#endif +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_GEOMETRY_MODULE_H diff --git a/dae-cpp/Eigen/Householder b/dae-cpp/Eigen/Householder new file mode 100644 index 0000000..5070e07 --- /dev/null +++ b/dae-cpp/Eigen/Householder @@ -0,0 +1,31 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_HOUSEHOLDER_MODULE_H +#define EIGEN_HOUSEHOLDER_MODULE_H + +#include "Core" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup Householder_Module Householder module + * This module provides Householder transformations. + * + * \code + * #include + * \endcode + */ + +// IWYU pragma: begin_exports +#include "src/Householder/Householder.h" +#include "src/Householder/HouseholderSequence.h" +#include "src/Householder/BlockHouseholder.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_HOUSEHOLDER_MODULE_H diff --git a/dae-cpp/Eigen/IterativeLinearSolvers b/dae-cpp/Eigen/IterativeLinearSolvers new file mode 100644 index 0000000..fe5159e --- /dev/null +++ b/dae-cpp/Eigen/IterativeLinearSolvers @@ -0,0 +1,52 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ITERATIVELINEARSOLVERS_MODULE_H +#define EIGEN_ITERATIVELINEARSOLVERS_MODULE_H + +#include "SparseCore" +#include "OrderingMethods" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** + * \defgroup IterativeLinearSolvers_Module IterativeLinearSolvers module + * + * This module currently provides iterative methods to solve problems of the form \c A \c x = \c b, where \c A is a + squared matrix, usually very large and sparse. + * Those solvers are accessible via the following classes: + * - ConjugateGradient for selfadjoint (hermitian) matrices, + * - LeastSquaresConjugateGradient for rectangular least-square problems, + * - BiCGSTAB for general square matrices. + * + * These iterative solvers are associated with some preconditioners: + * - IdentityPreconditioner - not really useful + * - DiagonalPreconditioner - also called Jacobi preconditioner, work very well on diagonal dominant matrices. + * - IncompleteLUT - incomplete LU factorization with dual thresholding + * + * Such problems can also be solved using the direct sparse decomposition modules: SparseCholesky, CholmodSupport, + UmfPackSupport, SuperLUSupport, AccelerateSupport. + * + \code + #include + \endcode + */ + +// IWYU pragma: begin_exports +#include "src/IterativeLinearSolvers/SolveWithGuess.h" +#include "src/IterativeLinearSolvers/IterativeSolverBase.h" +#include "src/IterativeLinearSolvers/BasicPreconditioners.h" +#include "src/IterativeLinearSolvers/ConjugateGradient.h" +#include "src/IterativeLinearSolvers/LeastSquareConjugateGradient.h" +#include "src/IterativeLinearSolvers/BiCGSTAB.h" +#include "src/IterativeLinearSolvers/IncompleteLUT.h" +#include "src/IterativeLinearSolvers/IncompleteCholesky.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_ITERATIVELINEARSOLVERS_MODULE_H diff --git a/dae-cpp/Eigen/Jacobi b/dae-cpp/Eigen/Jacobi new file mode 100644 index 0000000..31eb36a --- /dev/null +++ b/dae-cpp/Eigen/Jacobi @@ -0,0 +1,33 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_JACOBI_MODULE_H +#define EIGEN_JACOBI_MODULE_H + +#include "Core" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup Jacobi_Module Jacobi module + * This module provides Jacobi and Givens rotations. + * + * \code + * #include + * \endcode + * + * In addition to listed classes, it defines the two following MatrixBase methods to apply a Jacobi or Givens rotation: + * - MatrixBase::applyOnTheLeft() + * - MatrixBase::applyOnTheRight(). + */ + +// IWYU pragma: begin_exports +#include "src/Jacobi/Jacobi.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_JACOBI_MODULE_H diff --git a/dae-cpp/Eigen/KLUSupport b/dae-cpp/Eigen/KLUSupport new file mode 100644 index 0000000..13959a3 --- /dev/null +++ b/dae-cpp/Eigen/KLUSupport @@ -0,0 +1,43 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_KLUSUPPORT_MODULE_H +#define EIGEN_KLUSUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +extern "C" { +#include +#include +} + +/** \ingroup Support_modules + * \defgroup KLUSupport_Module KLUSupport module + * + * This module provides an interface to the KLU library which is part of the suitesparse package. It provides the following factorization class: + * - class KLU: a sparse LU factorization, well-suited for circuit simulation. + * + * \code + * #include + * \endcode + * + * In order to use this module, the klu and btf headers must be accessible from the include paths, and your binary must + * be linked to the klu library and its dependencies. The dependencies depend on how umfpack has been compiled. For a + * cmake based project, you can use our FindKLU.cmake module to help you in this task. + * + */ + +// IWYU pragma: begin_exports +#include "src/KLUSupport/KLUSupport.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_KLUSUPPORT_MODULE_H diff --git a/dae-cpp/Eigen/LU b/dae-cpp/Eigen/LU new file mode 100644 index 0000000..d804480 --- /dev/null +++ b/dae-cpp/Eigen/LU @@ -0,0 +1,46 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_LU_MODULE_H +#define EIGEN_LU_MODULE_H + +#include "Core" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup LU_Module LU module + * This module includes %LU decomposition and related notions such as matrix inversion and determinant. + * This module defines the following MatrixBase methods: + * - MatrixBase::inverse() + * - MatrixBase::determinant() + * + * \code + * #include + * \endcode + */ + +#include "src/misc/Kernel.h" +#include "src/misc/Image.h" + +// IWYU pragma: begin_exports +#include "src/LU/FullPivLU.h" +#include "src/LU/PartialPivLU.h" +#ifdef EIGEN_USE_LAPACKE +#include "src/misc/lapacke_helpers.h" +#include "src/LU/PartialPivLU_LAPACKE.h" +#endif +#include "src/LU/Determinant.h" +#include "src/LU/InverseImpl.h" + +#if defined EIGEN_VECTORIZE_SSE || defined EIGEN_VECTORIZE_NEON +#include "src/LU/arch/InverseSize4.h" +#endif +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_LU_MODULE_H diff --git a/dae-cpp/Eigen/MetisSupport b/dae-cpp/Eigen/MetisSupport new file mode 100644 index 0000000..3636d3a --- /dev/null +++ b/dae-cpp/Eigen/MetisSupport @@ -0,0 +1,35 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_METISSUPPORT_MODULE_H +#define EIGEN_METISSUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +extern "C" { +#include +} + +/** \ingroup Support_modules + * \defgroup MetisSupport_Module MetisSupport module + * + * \code + * #include + * \endcode + * This module defines an interface to the METIS reordering package (http://glaros.dtc.umn.edu/gkhome/views/metis). + * It can be used just as any other built-in method as explained in \link OrderingMethods_Module here. \endlink + */ + +// IWYU pragma: begin_exports +#include "src/MetisSupport/MetisSupport.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_METISSUPPORT_MODULE_H diff --git a/dae-cpp/Eigen/OrderingMethods b/dae-cpp/Eigen/OrderingMethods new file mode 100644 index 0000000..921b8a0 --- /dev/null +++ b/dae-cpp/Eigen/OrderingMethods @@ -0,0 +1,73 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ORDERINGMETHODS_MODULE_H +#define EIGEN_ORDERINGMETHODS_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** + * \defgroup OrderingMethods_Module OrderingMethods module + * + * This module is currently for internal use only + * + * It defines various built-in and external ordering methods for sparse matrices. + * They are typically used to reduce the number of elements during + * the sparse matrix decomposition (LLT, LU, QR). + * Precisely, in a preprocessing step, a permutation matrix P is computed using + * those ordering methods and applied to the columns of the matrix. + * Using for instance the sparse Cholesky decomposition, it is expected that + * the nonzeros elements in LLT(A*P) will be much smaller than that in LLT(A). + * + * + * Usage : + * \code + * #include + * \endcode + * + * A simple usage is as a template parameter in the sparse decomposition classes : + * + * \code + * SparseLU > solver; + * \endcode + * + * \code + * SparseQR > solver; + * \endcode + * + * It is possible as well to call directly a particular ordering method for your own purpose, + * \code + * AMDOrdering ordering; + * PermutationMatrix perm; + * SparseMatrix A; + * //Fill the matrix ... + * + * ordering(A, perm); // Call AMD + * \endcode + * + * \note Some of these methods (like AMD or METIS), need the sparsity pattern + * of the input matrix to be symmetric. When the matrix is structurally unsymmetric, + * Eigen computes internally the pattern of \f$A^T*A\f$ before calling the method. + * If your matrix is already symmetric (at leat in structure), you can avoid that + * by calling the method with a SelfAdjointView type. + * + * \code + * // Call the ordering on the pattern of the lower triangular matrix A + * ordering(A.selfadjointView(), perm); + * \endcode + */ + +// IWYU pragma: begin_exports +#include "src/OrderingMethods/Amd.h" +#include "src/OrderingMethods/Ordering.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_ORDERINGMETHODS_MODULE_H diff --git a/dae-cpp/Eigen/PaStiXSupport b/dae-cpp/Eigen/PaStiXSupport new file mode 100644 index 0000000..dd1cfcb --- /dev/null +++ b/dae-cpp/Eigen/PaStiXSupport @@ -0,0 +1,51 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_PASTIXSUPPORT_MODULE_H +#define EIGEN_PASTIXSUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +extern "C" { +#include +#include +} + +#ifdef complex +#undef complex +#endif + +/** \ingroup Support_modules + * \defgroup PaStiXSupport_Module PaStiXSupport module + * + * This module provides an interface to the PaSTiX library. + * PaSTiX is a general \b supernodal, \b parallel and \b opensource sparse solver. + * It provides the two following main factorization classes: + * - class PastixLLT : a supernodal, parallel LLt Cholesky factorization. + * - class PastixLDLT: a supernodal, parallel LDLt Cholesky factorization. + * - class PastixLU : a supernodal, parallel LU factorization (optimized for a symmetric pattern). + * + * \code + * #include + * \endcode + * + * In order to use this module, the PaSTiX headers must be accessible from the include paths, and your binary must be + * linked to the PaSTiX library and its dependencies. This wrapper resuires PaStiX version 5.x compiled without MPI + * support. The dependencies depend on how PaSTiX has been compiled. For a cmake based project, you can use our + * FindPaSTiX.cmake module to help you in this task. + * + */ + +// IWYU pragma: begin_exports +#include "src/PaStiXSupport/PaStiXSupport.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_PASTIXSUPPORT_MODULE_H diff --git a/dae-cpp/Eigen/PardisoSupport b/dae-cpp/Eigen/PardisoSupport new file mode 100644 index 0000000..4aef5fb --- /dev/null +++ b/dae-cpp/Eigen/PardisoSupport @@ -0,0 +1,38 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_PARDISOSUPPORT_MODULE_H +#define EIGEN_PARDISOSUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +#include + +/** \ingroup Support_modules + * \defgroup PardisoSupport_Module PardisoSupport module + * + * This module brings support for the Intel(R) MKL PARDISO direct sparse solvers. + * + * \code + * #include + * \endcode + * + * In order to use this module, the MKL headers must be accessible from the include paths, and your binary must be + * linked to the MKL library and its dependencies. See this \ref TopicUsingIntelMKL "page" for more information on + * MKL-Eigen integration. + * + */ + +// IWYU pragma: begin_exports +#include "src/PardisoSupport/PardisoSupport.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_PARDISOSUPPORT_MODULE_H diff --git a/dae-cpp/Eigen/QR b/dae-cpp/Eigen/QR new file mode 100644 index 0000000..c38b453 --- /dev/null +++ b/dae-cpp/Eigen/QR @@ -0,0 +1,48 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_QR_MODULE_H +#define EIGEN_QR_MODULE_H + +#include "Core" + +#include "Cholesky" +#include "Jacobi" +#include "Householder" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup QR_Module QR module + * + * + * + * This module provides various QR decompositions + * This module also provides some MatrixBase methods, including: + * - MatrixBase::householderQr() + * - MatrixBase::colPivHouseholderQr() + * - MatrixBase::fullPivHouseholderQr() + * + * \code + * #include + * \endcode + */ + +// IWYU pragma: begin_exports +#include "src/QR/HouseholderQR.h" +#include "src/QR/FullPivHouseholderQR.h" +#include "src/QR/ColPivHouseholderQR.h" +#include "src/QR/CompleteOrthogonalDecomposition.h" +#ifdef EIGEN_USE_LAPACKE +#include "src/misc/lapacke_helpers.h" +#include "src/QR/HouseholderQR_LAPACKE.h" +#include "src/QR/ColPivHouseholderQR_LAPACKE.h" +#endif +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_QR_MODULE_H diff --git a/dae-cpp/Eigen/QtAlignedMalloc b/dae-cpp/Eigen/QtAlignedMalloc new file mode 100644 index 0000000..585f8e8 --- /dev/null +++ b/dae-cpp/Eigen/QtAlignedMalloc @@ -0,0 +1,32 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_QTMALLOC_MODULE_H +#define EIGEN_QTMALLOC_MODULE_H + +#include "Core" + +#if (!EIGEN_MALLOC_ALREADY_ALIGNED) + +#include "src/Core/util/DisableStupidWarnings.h" + +void *qMalloc(std::size_t size) { return Eigen::internal::aligned_malloc(size); } + +void qFree(void *ptr) { Eigen::internal::aligned_free(ptr); } + +void *qRealloc(void *ptr, std::size_t size) { + void *newPtr = Eigen::internal::aligned_malloc(size); + std::memcpy(newPtr, ptr, size); + Eigen::internal::aligned_free(ptr); + return newPtr; +} + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif + +#endif // EIGEN_QTMALLOC_MODULE_H diff --git a/dae-cpp/Eigen/SPQRSupport b/dae-cpp/Eigen/SPQRSupport new file mode 100644 index 0000000..c01dbe0 --- /dev/null +++ b/dae-cpp/Eigen/SPQRSupport @@ -0,0 +1,41 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SPQRSUPPORT_MODULE_H +#define EIGEN_SPQRSUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +#include "SuiteSparseQR.hpp" + +/** \ingroup Support_modules + * \defgroup SPQRSupport_Module SuiteSparseQR module + * + * This module provides an interface to the SPQR library, which is part of the suitesparse package. + * + * \code + * #include + * \endcode + * + * In order to use this module, the SPQR headers must be accessible from the include paths, and your binary must be + * linked to the SPQR library and its dependencies (Cholmod, AMD, COLAMD,...). For a cmake based project, you can use + * our FindSPQR.cmake and FindCholmod.Cmake modules + * + */ + +#include "CholmodSupport" + +// IWYU pragma: begin_exports +#include "src/SPQRSupport/SuiteSparseQRSupport.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif diff --git a/dae-cpp/Eigen/SVD b/dae-cpp/Eigen/SVD new file mode 100644 index 0000000..2a013f8 --- /dev/null +++ b/dae-cpp/Eigen/SVD @@ -0,0 +1,56 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SVD_MODULE_H +#define EIGEN_SVD_MODULE_H + +#include "QR" +#include "Householder" +#include "Jacobi" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup SVD_Module SVD module + * + * + * + * This module provides SVD decomposition for matrices (both real and complex). + * Two decomposition algorithms are provided: + * - JacobiSVD implementing two-sided Jacobi iterations is numerically very accurate, fast for small matrices, but very + * slow for larger ones. + * - BDCSVD implementing a recursive divide & conquer strategy on top of an upper-bidiagonalization which remains fast + * for large problems. These decompositions are accessible via the respective classes and following MatrixBase methods: + * - MatrixBase::jacobiSvd() + * - MatrixBase::bdcSvd() + * + * \code + * #include + * \endcode + */ + +// IWYU pragma: begin_exports +#include "src/misc/RealSvd2x2.h" +#include "src/SVD/UpperBidiagonalization.h" +#include "src/SVD/SVDBase.h" +#include "src/SVD/JacobiSVD.h" +#include "src/SVD/BDCSVD.h" +#ifdef EIGEN_USE_LAPACKE +#ifdef EIGEN_USE_MKL +#include "mkl_lapacke.h" +#else +#include "src/misc/lapacke.h" +#endif +#ifndef EIGEN_USE_LAPACKE_STRICT +#include "src/SVD/JacobiSVD_LAPACKE.h" +#endif +#include "src/SVD/BDCSVD_LAPACKE.h" +#endif +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_SVD_MODULE_H diff --git a/dae-cpp/Eigen/Sparse b/dae-cpp/Eigen/Sparse new file mode 100644 index 0000000..4d0ee8b --- /dev/null +++ b/dae-cpp/Eigen/Sparse @@ -0,0 +1,33 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SPARSE_MODULE_H +#define EIGEN_SPARSE_MODULE_H + +/** \defgroup Sparse_Module Sparse meta-module + * + * Meta-module including all related modules: + * - \ref SparseCore_Module + * - \ref OrderingMethods_Module + * - \ref SparseCholesky_Module + * - \ref SparseLU_Module + * - \ref SparseQR_Module + * - \ref IterativeLinearSolvers_Module + * + \code + #include + \endcode + */ + +#include "SparseCore" +#include "OrderingMethods" +#include "SparseCholesky" +#include "SparseLU" +#include "SparseQR" +#include "IterativeLinearSolvers" + +#endif // EIGEN_SPARSE_MODULE_H diff --git a/dae-cpp/Eigen/SparseCholesky b/dae-cpp/Eigen/SparseCholesky new file mode 100644 index 0000000..6abdcd6 --- /dev/null +++ b/dae-cpp/Eigen/SparseCholesky @@ -0,0 +1,40 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2013 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SPARSECHOLESKY_MODULE_H +#define EIGEN_SPARSECHOLESKY_MODULE_H + +#include "SparseCore" +#include "OrderingMethods" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** + * \defgroup SparseCholesky_Module SparseCholesky module + * + * This module currently provides two variants of the direct sparse Cholesky decomposition for selfadjoint (hermitian) + * matrices. Those decompositions are accessible via the following classes: + * - SimplicialLLt, + * - SimplicialLDLt + * + * Such problems can also be solved using the ConjugateGradient solver from the IterativeLinearSolvers module. + * + * \code + * #include + * \endcode + */ + +// IWYU pragma: begin_exports +#include "src/SparseCholesky/SimplicialCholesky.h" +#include "src/SparseCholesky/SimplicialCholesky_impl.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_SPARSECHOLESKY_MODULE_H diff --git a/dae-cpp/Eigen/SparseCore b/dae-cpp/Eigen/SparseCore new file mode 100644 index 0000000..56a9401 --- /dev/null +++ b/dae-cpp/Eigen/SparseCore @@ -0,0 +1,70 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SPARSECORE_MODULE_H +#define EIGEN_SPARSECORE_MODULE_H + +#include "Core" + +#include "src/Core/util/DisableStupidWarnings.h" + +#include +#include +#include +#include +#include +#include + +/** + * \defgroup SparseCore_Module SparseCore module + * + * This module provides a sparse matrix representation, and basic associated matrix manipulations + * and operations. + * + * See the \ref TutorialSparse "Sparse tutorial" + * + * \code + * #include + * \endcode + * + * This module depends on: Core. + */ + +// IWYU pragma: begin_exports +#include "src/SparseCore/SparseUtil.h" +#include "src/SparseCore/SparseMatrixBase.h" +#include "src/SparseCore/SparseAssign.h" +#include "src/SparseCore/CompressedStorage.h" +#include "src/SparseCore/AmbiVector.h" +#include "src/SparseCore/SparseCompressedBase.h" +#include "src/SparseCore/SparseMatrix.h" +#include "src/SparseCore/SparseMap.h" +#include "src/SparseCore/SparseVector.h" +#include "src/SparseCore/SparseRef.h" +#include "src/SparseCore/SparseCwiseUnaryOp.h" +#include "src/SparseCore/SparseCwiseBinaryOp.h" +#include "src/SparseCore/SparseTranspose.h" +#include "src/SparseCore/SparseBlock.h" +#include "src/SparseCore/SparseDot.h" +#include "src/SparseCore/SparseRedux.h" +#include "src/SparseCore/SparseView.h" +#include "src/SparseCore/SparseDiagonalProduct.h" +#include "src/SparseCore/ConservativeSparseSparseProduct.h" +#include "src/SparseCore/SparseSparseProductWithPruning.h" +#include "src/SparseCore/SparseProduct.h" +#include "src/SparseCore/SparseDenseProduct.h" +#include "src/SparseCore/SparseSelfAdjointView.h" +#include "src/SparseCore/SparseTriangularView.h" +#include "src/SparseCore/TriangularSolver.h" +#include "src/SparseCore/SparsePermutation.h" +#include "src/SparseCore/SparseFuzzy.h" +#include "src/SparseCore/SparseSolverBase.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_SPARSECORE_MODULE_H diff --git a/dae-cpp/Eigen/SparseLU b/dae-cpp/Eigen/SparseLU new file mode 100644 index 0000000..6faf130 --- /dev/null +++ b/dae-cpp/Eigen/SparseLU @@ -0,0 +1,50 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2012 Désiré Nuentsa-Wakam +// Copyright (C) 2012 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SPARSELU_MODULE_H +#define EIGEN_SPARSELU_MODULE_H + +#include "SparseCore" + +/** + * \defgroup SparseLU_Module SparseLU module + * This module defines a supernodal factorization of general sparse matrices. + * The code is fully optimized for supernode-panel updates with specialized kernels. + * Please, see the documentation of the SparseLU class for more details. + */ + +// Ordering interface +#include "OrderingMethods" + +#include "src/Core/util/DisableStupidWarnings.h" + +// IWYU pragma: begin_exports +#include "src/SparseLU/SparseLU_Structs.h" +#include "src/SparseLU/SparseLU_SupernodalMatrix.h" +#include "src/SparseLU/SparseLUImpl.h" +#include "src/SparseCore/SparseColEtree.h" +#include "src/SparseLU/SparseLU_Memory.h" +#include "src/SparseLU/SparseLU_heap_relax_snode.h" +#include "src/SparseLU/SparseLU_relax_snode.h" +#include "src/SparseLU/SparseLU_pivotL.h" +#include "src/SparseLU/SparseLU_panel_dfs.h" +#include "src/SparseLU/SparseLU_kernel_bmod.h" +#include "src/SparseLU/SparseLU_panel_bmod.h" +#include "src/SparseLU/SparseLU_column_dfs.h" +#include "src/SparseLU/SparseLU_column_bmod.h" +#include "src/SparseLU/SparseLU_copy_to_ucol.h" +#include "src/SparseLU/SparseLU_pruneL.h" +#include "src/SparseLU/SparseLU_Utils.h" +#include "src/SparseLU/SparseLU.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_SPARSELU_MODULE_H diff --git a/dae-cpp/Eigen/SparseQR b/dae-cpp/Eigen/SparseQR new file mode 100644 index 0000000..b4f1cad --- /dev/null +++ b/dae-cpp/Eigen/SparseQR @@ -0,0 +1,38 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SPARSEQR_MODULE_H +#define EIGEN_SPARSEQR_MODULE_H + +#include "SparseCore" +#include "OrderingMethods" +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup SparseQR_Module SparseQR module + * \brief Provides QR decomposition for sparse matrices + * + * This module provides a simplicial version of the left-looking Sparse QR decomposition. + * The columns of the input matrix should be reordered to limit the fill-in during the + * decomposition. Built-in methods (COLAMD, AMD) or external methods (METIS) can be used to this end. + * See the \link OrderingMethods_Module OrderingMethods\endlink module for the list + * of built-in and external ordering methods. + * + * \code + * #include + * \endcode + * + * + */ + +// IWYU pragma: begin_exports +#include "src/SparseCore/SparseColEtree.h" +#include "src/SparseQR/SparseQR.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif diff --git a/dae-cpp/Eigen/StdDeque b/dae-cpp/Eigen/StdDeque new file mode 100644 index 0000000..01e1d76 --- /dev/null +++ b/dae-cpp/Eigen/StdDeque @@ -0,0 +1,30 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// Copyright (C) 2009 Hauke Heibel +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_STDDEQUE_MODULE_H +#define EIGEN_STDDEQUE_MODULE_H + +#include "Core" +#include + +#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && \ + (EIGEN_MAX_STATIC_ALIGN_BYTES <= 16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ + +#define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) + +#else + +// IWYU pragma: begin_exports +#include "src/StlSupport/StdDeque.h" +// IWYU pragma: end_exports + +#endif + +#endif // EIGEN_STDDEQUE_MODULE_H diff --git a/dae-cpp/Eigen/StdList b/dae-cpp/Eigen/StdList new file mode 100644 index 0000000..1453c9f --- /dev/null +++ b/dae-cpp/Eigen/StdList @@ -0,0 +1,29 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Hauke Heibel +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_STDLIST_MODULE_H +#define EIGEN_STDLIST_MODULE_H + +#include "Core" +#include + +#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && \ + (EIGEN_MAX_STATIC_ALIGN_BYTES <= 16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ + +#define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) + +#else + +// IWYU pragma: begin_exports +#include "src/StlSupport/StdList.h" +// IWYU pragma: end_exports + +#endif + +#endif // EIGEN_STDLIST_MODULE_H diff --git a/dae-cpp/Eigen/StdVector b/dae-cpp/Eigen/StdVector new file mode 100644 index 0000000..711a654 --- /dev/null +++ b/dae-cpp/Eigen/StdVector @@ -0,0 +1,30 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// Copyright (C) 2009 Hauke Heibel +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_STDVECTOR_MODULE_H +#define EIGEN_STDVECTOR_MODULE_H + +#include "Core" +#include + +#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && \ + (EIGEN_MAX_STATIC_ALIGN_BYTES <= 16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ + +#define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...) + +#else + +// IWYU pragma: begin_exports +#include "src/StlSupport/StdVector.h" +// IWYU pragma: end_exports + +#endif + +#endif // EIGEN_STDVECTOR_MODULE_H diff --git a/dae-cpp/Eigen/SuperLUSupport b/dae-cpp/Eigen/SuperLUSupport new file mode 100644 index 0000000..79e2222 --- /dev/null +++ b/dae-cpp/Eigen/SuperLUSupport @@ -0,0 +1,70 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SUPERLUSUPPORT_MODULE_H +#define EIGEN_SUPERLUSUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +#ifdef EMPTY +#define EIGEN_EMPTY_WAS_ALREADY_DEFINED +#endif + +typedef int int_t; +#include +#include +#include + +// slu_util.h defines a preprocessor token named EMPTY which is really polluting, +// so we remove it in favor of a SUPERLU_EMPTY token. +// If EMPTY was already defined then we don't undef it. + +#if defined(EIGEN_EMPTY_WAS_ALREADY_DEFINED) +#undef EIGEN_EMPTY_WAS_ALREADY_DEFINED +#elif defined(EMPTY) +#undef EMPTY +#endif + +#define SUPERLU_EMPTY (-1) + +namespace Eigen { +struct SluMatrix; +} + +/** \ingroup Support_modules + * \defgroup SuperLUSupport_Module SuperLUSupport module + * + * This module provides an interface to the SuperLU library. + * It provides the following factorization class: + * - class SuperLU: a supernodal sequential LU factorization. + * - class SuperILU: a supernodal sequential incomplete LU factorization (to be used as a preconditioner for iterative + * methods). + * + * \warning This wrapper requires at least versions 4.0 of SuperLU. The 3.x versions are not supported. + * + * \warning When including this module, you have to use SUPERLU_EMPTY instead of EMPTY which is no longer defined + * because it is too polluting. + * + * \code + * #include + * \endcode + * + * In order to use this module, the superlu headers must be accessible from the include paths, and your binary must be + * linked to the superlu library and its dependencies. The dependencies depend on how superlu has been compiled. For a + * cmake based project, you can use our FindSuperLU.cmake module to help you in this task. + * + */ + +// IWYU pragma: begin_exports +#include "src/SuperLUSupport/SuperLUSupport.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_SUPERLUSUPPORT_MODULE_H diff --git a/dae-cpp/Eigen/ThreadPool b/dae-cpp/Eigen/ThreadPool new file mode 100644 index 0000000..febb187 --- /dev/null +++ b/dae-cpp/Eigen/ThreadPool @@ -0,0 +1,78 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2016 Benoit Steiner +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_THREADPOOL_MODULE_H +#define EIGEN_THREADPOOL_MODULE_H + +#include "Core" + +#include "src/Core/util/DisableStupidWarnings.h" + +/** \defgroup ThreadPool_Module ThreadPool Module + * + * This module provides 2 threadpool implementations + * - a simple reference implementation + * - a faster non blocking implementation + * + * \code + * #include + * \endcode + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// There are non-parenthesized calls to "max" in the header, +// which trigger a check in test/main.h causing compilation to fail. +// We work around the check here by removing the check for max in +// the case where we have to emulate thread_local. +#ifdef max +#undef max +#endif +#include + +#include "src/Core/util/Meta.h" +#include "src/Core/util/MaxSizeVector.h" + +#ifndef EIGEN_MUTEX +#define EIGEN_MUTEX std::mutex +#endif +#ifndef EIGEN_MUTEX_LOCK +#define EIGEN_MUTEX_LOCK std::unique_lock +#endif +#ifndef EIGEN_CONDVAR +#define EIGEN_CONDVAR std::condition_variable +#endif + +// IWYU pragma: begin_exports +#include "src/ThreadPool/ThreadLocal.h" +#include "src/ThreadPool/ThreadYield.h" +#include "src/ThreadPool/ThreadCancel.h" +#include "src/ThreadPool/EventCount.h" +#include "src/ThreadPool/RunQueue.h" +#include "src/ThreadPool/ThreadPoolInterface.h" +#include "src/ThreadPool/ThreadEnvironment.h" +#include "src/ThreadPool/Barrier.h" +#include "src/ThreadPool/NonBlockingThreadPool.h" +// IWYU pragma: end_exports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_CXX11_THREADPOOL_MODULE_H diff --git a/dae-cpp/Eigen/UmfPackSupport b/dae-cpp/Eigen/UmfPackSupport new file mode 100644 index 0000000..126344c --- /dev/null +++ b/dae-cpp/Eigen/UmfPackSupport @@ -0,0 +1,42 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_UMFPACKSUPPORT_MODULE_H +#define EIGEN_UMFPACKSUPPORT_MODULE_H + +#include "SparseCore" + +#include "src/Core/util/DisableStupidWarnings.h" + +extern "C" { +#include +} + +/** \ingroup Support_modules + * \defgroup UmfPackSupport_Module UmfPackSupport module + * + * This module provides an interface to the UmfPack library which is part of the suitesparse package. It provides the following factorization class: + * - class UmfPackLU: a multifrontal sequential LU factorization. + * + * \code + * #include + * \endcode + * + * In order to use this module, the umfpack headers must be accessible from the include paths, and your binary must be + * linked to the umfpack library and its dependencies. The dependencies depend on how umfpack has been compiled. For a + * cmake based project, you can use our FindUmfPack.cmake module to help you in this task. + * + */ + +// IWYU pragma: begin_exports +#include "src/UmfPackSupport/UmfPackSupport.h" +// IWYU pragma: endexports + +#include "src/Core/util/ReenableStupidWarnings.h" + +#endif // EIGEN_UMFPACKSUPPORT_MODULE_H diff --git a/dae-cpp/Eigen/commit-d3cd3126520f1e81aeb2abb5e5ae77bd322f8193 b/dae-cpp/Eigen/commit-d3cd3126520f1e81aeb2abb5e5ae77bd322f8193 new file mode 100644 index 0000000..e69de29 diff --git a/dae-cpp/Eigen/src/AccelerateSupport/AccelerateSupport.h b/dae-cpp/Eigen/src/AccelerateSupport/AccelerateSupport.h new file mode 100644 index 0000000..09967ff --- /dev/null +++ b/dae-cpp/Eigen/src/AccelerateSupport/AccelerateSupport.h @@ -0,0 +1,423 @@ +#ifndef EIGEN_ACCELERATESUPPORT_H +#define EIGEN_ACCELERATESUPPORT_H + +#include + +#include + +namespace Eigen { + +template +class AccelerateImpl; + +/** \ingroup AccelerateSupport_Module + * \class AccelerateLLT + * \brief A direct Cholesky (LLT) factorization and solver based on Accelerate + * + * \warning Only single and double precision real scalar types are supported by Accelerate + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ additional information about the matrix structure. Default is Lower. + * + * \sa \ref TutorialSparseSolverConcept, class AccelerateLLT + */ +template +using AccelerateLLT = AccelerateImpl; + +/** \ingroup AccelerateSupport_Module + * \class AccelerateLDLT + * \brief The default Cholesky (LDLT) factorization and solver based on Accelerate + * + * \warning Only single and double precision real scalar types are supported by Accelerate + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ additional information about the matrix structure. Default is Lower. + * + * \sa \ref TutorialSparseSolverConcept, class AccelerateLDLT + */ +template +using AccelerateLDLT = AccelerateImpl; + +/** \ingroup AccelerateSupport_Module + * \class AccelerateLDLTUnpivoted + * \brief A direct Cholesky-like LDL^T factorization and solver based on Accelerate with only 1x1 pivots and no pivoting + * + * \warning Only single and double precision real scalar types are supported by Accelerate + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ additional information about the matrix structure. Default is Lower. + * + * \sa \ref TutorialSparseSolverConcept, class AccelerateLDLTUnpivoted + */ +template +using AccelerateLDLTUnpivoted = AccelerateImpl; + +/** \ingroup AccelerateSupport_Module + * \class AccelerateLDLTSBK + * \brief A direct Cholesky (LDLT) factorization and solver based on Accelerate with Supernode Bunch-Kaufman and static + * pivoting + * + * \warning Only single and double precision real scalar types are supported by Accelerate + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ additional information about the matrix structure. Default is Lower. + * + * \sa \ref TutorialSparseSolverConcept, class AccelerateLDLTSBK + */ +template +using AccelerateLDLTSBK = AccelerateImpl; + +/** \ingroup AccelerateSupport_Module + * \class AccelerateLDLTTPP + * \brief A direct Cholesky (LDLT) factorization and solver based on Accelerate with full threshold partial pivoting + * + * \warning Only single and double precision real scalar types are supported by Accelerate + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ additional information about the matrix structure. Default is Lower. + * + * \sa \ref TutorialSparseSolverConcept, class AccelerateLDLTTPP + */ +template +using AccelerateLDLTTPP = AccelerateImpl; + +/** \ingroup AccelerateSupport_Module + * \class AccelerateQR + * \brief A QR factorization and solver based on Accelerate + * + * \warning Only single and double precision real scalar types are supported by Accelerate + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * + * \sa \ref TutorialSparseSolverConcept, class AccelerateQR + */ +template +using AccelerateQR = AccelerateImpl; + +/** \ingroup AccelerateSupport_Module + * \class AccelerateCholeskyAtA + * \brief A QR factorization and solver based on Accelerate without storing Q (equivalent to A^TA = R^T R) + * + * \warning Only single and double precision real scalar types are supported by Accelerate + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * + * \sa \ref TutorialSparseSolverConcept, class AccelerateCholeskyAtA + */ +template +using AccelerateCholeskyAtA = AccelerateImpl; + +namespace internal { +template +struct AccelFactorizationDeleter { + void operator()(T* sym) { + if (sym) { + SparseCleanup(*sym); + delete sym; + sym = nullptr; + } + } +}; + +template +struct SparseTypesTraitBase { + typedef DenseVecT AccelDenseVector; + typedef DenseMatT AccelDenseMatrix; + typedef SparseMatT AccelSparseMatrix; + + typedef SparseOpaqueSymbolicFactorization SymbolicFactorization; + typedef NumFactT NumericFactorization; + + typedef AccelFactorizationDeleter SymbolicFactorizationDeleter; + typedef AccelFactorizationDeleter NumericFactorizationDeleter; +}; + +template +struct SparseTypesTrait {}; + +template <> +struct SparseTypesTrait : SparseTypesTraitBase {}; + +template <> +struct SparseTypesTrait + : SparseTypesTraitBase { +}; + +} // end namespace internal + +template +class AccelerateImpl : public SparseSolverBase > { + protected: + using Base = SparseSolverBase; + using Base::derived; + using Base::m_isInitialized; + + public: + using Base::_solve_impl; + + typedef MatrixType_ MatrixType; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::StorageIndex StorageIndex; + enum { ColsAtCompileTime = Dynamic, MaxColsAtCompileTime = Dynamic }; + enum { UpLo = UpLo_ }; + + using AccelDenseVector = typename internal::SparseTypesTrait::AccelDenseVector; + using AccelDenseMatrix = typename internal::SparseTypesTrait::AccelDenseMatrix; + using AccelSparseMatrix = typename internal::SparseTypesTrait::AccelSparseMatrix; + using SymbolicFactorization = typename internal::SparseTypesTrait::SymbolicFactorization; + using NumericFactorization = typename internal::SparseTypesTrait::NumericFactorization; + using SymbolicFactorizationDeleter = typename internal::SparseTypesTrait::SymbolicFactorizationDeleter; + using NumericFactorizationDeleter = typename internal::SparseTypesTrait::NumericFactorizationDeleter; + + AccelerateImpl() { + m_isInitialized = false; + + auto check_flag_set = [](int value, int flag) { return ((value & flag) == flag); }; + + if (check_flag_set(UpLo_, Symmetric)) { + m_sparseKind = SparseSymmetric; + m_triType = (UpLo_ & Lower) ? SparseLowerTriangle : SparseUpperTriangle; + } else if (check_flag_set(UpLo_, UnitLower)) { + m_sparseKind = SparseUnitTriangular; + m_triType = SparseLowerTriangle; + } else if (check_flag_set(UpLo_, UnitUpper)) { + m_sparseKind = SparseUnitTriangular; + m_triType = SparseUpperTriangle; + } else if (check_flag_set(UpLo_, StrictlyLower)) { + m_sparseKind = SparseTriangular; + m_triType = SparseLowerTriangle; + } else if (check_flag_set(UpLo_, StrictlyUpper)) { + m_sparseKind = SparseTriangular; + m_triType = SparseUpperTriangle; + } else if (check_flag_set(UpLo_, Lower)) { + m_sparseKind = SparseTriangular; + m_triType = SparseLowerTriangle; + } else if (check_flag_set(UpLo_, Upper)) { + m_sparseKind = SparseTriangular; + m_triType = SparseUpperTriangle; + } else { + m_sparseKind = SparseOrdinary; + m_triType = (UpLo_ & Lower) ? SparseLowerTriangle : SparseUpperTriangle; + } + + m_order = SparseOrderDefault; + } + + explicit AccelerateImpl(const MatrixType& matrix) : AccelerateImpl() { compute(matrix); } + + ~AccelerateImpl() {} + + inline Index cols() const { return m_nCols; } + inline Index rows() const { return m_nRows; } + + ComputationInfo info() const { + eigen_assert(m_isInitialized && "Decomposition is not initialized."); + return m_info; + } + + void analyzePattern(const MatrixType& matrix); + + void factorize(const MatrixType& matrix); + + void compute(const MatrixType& matrix); + + template + void _solve_impl(const MatrixBase& b, MatrixBase& dest) const; + + /** Sets the ordering algorithm to use. */ + void setOrder(SparseOrder_t order) { m_order = order; } + + private: + template + void buildAccelSparseMatrix(const SparseMatrix& a, AccelSparseMatrix& A, std::vector& columnStarts) { + const Index nColumnsStarts = a.cols() + 1; + + columnStarts.resize(nColumnsStarts); + + for (Index i = 0; i < nColumnsStarts; i++) columnStarts[i] = a.outerIndexPtr()[i]; + + SparseAttributes_t attributes{}; + attributes.transpose = false; + attributes.triangle = m_triType; + attributes.kind = m_sparseKind; + + SparseMatrixStructure structure{}; + structure.attributes = attributes; + structure.rowCount = static_cast(a.rows()); + structure.columnCount = static_cast(a.cols()); + structure.blockSize = 1; + structure.columnStarts = columnStarts.data(); + structure.rowIndices = const_cast(a.innerIndexPtr()); + + A.structure = structure; + A.data = const_cast(a.valuePtr()); + } + + void doAnalysis(AccelSparseMatrix& A) { + m_numericFactorization.reset(nullptr); + + SparseSymbolicFactorOptions opts{}; + opts.control = SparseDefaultControl; + opts.orderMethod = m_order; + opts.order = nullptr; + opts.ignoreRowsAndColumns = nullptr; + opts.malloc = malloc; + opts.free = free; + opts.reportError = nullptr; + + m_symbolicFactorization.reset(new SymbolicFactorization(SparseFactor(Solver_, A.structure, opts))); + + SparseStatus_t status = m_symbolicFactorization->status; + + updateInfoStatus(status); + + if (status != SparseStatusOK) m_symbolicFactorization.reset(nullptr); + } + + void doFactorization(AccelSparseMatrix& A) { + SparseStatus_t status = SparseStatusReleased; + + if (m_symbolicFactorization) { + m_numericFactorization.reset(new NumericFactorization(SparseFactor(*m_symbolicFactorization, A))); + + status = m_numericFactorization->status; + + if (status != SparseStatusOK) m_numericFactorization.reset(nullptr); + } + + updateInfoStatus(status); + } + + protected: + void updateInfoStatus(SparseStatus_t status) const { + switch (status) { + case SparseStatusOK: + m_info = Success; + break; + case SparseFactorizationFailed: + case SparseMatrixIsSingular: + m_info = NumericalIssue; + break; + case SparseInternalError: + case SparseParameterError: + case SparseStatusReleased: + default: + m_info = InvalidInput; + break; + } + } + + mutable ComputationInfo m_info; + Index m_nRows, m_nCols; + std::unique_ptr m_symbolicFactorization; + std::unique_ptr m_numericFactorization; + SparseKind_t m_sparseKind; + SparseTriangle_t m_triType; + SparseOrder_t m_order; +}; + +/** Computes the symbolic and numeric decomposition of matrix \a a */ +template +void AccelerateImpl::compute(const MatrixType& a) { + if (EnforceSquare_) eigen_assert(a.rows() == a.cols()); + + m_nRows = a.rows(); + m_nCols = a.cols(); + + AccelSparseMatrix A{}; + std::vector columnStarts; + + buildAccelSparseMatrix(a, A, columnStarts); + + doAnalysis(A); + + if (m_symbolicFactorization) doFactorization(A); + + m_isInitialized = true; +} + +/** Performs a symbolic decomposition on the sparsity pattern of matrix \a a. + * + * This function is particularly useful when solving for several problems having the same structure. + * + * \sa factorize() + */ +template +void AccelerateImpl::analyzePattern(const MatrixType& a) { + if (EnforceSquare_) eigen_assert(a.rows() == a.cols()); + + m_nRows = a.rows(); + m_nCols = a.cols(); + + AccelSparseMatrix A{}; + std::vector columnStarts; + + buildAccelSparseMatrix(a, A, columnStarts); + + doAnalysis(A); + + m_isInitialized = true; +} + +/** Performs a numeric decomposition of matrix \a a. + * + * The given matrix must have the same sparsity pattern as the matrix on which the symbolic decomposition has been + * performed. + * + * \sa analyzePattern() + */ +template +void AccelerateImpl::factorize(const MatrixType& a) { + eigen_assert(m_symbolicFactorization && "You must first call analyzePattern()"); + eigen_assert(m_nRows == a.rows() && m_nCols == a.cols()); + + if (EnforceSquare_) eigen_assert(a.rows() == a.cols()); + + AccelSparseMatrix A{}; + std::vector columnStarts; + + buildAccelSparseMatrix(a, A, columnStarts); + + doFactorization(A); +} + +template +template +void AccelerateImpl::_solve_impl(const MatrixBase& b, + MatrixBase& x) const { + if (!m_numericFactorization) { + m_info = InvalidInput; + return; + } + + eigen_assert(m_nRows == b.rows()); + eigen_assert(((b.cols() == 1) || b.outerStride() == b.rows())); + + SparseStatus_t status = SparseStatusOK; + + Scalar* b_ptr = const_cast(b.derived().data()); + Scalar* x_ptr = const_cast(x.derived().data()); + + AccelDenseMatrix xmat{}; + xmat.attributes = SparseAttributes_t(); + xmat.columnCount = static_cast(x.cols()); + xmat.rowCount = static_cast(x.rows()); + xmat.columnStride = xmat.rowCount; + xmat.data = x_ptr; + + AccelDenseMatrix bmat{}; + bmat.attributes = SparseAttributes_t(); + bmat.columnCount = static_cast(b.cols()); + bmat.rowCount = static_cast(b.rows()); + bmat.columnStride = bmat.rowCount; + bmat.data = b_ptr; + + SparseSolve(*m_numericFactorization, bmat, xmat); + + updateInfoStatus(status); +} + +} // end namespace Eigen + +#endif // EIGEN_ACCELERATESUPPORT_H diff --git a/dae-cpp/Eigen/src/AccelerateSupport/InternalHeaderCheck.h b/dae-cpp/Eigen/src/AccelerateSupport/InternalHeaderCheck.h new file mode 100644 index 0000000..69bcff5 --- /dev/null +++ b/dae-cpp/Eigen/src/AccelerateSupport/InternalHeaderCheck.h @@ -0,0 +1,3 @@ +#ifndef EIGEN_ACCELERATESUPPORT_MODULE_H +#error "Please include Eigen/AccelerateSupport instead of including headers inside the src directory directly." +#endif diff --git a/dae-cpp/Eigen/src/Cholesky/InternalHeaderCheck.h b/dae-cpp/Eigen/src/Cholesky/InternalHeaderCheck.h new file mode 100644 index 0000000..5de2b21 --- /dev/null +++ b/dae-cpp/Eigen/src/Cholesky/InternalHeaderCheck.h @@ -0,0 +1,3 @@ +#ifndef EIGEN_CHOLESKY_MODULE_H +#error "Please include Eigen/Cholesky instead of including headers inside the src directory directly." +#endif diff --git a/dae-cpp/Eigen/src/Cholesky/LDLT.h b/dae-cpp/Eigen/src/Cholesky/LDLT.h new file mode 100644 index 0000000..5d52ab2 --- /dev/null +++ b/dae-cpp/Eigen/src/Cholesky/LDLT.h @@ -0,0 +1,649 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2011 Gael Guennebaud +// Copyright (C) 2009 Keir Mierle +// Copyright (C) 2009 Benoit Jacob +// Copyright (C) 2011 Timothy E. Holy +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_LDLT_H +#define EIGEN_LDLT_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits > : traits { + typedef MatrixXpr XprKind; + typedef SolverStorage StorageKind; + typedef int StorageIndex; + enum { Flags = 0 }; +}; + +template +struct LDLT_Traits; + +// PositiveSemiDef means positive semi-definite and non-zero; same for NegativeSemiDef +enum SignMatrix { PositiveSemiDef, NegativeSemiDef, ZeroSign, Indefinite }; +} // namespace internal + +/** \ingroup Cholesky_Module + * + * \class LDLT + * + * \brief Robust Cholesky decomposition of a matrix with pivoting + * + * \tparam MatrixType_ the type of the matrix of which to compute the LDL^T Cholesky decomposition + * \tparam UpLo_ the triangular part that will be used for the decomposition: Lower (default) or Upper. + * The other triangular part won't be read. + * + * Perform a robust Cholesky decomposition of a positive semidefinite or negative semidefinite + * matrix \f$ A \f$ such that \f$ A = P^TLDL^*P \f$, where P is a permutation matrix, L + * is lower triangular with a unit diagonal and D is a diagonal matrix. + * + * The decomposition uses pivoting to ensure stability, so that D will have + * zeros in the bottom right rank(A) - n submatrix. Avoiding the square root + * on D also stabilizes the computation. + * + * Remember that Cholesky decompositions are not rank-revealing. Also, do not use a Cholesky + * decomposition to determine whether a system of equations has a solution. + * + * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. + * + * \sa MatrixBase::ldlt(), SelfAdjointView::ldlt(), class LLT + */ +template +class LDLT : public SolverBase > { + public: + typedef MatrixType_ MatrixType; + typedef SolverBase Base; + friend class SolverBase; + + EIGEN_GENERIC_PUBLIC_INTERFACE(LDLT) + enum { + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + UpLo = UpLo_ + }; + typedef Matrix TmpMatrixType; + + typedef Transpositions TranspositionType; + typedef PermutationMatrix PermutationType; + + typedef internal::LDLT_Traits Traits; + + /** \brief Default Constructor. + * + * The default constructor is useful in cases in which the user intends to + * perform decompositions via LDLT::compute(const MatrixType&). + */ + LDLT() : m_matrix(), m_transpositions(), m_sign(internal::ZeroSign), m_isInitialized(false) {} + + /** \brief Default Constructor with memory preallocation + * + * Like the default constructor but with preallocation of the internal data + * according to the specified problem \a size. + * \sa LDLT() + */ + explicit LDLT(Index size) + : m_matrix(size, size), + m_transpositions(size), + m_temporary(size), + m_sign(internal::ZeroSign), + m_isInitialized(false) {} + + /** \brief Constructor with decomposition + * + * This calculates the decomposition for the input \a matrix. + * + * \sa LDLT(Index size) + */ + template + explicit LDLT(const EigenBase& matrix) + : m_matrix(matrix.rows(), matrix.cols()), + m_transpositions(matrix.rows()), + m_temporary(matrix.rows()), + m_sign(internal::ZeroSign), + m_isInitialized(false) { + compute(matrix.derived()); + } + + /** \brief Constructs a LDLT factorization from a given matrix + * + * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c + * MatrixType is a Eigen::Ref. + * + * \sa LDLT(const EigenBase&) + */ + template + explicit LDLT(EigenBase& matrix) + : m_matrix(matrix.derived()), + m_transpositions(matrix.rows()), + m_temporary(matrix.rows()), + m_sign(internal::ZeroSign), + m_isInitialized(false) { + compute(matrix.derived()); + } + + /** Clear any existing decomposition + * \sa rankUpdate(w,sigma) + */ + void setZero() { m_isInitialized = false; } + + /** \returns a view of the upper triangular matrix U */ + inline typename Traits::MatrixU matrixU() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return Traits::getU(m_matrix); + } + + /** \returns a view of the lower triangular matrix L */ + inline typename Traits::MatrixL matrixL() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return Traits::getL(m_matrix); + } + + /** \returns the permutation matrix P as a transposition sequence. + */ + inline const TranspositionType& transpositionsP() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return m_transpositions; + } + + /** \returns the coefficients of the diagonal matrix D */ + inline Diagonal vectorD() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return m_matrix.diagonal(); + } + + /** \returns true if the matrix is positive (semidefinite) */ + inline bool isPositive() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return m_sign == internal::PositiveSemiDef || m_sign == internal::ZeroSign; + } + + /** \returns true if the matrix is negative (semidefinite) */ + inline bool isNegative(void) const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return m_sign == internal::NegativeSemiDef || m_sign == internal::ZeroSign; + } + +#ifdef EIGEN_PARSED_BY_DOXYGEN + /** \returns a solution x of \f$ A x = b \f$ using the current decomposition of A. + * + * This function also supports in-place solves using the syntax x = decompositionObject.solve(x) . + * + * \note_about_checking_solutions + * + * More precisely, this method solves \f$ A x = b \f$ using the decomposition \f$ A = P^T L D L^* P \f$ + * by solving the systems \f$ P^T y_1 = b \f$, \f$ L y_2 = y_1 \f$, \f$ D y_3 = y_2 \f$, + * \f$ L^* y_4 = y_3 \f$ and \f$ P x = y_4 \f$ in succession. If the matrix \f$ A \f$ is singular, then + * \f$ D \f$ will also be singular (all the other matrices are invertible). In that case, the + * least-square solution of \f$ D y_3 = y_2 \f$ is computed. This does not mean that this function + * computes the least-square solution of \f$ A x = b \f$ if \f$ A \f$ is singular. + * + * \sa MatrixBase::ldlt(), SelfAdjointView::ldlt() + */ + template + inline const Solve solve(const MatrixBase& b) const; +#endif + + template + bool solveInPlace(MatrixBase& bAndX) const; + + template + LDLT& compute(const EigenBase& matrix); + + /** \returns an estimate of the reciprocal condition number of the matrix of + * which \c *this is the LDLT decomposition. + */ + RealScalar rcond() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return internal::rcond_estimate_helper(m_l1_norm, *this); + } + + template + LDLT& rankUpdate(const MatrixBase& w, const RealScalar& alpha = 1); + + /** \returns the internal LDLT decomposition matrix + * + * TODO: document the storage layout + */ + inline const MatrixType& matrixLDLT() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return m_matrix; + } + + MatrixType reconstructedMatrix() const; + + /** \returns the adjoint of \c *this, that is, a const reference to the decomposition itself as the underlying matrix + * is self-adjoint. + * + * This method is provided for compatibility with other matrix decompositions, thus enabling generic code such as: + * \code x = decomposition.adjoint().solve(b) \endcode + */ + const LDLT& adjoint() const { return *this; } + + EIGEN_DEVICE_FUNC inline EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); } + EIGEN_DEVICE_FUNC inline EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); } + + /** \brief Reports whether previous computation was successful. + * + * \returns \c Success if computation was successful, + * \c NumericalIssue if the factorization failed because of a zero pivot. + */ + ComputationInfo info() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + return m_info; + } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + template + void _solve_impl(const RhsType& rhs, DstType& dst) const; + + template + void _solve_impl_transposed(const RhsType& rhs, DstType& dst) const; +#endif + + protected: + EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) + + /** \internal + * Used to compute and store the Cholesky decomposition A = L D L^* = U^* D U. + * The strict upper part is used during the decomposition, the strict lower + * part correspond to the coefficients of L (its diagonal is equal to 1 and + * is not stored), and the diagonal entries correspond to D. + */ + MatrixType m_matrix; + RealScalar m_l1_norm; + TranspositionType m_transpositions; + TmpMatrixType m_temporary; + internal::SignMatrix m_sign; + bool m_isInitialized; + ComputationInfo m_info; +}; + +namespace internal { + +template +struct ldlt_inplace; + +template <> +struct ldlt_inplace { + template + static bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, SignMatrix& sign) { + using std::abs; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + typedef typename TranspositionType::StorageIndex IndexType; + eigen_assert(mat.rows() == mat.cols()); + const Index size = mat.rows(); + bool found_zero_pivot = false; + bool ret = true; + + if (size <= 1) { + transpositions.setIdentity(); + if (size == 0) + sign = ZeroSign; + else if (numext::real(mat.coeff(0, 0)) > static_cast(0)) + sign = PositiveSemiDef; + else if (numext::real(mat.coeff(0, 0)) < static_cast(0)) + sign = NegativeSemiDef; + else + sign = ZeroSign; + return true; + } + + for (Index k = 0; k < size; ++k) { + // Find largest diagonal element + Index index_of_biggest_in_corner; + mat.diagonal().tail(size - k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner); + index_of_biggest_in_corner += k; + + transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner); + if (k != index_of_biggest_in_corner) { + // apply the transposition while taking care to consider only + // the lower triangular part + Index s = size - index_of_biggest_in_corner - 1; // trailing size after the biggest element + mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k)); + mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s)); + std::swap(mat.coeffRef(k, k), mat.coeffRef(index_of_biggest_in_corner, index_of_biggest_in_corner)); + for (Index i = k + 1; i < index_of_biggest_in_corner; ++i) { + Scalar tmp = mat.coeffRef(i, k); + mat.coeffRef(i, k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner, i)); + mat.coeffRef(index_of_biggest_in_corner, i) = numext::conj(tmp); + } + if (NumTraits::IsComplex) + mat.coeffRef(index_of_biggest_in_corner, k) = numext::conj(mat.coeff(index_of_biggest_in_corner, k)); + } + + // partition the matrix: + // A00 | - | - + // lu = A10 | A11 | - + // A20 | A21 | A22 + Index rs = size - k - 1; + Block A21(mat, k + 1, k, rs, 1); + Block A10(mat, k, 0, 1, k); + Block A20(mat, k + 1, 0, rs, k); + + if (k > 0) { + temp.head(k) = mat.diagonal().real().head(k).asDiagonal() * A10.adjoint(); + mat.coeffRef(k, k) -= (A10 * temp.head(k)).value(); + if (rs > 0) A21.noalias() -= A20 * temp.head(k); + } + + // In some previous versions of Eigen (e.g., 3.2.1), the scaling was omitted if the pivot + // was smaller than the cutoff value. However, since LDLT is not rank-revealing + // we should only make sure that we do not introduce INF or NaN values. + // Remark that LAPACK also uses 0 as the cutoff value. + RealScalar realAkk = numext::real(mat.coeffRef(k, k)); + bool pivot_is_valid = (abs(realAkk) > RealScalar(0)); + + if (k == 0 && !pivot_is_valid) { + // The entire diagonal is zero, there is nothing more to do + // except filling the transpositions, and checking whether the matrix is zero. + sign = ZeroSign; + for (Index j = 0; j < size; ++j) { + transpositions.coeffRef(j) = IndexType(j); + ret = ret && (mat.col(j).tail(size - j - 1).array() == Scalar(0)).all(); + } + return ret; + } + + if ((rs > 0) && pivot_is_valid) + A21 /= realAkk; + else if (rs > 0) + ret = ret && (A21.array() == Scalar(0)).all(); + + if (found_zero_pivot && pivot_is_valid) + ret = false; // factorization failed + else if (!pivot_is_valid) + found_zero_pivot = true; + + if (sign == PositiveSemiDef) { + if (realAkk < static_cast(0)) sign = Indefinite; + } else if (sign == NegativeSemiDef) { + if (realAkk > static_cast(0)) sign = Indefinite; + } else if (sign == ZeroSign) { + if (realAkk > static_cast(0)) + sign = PositiveSemiDef; + else if (realAkk < static_cast(0)) + sign = NegativeSemiDef; + } + } + + return ret; + } + + // Reference for the algorithm: Davis and Hager, "Multiple Rank + // Modifications of a Sparse Cholesky Factorization" (Algorithm 1) + // Trivial rearrangements of their computations (Timothy E. Holy) + // allow their algorithm to work for rank-1 updates even if the + // original matrix is not of full rank. + // Here only rank-1 updates are implemented, to reduce the + // requirement for intermediate storage and improve accuracy + template + static bool updateInPlace(MatrixType& mat, MatrixBase& w, + const typename MatrixType::RealScalar& sigma = 1) { + using numext::isfinite; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + + const Index size = mat.rows(); + eigen_assert(mat.cols() == size && w.size() == size); + + RealScalar alpha = 1; + + // Apply the update + for (Index j = 0; j < size; j++) { + // Check for termination due to an original decomposition of low-rank + if (!(isfinite)(alpha)) break; + + // Update the diagonal terms + RealScalar dj = numext::real(mat.coeff(j, j)); + Scalar wj = w.coeff(j); + RealScalar swj2 = sigma * numext::abs2(wj); + RealScalar gamma = dj * alpha + swj2; + + mat.coeffRef(j, j) += swj2 / alpha; + alpha += swj2 / dj; + + // Update the terms of L + Index rs = size - j - 1; + w.tail(rs) -= wj * mat.col(j).tail(rs); + if (!numext::is_exactly_zero(gamma)) mat.col(j).tail(rs) += (sigma * numext::conj(wj) / gamma) * w.tail(rs); + } + return true; + } + + template + static bool update(MatrixType& mat, const TranspositionType& transpositions, Workspace& tmp, const WType& w, + const typename MatrixType::RealScalar& sigma = 1) { + // Apply the permutation to the input w + tmp = transpositions * w; + + return ldlt_inplace::updateInPlace(mat, tmp, sigma); + } +}; + +template <> +struct ldlt_inplace { + template + static EIGEN_STRONG_INLINE bool unblocked(MatrixType& mat, TranspositionType& transpositions, Workspace& temp, + SignMatrix& sign) { + Transpose matt(mat); + return ldlt_inplace::unblocked(matt, transpositions, temp, sign); + } + + template + static EIGEN_STRONG_INLINE bool update(MatrixType& mat, TranspositionType& transpositions, Workspace& tmp, WType& w, + const typename MatrixType::RealScalar& sigma = 1) { + Transpose matt(mat); + return ldlt_inplace::update(matt, transpositions, tmp, w.conjugate(), sigma); + } +}; + +template +struct LDLT_Traits { + typedef const TriangularView MatrixL; + typedef const TriangularView MatrixU; + static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); } + static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); } +}; + +template +struct LDLT_Traits { + typedef const TriangularView MatrixL; + typedef const TriangularView MatrixU; + static inline MatrixL getL(const MatrixType& m) { return MatrixL(m.adjoint()); } + static inline MatrixU getU(const MatrixType& m) { return MatrixU(m); } +}; + +} // end namespace internal + +/** Compute / recompute the LDLT decomposition A = L D L^* = U^* D U of \a matrix + */ +template +template +LDLT& LDLT::compute(const EigenBase& a) { + eigen_assert(a.rows() == a.cols()); + const Index size = a.rows(); + + m_matrix = a.derived(); + + // Compute matrix L1 norm = max abs column sum. + m_l1_norm = RealScalar(0); + // TODO move this code to SelfAdjointView + for (Index col = 0; col < size; ++col) { + RealScalar abs_col_sum; + if (UpLo_ == Lower) + abs_col_sum = + m_matrix.col(col).tail(size - col).template lpNorm<1>() + m_matrix.row(col).head(col).template lpNorm<1>(); + else + abs_col_sum = + m_matrix.col(col).head(col).template lpNorm<1>() + m_matrix.row(col).tail(size - col).template lpNorm<1>(); + if (abs_col_sum > m_l1_norm) m_l1_norm = abs_col_sum; + } + + m_transpositions.resize(size); + m_isInitialized = false; + m_temporary.resize(size); + m_sign = internal::ZeroSign; + + m_info = internal::ldlt_inplace::unblocked(m_matrix, m_transpositions, m_temporary, m_sign) ? Success + : NumericalIssue; + + m_isInitialized = true; + return *this; +} + +/** Update the LDLT decomposition: given A = L D L^T, efficiently compute the decomposition of A + sigma w w^T. + * \param w a vector to be incorporated into the decomposition. + * \param sigma a scalar, +1 for updates and -1 for "downdates," which correspond to removing previously-added column + * vectors. Optional; default value is +1. \sa setZero() + */ +template +template +LDLT& LDLT::rankUpdate( + const MatrixBase& w, const typename LDLT::RealScalar& sigma) { + typedef typename TranspositionType::StorageIndex IndexType; + const Index size = w.rows(); + if (m_isInitialized) { + eigen_assert(m_matrix.rows() == size); + } else { + m_matrix.resize(size, size); + m_matrix.setZero(); + m_transpositions.resize(size); + for (Index i = 0; i < size; i++) m_transpositions.coeffRef(i) = IndexType(i); + m_temporary.resize(size); + m_sign = sigma >= 0 ? internal::PositiveSemiDef : internal::NegativeSemiDef; + m_isInitialized = true; + } + + internal::ldlt_inplace::update(m_matrix, m_transpositions, m_temporary, w, sigma); + + return *this; +} + +#ifndef EIGEN_PARSED_BY_DOXYGEN +template +template +void LDLT::_solve_impl(const RhsType& rhs, DstType& dst) const { + _solve_impl_transposed(rhs, dst); +} + +template +template +void LDLT::_solve_impl_transposed(const RhsType& rhs, DstType& dst) const { + // dst = P b + dst = m_transpositions * rhs; + + // dst = L^-1 (P b) + // dst = L^-*T (P b) + matrixL().template conjugateIf().solveInPlace(dst); + + // dst = D^-* (L^-1 P b) + // dst = D^-1 (L^-*T P b) + // more precisely, use pseudo-inverse of D (see bug 241) + using std::abs; + const typename Diagonal::RealReturnType vecD(vectorD()); + // In some previous versions, tolerance was set to the max of 1/highest (or rather numeric_limits::min()) + // and the maximal diagonal entry * epsilon as motivated by LAPACK's xGELSS: + // RealScalar tolerance = numext::maxi(vecD.array().abs().maxCoeff() * NumTraits::epsilon(),RealScalar(1) + // / NumTraits::highest()); However, LDLT is not rank revealing, and so adjusting the tolerance wrt to the + // highest diagonal element is not well justified and leads to numerical issues in some cases. Moreover, Lapack's + // xSYTRS routines use 0 for the tolerance. Using numeric_limits::min() gives us more robustness to denormals. + RealScalar tolerance = (std::numeric_limits::min)(); + for (Index i = 0; i < vecD.size(); ++i) { + if (abs(vecD(i)) > tolerance) + dst.row(i) /= vecD(i); + else + dst.row(i).setZero(); + } + + // dst = L^-* (D^-* L^-1 P b) + // dst = L^-T (D^-1 L^-*T P b) + matrixL().transpose().template conjugateIf().solveInPlace(dst); + + // dst = P^T (L^-* D^-* L^-1 P b) = A^-1 b + // dst = P^-T (L^-T D^-1 L^-*T P b) = A^-1 b + dst = m_transpositions.transpose() * dst; +} +#endif + +/** \internal use x = ldlt_object.solve(x); + * + * This is the \em in-place version of solve(). + * + * \param bAndX represents both the right-hand side matrix b and result x. + * + * \returns true always! If you need to check for existence of solutions, use another decomposition like LU, QR, or SVD. + * + * This version avoids a copy when the right hand side matrix b is not + * needed anymore. + * + * \sa LDLT::solve(), MatrixBase::ldlt() + */ +template +template +bool LDLT::solveInPlace(MatrixBase& bAndX) const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + eigen_assert(m_matrix.rows() == bAndX.rows()); + + bAndX = this->solve(bAndX); + + return true; +} + +/** \returns the matrix represented by the decomposition, + * i.e., it returns the product: P^T L D L^* P. + * This function is provided for debug purpose. */ +template +MatrixType LDLT::reconstructedMatrix() const { + eigen_assert(m_isInitialized && "LDLT is not initialized."); + const Index size = m_matrix.rows(); + MatrixType res(size, size); + + // P + res.setIdentity(); + res = transpositionsP() * res; + // L^* P + res = matrixU() * res; + // D(L^*P) + res = vectorD().real().asDiagonal() * res; + // L(DL^*P) + res = matrixL() * res; + // P^T (LDL^*P) + res = transpositionsP().transpose() * res; + + return res; +} + +/** \cholesky_module + * \returns the Cholesky decomposition with full pivoting without square root of \c *this + * \sa MatrixBase::ldlt() + */ +template +inline const LDLT::PlainObject, UpLo> +SelfAdjointView::ldlt() const { + return LDLT(m_matrix); +} + +/** \cholesky_module + * \returns the Cholesky decomposition with full pivoting without square root of \c *this + * \sa SelfAdjointView::ldlt() + */ +template +inline const LDLT::PlainObject> MatrixBase::ldlt() const { + return LDLT(derived()); +} + +} // end namespace Eigen + +#endif // EIGEN_LDLT_H diff --git a/dae-cpp/Eigen/src/Cholesky/LLT.h b/dae-cpp/Eigen/src/Cholesky/LLT.h new file mode 100644 index 0000000..01b4476 --- /dev/null +++ b/dae-cpp/Eigen/src/Cholesky/LLT.h @@ -0,0 +1,514 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_LLT_H +#define EIGEN_LLT_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +struct traits > : traits { + typedef MatrixXpr XprKind; + typedef SolverStorage StorageKind; + typedef int StorageIndex; + enum { Flags = 0 }; +}; + +template +struct LLT_Traits; +} // namespace internal + +/** \ingroup Cholesky_Module + * + * \class LLT + * + * \brief Standard Cholesky decomposition (LL^T) of a matrix and associated features + * + * \tparam MatrixType_ the type of the matrix of which we are computing the LL^T Cholesky decomposition + * \tparam UpLo_ the triangular part that will be used for the decomposition: Lower (default) or Upper. + * The other triangular part won't be read. + * + * This class performs a LL^T Cholesky decomposition of a symmetric, positive definite + * matrix A such that A = LL^* = U^*U, where L is lower triangular. + * + * While the Cholesky decomposition is particularly useful to solve selfadjoint problems like D^*D x = b, + * for that purpose, we recommend the Cholesky decomposition without square root which is more stable + * and even faster. Nevertheless, this standard Cholesky decomposition remains useful in many other + * situations like generalised eigen problems with hermitian matrices. + * + * Remember that Cholesky decompositions are not rank-revealing. This LLT decomposition is only stable on positive + * definite matrices, use LDLT instead for the semidefinite case. Also, do not use a Cholesky decomposition to determine + * whether a system of equations has a solution. + * + * Example: \include LLT_example.cpp + * Output: \verbinclude LLT_example.out + * + * \b Performance: for best performance, it is recommended to use a column-major storage format + * with the Lower triangular part (the default), or, equivalently, a row-major storage format + * with the Upper triangular part. Otherwise, you might get a 20% slowdown for the full factorization + * step, and rank-updates can be up to 3 times slower. + * + * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism. + * + * Note that during the decomposition, only the lower (or upper, as defined by UpLo_) triangular part of A is + * considered. Therefore, the strict lower part does not have to store correct values. + * + * \sa MatrixBase::llt(), SelfAdjointView::llt(), class LDLT + */ +template +class LLT : public SolverBase > { + public: + typedef MatrixType_ MatrixType; + typedef SolverBase Base; + friend class SolverBase; + + EIGEN_GENERIC_PUBLIC_INTERFACE(LLT) + enum { MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }; + + enum { PacketSize = internal::packet_traits::size, AlignmentMask = int(PacketSize) - 1, UpLo = UpLo_ }; + + typedef internal::LLT_Traits Traits; + + /** + * \brief Default Constructor. + * + * The default constructor is useful in cases in which the user intends to + * perform decompositions via LLT::compute(const MatrixType&). + */ + LLT() : m_matrix(), m_isInitialized(false) {} + + /** \brief Default Constructor with memory preallocation + * + * Like the default constructor but with preallocation of the internal data + * according to the specified problem \a size. + * \sa LLT() + */ + explicit LLT(Index size) : m_matrix(size, size), m_isInitialized(false) {} + + template + explicit LLT(const EigenBase& matrix) : m_matrix(matrix.rows(), matrix.cols()), m_isInitialized(false) { + compute(matrix.derived()); + } + + /** \brief Constructs a LLT factorization from a given matrix + * + * This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when + * \c MatrixType is a Eigen::Ref. + * + * \sa LLT(const EigenBase&) + */ + template + explicit LLT(EigenBase& matrix) : m_matrix(matrix.derived()), m_isInitialized(false) { + compute(matrix.derived()); + } + + /** \returns a view of the upper triangular matrix U */ + inline typename Traits::MatrixU matrixU() const { + eigen_assert(m_isInitialized && "LLT is not initialized."); + return Traits::getU(m_matrix); + } + + /** \returns a view of the lower triangular matrix L */ + inline typename Traits::MatrixL matrixL() const { + eigen_assert(m_isInitialized && "LLT is not initialized."); + return Traits::getL(m_matrix); + } + +#ifdef EIGEN_PARSED_BY_DOXYGEN + /** \returns the solution x of \f$ A x = b \f$ using the current decomposition of A. + * + * Since this LLT class assumes anyway that the matrix A is invertible, the solution + * theoretically exists and is unique regardless of b. + * + * Example: \include LLT_solve.cpp + * Output: \verbinclude LLT_solve.out + * + * \sa solveInPlace(), MatrixBase::llt(), SelfAdjointView::llt() + */ + template + inline const Solve solve(const MatrixBase& b) const; +#endif + + template + void solveInPlace(const MatrixBase& bAndX) const; + + template + LLT& compute(const EigenBase& matrix); + + /** \returns an estimate of the reciprocal condition number of the matrix of + * which \c *this is the Cholesky decomposition. + */ + RealScalar rcond() const { + eigen_assert(m_isInitialized && "LLT is not initialized."); + eigen_assert(m_info == Success && "LLT failed because matrix appears to be negative"); + return internal::rcond_estimate_helper(m_l1_norm, *this); + } + + /** \returns the LLT decomposition matrix + * + * TODO: document the storage layout + */ + inline const MatrixType& matrixLLT() const { + eigen_assert(m_isInitialized && "LLT is not initialized."); + return m_matrix; + } + + MatrixType reconstructedMatrix() const; + + /** \brief Reports whether previous computation was successful. + * + * \returns \c Success if computation was successful, + * \c NumericalIssue if the matrix.appears not to be positive definite. + */ + ComputationInfo info() const { + eigen_assert(m_isInitialized && "LLT is not initialized."); + return m_info; + } + + /** \returns the adjoint of \c *this, that is, a const reference to the decomposition itself as the underlying matrix + * is self-adjoint. + * + * This method is provided for compatibility with other matrix decompositions, thus enabling generic code such as: + * \code x = decomposition.adjoint().solve(b) \endcode + */ + const LLT& adjoint() const EIGEN_NOEXCEPT { return *this; } + + inline EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); } + inline EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); } + + template + LLT& rankUpdate(const VectorType& vec, const RealScalar& sigma = 1); + +#ifndef EIGEN_PARSED_BY_DOXYGEN + template + void _solve_impl(const RhsType& rhs, DstType& dst) const; + + template + void _solve_impl_transposed(const RhsType& rhs, DstType& dst) const; +#endif + + protected: + EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) + + /** \internal + * Used to compute and store L + * The strict upper part is not used and even not initialized. + */ + MatrixType m_matrix; + RealScalar m_l1_norm; + bool m_isInitialized; + ComputationInfo m_info; +}; + +namespace internal { + +template +struct llt_inplace; + +template +static Index llt_rank_update_lower(MatrixType& mat, const VectorType& vec, + const typename MatrixType::RealScalar& sigma) { + using std::sqrt; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + typedef typename MatrixType::ColXpr ColXpr; + typedef internal::remove_all_t ColXprCleaned; + typedef typename ColXprCleaned::SegmentReturnType ColXprSegment; + typedef Matrix TempVectorType; + typedef typename TempVectorType::SegmentReturnType TempVecSegment; + + Index n = mat.cols(); + eigen_assert(mat.rows() == n && vec.size() == n); + + TempVectorType temp; + + if (sigma > 0) { + // This version is based on Givens rotations. + // It is faster than the other one below, but only works for updates, + // i.e., for sigma > 0 + temp = sqrt(sigma) * vec; + + for (Index i = 0; i < n; ++i) { + JacobiRotation g; + g.makeGivens(mat(i, i), -temp(i), &mat(i, i)); + + Index rs = n - i - 1; + if (rs > 0) { + ColXprSegment x(mat.col(i).tail(rs)); + TempVecSegment y(temp.tail(rs)); + apply_rotation_in_the_plane(x, y, g); + } + } + } else { + temp = vec; + RealScalar beta = 1; + for (Index j = 0; j < n; ++j) { + RealScalar Ljj = numext::real(mat.coeff(j, j)); + RealScalar dj = numext::abs2(Ljj); + Scalar wj = temp.coeff(j); + RealScalar swj2 = sigma * numext::abs2(wj); + RealScalar gamma = dj * beta + swj2; + + RealScalar x = dj + swj2 / beta; + if (x <= RealScalar(0)) return j; + RealScalar nLjj = sqrt(x); + mat.coeffRef(j, j) = nLjj; + beta += swj2 / dj; + + // Update the terms of L + Index rs = n - j - 1; + if (rs) { + temp.tail(rs) -= (wj / Ljj) * mat.col(j).tail(rs); + if (!numext::is_exactly_zero(gamma)) + mat.col(j).tail(rs) = + (nLjj / Ljj) * mat.col(j).tail(rs) + (nLjj * sigma * numext::conj(wj) / gamma) * temp.tail(rs); + } + } + } + return -1; +} + +template +struct llt_inplace { + typedef typename NumTraits::Real RealScalar; + template + static Index unblocked(MatrixType& mat) { + using std::sqrt; + + eigen_assert(mat.rows() == mat.cols()); + const Index size = mat.rows(); + for (Index k = 0; k < size; ++k) { + Index rs = size - k - 1; // remaining size + + Block A21(mat, k + 1, k, rs, 1); + Block A10(mat, k, 0, 1, k); + Block A20(mat, k + 1, 0, rs, k); + + RealScalar x = numext::real(mat.coeff(k, k)); + if (k > 0) x -= A10.squaredNorm(); + if (x <= RealScalar(0)) return k; + mat.coeffRef(k, k) = x = sqrt(x); + if (k > 0 && rs > 0) A21.noalias() -= A20 * A10.adjoint(); + if (rs > 0) A21 /= x; + } + return -1; + } + + template + static Index blocked(MatrixType& m) { + eigen_assert(m.rows() == m.cols()); + Index size = m.rows(); + if (size < 32) return unblocked(m); + + Index blockSize = size / 8; + blockSize = (blockSize / 16) * 16; + blockSize = (std::min)((std::max)(blockSize, Index(8)), Index(128)); + + for (Index k = 0; k < size; k += blockSize) { + // partition the matrix: + // A00 | - | - + // lu = A10 | A11 | - + // A20 | A21 | A22 + Index bs = (std::min)(blockSize, size - k); + Index rs = size - k - bs; + Block A11(m, k, k, bs, bs); + Block A21(m, k + bs, k, rs, bs); + Block A22(m, k + bs, k + bs, rs, rs); + + Index ret; + if ((ret = unblocked(A11)) >= 0) return k + ret; + if (rs > 0) A11.adjoint().template triangularView().template solveInPlace(A21); + if (rs > 0) + A22.template selfadjointView().rankUpdate(A21, + typename NumTraits::Literal(-1)); // bottleneck + } + return -1; + } + + template + static Index rankUpdate(MatrixType& mat, const VectorType& vec, const RealScalar& sigma) { + return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); + } +}; + +template +struct llt_inplace { + typedef typename NumTraits::Real RealScalar; + + template + static EIGEN_STRONG_INLINE Index unblocked(MatrixType& mat) { + Transpose matt(mat); + return llt_inplace::unblocked(matt); + } + template + static EIGEN_STRONG_INLINE Index blocked(MatrixType& mat) { + Transpose matt(mat); + return llt_inplace::blocked(matt); + } + template + static Index rankUpdate(MatrixType& mat, const VectorType& vec, const RealScalar& sigma) { + Transpose matt(mat); + return llt_inplace::rankUpdate(matt, vec.conjugate(), sigma); + } +}; + +template +struct LLT_Traits { + typedef const TriangularView MatrixL; + typedef const TriangularView MatrixU; + static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); } + static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); } + static bool inplace_decomposition(MatrixType& m) { + return llt_inplace::blocked(m) == -1; + } +}; + +template +struct LLT_Traits { + typedef const TriangularView MatrixL; + typedef const TriangularView MatrixU; + static inline MatrixL getL(const MatrixType& m) { return MatrixL(m.adjoint()); } + static inline MatrixU getU(const MatrixType& m) { return MatrixU(m); } + static bool inplace_decomposition(MatrixType& m) { + return llt_inplace::blocked(m) == -1; + } +}; + +} // end namespace internal + +/** Computes / recomputes the Cholesky decomposition A = LL^* = U^*U of \a matrix + * + * \returns a reference to *this + * + * Example: \include TutorialLinAlgComputeTwice.cpp + * Output: \verbinclude TutorialLinAlgComputeTwice.out + */ +template +template +LLT& LLT::compute(const EigenBase& a) { + eigen_assert(a.rows() == a.cols()); + const Index size = a.rows(); + m_matrix.resize(size, size); + if (!internal::is_same_dense(m_matrix, a.derived())) m_matrix = a.derived(); + + // Compute matrix L1 norm = max abs column sum. + m_l1_norm = RealScalar(0); + // TODO move this code to SelfAdjointView + for (Index col = 0; col < size; ++col) { + RealScalar abs_col_sum; + if (UpLo_ == Lower) + abs_col_sum = + m_matrix.col(col).tail(size - col).template lpNorm<1>() + m_matrix.row(col).head(col).template lpNorm<1>(); + else + abs_col_sum = + m_matrix.col(col).head(col).template lpNorm<1>() + m_matrix.row(col).tail(size - col).template lpNorm<1>(); + if (abs_col_sum > m_l1_norm) m_l1_norm = abs_col_sum; + } + + m_isInitialized = true; + bool ok = Traits::inplace_decomposition(m_matrix); + m_info = ok ? Success : NumericalIssue; + + return *this; +} + +/** Performs a rank one update (or dowdate) of the current decomposition. + * If A = LL^* before the rank one update, + * then after it we have LL^* = A + sigma * v v^* where \a v must be a vector + * of same dimension. + */ +template +template +LLT& LLT::rankUpdate(const VectorType& v, const RealScalar& sigma) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorType); + eigen_assert(v.size() == m_matrix.cols()); + eigen_assert(m_isInitialized); + if (internal::llt_inplace::rankUpdate(m_matrix, v, sigma) >= 0) + m_info = NumericalIssue; + else + m_info = Success; + + return *this; +} + +#ifndef EIGEN_PARSED_BY_DOXYGEN +template +template +void LLT::_solve_impl(const RhsType& rhs, DstType& dst) const { + _solve_impl_transposed(rhs, dst); +} + +template +template +void LLT::_solve_impl_transposed(const RhsType& rhs, DstType& dst) const { + dst = rhs; + + matrixL().template conjugateIf().solveInPlace(dst); + matrixU().template conjugateIf().solveInPlace(dst); +} +#endif + +/** \internal use x = llt_object.solve(x); + * + * This is the \em in-place version of solve(). + * + * \param bAndX represents both the right-hand side matrix b and result x. + * + * This version avoids a copy when the right hand side matrix b is not needed anymore. + * + * \warning The parameter is only marked 'const' to make the C++ compiler accept a temporary expression here. + * This function will const_cast it, so constness isn't honored here. + * + * \sa LLT::solve(), MatrixBase::llt() + */ +template +template +void LLT::solveInPlace(const MatrixBase& bAndX) const { + eigen_assert(m_isInitialized && "LLT is not initialized."); + eigen_assert(m_matrix.rows() == bAndX.rows()); + matrixL().solveInPlace(bAndX); + matrixU().solveInPlace(bAndX); +} + +/** \returns the matrix represented by the decomposition, + * i.e., it returns the product: L L^*. + * This function is provided for debug purpose. */ +template +MatrixType LLT::reconstructedMatrix() const { + eigen_assert(m_isInitialized && "LLT is not initialized."); + return matrixL() * matrixL().adjoint().toDenseMatrix(); +} + +/** \cholesky_module + * \returns the LLT decomposition of \c *this + * \sa SelfAdjointView::llt() + */ +template +inline const LLT::PlainObject> MatrixBase::llt() const { + return LLT(derived()); +} + +/** \cholesky_module + * \returns the LLT decomposition of \c *this + * \sa SelfAdjointView::llt() + */ +template +inline const LLT::PlainObject, UpLo> SelfAdjointView::llt() + const { + return LLT(m_matrix); +} + +} // end namespace Eigen + +#endif // EIGEN_LLT_H diff --git a/dae-cpp/Eigen/src/Cholesky/LLT_LAPACKE.h b/dae-cpp/Eigen/src/Cholesky/LLT_LAPACKE.h new file mode 100644 index 0000000..cb55b15 --- /dev/null +++ b/dae-cpp/Eigen/src/Cholesky/LLT_LAPACKE.h @@ -0,0 +1,124 @@ +/* + Copyright (c) 2011, Intel Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + ******************************************************************************** + * Content : Eigen bindings to LAPACKe + * LLt decomposition based on LAPACKE_?potrf function. + ******************************************************************************** +*/ + +#ifndef EIGEN_LLT_LAPACKE_H +#define EIGEN_LLT_LAPACKE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +namespace lapacke_helpers { +// ------------------------------------------------------------------------------------------------------------------- +// Dispatch for rank update handling upper and lower parts +// ------------------------------------------------------------------------------------------------------------------- + +template +struct rank_update {}; + +template <> +struct rank_update { + template + static Index run(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma) { + return Eigen::internal::llt_rank_update_lower(mat, vec, sigma); + } +}; + +template <> +struct rank_update { + template + static Index run(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma) { + Transpose matt(mat); + return Eigen::internal::llt_rank_update_lower(matt, vec.conjugate(), sigma); + } +}; + +// ------------------------------------------------------------------------------------------------------------------- +// Generic lapacke llt implementation that hands of to the dispatches +// ------------------------------------------------------------------------------------------------------------------- + +template +struct lapacke_llt { + EIGEN_STATIC_ASSERT(((Mode == Lower) || (Mode == Upper)), MODE_MUST_BE_UPPER_OR_LOWER) + template + static Index blocked(MatrixType &m) { + eigen_assert(m.rows() == m.cols()); + if (m.rows() == 0) { + return -1; + } + /* Set up parameters for ?potrf */ + lapack_int size = to_lapack(m.rows()); + lapack_int matrix_order = lapack_storage_of(m); + constexpr char uplo = Mode == Upper ? 'U' : 'L'; + Scalar *a = &(m.coeffRef(0, 0)); + lapack_int lda = to_lapack(m.outerStride()); + + lapack_int info = potrf(matrix_order, uplo, size, to_lapack(a), lda); + info = (info == 0) ? -1 : info > 0 ? info - 1 : size; + return info; + } + + template + static Index rankUpdate(MatrixType &mat, const VectorType &vec, const typename MatrixType::RealScalar &sigma) { + return rank_update::run(mat, vec, sigma); + } +}; +} // namespace lapacke_helpers +// end namespace lapacke_helpers + +/* + * Here, we just put the generic implementation from lapacke_llt into a full specialization of the llt_inplace + * type. By being a full specialization, the versions defined here thus get precedence over the generic implementation + * in LLT.h for double, float and complex double, complex float types. + */ + +#define EIGEN_LAPACKE_LLT(EIGTYPE) \ + template <> \ + struct llt_inplace : public lapacke_helpers::lapacke_llt {}; \ + template <> \ + struct llt_inplace : public lapacke_helpers::lapacke_llt {}; + +EIGEN_LAPACKE_LLT(double) +EIGEN_LAPACKE_LLT(float) +EIGEN_LAPACKE_LLT(std::complex) +EIGEN_LAPACKE_LLT(std::complex) + +#undef EIGEN_LAPACKE_LLT + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_LLT_LAPACKE_H diff --git a/dae-cpp/Eigen/src/CholmodSupport/CholmodSupport.h b/dae-cpp/Eigen/src/CholmodSupport/CholmodSupport.h new file mode 100644 index 0000000..e5b46c4 --- /dev/null +++ b/dae-cpp/Eigen/src/CholmodSupport/CholmodSupport.h @@ -0,0 +1,738 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CHOLMODSUPPORT_H +#define EIGEN_CHOLMODSUPPORT_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +struct cholmod_configure_matrix; + +template <> +struct cholmod_configure_matrix { + template + static void run(CholmodType& mat) { + mat.xtype = CHOLMOD_REAL; + mat.dtype = CHOLMOD_DOUBLE; + } +}; + +template <> +struct cholmod_configure_matrix > { + template + static void run(CholmodType& mat) { + mat.xtype = CHOLMOD_COMPLEX; + mat.dtype = CHOLMOD_DOUBLE; + } +}; + +// Other scalar types are not yet supported by Cholmod +// template<> struct cholmod_configure_matrix { +// template +// static void run(CholmodType& mat) { +// mat.xtype = CHOLMOD_REAL; +// mat.dtype = CHOLMOD_SINGLE; +// } +// }; +// +// template<> struct cholmod_configure_matrix > { +// template +// static void run(CholmodType& mat) { +// mat.xtype = CHOLMOD_COMPLEX; +// mat.dtype = CHOLMOD_SINGLE; +// } +// }; + +} // namespace internal + +/** Wraps the Eigen sparse matrix \a mat into a Cholmod sparse matrix object. + * Note that the data are shared. + */ +template +cholmod_sparse viewAsCholmod(Ref > mat) { + cholmod_sparse res; + res.nzmax = mat.nonZeros(); + res.nrow = mat.rows(); + res.ncol = mat.cols(); + res.p = mat.outerIndexPtr(); + res.i = mat.innerIndexPtr(); + res.x = mat.valuePtr(); + res.z = 0; + res.sorted = 1; + if (mat.isCompressed()) { + res.packed = 1; + res.nz = 0; + } else { + res.packed = 0; + res.nz = mat.innerNonZeroPtr(); + } + + res.dtype = 0; + res.stype = -1; + + if (internal::is_same::value) { + res.itype = CHOLMOD_INT; + } else if (internal::is_same::value) { + res.itype = CHOLMOD_LONG; + } else { + eigen_assert(false && "Index type not supported yet"); + } + + // setup res.xtype + internal::cholmod_configure_matrix::run(res); + + res.stype = 0; + + return res; +} + +template +const cholmod_sparse viewAsCholmod(const SparseMatrix& mat) { + cholmod_sparse res = viewAsCholmod(Ref >(mat.const_cast_derived())); + return res; +} + +template +const cholmod_sparse viewAsCholmod(const SparseVector& mat) { + cholmod_sparse res = viewAsCholmod(Ref >(mat.const_cast_derived())); + return res; +} + +/** Returns a view of the Eigen sparse matrix \a mat as Cholmod sparse matrix. + * The data are not copied but shared. */ +template +cholmod_sparse viewAsCholmod(const SparseSelfAdjointView, UpLo>& mat) { + cholmod_sparse res = viewAsCholmod(Ref >(mat.matrix().const_cast_derived())); + + if (UpLo == Upper) res.stype = 1; + if (UpLo == Lower) res.stype = -1; + // swap stype for rowmajor matrices (only works for real matrices) + EIGEN_STATIC_ASSERT((Options_ & RowMajorBit) == 0 || NumTraits::IsComplex == 0, + THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); + if (Options_ & RowMajorBit) res.stype *= -1; + + return res; +} + +/** Returns a view of the Eigen \b dense matrix \a mat as Cholmod dense matrix. + * The data are not copied but shared. */ +template +cholmod_dense viewAsCholmod(MatrixBase& mat) { + EIGEN_STATIC_ASSERT((internal::traits::Flags & RowMajorBit) == 0, + THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); + typedef typename Derived::Scalar Scalar; + + cholmod_dense res; + res.nrow = mat.rows(); + res.ncol = mat.cols(); + res.nzmax = res.nrow * res.ncol; + res.d = Derived::IsVectorAtCompileTime ? mat.derived().size() : mat.derived().outerStride(); + res.x = (void*)(mat.derived().data()); + res.z = 0; + + internal::cholmod_configure_matrix::run(res); + + return res; +} + +/** Returns a view of the Cholmod sparse matrix \a cm as an Eigen sparse matrix. + * The data are not copied but shared. */ +template +Map > viewAsEigen(cholmod_sparse& cm) { + return Map >( + cm.nrow, cm.ncol, static_cast(cm.p)[cm.ncol], static_cast(cm.p), + static_cast(cm.i), static_cast(cm.x)); +} + +/** Returns a view of the Cholmod sparse matrix factor \a cm as an Eigen sparse matrix. + * The data are not copied but shared. */ +template +Map > viewAsEigen(cholmod_factor& cm) { + return Map >( + cm.n, cm.n, static_cast(cm.p)[cm.n], static_cast(cm.p), + static_cast(cm.i), static_cast(cm.x)); +} + +namespace internal { + +// template specializations for int and long that call the correct cholmod method + +#define EIGEN_CHOLMOD_SPECIALIZE0(ret, name) \ + template \ + inline ret cm_##name(cholmod_common& Common) { \ + return cholmod_##name(&Common); \ + } \ + template <> \ + inline ret cm_##name(cholmod_common & Common) { \ + return cholmod_l_##name(&Common); \ + } + +#define EIGEN_CHOLMOD_SPECIALIZE1(ret, name, t1, a1) \ + template \ + inline ret cm_##name(t1& a1, cholmod_common& Common) { \ + return cholmod_##name(&a1, &Common); \ + } \ + template <> \ + inline ret cm_##name(t1 & a1, cholmod_common & Common) { \ + return cholmod_l_##name(&a1, &Common); \ + } + +EIGEN_CHOLMOD_SPECIALIZE0(int, start) +EIGEN_CHOLMOD_SPECIALIZE0(int, finish) + +EIGEN_CHOLMOD_SPECIALIZE1(int, free_factor, cholmod_factor*, L) +EIGEN_CHOLMOD_SPECIALIZE1(int, free_dense, cholmod_dense*, X) +EIGEN_CHOLMOD_SPECIALIZE1(int, free_sparse, cholmod_sparse*, A) + +EIGEN_CHOLMOD_SPECIALIZE1(cholmod_factor*, analyze, cholmod_sparse, A) +EIGEN_CHOLMOD_SPECIALIZE1(cholmod_sparse*, factor_to_sparse, cholmod_factor, L) + +template +inline cholmod_dense* cm_solve(int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common& Common) { + return cholmod_solve(sys, &L, &B, &Common); +} +template <> +inline cholmod_dense* cm_solve(int sys, cholmod_factor& L, cholmod_dense& B, cholmod_common& Common) { + return cholmod_l_solve(sys, &L, &B, &Common); +} + +template +inline cholmod_sparse* cm_spsolve(int sys, cholmod_factor& L, cholmod_sparse& B, cholmod_common& Common) { + return cholmod_spsolve(sys, &L, &B, &Common); +} +template <> +inline cholmod_sparse* cm_spsolve(int sys, cholmod_factor& L, cholmod_sparse& B, + cholmod_common& Common) { + return cholmod_l_spsolve(sys, &L, &B, &Common); +} + +template +inline int cm_factorize_p(cholmod_sparse* A, double beta[2], StorageIndex_* fset, std::size_t fsize, cholmod_factor* L, + cholmod_common& Common) { + return cholmod_factorize_p(A, beta, fset, fsize, L, &Common); +} +template <> +inline int cm_factorize_p(cholmod_sparse* A, double beta[2], SuiteSparse_long* fset, + std::size_t fsize, cholmod_factor* L, cholmod_common& Common) { + return cholmod_l_factorize_p(A, beta, fset, fsize, L, &Common); +} + +#undef EIGEN_CHOLMOD_SPECIALIZE0 +#undef EIGEN_CHOLMOD_SPECIALIZE1 + +} // namespace internal + +enum CholmodMode { CholmodAuto, CholmodSimplicialLLt, CholmodSupernodalLLt, CholmodLDLt }; + +/** \ingroup CholmodSupport_Module + * \class CholmodBase + * \brief The base class for the direct Cholesky factorization of Cholmod + * \sa class CholmodSupernodalLLT, class CholmodSimplicialLDLT, class CholmodSimplicialLLT + */ +template +class CholmodBase : public SparseSolverBase { + protected: + typedef SparseSolverBase Base; + using Base::derived; + using Base::m_isInitialized; + + public: + typedef MatrixType_ MatrixType; + enum { UpLo = UpLo_ }; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + typedef MatrixType CholMatrixType; + typedef typename MatrixType::StorageIndex StorageIndex; + enum { ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }; + + public: + CholmodBase() : m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false) { + EIGEN_STATIC_ASSERT((internal::is_same::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY); + m_shiftOffset[0] = m_shiftOffset[1] = 0.0; + internal::cm_start(m_cholmod); + } + + explicit CholmodBase(const MatrixType& matrix) + : m_cholmodFactor(0), m_info(Success), m_factorizationIsOk(false), m_analysisIsOk(false) { + EIGEN_STATIC_ASSERT((internal::is_same::value), CHOLMOD_SUPPORTS_DOUBLE_PRECISION_ONLY); + m_shiftOffset[0] = m_shiftOffset[1] = 0.0; + internal::cm_start(m_cholmod); + compute(matrix); + } + + ~CholmodBase() { + if (m_cholmodFactor) internal::cm_free_factor(m_cholmodFactor, m_cholmod); + internal::cm_finish(m_cholmod); + } + + inline StorageIndex cols() const { return internal::convert_index(m_cholmodFactor->n); } + inline StorageIndex rows() const { return internal::convert_index(m_cholmodFactor->n); } + + /** \brief Reports whether previous computation was successful. + * + * \returns \c Success if computation was successful, + * \c NumericalIssue if the matrix.appears to be negative. + */ + ComputationInfo info() const { + eigen_assert(m_isInitialized && "Decomposition is not initialized."); + return m_info; + } + + /** Computes the sparse Cholesky decomposition of \a matrix */ + Derived& compute(const MatrixType& matrix) { + analyzePattern(matrix); + factorize(matrix); + return derived(); + } + + /** Performs a symbolic decomposition on the sparsity pattern of \a matrix. + * + * This function is particularly useful when solving for several problems having the same structure. + * + * \sa factorize() + */ + void analyzePattern(const MatrixType& matrix) { + if (m_cholmodFactor) { + internal::cm_free_factor(m_cholmodFactor, m_cholmod); + m_cholmodFactor = 0; + } + cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView()); + m_cholmodFactor = internal::cm_analyze(A, m_cholmod); + + this->m_isInitialized = true; + this->m_info = Success; + m_analysisIsOk = true; + m_factorizationIsOk = false; + } + + /** Performs a numeric decomposition of \a matrix + * + * The given matrix must have the same sparsity pattern as the matrix on which the symbolic decomposition has been + * performed. + * + * \sa analyzePattern() + */ + void factorize(const MatrixType& matrix) { + eigen_assert(m_analysisIsOk && "You must first call analyzePattern()"); + cholmod_sparse A = viewAsCholmod(matrix.template selfadjointView()); + internal::cm_factorize_p(&A, m_shiftOffset, 0, 0, m_cholmodFactor, m_cholmod); + + // If the factorization failed, either the input matrix was zero (so m_cholmodFactor == nullptr), or minor is the + // column at which it failed. On success minor == n. + this->m_info = + (m_cholmodFactor != nullptr && m_cholmodFactor->minor == m_cholmodFactor->n ? Success : NumericalIssue); + m_factorizationIsOk = true; + } + + /** Returns a reference to the Cholmod's configuration structure to get a full control over the performed operations. + * See the Cholmod user guide for details. */ + cholmod_common& cholmod() { return m_cholmod; } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** \internal */ + template + void _solve_impl(const MatrixBase& b, MatrixBase& dest) const { + eigen_assert(m_factorizationIsOk && + "The decomposition is not in a valid state for solving, you must first call either compute() or " + "symbolic()/numeric()"); + const Index size = m_cholmodFactor->n; + EIGEN_UNUSED_VARIABLE(size); + eigen_assert(size == b.rows()); + + // Cholmod needs column-major storage without inner-stride, which corresponds to the default behavior of Ref. + Ref > b_ref(b.derived()); + + cholmod_dense b_cd = viewAsCholmod(b_ref); + cholmod_dense* x_cd = internal::cm_solve(CHOLMOD_A, *m_cholmodFactor, b_cd, m_cholmod); + if (!x_cd) { + this->m_info = NumericalIssue; + return; + } + // TODO optimize this copy by swapping when possible (be careful with alignment, etc.) + // NOTE Actually, the copy can be avoided by calling cholmod_solve2 instead of cholmod_solve + dest = Matrix::Map(reinterpret_cast(x_cd->x), + b.rows(), b.cols()); + internal::cm_free_dense(x_cd, m_cholmod); + } + + /** \internal */ + template + void _solve_impl(const SparseMatrixBase& b, SparseMatrixBase& dest) const { + eigen_assert(m_factorizationIsOk && + "The decomposition is not in a valid state for solving, you must first call either compute() or " + "symbolic()/numeric()"); + const Index size = m_cholmodFactor->n; + EIGEN_UNUSED_VARIABLE(size); + eigen_assert(size == b.rows()); + + // note: cs stands for Cholmod Sparse + Ref > b_ref( + b.const_cast_derived()); + cholmod_sparse b_cs = viewAsCholmod(b_ref); + cholmod_sparse* x_cs = internal::cm_spsolve(CHOLMOD_A, *m_cholmodFactor, b_cs, m_cholmod); + if (!x_cs) { + this->m_info = NumericalIssue; + return; + } + // TODO optimize this copy by swapping when possible (be careful with alignment, etc.) + // NOTE cholmod_spsolve in fact just calls the dense solver for blocks of 4 columns at a time (similar to Eigen's + // sparse solver) + dest.derived() = viewAsEigen(*x_cs); + internal::cm_free_sparse(x_cs, m_cholmod); + } +#endif // EIGEN_PARSED_BY_DOXYGEN + + /** Sets the shift parameter that will be used to adjust the diagonal coefficients during the numerical factorization. + * + * During the numerical factorization, an offset term is added to the diagonal coefficients:\n + * \c d_ii = \a offset + \c d_ii + * + * The default is \a offset=0. + * + * \returns a reference to \c *this. + */ + Derived& setShift(const RealScalar& offset) { + m_shiftOffset[0] = double(offset); + return derived(); + } + + /** \returns the determinant of the underlying matrix from the current factorization */ + Scalar determinant() const { + using std::exp; + return exp(logDeterminant()); + } + + /** \returns the log determinant of the underlying matrix from the current factorization */ + Scalar logDeterminant() const { + using numext::real; + using std::log; + eigen_assert(m_factorizationIsOk && + "The decomposition is not in a valid state for solving, you must first call either compute() or " + "symbolic()/numeric()"); + + RealScalar logDet = 0; + Scalar* x = static_cast(m_cholmodFactor->x); + if (m_cholmodFactor->is_super) { + // Supernodal factorization stored as a packed list of dense column-major blocs, + // as described by the following structure: + + // super[k] == index of the first column of the j-th super node + StorageIndex* super = static_cast(m_cholmodFactor->super); + // pi[k] == offset to the description of row indices + StorageIndex* pi = static_cast(m_cholmodFactor->pi); + // px[k] == offset to the respective dense block + StorageIndex* px = static_cast(m_cholmodFactor->px); + + Index nb_super_nodes = m_cholmodFactor->nsuper; + for (Index k = 0; k < nb_super_nodes; ++k) { + StorageIndex ncols = super[k + 1] - super[k]; + StorageIndex nrows = pi[k + 1] - pi[k]; + + Map, 0, InnerStride<> > sk(x + px[k], ncols, InnerStride<>(nrows + 1)); + logDet += sk.real().log().sum(); + } + } else { + // Simplicial factorization stored as standard CSC matrix. + StorageIndex* p = static_cast(m_cholmodFactor->p); + Index size = m_cholmodFactor->n; + for (Index k = 0; k < size; ++k) logDet += log(real(x[p[k]])); + } + if (m_cholmodFactor->is_ll) logDet *= 2.0; + return logDet; + } + + template + void dumpMemory(Stream& /*s*/) {} + + protected: + mutable cholmod_common m_cholmod; + cholmod_factor* m_cholmodFactor; + double m_shiftOffset[2]; + mutable ComputationInfo m_info; + int m_factorizationIsOk; + int m_analysisIsOk; +}; + +/** \ingroup CholmodSupport_Module + * \class CholmodSimplicialLLT + * \brief A simplicial direct Cholesky (LLT) factorization and solver based on Cholmod + * + * This class allows to solve for A.X = B sparse linear problems via a simplicial LL^T Cholesky factorization + * using the Cholmod library. + * This simplicial variant is equivalent to Eigen's built-in SimplicialLLT class. Therefore, it has little practical + * interest. The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices X and B can be + * either dense or sparse. + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ the triangular part that will be used for the computations. It can be Lower + * or Upper. Default is Lower. + * + * \implsparsesolverconcept + * + * This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non + * compressed. + * + * \warning Only double precision real and complex scalar types are supported by Cholmod. + * + * \sa \ref TutorialSparseSolverConcept, class CholmodSupernodalLLT, class SimplicialLLT + */ +template +class CholmodSimplicialLLT : public CholmodBase > { + typedef CholmodBase Base; + using Base::m_cholmod; + + public: + typedef MatrixType_ MatrixType; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + typedef typename MatrixType::StorageIndex StorageIndex; + typedef TriangularView MatrixL; + typedef TriangularView MatrixU; + + CholmodSimplicialLLT() : Base() { init(); } + + CholmodSimplicialLLT(const MatrixType& matrix) : Base() { + init(); + this->compute(matrix); + } + + ~CholmodSimplicialLLT() {} + + /** \returns an expression of the factor L */ + inline MatrixL matrixL() const { return viewAsEigen(*Base::m_cholmodFactor); } + + /** \returns an expression of the factor U (= L^*) */ + inline MatrixU matrixU() const { return matrixL().adjoint(); } + + protected: + void init() { + m_cholmod.final_asis = 0; + m_cholmod.supernodal = CHOLMOD_SIMPLICIAL; + m_cholmod.final_ll = 1; + } +}; + +/** \ingroup CholmodSupport_Module + * \class CholmodSimplicialLDLT + * \brief A simplicial direct Cholesky (LDLT) factorization and solver based on Cholmod + * + * This class allows to solve for A.X = B sparse linear problems via a simplicial LDL^T Cholesky factorization + * using the Cholmod library. + * This simplicial variant is equivalent to Eigen's built-in SimplicialLDLT class. Therefore, it has little practical + * interest. The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices X and B can be + * either dense or sparse. + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ the triangular part that will be used for the computations. It can be Lower + * or Upper. Default is Lower. + * + * \implsparsesolverconcept + * + * This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non + * compressed. + * + * \warning Only double precision real and complex scalar types are supported by Cholmod. + * + * \sa \ref TutorialSparseSolverConcept, class CholmodSupernodalLLT, class SimplicialLDLT + */ +template +class CholmodSimplicialLDLT : public CholmodBase > { + typedef CholmodBase Base; + using Base::m_cholmod; + + public: + typedef MatrixType_ MatrixType; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + typedef typename MatrixType::StorageIndex StorageIndex; + typedef Matrix VectorType; + typedef TriangularView MatrixL; + typedef TriangularView MatrixU; + + CholmodSimplicialLDLT() : Base() { init(); } + + CholmodSimplicialLDLT(const MatrixType& matrix) : Base() { + init(); + this->compute(matrix); + } + + ~CholmodSimplicialLDLT() {} + + /** \returns a vector expression of the diagonal D */ + inline VectorType vectorD() const { + auto cholmodL = viewAsEigen(*Base::m_cholmodFactor); + + VectorType D{cholmodL.rows()}; + + for (Index k = 0; k < cholmodL.outerSize(); ++k) { + typename decltype(cholmodL)::InnerIterator it{cholmodL, k}; + D(k) = it.value(); + } + + return D; + } + + /** \returns an expression of the factor L */ + inline MatrixL matrixL() const { return viewAsEigen(*Base::m_cholmodFactor); } + + /** \returns an expression of the factor U (= L^*) */ + inline MatrixU matrixU() const { return matrixL().adjoint(); } + + protected: + void init() { + m_cholmod.final_asis = 1; + m_cholmod.supernodal = CHOLMOD_SIMPLICIAL; + } +}; + +/** \ingroup CholmodSupport_Module + * \class CholmodSupernodalLLT + * \brief A supernodal Cholesky (LLT) factorization and solver based on Cholmod + * + * This class allows to solve for A.X = B sparse linear problems via a supernodal LL^T Cholesky factorization + * using the Cholmod library. + * This supernodal variant performs best on dense enough problems, e.g., 3D FEM, or very high order 2D FEM. + * The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices + * X and B can be either dense or sparse. + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ the triangular part that will be used for the computations. It can be Lower + * or Upper. Default is Lower. + * + * \implsparsesolverconcept + * + * This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non + * compressed. + * + * \warning Only double precision real and complex scalar types are supported by Cholmod. + * + * \sa \ref TutorialSparseSolverConcept + */ +template +class CholmodSupernodalLLT : public CholmodBase > { + typedef CholmodBase Base; + using Base::m_cholmod; + + public: + typedef MatrixType_ MatrixType; + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + typedef typename MatrixType::StorageIndex StorageIndex; + + CholmodSupernodalLLT() : Base() { init(); } + + CholmodSupernodalLLT(const MatrixType& matrix) : Base() { + init(); + this->compute(matrix); + } + + ~CholmodSupernodalLLT() {} + + /** \returns an expression of the factor L */ + inline MatrixType matrixL() const { + // Convert Cholmod factor's supernodal storage format to Eigen's CSC storage format + cholmod_sparse* cholmodL = internal::cm_factor_to_sparse(*Base::m_cholmodFactor, m_cholmod); + MatrixType L = viewAsEigen(*cholmodL); + internal::cm_free_sparse(cholmodL, m_cholmod); + + return L; + } + + /** \returns an expression of the factor U (= L^*) */ + inline MatrixType matrixU() const { return matrixL().adjoint(); } + + protected: + void init() { + m_cholmod.final_asis = 1; + m_cholmod.supernodal = CHOLMOD_SUPERNODAL; + } +}; + +/** \ingroup CholmodSupport_Module + * \class CholmodDecomposition + * \brief A general Cholesky factorization and solver based on Cholmod + * + * This class allows to solve for A.X = B sparse linear problems via a LL^T or LDL^T Cholesky factorization + * using the Cholmod library. The sparse matrix A must be selfadjoint and positive definite. The vectors or matrices + * X and B can be either dense or sparse. + * + * This variant permits to change the underlying Cholesky method at runtime. + * On the other hand, it does not provide access to the result of the factorization. + * The default is to let Cholmod automatically choose between a simplicial and supernodal factorization. + * + * \tparam MatrixType_ the type of the sparse matrix A, it must be a SparseMatrix<> + * \tparam UpLo_ the triangular part that will be used for the computations. It can be Lower + * or Upper. Default is Lower. + * + * \implsparsesolverconcept + * + * This class supports all kind of SparseMatrix<>: row or column major; upper, lower, or both; compressed or non + * compressed. + * + * \warning Only double precision real and complex scalar types are supported by Cholmod. + * + * \sa \ref TutorialSparseSolverConcept + */ +template +class CholmodDecomposition : public CholmodBase > { + typedef CholmodBase Base; + using Base::m_cholmod; + + public: + typedef MatrixType_ MatrixType; + + CholmodDecomposition() : Base() { init(); } + + CholmodDecomposition(const MatrixType& matrix) : Base() { + init(); + this->compute(matrix); + } + + ~CholmodDecomposition() {} + + void setMode(CholmodMode mode) { + switch (mode) { + case CholmodAuto: + m_cholmod.final_asis = 1; + m_cholmod.supernodal = CHOLMOD_AUTO; + break; + case CholmodSimplicialLLt: + m_cholmod.final_asis = 0; + m_cholmod.supernodal = CHOLMOD_SIMPLICIAL; + m_cholmod.final_ll = 1; + break; + case CholmodSupernodalLLt: + m_cholmod.final_asis = 1; + m_cholmod.supernodal = CHOLMOD_SUPERNODAL; + break; + case CholmodLDLt: + m_cholmod.final_asis = 1; + m_cholmod.supernodal = CHOLMOD_SIMPLICIAL; + break; + default: + break; + } + } + + protected: + void init() { + m_cholmod.final_asis = 1; + m_cholmod.supernodal = CHOLMOD_AUTO; + } +}; + +} // end namespace Eigen + +#endif // EIGEN_CHOLMODSUPPORT_H diff --git a/dae-cpp/Eigen/src/CholmodSupport/InternalHeaderCheck.h b/dae-cpp/Eigen/src/CholmodSupport/InternalHeaderCheck.h new file mode 100644 index 0000000..0fb3abc --- /dev/null +++ b/dae-cpp/Eigen/src/CholmodSupport/InternalHeaderCheck.h @@ -0,0 +1,3 @@ +#ifndef EIGEN_CHOLMODSUPPORT_MODULE_H +#error "Please include Eigen/CholmodSupport instead of including headers inside the src directory directly." +#endif diff --git a/dae-cpp/Eigen/src/Core/ArithmeticSequence.h b/dae-cpp/Eigen/src/Core/ArithmeticSequence.h new file mode 100644 index 0000000..ae3fac3 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/ArithmeticSequence.h @@ -0,0 +1,269 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2017 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ARITHMETIC_SEQUENCE_H +#define EIGEN_ARITHMETIC_SEQUENCE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +// Helper to cleanup the type of the increment: +template +struct cleanup_seq_incr { + typedef typename cleanup_index_type::type type; +}; + +} // namespace internal + +//-------------------------------------------------------------------------------- +// seq(first,last,incr) and seqN(first,size,incr) +//-------------------------------------------------------------------------------- + +template > +class ArithmeticSequence; + +template +ArithmeticSequence::type, + typename internal::cleanup_index_type::type, + typename internal::cleanup_seq_incr::type> +seqN(FirstType first, SizeType size, IncrType incr); + +/** \class ArithmeticSequence + * \ingroup Core_Module + * + * This class represents an arithmetic progression \f$ a_0, a_1, a_2, ..., a_{n-1}\f$ defined by + * its \em first value \f$ a_0 \f$, its \em size (aka length) \em n, and the \em increment (aka stride) + * that is equal to \f$ a_{i+1}-a_{i}\f$ for any \em i. + * + * It is internally used as the return type of the Eigen::seq and Eigen::seqN functions, and as the input arguments + * of DenseBase::operator()(const RowIndices&, const ColIndices&), and most of the time this is the + * only way it is used. + * + * \tparam FirstType type of the first element, usually an Index, + * but internally it can be a symbolic expression + * \tparam SizeType type representing the size of the sequence, usually an Index + * or a compile time integral constant. Internally, it can also be a symbolic expression + * \tparam IncrType type of the increment, can be a runtime Index, or a compile time integral constant (default is + * compile-time 1) + * + * \sa Eigen::seq, Eigen::seqN, DenseBase::operator()(const RowIndices&, const ColIndices&), class IndexedView + */ +template +class ArithmeticSequence { + public: + ArithmeticSequence(FirstType first, SizeType size) : m_first(first), m_size(size) {} + ArithmeticSequence(FirstType first, SizeType size, IncrType incr) : m_first(first), m_size(size), m_incr(incr) {} + + enum { + SizeAtCompileTime = internal::get_fixed_value::value, + IncrAtCompileTime = internal::get_fixed_value::value + }; + + /** \returns the size, i.e., number of elements, of the sequence */ + Index size() const { return m_size; } + + /** \returns the first element \f$ a_0 \f$ in the sequence */ + Index first() const { return m_first; } + + /** \returns the value \f$ a_i \f$ at index \a i in the sequence. */ + Index operator[](Index i) const { return m_first + i * m_incr; } + + const FirstType& firstObject() const { return m_first; } + const SizeType& sizeObject() const { return m_size; } + const IncrType& incrObject() const { return m_incr; } + + protected: + FirstType m_first; + SizeType m_size; + IncrType m_incr; + + public: + auto reverse() const -> decltype(Eigen::seqN(m_first + (m_size + fix<-1>()) * m_incr, m_size, -m_incr)) { + return seqN(m_first + (m_size + fix<-1>()) * m_incr, m_size, -m_incr); + } +}; + +/** \returns an ArithmeticSequence starting at \a first, of length \a size, and increment \a incr + * + * \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */ +template +ArithmeticSequence::type, + typename internal::cleanup_index_type::type, + typename internal::cleanup_seq_incr::type> +seqN(FirstType first, SizeType size, IncrType incr) { + return ArithmeticSequence::type, + typename internal::cleanup_index_type::type, + typename internal::cleanup_seq_incr::type>(first, size, incr); +} + +/** \returns an ArithmeticSequence starting at \a first, of length \a size, and unit increment + * + * \sa seqN(FirstType,SizeType,IncrType), seq(FirstType,LastType) */ +template +ArithmeticSequence::type, + typename internal::cleanup_index_type::type> +seqN(FirstType first, SizeType size) { + return ArithmeticSequence::type, + typename internal::cleanup_index_type::type>(first, size); +} + +#ifdef EIGEN_PARSED_BY_DOXYGEN + +/** \returns an ArithmeticSequence starting at \a f, up (or down) to \a l, and with positive (or negative) increment \a + * incr + * + * It is essentially an alias to: + * \code + * seqN(f, (l-f+incr)/incr, incr); + * \endcode + * + * \sa seqN(FirstType,SizeType,IncrType), seq(FirstType,LastType) + */ +template +auto seq(FirstType f, LastType l, IncrType incr); + +/** \returns an ArithmeticSequence starting at \a f, up (or down) to \a l, and unit increment + * + * It is essentially an alias to: + * \code + * seqN(f,l-f+1); + * \endcode + * + * \sa seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) + */ +template +auto seq(FirstType f, LastType l); + +#else // EIGEN_PARSED_BY_DOXYGEN + +template +auto seq(FirstType f, LastType l) + -> decltype(seqN(typename internal::cleanup_index_type::type(f), + (typename internal::cleanup_index_type::type(l) - + typename internal::cleanup_index_type::type(f) + fix<1>()))) { + return seqN(typename internal::cleanup_index_type::type(f), + (typename internal::cleanup_index_type::type(l) - + typename internal::cleanup_index_type::type(f) + fix<1>())); +} + +template +auto seq(FirstType f, LastType l, IncrType incr) + -> decltype(seqN(typename internal::cleanup_index_type::type(f), + (typename internal::cleanup_index_type::type(l) - + typename internal::cleanup_index_type::type(f) + + typename internal::cleanup_seq_incr::type(incr)) / + typename internal::cleanup_seq_incr::type(incr), + typename internal::cleanup_seq_incr::type(incr))) { + typedef typename internal::cleanup_seq_incr::type CleanedIncrType; + return seqN(typename internal::cleanup_index_type::type(f), + (typename internal::cleanup_index_type::type(l) - + typename internal::cleanup_index_type::type(f) + CleanedIncrType(incr)) / + CleanedIncrType(incr), + CleanedIncrType(incr)); +} + +#endif // EIGEN_PARSED_BY_DOXYGEN + +namespace placeholders { + +/** \cpp11 + * \returns a symbolic ArithmeticSequence representing the last \a size elements with increment \a incr. + * + * It is a shortcut for: \code seqN(last-(size-fix<1>)*incr, size, incr) \endcode + * + * \sa lastN(SizeType), seqN(FirstType,SizeType), seq(FirstType,LastType,IncrType) */ +template +auto lastN(SizeType size, IncrType incr) + -> decltype(seqN(Eigen::placeholders::last - (size - fix<1>()) * incr, size, incr)) { + return seqN(Eigen::placeholders::last - (size - fix<1>()) * incr, size, incr); +} + +/** \cpp11 + * \returns a symbolic ArithmeticSequence representing the last \a size elements with a unit increment. + * + * It is a shortcut for: \code seq(last+fix<1>-size, last) \endcode + * + * \sa lastN(SizeType,IncrType, seqN(FirstType,SizeType), seq(FirstType,LastType) */ +template +auto lastN(SizeType size) -> decltype(seqN(Eigen::placeholders::last + fix<1>() - size, size)) { + return seqN(Eigen::placeholders::last + fix<1>() - size, size); +} + +} // namespace placeholders + +namespace internal { + +// Convert a symbolic span into a usable one (i.e., remove last/end "keywords") +template +struct make_size_type { + typedef std::conditional_t::value, Index, T> type; +}; + +template +struct IndexedViewCompatibleType, XprSize> { + typedef ArithmeticSequence::type, IncrType> type; +}; + +template +ArithmeticSequence::type, IncrType> makeIndexedViewCompatible( + const ArithmeticSequence& ids, Index size, SpecializedType) { + return ArithmeticSequence::type, IncrType>( + eval_expr_given_size(ids.firstObject(), size), eval_expr_given_size(ids.sizeObject(), size), ids.incrObject()); +} + +template +struct get_compile_time_incr > { + enum { value = get_fixed_value::value }; +}; + +template +constexpr Index get_runtime_incr(const ArithmeticSequence& x) EIGEN_NOEXCEPT { + return static_cast(x.incrObject()); +} + +} // end namespace internal + +/** \namespace Eigen::indexing + * \ingroup Core_Module + * + * The sole purpose of this namespace is to be able to import all functions + * and symbols that are expected to be used within operator() for indexing + * and slicing. If you already imported the whole Eigen namespace: + * \code using namespace Eigen; \endcode + * then you are already all set. Otherwise, if you don't want/cannot import + * the whole Eigen namespace, the following line: + * \code using namespace Eigen::indexing; \endcode + * is equivalent to: + * \code + using Eigen::fix; + using Eigen::seq; + using Eigen::seqN; + using Eigen::placeholders::all; + using Eigen::placeholders::last; + using Eigen::placeholders::lastN; // c++11 only + using Eigen::placeholders::lastp1; + \endcode + */ +namespace indexing { +using Eigen::fix; +using Eigen::seq; +using Eigen::seqN; +using Eigen::placeholders::all; +using Eigen::placeholders::last; +using Eigen::placeholders::lastN; +using Eigen::placeholders::lastp1; +} // namespace indexing + +} // end namespace Eigen + +#endif // EIGEN_ARITHMETIC_SEQUENCE_H diff --git a/dae-cpp/Eigen/src/Core/Array.h b/dae-cpp/Eigen/src/Core/Array.h new file mode 100644 index 0000000..29c9682 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Array.h @@ -0,0 +1,369 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ARRAY_H +#define EIGEN_ARRAY_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits> + : traits> { + typedef ArrayXpr XprKind; + typedef ArrayBase> XprBase; +}; +} // namespace internal + +/** \class Array + * \ingroup Core_Module + * + * \brief General-purpose arrays with easy API for coefficient-wise operations + * + * The %Array class is very similar to the Matrix class. It provides + * general-purpose one- and two-dimensional arrays. The difference between the + * %Array and the %Matrix class is primarily in the API: the API for the + * %Array class provides easy access to coefficient-wise operations, while the + * API for the %Matrix class provides easy access to linear-algebra + * operations. + * + * See documentation of class Matrix for detailed information on the template parameters + * storage layout. + * + * This class can be extended with the help of the plugin mechanism described on the page + * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAY_PLUGIN. + * + * \sa \blank \ref TutorialArrayClass, \ref TopicClassHierarchy + */ +template +class Array : public PlainObjectBase> { + public: + typedef PlainObjectBase Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Array) + + enum { Options = Options_ }; + typedef typename Base::PlainObject PlainObject; + + protected: + template + friend struct internal::conservative_resize_like_impl; + + using Base::m_storage; + + public: + using Base::base; + using Base::coeff; + using Base::coeffRef; + + /** + * The usage of + * using Base::operator=; + * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped + * the usage of 'using'. This should be done only for operator=. + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array& operator=(const EigenBase& other) { + return Base::operator=(other); + } + + /** Set all the entries to \a value. + * \sa DenseBase::setConstant(), DenseBase::fill() + */ + /* This overload is needed because the usage of + * using Base::operator=; + * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped + * the usage of 'using'. This should be done only for operator=. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array& operator=(const Scalar& value) { + Base::setConstant(value); + return *this; + } + + /** Copies the value of the expression \a other into \c *this with automatic resizing. + * + * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized), + * it will be initialized. + * + * Note that copying a row-vector into a vector (and conversely) is allowed. + * The resizing, if any, is then done in the appropriate way so that row-vectors + * remain row-vectors and vectors remain vectors. + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array& operator=(const DenseBase& other) { + return Base::_set(other); + } + + /** This is a special case of the templated operator=. Its purpose is to + * prevent a default operator= from hiding the templated operator=. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array& operator=(const Array& other) { return Base::_set(other); } + + /** Default constructor. + * + * For fixed-size matrices, does nothing. + * + * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix + * is called a null matrix. This constructor is the unique way to create null matrices: resizing + * a matrix to 0 is not supported. + * + * \sa resize(Index,Index) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array() : Base() { EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + // FIXME is it still needed ?? + /** \internal */ + EIGEN_DEVICE_FUNC Array(internal::constructor_without_unaligned_array_assert) + : Base(internal::constructor_without_unaligned_array_assert()){EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED} +#endif + + EIGEN_DEVICE_FUNC Array(Array && other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible::value) + : Base(std::move(other)) { + } + EIGEN_DEVICE_FUNC Array& operator=(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable::value) { + Base::operator=(std::move(other)); + return *this; + } + + /** \copydoc PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const + * ArgTypes&... args) + * + * Example: \include Array_variadic_ctor_cxx11.cpp + * Output: \verbinclude Array_variadic_ctor_cxx11.out + * + * \sa Array(const std::initializer_list>&) + * \sa Array(const Scalar&), Array(const Scalar&,const Scalar&) + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, + const ArgTypes&... args) + : Base(a0, a1, a2, a3, args...) {} + + /** \brief Constructs an array and initializes it from the coefficients given as initializer-lists grouped by row. + * \cpp11 + * + * In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients: + * + * Example: \include Array_initializer_list_23_cxx11.cpp + * Output: \verbinclude Array_initializer_list_23_cxx11.out + * + * Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is + * triggered. + * + * In the case of a compile-time column 1D array, implicit transposition from a single row is allowed. + * Therefore Array{{1,2,3,4,5}} is legal and the more verbose syntax + * Array{{1},{2},{3},{4},{5}} can be avoided: + * + * Example: \include Array_initializer_list_vector_cxx11.cpp + * Output: \verbinclude Array_initializer_list_vector_cxx11.out + * + * In the case of fixed-sized arrays, the initializer list sizes must exactly match the array sizes, + * and implicit transposition is allowed for compile-time 1D arrays only. + * + * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Array( + const std::initializer_list>& list) + : Base(list) {} + +#ifndef EIGEN_PARSED_BY_DOXYGEN + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Array(const T& x) { + Base::template _init1(x); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1) { + this->template _init2(val0, val1); + } + +#else + /** \brief Constructs a fixed-sized array initialized with coefficients starting at \a data */ + EIGEN_DEVICE_FUNC explicit Array(const Scalar* data); + /** Constructs a vector or row-vector with given dimension. \only_for_vectors + * + * Note that this is only useful for dynamic-size vectors. For fixed-size vectors, + * it is redundant to pass the dimension here, so it makes more sense to use the default + * constructor Array() instead. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Array(Index dim); + /** constructs an initialized 1x1 Array with the given coefficient + * \sa const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args */ + Array(const Scalar& value); + /** constructs an uninitialized array with \a rows rows and \a cols columns. + * + * This is useful for dynamic-size arrays. For fixed-size arrays, + * it is redundant to pass these parameters, so one should use the default constructor + * Array() instead. */ + Array(Index rows, Index cols); + /** constructs an initialized 2D vector with given coefficients + * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) */ + Array(const Scalar& val0, const Scalar& val1); +#endif // end EIGEN_PARSED_BY_DOXYGEN + + /** constructs an initialized 3D vector with given coefficients + * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2) { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3) + m_storage.data()[0] = val0; + m_storage.data()[1] = val1; + m_storage.data()[2] = val2; + } + /** constructs an initialized 4D vector with given coefficients + * \sa Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, + const Scalar& val3) { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4) + m_storage.data()[0] = val0; + m_storage.data()[1] = val1; + m_storage.data()[2] = val2; + m_storage.data()[3] = val3; + } + + /** Copy constructor */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Array& other) : Base(other) {} + + private: + struct PrivateType {}; + + public: + /** \sa MatrixBase::operator=(const EigenBase&) */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array( + const EigenBase& other, + std::enable_if_t::value, PrivateType> = + PrivateType()) + : Base(other.derived()) {} + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { return 1; } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); } + +#ifdef EIGEN_ARRAY_PLUGIN +#include EIGEN_ARRAY_PLUGIN +#endif + + private: + template + friend struct internal::matrix_swap_impl; +}; + +/** \defgroup arraytypedefs Global array typedefs + * \ingroup Core_Module + * + * %Eigen defines several typedef shortcuts for most common 1D and 2D array types. + * + * The general patterns are the following: + * + * \c ArrayRowsColsType where \c Rows and \c Cols can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for + * dynamic size, and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c + * cd for complex double. + * + * For example, \c Array33d is a fixed-size 3x3 array type of doubles, and \c ArrayXXf is a dynamic-size matrix of + * floats. + * + * There are also \c ArraySizeType which are self-explanatory. For example, \c Array4cf is + * a fixed-size 1D array of 4 complex floats. + * + * With \cpp11, template alias are also defined for common sizes. + * They follow the same pattern as above except that the scalar type suffix is replaced by a + * template parameter, i.e.: + * - `ArrayRowsCols` where `Rows` and `Cols` can be \c 2,\c 3,\c 4, or \c X for fixed or dynamic size. + * - `ArraySize` where `Size` can be \c 2,\c 3,\c 4 or \c X for fixed or dynamic size 1D arrays. + * + * \sa class Array + */ + +#define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ + /** \ingroup arraytypedefs */ \ + typedef Array Array##SizeSuffix##SizeSuffix##TypeSuffix; \ + /** \ingroup arraytypedefs */ \ + typedef Array Array##SizeSuffix##TypeSuffix; + +#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \ + /** \ingroup arraytypedefs */ \ + typedef Array Array##Size##X##TypeSuffix; \ + /** \ingroup arraytypedefs */ \ + typedef Array Array##X##Size##TypeSuffix; + +#define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ + EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \ + EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \ + EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \ + EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \ + EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \ + EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \ + EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4) + +EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i) +EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f) +EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d) +EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex, cf) +EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex, cd) + +#undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES +#undef EIGEN_MAKE_ARRAY_TYPEDEFS +#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS + +#define EIGEN_MAKE_ARRAY_TYPEDEFS(Size, SizeSuffix) \ + /** \ingroup arraytypedefs */ \ + /** \brief \cpp11 */ \ + template \ + using Array##SizeSuffix##SizeSuffix = Array; \ + /** \ingroup arraytypedefs */ \ + /** \brief \cpp11 */ \ + template \ + using Array##SizeSuffix = Array; + +#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Size) \ + /** \ingroup arraytypedefs */ \ + /** \brief \cpp11 */ \ + template \ + using Array##Size##X = Array; \ + /** \ingroup arraytypedefs */ \ + /** \brief \cpp11 */ \ + template \ + using Array##X##Size = Array; + +EIGEN_MAKE_ARRAY_TYPEDEFS(2, 2) +EIGEN_MAKE_ARRAY_TYPEDEFS(3, 3) +EIGEN_MAKE_ARRAY_TYPEDEFS(4, 4) +EIGEN_MAKE_ARRAY_TYPEDEFS(Dynamic, X) +EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(2) +EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(3) +EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(4) + +#undef EIGEN_MAKE_ARRAY_TYPEDEFS +#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS + +#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \ + using Eigen::Matrix##SizeSuffix##TypeSuffix; \ + using Eigen::Vector##SizeSuffix##TypeSuffix; \ + using Eigen::RowVector##SizeSuffix##TypeSuffix; + +#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) + +#define EIGEN_USING_ARRAY_TYPEDEFS \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \ + EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd) + +} // end namespace Eigen + +#endif // EIGEN_ARRAY_H diff --git a/dae-cpp/Eigen/src/Core/ArrayBase.h b/dae-cpp/Eigen/src/Core/ArrayBase.h new file mode 100644 index 0000000..6237df4 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/ArrayBase.h @@ -0,0 +1,222 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ARRAYBASE_H +#define EIGEN_ARRAYBASE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +template +class MatrixWrapper; + +/** \class ArrayBase + * \ingroup Core_Module + * + * \brief Base class for all 1D and 2D array, and related expressions + * + * An array is similar to a dense vector or matrix. While matrices are mathematical + * objects with well defined linear algebra operators, an array is just a collection + * of scalar values arranged in a one or two dimensional fashion. As the main consequence, + * all operations applied to an array are performed coefficient wise. Furthermore, + * arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient + * constructors allowing to easily write generic code working for both scalar values + * and arrays. + * + * This class is the base that is inherited by all array expression types. + * + * \tparam Derived is the derived type, e.g., an array or an expression type. + * + * This class can be extended with the help of the plugin mechanism described on the page + * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN. + * + * \sa class MatrixBase, \ref TopicClassHierarchy + */ +template +class ArrayBase : public DenseBase { + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** The base class for a given storage type. */ + typedef ArrayBase StorageBaseType; + + typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl; + + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::Scalar Scalar; + typedef typename internal::packet_traits::type PacketScalar; + typedef typename NumTraits::Real RealScalar; + + typedef DenseBase Base; + using Base::ColsAtCompileTime; + using Base::Flags; + using Base::IsVectorAtCompileTime; + using Base::MaxColsAtCompileTime; + using Base::MaxRowsAtCompileTime; + using Base::MaxSizeAtCompileTime; + using Base::RowsAtCompileTime; + using Base::SizeAtCompileTime; + + using Base::coeff; + using Base::coeffRef; + using Base::cols; + using Base::const_cast_derived; + using Base::derived; + using Base::lazyAssign; + using Base::rows; + using Base::size; + using Base::operator-; + using Base::operator=; + using Base::operator+=; + using Base::operator-=; + using Base::operator*=; + using Base::operator/=; + + typedef typename Base::CoeffReturnType CoeffReturnType; + +#endif // not EIGEN_PARSED_BY_DOXYGEN + +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef typename Base::PlainObject PlainObject; + + /** \internal Represents a matrix with all coefficients equal to one another*/ + typedef CwiseNullaryOp, PlainObject> ConstantReturnType; +#endif // not EIGEN_PARSED_BY_DOXYGEN + +#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase +#define EIGEN_DOC_UNARY_ADDONS(X, Y) +#include "../plugins/MatrixCwiseUnaryOps.inc" +#include "../plugins/ArrayCwiseUnaryOps.inc" +#include "../plugins/CommonCwiseBinaryOps.inc" +#include "../plugins/MatrixCwiseBinaryOps.inc" +#include "../plugins/ArrayCwiseBinaryOps.inc" +#ifdef EIGEN_ARRAYBASE_PLUGIN +#include EIGEN_ARRAYBASE_PLUGIN +#endif +#undef EIGEN_CURRENT_STORAGE_BASE_CLASS +#undef EIGEN_DOC_UNARY_ADDONS + + /** Special case of the template operator=, in order to prevent the compiler + * from generating a default operator= (issue hit with g++ 4.1) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const ArrayBase& other) { + internal::call_assignment(derived(), other.derived()); + return derived(); + } + + /** Set all the entries to \a value. + * \sa DenseBase::setConstant(), DenseBase::fill() */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Scalar& value) { + Base::setConstant(value); + return derived(); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const Scalar& scalar); + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const Scalar& scalar); + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const ArrayBase& other); + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const ArrayBase& other); + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*=(const ArrayBase& other); + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator/=(const ArrayBase& other); + + public: + EIGEN_DEVICE_FUNC ArrayBase& array() { return *this; } + EIGEN_DEVICE_FUNC const ArrayBase& array() const { return *this; } + + /** \returns an \link Eigen::MatrixBase Matrix \endlink expression of this array + * \sa MatrixBase::array() */ + EIGEN_DEVICE_FUNC MatrixWrapper matrix() { return MatrixWrapper(derived()); } + EIGEN_DEVICE_FUNC const MatrixWrapper matrix() const { + return MatrixWrapper(derived()); + } + + // template + // inline void evalTo(Dest& dst) const { dst = matrix(); } + + protected: + EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase) + EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase) + + private: + explicit ArrayBase(Index); + ArrayBase(Index, Index); + template + explicit ArrayBase(const ArrayBase&); + + protected: + // mixing arrays and matrices is not legal + template + Derived& operator+=(const MatrixBase&) { + EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1, + YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); + return *this; + } + // mixing arrays and matrices is not legal + template + Derived& operator-=(const MatrixBase&) { + EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1, + YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); + return *this; + } +}; + +/** replaces \c *this by \c *this - \a other. + * + * \returns a reference to \c *this + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& ArrayBase::operator-=(const ArrayBase& other) { + call_assignment(derived(), other.derived(), internal::sub_assign_op()); + return derived(); +} + +/** replaces \c *this by \c *this + \a other. + * + * \returns a reference to \c *this + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& ArrayBase::operator+=(const ArrayBase& other) { + call_assignment(derived(), other.derived(), internal::add_assign_op()); + return derived(); +} + +/** replaces \c *this by \c *this * \a other coefficient wise. + * + * \returns a reference to \c *this + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& ArrayBase::operator*=(const ArrayBase& other) { + call_assignment(derived(), other.derived(), internal::mul_assign_op()); + return derived(); +} + +/** replaces \c *this by \c *this / \a other coefficient wise. + * + * \returns a reference to \c *this + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& ArrayBase::operator/=(const ArrayBase& other) { + call_assignment(derived(), other.derived(), internal::div_assign_op()); + return derived(); +} + +} // end namespace Eigen + +#endif // EIGEN_ARRAYBASE_H diff --git a/dae-cpp/Eigen/src/Core/ArrayWrapper.h b/dae-cpp/Eigen/src/Core/ArrayWrapper.h new file mode 100644 index 0000000..b45395d --- /dev/null +++ b/dae-cpp/Eigen/src/Core/ArrayWrapper.h @@ -0,0 +1,173 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ARRAYWRAPPER_H +#define EIGEN_ARRAYWRAPPER_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class ArrayWrapper + * \ingroup Core_Module + * + * \brief Expression of a mathematical vector or matrix as an array object + * + * This class is the return type of MatrixBase::array(), and most of the time + * this is the only way it is use. + * + * \sa MatrixBase::array(), class MatrixWrapper + */ + +namespace internal { +template +struct traits > : public traits > { + typedef ArrayXpr XprKind; + // Let's remove NestByRefBit + enum { + Flags0 = traits >::Flags, + LvalueBitFlag = is_lvalue::value ? LvalueBit : 0, + Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag + }; +}; +} // namespace internal + +template +class ArrayWrapper : public ArrayBase > { + public: + typedef ArrayBase Base; + EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper) + typedef internal::remove_all_t NestedExpression; + + typedef std::conditional_t::value, Scalar, const Scalar> + ScalarWithConstIfNotLvalue; + + typedef typename internal::ref_selector::non_const_type NestedExpressionType; + + using Base::coeffRef; + + EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {} + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { + return m_expression.outerStride(); + } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { + return m_expression.innerStride(); + } + + EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } + EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_expression.data(); } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const { + return m_expression.coeffRef(rowId, colId); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { return m_expression.coeffRef(index); } + + template + EIGEN_DEVICE_FUNC inline void evalTo(Dest& dst) const { + dst = m_expression; + } + + EIGEN_DEVICE_FUNC const internal::remove_all_t& nestedExpression() const { + return m_expression; + } + + /** Forwards the resizing request to the nested expression + * \sa DenseBase::resize(Index) */ + EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); } + /** Forwards the resizing request to the nested expression + * \sa DenseBase::resize(Index,Index)*/ + EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { m_expression.resize(rows, cols); } + + protected: + NestedExpressionType m_expression; +}; + +/** \class MatrixWrapper + * \ingroup Core_Module + * + * \brief Expression of an array as a mathematical vector or matrix + * + * This class is the return type of ArrayBase::matrix(), and most of the time + * this is the only way it is use. + * + * \sa MatrixBase::matrix(), class ArrayWrapper + */ + +namespace internal { +template +struct traits > : public traits > { + typedef MatrixXpr XprKind; + // Let's remove NestByRefBit + enum { + Flags0 = traits >::Flags, + LvalueBitFlag = is_lvalue::value ? LvalueBit : 0, + Flags = (Flags0 & ~(NestByRefBit | LvalueBit)) | LvalueBitFlag + }; +}; +} // namespace internal + +template +class MatrixWrapper : public MatrixBase > { + public: + typedef MatrixBase > Base; + EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper) + typedef internal::remove_all_t NestedExpression; + + typedef std::conditional_t::value, Scalar, const Scalar> + ScalarWithConstIfNotLvalue; + + typedef typename internal::ref_selector::non_const_type NestedExpressionType; + + using Base::coeffRef; + + EIGEN_DEVICE_FUNC explicit inline MatrixWrapper(ExpressionType& matrix) : m_expression(matrix) {} + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { + return m_expression.outerStride(); + } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { + return m_expression.innerStride(); + } + + EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } + EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_expression.data(); } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const { + return m_expression.derived().coeffRef(rowId, colId); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { return m_expression.coeffRef(index); } + + EIGEN_DEVICE_FUNC const internal::remove_all_t& nestedExpression() const { + return m_expression; + } + + /** Forwards the resizing request to the nested expression + * \sa DenseBase::resize(Index) */ + EIGEN_DEVICE_FUNC void resize(Index newSize) { m_expression.resize(newSize); } + /** Forwards the resizing request to the nested expression + * \sa DenseBase::resize(Index,Index)*/ + EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { m_expression.resize(rows, cols); } + + protected: + NestedExpressionType m_expression; +}; + +} // end namespace Eigen + +#endif // EIGEN_ARRAYWRAPPER_H diff --git a/dae-cpp/Eigen/src/Core/Assign.h b/dae-cpp/Eigen/src/Core/Assign.h new file mode 100644 index 0000000..4b30f7b --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Assign.h @@ -0,0 +1,80 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2007 Michael Olbrich +// Copyright (C) 2006-2010 Benoit Jacob +// Copyright (C) 2008 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ASSIGN_H +#define EIGEN_ASSIGN_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::lazyAssign(const DenseBase& other) { + enum { SameType = internal::is_same::value }; + + EIGEN_STATIC_ASSERT_LVALUE(Derived) + EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived, OtherDerived) + EIGEN_STATIC_ASSERT( + SameType, + YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) + + eigen_assert(rows() == other.rows() && cols() == other.cols()); + internal::call_assignment_no_alias(derived(), other.derived()); + + return derived(); +} + +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::operator=(const DenseBase& other) { + internal::call_assignment(derived(), other.derived()); + return derived(); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::operator=(const DenseBase& other) { + internal::call_assignment(derived(), other.derived()); + return derived(); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const MatrixBase& other) { + internal::call_assignment(derived(), other.derived()); + return derived(); +} + +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const DenseBase& other) { + internal::call_assignment(derived(), other.derived()); + return derived(); +} + +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const EigenBase& other) { + internal::call_assignment(derived(), other.derived()); + return derived(); +} + +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::operator=( + const ReturnByValue& other) { + other.derived().evalTo(derived()); + return derived(); +} + +} // end namespace Eigen + +#endif // EIGEN_ASSIGN_H diff --git a/dae-cpp/Eigen/src/Core/AssignEvaluator.h b/dae-cpp/Eigen/src/Core/AssignEvaluator.h new file mode 100644 index 0000000..f7f0b23 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/AssignEvaluator.h @@ -0,0 +1,951 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2011 Benoit Jacob +// Copyright (C) 2011-2014 Gael Guennebaud +// Copyright (C) 2011-2012 Jitse Niesen +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ASSIGN_EVALUATOR_H +#define EIGEN_ASSIGN_EVALUATOR_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +// This implementation is based on Assign.h + +namespace internal { + +/*************************************************************************** + * Part 1 : the logic deciding a strategy for traversal and unrolling * + ***************************************************************************/ + +// copy_using_evaluator_traits is based on assign_traits + +template +struct copy_using_evaluator_traits { + typedef typename DstEvaluator::XprType Dst; + typedef typename Dst::Scalar DstScalar; + + enum { DstFlags = DstEvaluator::Flags, SrcFlags = SrcEvaluator::Flags }; + + public: + enum { + DstAlignment = DstEvaluator::Alignment, + SrcAlignment = SrcEvaluator::Alignment, + DstHasDirectAccess = (DstFlags & DirectAccessBit) == DirectAccessBit, + JointAlignment = plain_enum_min(DstAlignment, SrcAlignment) + }; + + private: + enum { + InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime) + : int(DstFlags) & RowMajorBit ? int(Dst::ColsAtCompileTime) + : int(Dst::RowsAtCompileTime), + InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime) + : int(DstFlags) & RowMajorBit ? int(Dst::MaxColsAtCompileTime) + : int(Dst::MaxRowsAtCompileTime), + RestrictedInnerSize = min_size_prefer_fixed(InnerSize, MaxPacketSize), + RestrictedLinearSize = min_size_prefer_fixed(Dst::SizeAtCompileTime, MaxPacketSize), + OuterStride = int(outer_stride_at_compile_time::ret), + MaxSizeAtCompileTime = Dst::SizeAtCompileTime + }; + + // TODO distinguish between linear traversal and inner-traversals + typedef typename find_best_packet::type LinearPacketType; + typedef typename find_best_packet::type InnerPacketType; + + enum { + LinearPacketSize = unpacket_traits::size, + InnerPacketSize = unpacket_traits::size + }; + + public: + enum { + LinearRequiredAlignment = unpacket_traits::alignment, + InnerRequiredAlignment = unpacket_traits::alignment + }; + + private: + enum { + DstIsRowMajor = DstFlags & RowMajorBit, + SrcIsRowMajor = SrcFlags & RowMajorBit, + StorageOrdersAgree = (int(DstIsRowMajor) == int(SrcIsRowMajor)), + MightVectorize = bool(StorageOrdersAgree) && (int(DstFlags) & int(SrcFlags) & ActualPacketAccessBit) && + bool(functor_traits::PacketAccess), + MayInnerVectorize = MightVectorize && int(InnerSize) != Dynamic && int(InnerSize) % int(InnerPacketSize) == 0 && + int(OuterStride) != Dynamic && int(OuterStride) % int(InnerPacketSize) == 0 && + (EIGEN_UNALIGNED_VECTORIZE || int(JointAlignment) >= int(InnerRequiredAlignment)), + MayLinearize = bool(StorageOrdersAgree) && (int(DstFlags) & int(SrcFlags) & LinearAccessBit), + MayLinearVectorize = bool(MightVectorize) && bool(MayLinearize) && bool(DstHasDirectAccess) && + (EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment) >= int(LinearRequiredAlignment)) || + MaxSizeAtCompileTime == Dynamic), + /* If the destination isn't aligned, we have to do runtime checks and we don't unroll, + so it's only good for large enough sizes. */ + MaySliceVectorize = bool(MightVectorize) && bool(DstHasDirectAccess) && + (int(InnerMaxSize) == Dynamic || + int(InnerMaxSize) >= (EIGEN_UNALIGNED_VECTORIZE ? InnerPacketSize : (3 * InnerPacketSize))) + /* slice vectorization can be slow, so we only want it if the slices are big, which is + indicated by InnerMaxSize rather than InnerSize, think of the case of a dynamic block + in a fixed-size matrix + However, with EIGEN_UNALIGNED_VECTORIZE and unrolling, slice vectorization is still worth it */ + }; + + public: + enum { + Traversal = int(Dst::SizeAtCompileTime) == 0 + ? int(AllAtOnceTraversal) // If compile-size is zero, traversing will fail at compile-time. + : (int(MayLinearVectorize) && (LinearPacketSize > InnerPacketSize)) ? int(LinearVectorizedTraversal) + : int(MayInnerVectorize) ? int(InnerVectorizedTraversal) + : int(MayLinearVectorize) ? int(LinearVectorizedTraversal) + : int(MaySliceVectorize) ? int(SliceVectorizedTraversal) + : int(MayLinearize) ? int(LinearTraversal) + : int(DefaultTraversal), + Vectorized = int(Traversal) == InnerVectorizedTraversal || int(Traversal) == LinearVectorizedTraversal || + int(Traversal) == SliceVectorizedTraversal + }; + + typedef std::conditional_t PacketType; + + private: + enum { + ActualPacketSize = int(Traversal) == LinearVectorizedTraversal ? LinearPacketSize + : Vectorized ? InnerPacketSize + : 1, + UnrollingLimit = EIGEN_UNROLLING_LIMIT * ActualPacketSize, + MayUnrollCompletely = + int(Dst::SizeAtCompileTime) != Dynamic && + int(Dst::SizeAtCompileTime) * (int(DstEvaluator::CoeffReadCost) + int(SrcEvaluator::CoeffReadCost)) <= + int(UnrollingLimit), + MayUnrollInner = + int(InnerSize) != Dynamic && + int(InnerSize) * (int(DstEvaluator::CoeffReadCost) + int(SrcEvaluator::CoeffReadCost)) <= int(UnrollingLimit) + }; + + public: + enum { + Unrolling = (int(Traversal) == int(InnerVectorizedTraversal) || int(Traversal) == int(DefaultTraversal)) + ? (int(MayUnrollCompletely) ? int(CompleteUnrolling) + : int(MayUnrollInner) ? int(InnerUnrolling) + : int(NoUnrolling)) + : int(Traversal) == int(LinearVectorizedTraversal) + ? (bool(MayUnrollCompletely) && + (EIGEN_UNALIGNED_VECTORIZE || (int(DstAlignment) >= int(LinearRequiredAlignment))) + ? int(CompleteUnrolling) + : int(NoUnrolling)) + : int(Traversal) == int(LinearTraversal) + ? (bool(MayUnrollCompletely) ? int(CompleteUnrolling) : int(NoUnrolling)) +#if EIGEN_UNALIGNED_VECTORIZE + : int(Traversal) == int(SliceVectorizedTraversal) + ? (bool(MayUnrollInner) ? int(InnerUnrolling) : int(NoUnrolling)) +#endif + : int(NoUnrolling) + }; + +#ifdef EIGEN_DEBUG_ASSIGN + static void debug() { + std::cerr << "DstXpr: " << typeid(typename DstEvaluator::XprType).name() << std::endl; + std::cerr << "SrcXpr: " << typeid(typename SrcEvaluator::XprType).name() << std::endl; + std::cerr.setf(std::ios::hex, std::ios::basefield); + std::cerr << "DstFlags" + << " = " << DstFlags << " (" << demangle_flags(DstFlags) << " )" << std::endl; + std::cerr << "SrcFlags" + << " = " << SrcFlags << " (" << demangle_flags(SrcFlags) << " )" << std::endl; + std::cerr.unsetf(std::ios::hex); + EIGEN_DEBUG_VAR(DstAlignment) + EIGEN_DEBUG_VAR(SrcAlignment) + EIGEN_DEBUG_VAR(LinearRequiredAlignment) + EIGEN_DEBUG_VAR(InnerRequiredAlignment) + EIGEN_DEBUG_VAR(JointAlignment) + EIGEN_DEBUG_VAR(InnerSize) + EIGEN_DEBUG_VAR(InnerMaxSize) + EIGEN_DEBUG_VAR(LinearPacketSize) + EIGEN_DEBUG_VAR(InnerPacketSize) + EIGEN_DEBUG_VAR(ActualPacketSize) + EIGEN_DEBUG_VAR(StorageOrdersAgree) + EIGEN_DEBUG_VAR(MightVectorize) + EIGEN_DEBUG_VAR(MayLinearize) + EIGEN_DEBUG_VAR(MayInnerVectorize) + EIGEN_DEBUG_VAR(MayLinearVectorize) + EIGEN_DEBUG_VAR(MaySliceVectorize) + std::cerr << "Traversal" + << " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl; + EIGEN_DEBUG_VAR(SrcEvaluator::CoeffReadCost) + EIGEN_DEBUG_VAR(DstEvaluator::CoeffReadCost) + EIGEN_DEBUG_VAR(Dst::SizeAtCompileTime) + EIGEN_DEBUG_VAR(UnrollingLimit) + EIGEN_DEBUG_VAR(MayUnrollCompletely) + EIGEN_DEBUG_VAR(MayUnrollInner) + std::cerr << "Unrolling" + << " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl; + std::cerr << std::endl; + } +#endif +}; + +/*************************************************************************** + * Part 2 : meta-unrollers + ***************************************************************************/ + +/************************ +*** Default traversal *** +************************/ + +template +struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling { + // FIXME: this is not very clean, perhaps this information should be provided by the kernel? + typedef typename Kernel::DstEvaluatorType DstEvaluatorType; + typedef typename DstEvaluatorType::XprType DstXprType; + + enum { outer = Index / DstXprType::InnerSizeAtCompileTime, inner = Index % DstXprType::InnerSizeAtCompileTime }; + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) { + kernel.assignCoeffByOuterInner(outer, inner); + copy_using_evaluator_DefaultTraversal_CompleteUnrolling::run(kernel); + } +}; + +template +struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&) {} +}; + +template +struct copy_using_evaluator_DefaultTraversal_InnerUnrolling { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel, Index outer) { + kernel.assignCoeffByOuterInner(outer, Index_); + copy_using_evaluator_DefaultTraversal_InnerUnrolling::run(kernel, outer); + } +}; + +template +struct copy_using_evaluator_DefaultTraversal_InnerUnrolling { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index) {} +}; + +/*********************** +*** Linear traversal *** +***********************/ + +template +struct copy_using_evaluator_LinearTraversal_CompleteUnrolling { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) { + kernel.assignCoeff(Index); + copy_using_evaluator_LinearTraversal_CompleteUnrolling::run(kernel); + } +}; + +template +struct copy_using_evaluator_LinearTraversal_CompleteUnrolling { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) {} +}; + +/************************** +*** Inner vectorization *** +**************************/ + +template +struct copy_using_evaluator_innervec_CompleteUnrolling { + // FIXME: this is not very clean, perhaps this information should be provided by the kernel? + typedef typename Kernel::DstEvaluatorType DstEvaluatorType; + typedef typename DstEvaluatorType::XprType DstXprType; + typedef typename Kernel::PacketType PacketType; + + enum { + outer = Index / DstXprType::InnerSizeAtCompileTime, + inner = Index % DstXprType::InnerSizeAtCompileTime, + SrcAlignment = Kernel::AssignmentTraits::SrcAlignment, + DstAlignment = Kernel::AssignmentTraits::DstAlignment + }; + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) { + kernel.template assignPacketByOuterInner(outer, inner); + enum { NextIndex = Index + unpacket_traits::size }; + copy_using_evaluator_innervec_CompleteUnrolling::run(kernel); + } +}; + +template +struct copy_using_evaluator_innervec_CompleteUnrolling { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&) {} +}; + +template +struct copy_using_evaluator_innervec_InnerUnrolling { + typedef typename Kernel::PacketType PacketType; + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel, Index outer) { + kernel.template assignPacketByOuterInner(outer, Index_); + enum { NextIndex = Index_ + unpacket_traits::size }; + copy_using_evaluator_innervec_InnerUnrolling::run(kernel, + outer); + } +}; + +template +struct copy_using_evaluator_innervec_InnerUnrolling { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index) {} +}; + +/*************************************************************************** + * Part 3 : implementation of all cases + ***************************************************************************/ + +// dense_assignment_loop is based on assign_impl + +template +struct dense_assignment_loop; + +/************************ +***** Special Cases ***** +************************/ + +// Zero-sized assignment is a no-op. +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE EIGEN_CONSTEXPR run(Kernel& /*kernel*/) { + EIGEN_STATIC_ASSERT(int(Kernel::DstEvaluatorType::XprType::SizeAtCompileTime) == 0, + EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT) + } +}; + +/************************ +*** Default traversal *** +************************/ + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE run(Kernel& kernel) { + for (Index outer = 0; outer < kernel.outerSize(); ++outer) { + for (Index inner = 0; inner < kernel.innerSize(); ++inner) { + kernel.assignCoeffByOuterInner(outer, inner); + } + } + } +}; + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) { + typedef typename Kernel::DstEvaluatorType::XprType DstXprType; + copy_using_evaluator_DefaultTraversal_CompleteUnrolling::run(kernel); + } +}; + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) { + typedef typename Kernel::DstEvaluatorType::XprType DstXprType; + + const Index outerSize = kernel.outerSize(); + for (Index outer = 0; outer < outerSize; ++outer) + copy_using_evaluator_DefaultTraversal_InnerUnrolling::run(kernel, + outer); + } +}; + +/*************************** +*** Linear vectorization *** +***************************/ + +// The goal of unaligned_dense_assignment_loop is simply to factorize the handling +// of the non vectorizable beginning and ending parts + +template +struct unaligned_dense_assignment_loop { + // if IsAligned = true, then do nothing + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&, Index, Index) {} +}; + +template <> +struct unaligned_dense_assignment_loop { + // MSVC must not inline this functions. If it does, it fails to optimize the + // packet access path. + // FIXME check which version exhibits this issue +#if EIGEN_COMP_MSVC + template + static EIGEN_DONT_INLINE void run(Kernel& kernel, Index start, Index end) +#else + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel, Index start, Index end) +#endif + { + for (Index index = start; index < end; ++index) kernel.assignCoeff(index); + } +}; + +template +struct copy_using_evaluator_linearvec_CompleteUnrolling { + // FIXME: this is not very clean, perhaps this information should be provided by the kernel? + typedef typename Kernel::DstEvaluatorType DstEvaluatorType; + typedef typename DstEvaluatorType::XprType DstXprType; + typedef typename Kernel::PacketType PacketType; + + enum { SrcAlignment = Kernel::AssignmentTraits::SrcAlignment, DstAlignment = Kernel::AssignmentTraits::DstAlignment }; + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) { + kernel.template assignPacket(Index); + enum { NextIndex = Index + unpacket_traits::size }; + copy_using_evaluator_linearvec_CompleteUnrolling::run(kernel); + } +}; + +template +struct copy_using_evaluator_linearvec_CompleteUnrolling { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&) {} +}; + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) { + const Index size = kernel.size(); + typedef typename Kernel::Scalar Scalar; + typedef typename Kernel::PacketType PacketType; + enum { + requestedAlignment = Kernel::AssignmentTraits::LinearRequiredAlignment, + packetSize = unpacket_traits::size, + dstIsAligned = int(Kernel::AssignmentTraits::DstAlignment) >= int(requestedAlignment), + dstAlignment = packet_traits::AlignedOnScalar ? int(requestedAlignment) + : int(Kernel::AssignmentTraits::DstAlignment), + srcAlignment = Kernel::AssignmentTraits::JointAlignment + }; + const Index alignedStart = + dstIsAligned ? 0 : internal::first_aligned(kernel.dstDataPtr(), size); + const Index alignedEnd = alignedStart + ((size - alignedStart) / packetSize) * packetSize; + + unaligned_dense_assignment_loop::run(kernel, 0, alignedStart); + + for (Index index = alignedStart; index < alignedEnd; index += packetSize) + kernel.template assignPacket(index); + + unaligned_dense_assignment_loop<>::run(kernel, alignedEnd, size); + } +}; + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) { + typedef typename Kernel::DstEvaluatorType::XprType DstXprType; + typedef typename Kernel::PacketType PacketType; + + enum { + size = DstXprType::SizeAtCompileTime, + packetSize = unpacket_traits::size, + alignedSize = (int(size) / packetSize) * packetSize + }; + + copy_using_evaluator_linearvec_CompleteUnrolling::run(kernel); + copy_using_evaluator_LinearTraversal_CompleteUnrolling::run(kernel); + } +}; + +/************************** +*** Inner vectorization *** +**************************/ + +template +struct dense_assignment_loop { + typedef typename Kernel::PacketType PacketType; + enum { SrcAlignment = Kernel::AssignmentTraits::SrcAlignment, DstAlignment = Kernel::AssignmentTraits::DstAlignment }; + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) { + const Index innerSize = kernel.innerSize(); + const Index outerSize = kernel.outerSize(); + const Index packetSize = unpacket_traits::size; + for (Index outer = 0; outer < outerSize; ++outer) + for (Index inner = 0; inner < innerSize; inner += packetSize) + kernel.template assignPacketByOuterInner(outer, inner); + } +}; + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) { + typedef typename Kernel::DstEvaluatorType::XprType DstXprType; + copy_using_evaluator_innervec_CompleteUnrolling::run(kernel); + } +}; + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) { + typedef typename Kernel::DstEvaluatorType::XprType DstXprType; + typedef typename Kernel::AssignmentTraits Traits; + const Index outerSize = kernel.outerSize(); + for (Index outer = 0; outer < outerSize; ++outer) + copy_using_evaluator_innervec_InnerUnrolling::run(kernel, outer); + } +}; + +/*********************** +*** Linear traversal *** +***********************/ + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) { + const Index size = kernel.size(); + for (Index i = 0; i < size; ++i) kernel.assignCoeff(i); + } +}; + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) { + typedef typename Kernel::DstEvaluatorType::XprType DstXprType; + copy_using_evaluator_LinearTraversal_CompleteUnrolling::run(kernel); + } +}; + +/************************** +*** Slice vectorization *** +***************************/ + +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) { + typedef typename Kernel::Scalar Scalar; + typedef typename Kernel::PacketType PacketType; + enum { + packetSize = unpacket_traits::size, + requestedAlignment = int(Kernel::AssignmentTraits::InnerRequiredAlignment), + alignable = + packet_traits::AlignedOnScalar || int(Kernel::AssignmentTraits::DstAlignment) >= sizeof(Scalar), + dstIsAligned = int(Kernel::AssignmentTraits::DstAlignment) >= int(requestedAlignment), + dstAlignment = alignable ? int(requestedAlignment) : int(Kernel::AssignmentTraits::DstAlignment) + }; + const Scalar* dst_ptr = kernel.dstDataPtr(); + if ((!bool(dstIsAligned)) && (std::uintptr_t(dst_ptr) % sizeof(Scalar)) > 0) { + // the pointer is not aligned-on scalar, so alignment is not possible + return dense_assignment_loop::run(kernel); + } + const Index packetAlignedMask = packetSize - 1; + const Index innerSize = kernel.innerSize(); + const Index outerSize = kernel.outerSize(); + const Index alignedStep = alignable ? (packetSize - kernel.outerStride() % packetSize) & packetAlignedMask : 0; + Index alignedStart = + ((!alignable) || bool(dstIsAligned)) ? 0 : internal::first_aligned(dst_ptr, innerSize); + + for (Index outer = 0; outer < outerSize; ++outer) { + const Index alignedEnd = alignedStart + ((innerSize - alignedStart) & ~packetAlignedMask); + // do the non-vectorizable part of the assignment + for (Index inner = 0; inner < alignedStart; ++inner) kernel.assignCoeffByOuterInner(outer, inner); + + // do the vectorizable part of the assignment + for (Index inner = alignedStart; inner < alignedEnd; inner += packetSize) + kernel.template assignPacketByOuterInner(outer, inner); + + // do the non-vectorizable part of the assignment + for (Index inner = alignedEnd; inner < innerSize; ++inner) kernel.assignCoeffByOuterInner(outer, inner); + + alignedStart = numext::mini((alignedStart + alignedStep) % packetSize, innerSize); + } + } +}; + +#if EIGEN_UNALIGNED_VECTORIZE +template +struct dense_assignment_loop { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) { + typedef typename Kernel::DstEvaluatorType::XprType DstXprType; + typedef typename Kernel::PacketType PacketType; + + enum { + innerSize = DstXprType::InnerSizeAtCompileTime, + packetSize = unpacket_traits::size, + vectorizableSize = (int(innerSize) / int(packetSize)) * int(packetSize), + size = DstXprType::SizeAtCompileTime + }; + + for (Index outer = 0; outer < kernel.outerSize(); ++outer) { + copy_using_evaluator_innervec_InnerUnrolling::run(kernel, outer); + copy_using_evaluator_DefaultTraversal_InnerUnrolling::run(kernel, outer); + } + } +}; +#endif + +/*************************************************************************** + * Part 4 : Generic dense assignment kernel + ***************************************************************************/ + +// This class generalize the assignment of a coefficient (or packet) from one dense evaluator +// to another dense writable evaluator. +// It is parametrized by the two evaluators, and the actual assignment functor. +// This abstraction level permits to keep the evaluation loops as simple and as generic as possible. +// One can customize the assignment using this generic dense_assignment_kernel with different +// functors, or by completely overloading it, by-passing a functor. +template +class generic_dense_assignment_kernel { + protected: + typedef typename DstEvaluatorTypeT::XprType DstXprType; + typedef typename SrcEvaluatorTypeT::XprType SrcXprType; + + public: + typedef DstEvaluatorTypeT DstEvaluatorType; + typedef SrcEvaluatorTypeT SrcEvaluatorType; + typedef typename DstEvaluatorType::Scalar Scalar; + typedef copy_using_evaluator_traits AssignmentTraits; + typedef typename AssignmentTraits::PacketType PacketType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE generic_dense_assignment_kernel(DstEvaluatorType& dst, + const SrcEvaluatorType& src, + const Functor& func, DstXprType& dstExpr) + : m_dst(dst), m_src(src), m_functor(func), m_dstExpr(dstExpr) { +#ifdef EIGEN_DEBUG_ASSIGN + AssignmentTraits::debug(); +#endif + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_dstExpr.size(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerSize() const EIGEN_NOEXCEPT { return m_dstExpr.innerSize(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const EIGEN_NOEXCEPT { return m_dstExpr.outerSize(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_dstExpr.rows(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_dstExpr.cols(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT { return m_dstExpr.outerStride(); } + + EIGEN_DEVICE_FUNC DstEvaluatorType& dstEvaluator() EIGEN_NOEXCEPT { return m_dst; } + EIGEN_DEVICE_FUNC const SrcEvaluatorType& srcEvaluator() const EIGEN_NOEXCEPT { return m_src; } + + /// Assign src(row,col) to dst(row,col) through the assignment functor. + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col) { + m_functor.assignCoeff(m_dst.coeffRef(row, col), m_src.coeff(row, col)); + } + + /// \sa assignCoeff(Index,Index) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index index) { + m_functor.assignCoeff(m_dst.coeffRef(index), m_src.coeff(index)); + } + + /// \sa assignCoeff(Index,Index) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeffByOuterInner(Index outer, Index inner) { + Index row = rowIndexByOuterInner(outer, inner); + Index col = colIndexByOuterInner(outer, inner); + assignCoeff(row, col); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index row, Index col) { + m_functor.template assignPacket(&m_dst.coeffRef(row, col), + m_src.template packet(row, col)); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index index) { + m_functor.template assignPacket(&m_dst.coeffRef(index), m_src.template packet(index)); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner) { + Index row = rowIndexByOuterInner(outer, inner); + Index col = colIndexByOuterInner(outer, inner); + assignPacket(row, col); + } + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) { + typedef typename DstEvaluatorType::ExpressionTraits Traits; + return int(Traits::RowsAtCompileTime) == 1 ? 0 + : int(Traits::ColsAtCompileTime) == 1 ? inner + : int(DstEvaluatorType::Flags) & RowMajorBit ? outer + : inner; + } + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) { + typedef typename DstEvaluatorType::ExpressionTraits Traits; + return int(Traits::ColsAtCompileTime) == 1 ? 0 + : int(Traits::RowsAtCompileTime) == 1 ? inner + : int(DstEvaluatorType::Flags) & RowMajorBit ? inner + : outer; + } + + EIGEN_DEVICE_FUNC const Scalar* dstDataPtr() const { return m_dstExpr.data(); } + + protected: + DstEvaluatorType& m_dst; + const SrcEvaluatorType& m_src; + const Functor& m_functor; + // TODO find a way to avoid the needs of the original expression + DstXprType& m_dstExpr; +}; + +// Special kernel used when computing small products whose operands have dynamic dimensions. It ensures that the +// PacketSize used is no larger than 4, thereby increasing the chance that vectorized instructions will be used +// when computing the product. + +template +class restricted_packet_dense_assignment_kernel + : public generic_dense_assignment_kernel { + protected: + typedef generic_dense_assignment_kernel Base; + + public: + typedef typename Base::Scalar Scalar; + typedef typename Base::DstXprType DstXprType; + typedef copy_using_evaluator_traits AssignmentTraits; + typedef typename AssignmentTraits::PacketType PacketType; + + EIGEN_DEVICE_FUNC restricted_packet_dense_assignment_kernel(DstEvaluatorTypeT& dst, const SrcEvaluatorTypeT& src, + const Functor& func, DstXprType& dstExpr) + : Base(dst, src, func, dstExpr) {} +}; + +/*************************************************************************** + * Part 5 : Entry point for dense rectangular assignment + ***************************************************************************/ + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize_if_allowed(DstXprType& dst, const SrcXprType& src, + const Functor& /*func*/) { + EIGEN_ONLY_USED_FOR_DEBUG(dst); + EIGEN_ONLY_USED_FOR_DEBUG(src); + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize_if_allowed(DstXprType& dst, const SrcXprType& src, + const internal::assign_op& /*func*/) { + Index dstRows = src.rows(); + Index dstCols = src.cols(); + if (((dst.rows() != dstRows) || (dst.cols() != dstCols))) dst.resize(dstRows, dstCols); + eigen_assert(dst.rows() == dstRows && dst.cols() == dstCols); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_dense_assignment_loop(DstXprType& dst, + const SrcXprType& src, + const Functor& func) { + typedef evaluator DstEvaluatorType; + typedef evaluator SrcEvaluatorType; + + SrcEvaluatorType srcEvaluator(src); + + // NOTE To properly handle A = (A*A.transpose())/s with A rectangular, + // we need to resize the destination after the source evaluator has been created. + resize_if_allowed(dst, src, func); + + DstEvaluatorType dstEvaluator(dst); + + typedef generic_dense_assignment_kernel Kernel; + Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived()); + + dense_assignment_loop::run(kernel); +} + +// Specialization for filling the destination with a constant value. +#ifndef EIGEN_GPU_COMPILE_PHASE +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop( + DstXprType& dst, + const Eigen::CwiseNullaryOp, DstXprType>& src, + const internal::assign_op& func) { + resize_if_allowed(dst, src, func); + std::fill_n(dst.data(), dst.size(), src.functor()()); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src) { + call_dense_assignment_loop(dst, src, internal::assign_op()); +} + +/*************************************************************************** + * Part 6 : Generic assignment + ***************************************************************************/ + +// Based on the respective shapes of the destination and source, +// the class AssignmentKind determine the kind of assignment mechanism. +// AssignmentKind must define a Kind typedef. +template +struct AssignmentKind; + +// Assignment kind defined in this file: +struct Dense2Dense {}; +struct EigenBase2EigenBase {}; + +template +struct AssignmentKind { + typedef EigenBase2EigenBase Kind; +}; +template <> +struct AssignmentKind { + typedef Dense2Dense Kind; +}; + +// This is the main assignment class +template ::Shape, + typename evaluator_traits::Shape>::Kind, + typename EnableIf = void> +struct Assignment; + +// The only purpose of this call_assignment() function is to deal with noalias() / "assume-aliasing" and automatic +// transposition. Indeed, I (Gael) think that this concept of "assume-aliasing" was a mistake, and it makes thing quite +// complicated. So this intermediate function removes everything related to "assume-aliasing" such that Assignment does +// not has to bother about these annoying details. + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(Dst& dst, const Src& src) { + call_assignment(dst, src, internal::assign_op()); +} +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(const Dst& dst, const Src& src) { + call_assignment(dst, src, internal::assign_op()); +} + +// Deal with "assume-aliasing" +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment( + Dst& dst, const Src& src, const Func& func, std::enable_if_t::value, void*> = 0) { + typename plain_matrix_type::type tmp(src); + call_assignment_no_alias(dst, tmp, func); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment( + Dst& dst, const Src& src, const Func& func, std::enable_if_t::value, void*> = 0) { + call_assignment_no_alias(dst, src, func); +} + +// by-pass "assume-aliasing" +// When there is no aliasing, we require that 'dst' has been properly resized +template class StorageBase, typename Src, typename Func> +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment(NoAlias& dst, + const Src& src, const Func& func) { + call_assignment_no_alias(dst.expression(), src, func); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias(Dst& dst, const Src& src, + const Func& func) { + enum { + NeedToTranspose = ((int(Dst::RowsAtCompileTime) == 1 && int(Src::ColsAtCompileTime) == 1) || + (int(Dst::ColsAtCompileTime) == 1 && int(Src::RowsAtCompileTime) == 1)) && + int(Dst::SizeAtCompileTime) != 1 + }; + + typedef std::conditional_t, Dst> ActualDstTypeCleaned; + typedef std::conditional_t, Dst&> ActualDstType; + ActualDstType actualDst(dst); + + // TODO check whether this is the right place to perform these checks: + EIGEN_STATIC_ASSERT_LVALUE(Dst) + EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned, Src) + EIGEN_CHECK_BINARY_COMPATIBILIY(Func, typename ActualDstTypeCleaned::Scalar, typename Src::Scalar); + + Assignment::run(actualDst, src, func); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_restricted_packet_assignment_no_alias(Dst& dst, const Src& src, + const Func& func) { + typedef evaluator DstEvaluatorType; + typedef evaluator SrcEvaluatorType; + typedef restricted_packet_dense_assignment_kernel Kernel; + + EIGEN_STATIC_ASSERT_LVALUE(Dst) + EIGEN_CHECK_BINARY_COMPATIBILIY(Func, typename Dst::Scalar, typename Src::Scalar); + + SrcEvaluatorType srcEvaluator(src); + resize_if_allowed(dst, src, func); + + DstEvaluatorType dstEvaluator(dst); + Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived()); + + dense_assignment_loop::run(kernel); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias(Dst& dst, const Src& src) { + call_assignment_no_alias(dst, src, internal::assign_op()); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias_no_transpose(Dst& dst, + const Src& src, + const Func& func) { + // TODO check whether this is the right place to perform these checks: + EIGEN_STATIC_ASSERT_LVALUE(Dst) + EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Dst, Src) + EIGEN_CHECK_BINARY_COMPATIBILIY(Func, typename Dst::Scalar, typename Src::Scalar); + + Assignment::run(dst, src, func); +} +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias_no_transpose(Dst& dst, + const Src& src) { + call_assignment_no_alias_no_transpose(dst, src, internal::assign_op()); +} + +// forward declaration +template +EIGEN_DEVICE_FUNC void check_for_aliasing(const Dst& dst, const Src& src); + +// Generic Dense to Dense assignment +// Note that the last template argument "Weak" is needed to make it possible to perform +// both partial specialization+SFINAE without ambiguous specialization +template +struct Assignment { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src, const Functor& func) { +#ifndef EIGEN_NO_DEBUG + internal::check_for_aliasing(dst, src); +#endif + + call_dense_assignment_loop(dst, src, func); + } +}; + +// Generic assignment through evalTo. +// TODO: not sure we have to keep that one, but it helps porting current code to new evaluator mechanism. +// Note that the last template argument "Weak" is needed to make it possible to perform +// both partial specialization+SFINAE without ambiguous specialization +template +struct Assignment { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run( + DstXprType& dst, const SrcXprType& src, + const internal::assign_op& /*func*/) { + Index dstRows = src.rows(); + Index dstCols = src.cols(); + if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols); + + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + src.evalTo(dst); + } + + // NOTE The following two functions are templated to avoid their instantiation if not needed + // This is needed because some expressions supports evalTo only and/or have 'void' as scalar type. + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run( + DstXprType& dst, const SrcXprType& src, + const internal::add_assign_op& /*func*/) { + Index dstRows = src.rows(); + Index dstCols = src.cols(); + if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols); + + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + src.addTo(dst); + } + + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run( + DstXprType& dst, const SrcXprType& src, + const internal::sub_assign_op& /*func*/) { + Index dstRows = src.rows(); + Index dstCols = src.cols(); + if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols); + + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + src.subTo(dst); + } +}; + +} // namespace internal + +} // end namespace Eigen + +#endif // EIGEN_ASSIGN_EVALUATOR_H diff --git a/dae-cpp/Eigen/src/Core/Assign_MKL.h b/dae-cpp/Eigen/src/Core/Assign_MKL.h new file mode 100644 index 0000000..5b566cd --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Assign_MKL.h @@ -0,0 +1,183 @@ +/* + Copyright (c) 2011, Intel Corporation. All rights reserved. + Copyright (C) 2015 Gael Guennebaud + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Intel Corporation nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + ******************************************************************************** + * Content : Eigen bindings to Intel(R) MKL + * MKL VML support for coefficient-wise unary Eigen expressions like a=b.sin() + ******************************************************************************** +*/ + +#ifndef EIGEN_ASSIGN_VML_H +#define EIGEN_ASSIGN_VML_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +class vml_assign_traits { + private: + enum { + DstHasDirectAccess = Dst::Flags & DirectAccessBit, + SrcHasDirectAccess = Src::Flags & DirectAccessBit, + StorageOrdersAgree = (int(Dst::IsRowMajor) == int(Src::IsRowMajor)), + InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime) + : int(Dst::Flags) & RowMajorBit ? int(Dst::ColsAtCompileTime) + : int(Dst::RowsAtCompileTime), + InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime) + : int(Dst::Flags) & RowMajorBit ? int(Dst::MaxColsAtCompileTime) + : int(Dst::MaxRowsAtCompileTime), + MaxSizeAtCompileTime = Dst::SizeAtCompileTime, + + MightEnableVml = StorageOrdersAgree && DstHasDirectAccess && SrcHasDirectAccess && + Src::InnerStrideAtCompileTime == 1 && Dst::InnerStrideAtCompileTime == 1, + MightLinearize = MightEnableVml && (int(Dst::Flags) & int(Src::Flags) & LinearAccessBit), + VmlSize = MightLinearize ? MaxSizeAtCompileTime : InnerMaxSize, + LargeEnough = VmlSize == Dynamic || VmlSize >= EIGEN_MKL_VML_THRESHOLD + }; + + public: + enum { EnableVml = MightEnableVml && LargeEnough, Traversal = MightLinearize ? LinearTraversal : DefaultTraversal }; +}; + +#define EIGEN_PP_EXPAND(ARG) ARG +#if !defined(EIGEN_FAST_MATH) || (EIGEN_FAST_MATH != 1) +#define EIGEN_VMLMODE_EXPAND_xLA , VML_HA +#else +#define EIGEN_VMLMODE_EXPAND_xLA , VML_LA +#endif + +#define EIGEN_VMLMODE_EXPAND_x_ + +#define EIGEN_VMLMODE_PREFIX_xLA vm +#define EIGEN_VMLMODE_PREFIX_x_ v +#define EIGEN_VMLMODE_PREFIX(VMLMODE) EIGEN_CAT(EIGEN_VMLMODE_PREFIX_x, VMLMODE) + +#define EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \ + template \ + struct Assignment, SrcXprNested>, \ + assign_op, Dense2Dense, \ + std::enable_if_t::EnableVml>> { \ + typedef CwiseUnaryOp, SrcXprNested> SrcXprType; \ + static void run(DstXprType &dst, const SrcXprType &src, const assign_op &func) { \ + resize_if_allowed(dst, src, func); \ + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \ + if (vml_assign_traits::Traversal == LinearTraversal) { \ + VMLOP(dst.size(), (const VMLTYPE *)src.nestedExpression().data(), \ + (VMLTYPE *)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \ + } else { \ + const Index outerSize = dst.outerSize(); \ + for (Index outer = 0; outer < outerSize; ++outer) { \ + const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.nestedExpression().coeffRef(outer, 0)) \ + : &(src.nestedExpression().coeffRef(0, outer)); \ + EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer, 0)) : &(dst.coeffRef(0, outer)); \ + VMLOP(dst.innerSize(), (const VMLTYPE *)src_ptr, \ + (VMLTYPE *)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \ + } \ + } \ + } \ + }; + +#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \ + EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE), s##VMLOP), float, float, VMLMODE) \ + EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE), d##VMLOP), double, double, VMLMODE) + +#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE) \ + EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE), c##VMLOP), scomplex, \ + MKL_Complex8, VMLMODE) \ + EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE), z##VMLOP), dcomplex, \ + MKL_Complex16, VMLMODE) + +#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS(EIGENOP, VMLOP, VMLMODE) \ + EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \ + EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE) + +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sin, Sin, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(asin, Asin, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sinh, Sinh, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(cos, Cos, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(acos, Acos, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(cosh, Cosh, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(tan, Tan, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(atan, Atan, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(tanh, Tanh, LA) +// EIGEN_MKL_VML_DECLARE_UNARY_CALLS(abs, Abs, _) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(exp, Exp, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(log, Ln, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(log10, Log10, LA) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS(sqrt, Sqrt, _) + +EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(square, Sqr, _) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(arg, Arg, _) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(round, Round, _) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(floor, Floor, _) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(ceil, Ceil, _) +EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(cbrt, Cbrt, _) + +#define EIGEN_MKL_VML_DECLARE_POW_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \ + template \ + struct Assignment, SrcXprNested, \ + const CwiseNullaryOp, Plain>>, \ + assign_op, Dense2Dense, \ + std::enable_if_t::EnableVml>> { \ + typedef CwiseBinaryOp, SrcXprNested, \ + const CwiseNullaryOp, Plain>> \ + SrcXprType; \ + static void run(DstXprType &dst, const SrcXprType &src, const assign_op &func) { \ + resize_if_allowed(dst, src, func); \ + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \ + VMLTYPE exponent = reinterpret_cast(src.rhs().functor().m_other); \ + if (vml_assign_traits::Traversal == LinearTraversal) { \ + VMLOP(dst.size(), (const VMLTYPE *)src.lhs().data(), exponent, \ + (VMLTYPE *)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \ + } else { \ + const Index outerSize = dst.outerSize(); \ + for (Index outer = 0; outer < outerSize; ++outer) { \ + const EIGENTYPE *src_ptr = \ + src.IsRowMajor ? &(src.lhs().coeffRef(outer, 0)) : &(src.lhs().coeffRef(0, outer)); \ + EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer, 0)) : &(dst.coeffRef(0, outer)); \ + VMLOP(dst.innerSize(), (const VMLTYPE *)src_ptr, exponent, \ + (VMLTYPE *)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \ + } \ + } \ + } \ + }; + +EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmsPowx, float, float, LA) +EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmdPowx, double, double, LA) +EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmcPowx, scomplex, MKL_Complex8, LA) +EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmzPowx, dcomplex, MKL_Complex16, LA) + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_ASSIGN_VML_H diff --git a/dae-cpp/Eigen/src/Core/BandMatrix.h b/dae-cpp/Eigen/src/Core/BandMatrix.h new file mode 100644 index 0000000..ca991ca --- /dev/null +++ b/dae-cpp/Eigen/src/Core/BandMatrix.h @@ -0,0 +1,338 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_BANDMATRIX_H +#define EIGEN_BANDMATRIX_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +class BandMatrixBase : public EigenBase { + public: + enum { + Flags = internal::traits::Flags, + CoeffReadCost = internal::traits::CoeffReadCost, + RowsAtCompileTime = internal::traits::RowsAtCompileTime, + ColsAtCompileTime = internal::traits::ColsAtCompileTime, + MaxRowsAtCompileTime = internal::traits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = internal::traits::MaxColsAtCompileTime, + Supers = internal::traits::Supers, + Subs = internal::traits::Subs, + Options = internal::traits::Options + }; + typedef typename internal::traits::Scalar Scalar; + typedef Matrix DenseMatrixType; + typedef typename DenseMatrixType::StorageIndex StorageIndex; + typedef typename internal::traits::CoefficientsType CoefficientsType; + typedef EigenBase Base; + + protected: + enum { + DataRowsAtCompileTime = ((Supers != Dynamic) && (Subs != Dynamic)) ? 1 + Supers + Subs : Dynamic, + SizeAtCompileTime = min_size_prefer_dynamic(RowsAtCompileTime, ColsAtCompileTime) + }; + + public: + using Base::cols; + using Base::derived; + using Base::rows; + + /** \returns the number of super diagonals */ + inline Index supers() const { return derived().supers(); } + + /** \returns the number of sub diagonals */ + inline Index subs() const { return derived().subs(); } + + /** \returns an expression of the underlying coefficient matrix */ + inline const CoefficientsType& coeffs() const { return derived().coeffs(); } + + /** \returns an expression of the underlying coefficient matrix */ + inline CoefficientsType& coeffs() { return derived().coeffs(); } + + /** \returns a vector expression of the \a i -th column, + * only the meaningful part is returned. + * \warning the internal storage must be column major. */ + inline Block col(Index i) { + EIGEN_STATIC_ASSERT((int(Options) & int(RowMajor)) == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES); + Index start = 0; + Index len = coeffs().rows(); + if (i <= supers()) { + start = supers() - i; + len = (std::min)(rows(), std::max(0, coeffs().rows() - (supers() - i))); + } else if (i >= rows() - subs()) + len = std::max(0, coeffs().rows() - (i + 1 - rows() + subs())); + return Block(coeffs(), start, i, len, 1); + } + + /** \returns a vector expression of the main diagonal */ + inline Block diagonal() { + return Block(coeffs(), supers(), 0, 1, (std::min)(rows(), cols())); + } + + /** \returns a vector expression of the main diagonal (const version) */ + inline const Block diagonal() const { + return Block(coeffs(), supers(), 0, 1, (std::min)(rows(), cols())); + } + + template + struct DiagonalIntReturnType { + enum { + ReturnOpposite = + (int(Options) & int(SelfAdjoint)) && (((Index) > 0 && Supers == 0) || ((Index) < 0 && Subs == 0)), + Conjugate = ReturnOpposite && NumTraits::IsComplex, + ActualIndex = ReturnOpposite ? -Index : Index, + DiagonalSize = + (RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) + ? Dynamic + : (ActualIndex < 0 ? min_size_prefer_dynamic(ColsAtCompileTime, RowsAtCompileTime + ActualIndex) + : min_size_prefer_dynamic(RowsAtCompileTime, ColsAtCompileTime - ActualIndex)) + }; + typedef Block BuildType; + typedef std::conditional_t, BuildType>, BuildType> + Type; + }; + + /** \returns a vector expression of the \a N -th sub or super diagonal */ + template + inline typename DiagonalIntReturnType::Type diagonal() { + return typename DiagonalIntReturnType::BuildType(coeffs(), supers() - N, (std::max)(0, N), 1, diagonalLength(N)); + } + + /** \returns a vector expression of the \a N -th sub or super diagonal */ + template + inline const typename DiagonalIntReturnType::Type diagonal() const { + return typename DiagonalIntReturnType::BuildType(coeffs(), supers() - N, (std::max)(0, N), 1, diagonalLength(N)); + } + + /** \returns a vector expression of the \a i -th sub or super diagonal */ + inline Block diagonal(Index i) { + eigen_assert((i < 0 && -i <= subs()) || (i >= 0 && i <= supers())); + return Block(coeffs(), supers() - i, std::max(0, i), 1, diagonalLength(i)); + } + + /** \returns a vector expression of the \a i -th sub or super diagonal */ + inline const Block diagonal(Index i) const { + eigen_assert((i < 0 && -i <= subs()) || (i >= 0 && i <= supers())); + return Block(coeffs(), supers() - i, std::max(0, i), 1, + diagonalLength(i)); + } + + template + inline void evalTo(Dest& dst) const { + dst.resize(rows(), cols()); + dst.setZero(); + dst.diagonal() = diagonal(); + for (Index i = 1; i <= supers(); ++i) dst.diagonal(i) = diagonal(i); + for (Index i = 1; i <= subs(); ++i) dst.diagonal(-i) = diagonal(-i); + } + + DenseMatrixType toDenseMatrix() const { + DenseMatrixType res(rows(), cols()); + evalTo(res); + return res; + } + + protected: + inline Index diagonalLength(Index i) const { + return i < 0 ? (std::min)(cols(), rows() + i) : (std::min)(rows(), cols() - i); + } +}; + +/** + * \class BandMatrix + * \ingroup Core_Module + * + * \brief Represents a rectangular matrix with a banded storage + * + * \tparam Scalar_ Numeric type, i.e. float, double, int + * \tparam Rows_ Number of rows, or \b Dynamic + * \tparam Cols_ Number of columns, or \b Dynamic + * \tparam Supers_ Number of super diagonal + * \tparam Subs_ Number of sub diagonal + * \tparam Options_ A combination of either \b #RowMajor or \b #ColMajor, and of \b #SelfAdjoint + * The former controls \ref TopicStorageOrders "storage order", and defaults to + * column-major. The latter controls whether the matrix represents a selfadjoint + * matrix in which case either Supers of Subs have to be null. + * + * \sa class TridiagonalMatrix + */ + +template +struct traits > { + typedef Scalar_ Scalar; + typedef Dense StorageKind; + typedef Eigen::Index StorageIndex; + enum { + CoeffReadCost = NumTraits::ReadCost, + RowsAtCompileTime = Rows_, + ColsAtCompileTime = Cols_, + MaxRowsAtCompileTime = Rows_, + MaxColsAtCompileTime = Cols_, + Flags = LvalueBit, + Supers = Supers_, + Subs = Subs_, + Options = Options_, + DataRowsAtCompileTime = ((Supers != Dynamic) && (Subs != Dynamic)) ? 1 + Supers + Subs : Dynamic + }; + typedef Matrix + CoefficientsType; +}; + +template +class BandMatrix : public BandMatrixBase > { + public: + typedef typename internal::traits::Scalar Scalar; + typedef typename internal::traits::StorageIndex StorageIndex; + typedef typename internal::traits::CoefficientsType CoefficientsType; + + explicit inline BandMatrix(Index rows = Rows, Index cols = Cols, Index supers = Supers, Index subs = Subs) + : m_coeffs(1 + supers + subs, cols), m_rows(rows), m_supers(supers), m_subs(subs) {} + + /** \returns the number of columns */ + inline EIGEN_CONSTEXPR Index rows() const { return m_rows.value(); } + + /** \returns the number of rows */ + inline EIGEN_CONSTEXPR Index cols() const { return m_coeffs.cols(); } + + /** \returns the number of super diagonals */ + inline EIGEN_CONSTEXPR Index supers() const { return m_supers.value(); } + + /** \returns the number of sub diagonals */ + inline EIGEN_CONSTEXPR Index subs() const { return m_subs.value(); } + + inline const CoefficientsType& coeffs() const { return m_coeffs; } + inline CoefficientsType& coeffs() { return m_coeffs; } + + protected: + CoefficientsType m_coeffs; + internal::variable_if_dynamic m_rows; + internal::variable_if_dynamic m_supers; + internal::variable_if_dynamic m_subs; +}; + +template +class BandMatrixWrapper; + +template +struct traits > { + typedef typename CoefficientsType_::Scalar Scalar; + typedef typename CoefficientsType_::StorageKind StorageKind; + typedef typename CoefficientsType_::StorageIndex StorageIndex; + enum { + CoeffReadCost = internal::traits::CoeffReadCost, + RowsAtCompileTime = Rows_, + ColsAtCompileTime = Cols_, + MaxRowsAtCompileTime = Rows_, + MaxColsAtCompileTime = Cols_, + Flags = LvalueBit, + Supers = Supers_, + Subs = Subs_, + Options = Options_, + DataRowsAtCompileTime = ((Supers != Dynamic) && (Subs != Dynamic)) ? 1 + Supers + Subs : Dynamic + }; + typedef CoefficientsType_ CoefficientsType; +}; + +template +class BandMatrixWrapper + : public BandMatrixBase > { + public: + typedef typename internal::traits::Scalar Scalar; + typedef typename internal::traits::CoefficientsType CoefficientsType; + typedef typename internal::traits::StorageIndex StorageIndex; + + explicit inline BandMatrixWrapper(const CoefficientsType& coeffs, Index rows = Rows_, Index cols = Cols_, + Index supers = Supers_, Index subs = Subs_) + : m_coeffs(coeffs), m_rows(rows), m_supers(supers), m_subs(subs) { + EIGEN_UNUSED_VARIABLE(cols); + // eigen_assert(coeffs.cols()==cols() && (supers()+subs()+1)==coeffs.rows()); + } + + /** \returns the number of columns */ + inline EIGEN_CONSTEXPR Index rows() const { return m_rows.value(); } + + /** \returns the number of rows */ + inline EIGEN_CONSTEXPR Index cols() const { return m_coeffs.cols(); } + + /** \returns the number of super diagonals */ + inline EIGEN_CONSTEXPR Index supers() const { return m_supers.value(); } + + /** \returns the number of sub diagonals */ + inline EIGEN_CONSTEXPR Index subs() const { return m_subs.value(); } + + inline const CoefficientsType& coeffs() const { return m_coeffs; } + + protected: + const CoefficientsType& m_coeffs; + internal::variable_if_dynamic m_rows; + internal::variable_if_dynamic m_supers; + internal::variable_if_dynamic m_subs; +}; + +/** + * \class TridiagonalMatrix + * \ingroup Core_Module + * + * \brief Represents a tridiagonal matrix with a compact banded storage + * + * \tparam Scalar Numeric type, i.e. float, double, int + * \tparam Size Number of rows and cols, or \b Dynamic + * \tparam Options Can be 0 or \b SelfAdjoint + * + * \sa class BandMatrix + */ +template +class TridiagonalMatrix : public BandMatrix { + typedef BandMatrix Base; + typedef typename Base::StorageIndex StorageIndex; + + public: + explicit TridiagonalMatrix(Index size = Size) : Base(size, size, Options & SelfAdjoint ? 0 : 1, 1) {} + + inline typename Base::template DiagonalIntReturnType<1>::Type super() { return Base::template diagonal<1>(); } + inline const typename Base::template DiagonalIntReturnType<1>::Type super() const { + return Base::template diagonal<1>(); + } + inline typename Base::template DiagonalIntReturnType<-1>::Type sub() { return Base::template diagonal<-1>(); } + inline const typename Base::template DiagonalIntReturnType<-1>::Type sub() const { + return Base::template diagonal<-1>(); + } + + protected: +}; + +struct BandShape {}; + +template +struct evaluator_traits > + : public evaluator_traits_base > { + typedef BandShape Shape; +}; + +template +struct evaluator_traits > + : public evaluator_traits_base > { + typedef BandShape Shape; +}; + +template <> +struct AssignmentKind { + typedef EigenBase2EigenBase Kind; +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_BANDMATRIX_H diff --git a/dae-cpp/Eigen/src/Core/Block.h b/dae-cpp/Eigen/src/Core/Block.h new file mode 100644 index 0000000..9b16ed2 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Block.h @@ -0,0 +1,439 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2006-2010 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_BLOCK_H +#define EIGEN_BLOCK_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits> : traits { + typedef typename traits::Scalar Scalar; + typedef typename traits::StorageKind StorageKind; + typedef typename traits::XprKind XprKind; + typedef typename ref_selector::type XprTypeNested; + typedef std::remove_reference_t XprTypeNested_; + enum { + MatrixRows = traits::RowsAtCompileTime, + MatrixCols = traits::ColsAtCompileTime, + RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows, + ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols, + MaxRowsAtCompileTime = BlockRows == 0 ? 0 + : RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) + : int(traits::MaxRowsAtCompileTime), + MaxColsAtCompileTime = BlockCols == 0 ? 0 + : ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) + : int(traits::MaxColsAtCompileTime), + + XprTypeIsRowMajor = (int(traits::Flags) & RowMajorBit) != 0, + IsRowMajor = (MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1) ? 1 + : (MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1) ? 0 + : XprTypeIsRowMajor, + HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor), + InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime), + InnerStrideAtCompileTime = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time::ret) + : int(outer_stride_at_compile_time::ret), + OuterStrideAtCompileTime = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time::ret) + : int(inner_stride_at_compile_time::ret), + + // FIXME, this traits is rather specialized for dense object and it needs to be cleaned further + FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, + FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, + Flags = (traits::Flags & (DirectAccessBit | (InnerPanel_ ? CompressedAccessBit : 0))) | FlagsLvalueBit | + FlagsRowMajorBit, + // FIXME DirectAccessBit should not be handled by expressions + // + // Alignment is needed by MapBase's assertions + // We can sefely set it to false here. Internal alignment errors will be detected by an eigen_internal_assert in the + // respective evaluator + Alignment = 0, + InnerPanel = InnerPanel_ ? 1 : 0 + }; +}; + +template ::ret> +class BlockImpl_dense; + +} // end namespace internal + +template +class BlockImpl; + +/** \class Block + * \ingroup Core_Module + * + * \brief Expression of a fixed-size or dynamic-size block + * + * \tparam XprType the type of the expression in which we are taking a block + * \tparam BlockRows the number of rows of the block we are taking at compile time (optional) + * \tparam BlockCols the number of columns of the block we are taking at compile time (optional) + * \tparam InnerPanel is true, if the block maps to a set of rows of a row major matrix or + * to set of columns of a column major matrix (optional). The parameter allows to determine + * at compile time whether aligned access is possible on the block expression. + * + * This class represents an expression of either a fixed-size or dynamic-size block. It is the return + * type of DenseBase::block(Index,Index,Index,Index) and DenseBase::block(Index,Index) and + * most of the time this is the only way it is used. + * + * However, if you want to directly manipulate block expressions, + * for instance if you want to write a function returning such an expression, you + * will need to use this class. + * + * Here is an example illustrating the dynamic case: + * \include class_Block.cpp + * Output: \verbinclude class_Block.out + * + * \note Even though this expression has dynamic size, in the case where \a XprType + * has fixed size, this expression inherits a fixed maximal size which means that evaluating + * it does not cause a dynamic memory allocation. + * + * Here is an example illustrating the fixed-size case: + * \include class_FixedBlock.cpp + * Output: \verbinclude class_FixedBlock.out + * + * \sa DenseBase::block(Index,Index,Index,Index), DenseBase::block(Index,Index), class VectorBlock + */ +template +class Block + : public BlockImpl::StorageKind> { + typedef BlockImpl::StorageKind> Impl; + using BlockHelper = internal::block_xpr_helper; + + public: + // typedef typename Impl::Base Base; + typedef Impl Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(Block) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) + + typedef internal::remove_all_t NestedExpression; + + /** Column or Row constructor + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block(XprType& xpr, Index i) : Impl(xpr, i) { + eigen_assert((i >= 0) && (((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) && i < xpr.rows()) || + ((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) && i < xpr.cols()))); + } + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block(XprType& xpr, Index startRow, Index startCol) + : Impl(xpr, startRow, startCol) { + EIGEN_STATIC_ASSERT(RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic, + THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE) + eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows() && startCol >= 0 && + BlockCols >= 0 && startCol + BlockCols <= xpr.cols()); + } + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block(XprType& xpr, Index startRow, Index startCol, Index blockRows, + Index blockCols) + : Impl(xpr, startRow, startCol, blockRows, blockCols) { + eigen_assert((RowsAtCompileTime == Dynamic || RowsAtCompileTime == blockRows) && + (ColsAtCompileTime == Dynamic || ColsAtCompileTime == blockCols)); + eigen_assert(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows && startCol >= 0 && + blockCols >= 0 && startCol <= xpr.cols() - blockCols); + } + + // convert nested blocks (e.g. Block>) to a simple block expression (Block) + + using ConstUnwindReturnType = Block; + using UnwindReturnType = Block; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ConstUnwindReturnType unwind() const { + return ConstUnwindReturnType(BlockHelper::base(*this), BlockHelper::row(*this, 0), BlockHelper::col(*this, 0), + this->rows(), this->cols()); + } + + template ::value>> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UnwindReturnType unwind() { + return UnwindReturnType(BlockHelper::base(*this), BlockHelper::row(*this, 0), BlockHelper::col(*this, 0), + this->rows(), this->cols()); + } +}; + +// The generic default implementation for dense block simply forward to the internal::BlockImpl_dense +// that must be specialized for direct and non-direct access... +template +class BlockImpl + : public internal::BlockImpl_dense { + typedef internal::BlockImpl_dense Impl; + typedef typename XprType::StorageIndex StorageIndex; + + public: + typedef Impl Base; + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index i) : Impl(xpr, i) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol) + : Impl(xpr, startRow, startCol) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol, Index blockRows, + Index blockCols) + : Impl(xpr, startRow, startCol, blockRows, blockCols) {} +}; + +namespace internal { + +/** \internal Internal implementation of dense Blocks in the general case. */ +template +class BlockImpl_dense : public internal::dense_xpr_base>::type { + typedef Block BlockType; + typedef typename internal::ref_selector::non_const_type XprTypeNested; + + public: + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(BlockType) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense) + + // class InnerIterator; // FIXME apparently never used + + /** Column or Row constructor + */ + EIGEN_DEVICE_FUNC inline BlockImpl_dense(XprType& xpr, Index i) + : m_xpr(xpr), + // It is a row if and only if BlockRows==1 and BlockCols==XprType::ColsAtCompileTime, + // and it is a column if and only if BlockRows==XprType::RowsAtCompileTime and BlockCols==1, + // all other cases are invalid. + // The case a 1x1 matrix seems ambiguous, but the result is the same anyway. + m_startRow((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) ? i : 0), + m_startCol((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) ? i : 0), + m_blockRows(BlockRows == 1 ? 1 : xpr.rows()), + m_blockCols(BlockCols == 1 ? 1 : xpr.cols()) {} + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol) + : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(BlockRows), m_blockCols(BlockCols) {} + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol, Index blockRows, + Index blockCols) + : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(blockRows), m_blockCols(blockCols) {} + + EIGEN_DEVICE_FUNC inline Index rows() const { return m_blockRows.value(); } + EIGEN_DEVICE_FUNC inline Index cols() const { return m_blockCols.value(); } + + EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index rowId, Index colId) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + return m_xpr.coeffRef(rowId + m_startRow.value(), colId + m_startCol.value()); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const { + return m_xpr.derived().coeffRef(rowId + m_startRow.value(), colId + m_startCol.value()); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const { + return m_xpr.coeff(rowId + m_startRow.value(), colId + m_startCol.value()); + } + + EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), + m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { + return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), + m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); + } + + EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const { + return m_xpr.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), + m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); + } + + template + EIGEN_DEVICE_FUNC inline PacketScalar packet(Index rowId, Index colId) const { + return m_xpr.template packet(rowId + m_startRow.value(), colId + m_startCol.value()); + } + + template + EIGEN_DEVICE_FUNC inline void writePacket(Index rowId, Index colId, const PacketScalar& val) { + m_xpr.template writePacket(rowId + m_startRow.value(), colId + m_startCol.value(), val); + } + + template + EIGEN_DEVICE_FUNC inline PacketScalar packet(Index index) const { + return m_xpr.template packet(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), + m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0)); + } + + template + EIGEN_DEVICE_FUNC inline void writePacket(Index index, const PacketScalar& val) { + m_xpr.template writePacket(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index), + m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val); + } + +#ifdef EIGEN_PARSED_BY_DOXYGEN + /** \sa MapBase::data() */ + EIGEN_DEVICE_FUNC inline const Scalar* data() const; + EIGEN_DEVICE_FUNC inline Index innerStride() const; + EIGEN_DEVICE_FUNC inline Index outerStride() const; +#endif + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all_t& nestedExpression() const { + return m_xpr; + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE XprType& nestedExpression() { return m_xpr; } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR StorageIndex startRow() const EIGEN_NOEXCEPT { + return m_startRow.value(); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR StorageIndex startCol() const EIGEN_NOEXCEPT { + return m_startCol.value(); + } + + protected: + XprTypeNested m_xpr; + const internal::variable_if_dynamic + m_startRow; + const internal::variable_if_dynamic + m_startCol; + const internal::variable_if_dynamic m_blockRows; + const internal::variable_if_dynamic m_blockCols; +}; + +/** \internal Internal implementation of dense Blocks in the direct access case.*/ +template +class BlockImpl_dense + : public MapBase> { + typedef Block BlockType; + typedef typename internal::ref_selector::non_const_type XprTypeNested; + enum { XprTypeIsRowMajor = (int(traits::Flags) & RowMajorBit) != 0 }; + + /** \internal Returns base+offset (unless base is null, in which case returns null). + * Adding an offset to nullptr is undefined behavior, so we must avoid it. + */ + template + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE static Scalar* add_to_nullable_pointer(Scalar* base, + Index offset) { + return base != nullptr ? base + offset : nullptr; + } + + public: + typedef MapBase Base; + EIGEN_DENSE_PUBLIC_INTERFACE(BlockType) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense) + + /** Column or Row constructor + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index i) + : Base((BlockRows == 0 || BlockCols == 0) + ? nullptr + : add_to_nullable_pointer( + xpr.data(), + i * (((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) && (!XprTypeIsRowMajor)) || + ((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) && + (XprTypeIsRowMajor)) + ? xpr.innerStride() + : xpr.outerStride())), + BlockRows == 1 ? 1 : xpr.rows(), BlockCols == 1 ? 1 : xpr.cols()), + m_xpr(xpr), + m_startRow((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) ? i : 0), + m_startCol((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) ? i : 0) { + init(); + } + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index startRow, Index startCol) + : Base((BlockRows == 0 || BlockCols == 0) + ? nullptr + : add_to_nullable_pointer(xpr.data(), + xpr.innerStride() * (XprTypeIsRowMajor ? startCol : startRow) + + xpr.outerStride() * (XprTypeIsRowMajor ? startRow : startCol))), + m_xpr(xpr), + m_startRow(startRow), + m_startCol(startCol) { + init(); + } + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index startRow, Index startCol, Index blockRows, + Index blockCols) + : Base((blockRows == 0 || blockCols == 0) + ? nullptr + : add_to_nullable_pointer(xpr.data(), + xpr.innerStride() * (XprTypeIsRowMajor ? startCol : startRow) + + xpr.outerStride() * (XprTypeIsRowMajor ? startRow : startCol)), + blockRows, blockCols), + m_xpr(xpr), + m_startRow(startRow), + m_startCol(startCol) { + init(); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all_t& nestedExpression() const + EIGEN_NOEXCEPT { + return m_xpr; + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE XprType& nestedExpression() { return m_xpr; } + + /** \sa MapBase::innerStride() */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT { + return internal::traits::HasSameStorageOrderAsXprType ? m_xpr.innerStride() : m_xpr.outerStride(); + } + + /** \sa MapBase::outerStride() */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT { + return internal::traits::HasSameStorageOrderAsXprType ? m_xpr.outerStride() : m_xpr.innerStride(); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR StorageIndex startRow() const EIGEN_NOEXCEPT { + return m_startRow.value(); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR StorageIndex startCol() const EIGEN_NOEXCEPT { + return m_startCol.value(); + } + +#ifndef __SUNPRO_CC + // FIXME sunstudio is not friendly with the above friend... + // META-FIXME there is no 'friend' keyword around here. Is this obsolete? + protected: +#endif + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** \internal used by allowAligned() */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, const Scalar* data, Index blockRows, + Index blockCols) + : Base(data, blockRows, blockCols), m_xpr(xpr) { + init(); + } +#endif + + protected: + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void init() { + m_outerStride = + internal::traits::HasSameStorageOrderAsXprType ? m_xpr.outerStride() : m_xpr.innerStride(); + } + + XprTypeNested m_xpr; + const internal::variable_if_dynamic + m_startRow; + const internal::variable_if_dynamic + m_startCol; + Index m_outerStride; +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_BLOCK_H diff --git a/dae-cpp/Eigen/src/Core/CommaInitializer.h b/dae-cpp/Eigen/src/Core/CommaInitializer.h new file mode 100644 index 0000000..c629123 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/CommaInitializer.h @@ -0,0 +1,149 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2006-2008 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_COMMAINITIALIZER_H +#define EIGEN_COMMAINITIALIZER_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class CommaInitializer + * \ingroup Core_Module + * + * \brief Helper class used by the comma initializer operator + * + * This class is internally used to implement the comma initializer feature. It is + * the return type of MatrixBase::operator<<, and most of the time this is the only + * way it is used. + * + * \sa \blank \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished() + */ +template +struct CommaInitializer { + typedef typename XprType::Scalar Scalar; + + EIGEN_DEVICE_FUNC inline CommaInitializer(XprType& xpr, const Scalar& s) + : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1) { + eigen_assert(m_xpr.rows() > 0 && m_xpr.cols() > 0 && "Cannot comma-initialize a 0x0 matrix (operator<<)"); + m_xpr.coeffRef(0, 0) = s; + } + + template + EIGEN_DEVICE_FUNC inline CommaInitializer(XprType& xpr, const DenseBase& other) + : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows()) { + eigen_assert(m_xpr.rows() >= other.rows() && m_xpr.cols() >= other.cols() && + "Cannot comma-initialize a 0x0 matrix (operator<<)"); + m_xpr.template block(0, 0, other.rows(), + other.cols()) = other; + } + + /* Copy/Move constructor which transfers ownership. This is crucial in + * absence of return value optimization to avoid assertions during destruction. */ + // FIXME in C++11 mode this could be replaced by a proper RValue constructor + EIGEN_DEVICE_FUNC inline CommaInitializer(const CommaInitializer& o) + : m_xpr(o.m_xpr), m_row(o.m_row), m_col(o.m_col), m_currentBlockRows(o.m_currentBlockRows) { + // Mark original object as finished. In absence of R-value references we need to const_cast: + const_cast(o).m_row = m_xpr.rows(); + const_cast(o).m_col = m_xpr.cols(); + const_cast(o).m_currentBlockRows = 0; + } + + /* inserts a scalar value in the target matrix */ + EIGEN_DEVICE_FUNC CommaInitializer &operator,(const Scalar& s) { + if (m_col == m_xpr.cols()) { + m_row += m_currentBlockRows; + m_col = 0; + m_currentBlockRows = 1; + eigen_assert(m_row < m_xpr.rows() && "Too many rows passed to comma initializer (operator<<)"); + } + eigen_assert(m_col < m_xpr.cols() && "Too many coefficients passed to comma initializer (operator<<)"); + eigen_assert(m_currentBlockRows == 1); + m_xpr.coeffRef(m_row, m_col++) = s; + return *this; + } + + /* inserts a matrix expression in the target matrix */ + template + EIGEN_DEVICE_FUNC CommaInitializer &operator,(const DenseBase& other) { + if (m_col == m_xpr.cols() && (other.cols() != 0 || other.rows() != m_currentBlockRows)) { + m_row += m_currentBlockRows; + m_col = 0; + m_currentBlockRows = other.rows(); + eigen_assert(m_row + m_currentBlockRows <= m_xpr.rows() && + "Too many rows passed to comma initializer (operator<<)"); + } + eigen_assert((m_col + other.cols() <= m_xpr.cols()) && + "Too many coefficients passed to comma initializer (operator<<)"); + eigen_assert(m_currentBlockRows == other.rows()); + m_xpr.template block(m_row, m_col, other.rows(), + other.cols()) = other; + m_col += other.cols(); + return *this; + } + + EIGEN_DEVICE_FUNC inline ~CommaInitializer() +#if defined VERIFY_RAISES_ASSERT && (!defined EIGEN_NO_ASSERTION_CHECKING) && defined EIGEN_EXCEPTIONS + EIGEN_EXCEPTION_SPEC(Eigen::eigen_assert_exception) +#endif + { + finished(); + } + + /** \returns the built matrix once all its coefficients have been set. + * Calling finished is 100% optional. Its purpose is to write expressions + * like this: + * \code + * quaternion.fromRotationMatrix((Matrix3f() << axis0, axis1, axis2).finished()); + * \endcode + */ + EIGEN_DEVICE_FUNC inline XprType& finished() { + eigen_assert(((m_row + m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0) && m_col == m_xpr.cols() && + "Too few coefficients passed to comma initializer (operator<<)"); + return m_xpr; + } + + XprType& m_xpr; // target expression + Index m_row; // current row id + Index m_col; // current col id + Index m_currentBlockRows; // current block height +}; + +/** \anchor MatrixBaseCommaInitRef + * Convenient operator to set the coefficients of a matrix. + * + * The coefficients must be provided in a row major order and exactly match + * the size of the matrix. Otherwise an assertion is raised. + * + * Example: \include MatrixBase_set.cpp + * Output: \verbinclude MatrixBase_set.out + * + * \note According the c++ standard, the argument expressions of this comma initializer are evaluated in arbitrary + * order. + * + * \sa CommaInitializer::finished(), class CommaInitializer + */ +template +EIGEN_DEVICE_FUNC inline CommaInitializer DenseBase::operator<<(const Scalar& s) { + return CommaInitializer(*static_cast(this), s); +} + +/** \sa operator<<(const Scalar&) */ +template +template +EIGEN_DEVICE_FUNC inline CommaInitializer DenseBase::operator<<( + const DenseBase& other) { + return CommaInitializer(*static_cast(this), other); +} + +} // end namespace Eigen + +#endif // EIGEN_COMMAINITIALIZER_H diff --git a/dae-cpp/Eigen/src/Core/ConditionEstimator.h b/dae-cpp/Eigen/src/Core/ConditionEstimator.h new file mode 100644 index 0000000..dd1770b --- /dev/null +++ b/dae-cpp/Eigen/src/Core/ConditionEstimator.h @@ -0,0 +1,173 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google.com) +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CONDITIONESTIMATOR_H +#define EIGEN_CONDITIONESTIMATOR_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +struct rcond_compute_sign { + static inline Vector run(const Vector& v) { + const RealVector v_abs = v.cwiseAbs(); + return (v_abs.array() == static_cast(0)) + .select(Vector::Ones(v.size()), v.cwiseQuotient(v_abs)); + } +}; + +// Partial specialization to avoid elementwise division for real vectors. +template +struct rcond_compute_sign { + static inline Vector run(const Vector& v) { + return (v.array() < static_cast(0)) + .select(-Vector::Ones(v.size()), Vector::Ones(v.size())); + } +}; + +/** + * \returns an estimate of ||inv(matrix)||_1 given a decomposition of + * \a matrix that implements .solve() and .adjoint().solve() methods. + * + * This function implements Algorithms 4.1 and 5.1 from + * http://www.maths.manchester.ac.uk/~higham/narep/narep135.pdf + * which also forms the basis for the condition number estimators in + * LAPACK. Since at most 10 calls to the solve method of dec are + * performed, the total cost is O(dims^2), as opposed to O(dims^3) + * needed to compute the inverse matrix explicitly. + * + * The most common usage is in estimating the condition number + * ||matrix||_1 * ||inv(matrix)||_1. The first term ||matrix||_1 can be + * computed directly in O(n^2) operations. + * + * Supports the following decompositions: FullPivLU, PartialPivLU, LDLT, and + * LLT. + * + * \sa FullPivLU, PartialPivLU, LDLT, LLT. + */ +template +typename Decomposition::RealScalar rcond_invmatrix_L1_norm_estimate(const Decomposition& dec) { + typedef typename Decomposition::MatrixType MatrixType; + typedef typename Decomposition::Scalar Scalar; + typedef typename Decomposition::RealScalar RealScalar; + typedef typename internal::plain_col_type::type Vector; + typedef typename internal::plain_col_type::type RealVector; + const bool is_complex = (NumTraits::IsComplex != 0); + + eigen_assert(dec.rows() == dec.cols()); + const Index n = dec.rows(); + if (n == 0) return 0; + + // Disable Index to float conversion warning +#ifdef __INTEL_COMPILER +#pragma warning push +#pragma warning(disable : 2259) +#endif + Vector v = dec.solve(Vector::Ones(n) / Scalar(n)); +#ifdef __INTEL_COMPILER +#pragma warning pop +#endif + + // lower_bound is a lower bound on + // ||inv(matrix)||_1 = sup_v ||inv(matrix) v||_1 / ||v||_1 + // and is the objective maximized by the ("super-") gradient ascent + // algorithm below. + RealScalar lower_bound = v.template lpNorm<1>(); + if (n == 1) return lower_bound; + + // Gradient ascent algorithm follows: We know that the optimum is achieved at + // one of the simplices v = e_i, so in each iteration we follow a + // super-gradient to move towards the optimal one. + RealScalar old_lower_bound = lower_bound; + Vector sign_vector(n); + Vector old_sign_vector; + Index v_max_abs_index = -1; + Index old_v_max_abs_index = v_max_abs_index; + for (int k = 0; k < 4; ++k) { + sign_vector = internal::rcond_compute_sign::run(v); + if (k > 0 && !is_complex && sign_vector == old_sign_vector) { + // Break if the solution stagnated. + break; + } + // v_max_abs_index = argmax |real( inv(matrix)^T * sign_vector )| + v = dec.adjoint().solve(sign_vector); + v.real().cwiseAbs().maxCoeff(&v_max_abs_index); + if (v_max_abs_index == old_v_max_abs_index) { + // Break if the solution stagnated. + break; + } + // Move to the new simplex e_j, where j = v_max_abs_index. + v = dec.solve(Vector::Unit(n, v_max_abs_index)); // v = inv(matrix) * e_j. + lower_bound = v.template lpNorm<1>(); + if (lower_bound <= old_lower_bound) { + // Break if the gradient step did not increase the lower_bound. + break; + } + if (!is_complex) { + old_sign_vector = sign_vector; + } + old_v_max_abs_index = v_max_abs_index; + old_lower_bound = lower_bound; + } + // The following calculates an independent estimate of ||matrix||_1 by + // multiplying matrix by a vector with entries of slowly increasing + // magnitude and alternating sign: + // v_i = (-1)^{i} (1 + (i / (dim-1))), i = 0,...,dim-1. + // This improvement to Hager's algorithm above is due to Higham. It was + // added to make the algorithm more robust in certain corner cases where + // large elements in the matrix might otherwise escape detection due to + // exact cancellation (especially when op and op_adjoint correspond to a + // sequence of backsubstitutions and permutations), which could cause + // Hager's algorithm to vastly underestimate ||matrix||_1. + Scalar alternating_sign(RealScalar(1)); + for (Index i = 0; i < n; ++i) { + // The static_cast is needed when Scalar is a complex and RealScalar implements expression templates + v[i] = alternating_sign * static_cast(RealScalar(1) + (RealScalar(i) / (RealScalar(n - 1)))); + alternating_sign = -alternating_sign; + } + v = dec.solve(v); + const RealScalar alternate_lower_bound = (2 * v.template lpNorm<1>()) / (3 * RealScalar(n)); + return numext::maxi(lower_bound, alternate_lower_bound); +} + +/** \brief Reciprocal condition number estimator. + * + * Computing a decomposition of a dense matrix takes O(n^3) operations, while + * this method estimates the condition number quickly and reliably in O(n^2) + * operations. + * + * \returns an estimate of the reciprocal condition number + * (1 / (||matrix||_1 * ||inv(matrix)||_1)) of matrix, given ||matrix||_1 and + * its decomposition. Supports the following decompositions: FullPivLU, + * PartialPivLU, LDLT, and LLT. + * + * \sa FullPivLU, PartialPivLU, LDLT, LLT. + */ +template +typename Decomposition::RealScalar rcond_estimate_helper(typename Decomposition::RealScalar matrix_norm, + const Decomposition& dec) { + typedef typename Decomposition::RealScalar RealScalar; + eigen_assert(dec.rows() == dec.cols()); + if (dec.rows() == 0) return NumTraits::infinity(); + if (numext::is_exactly_zero(matrix_norm)) return RealScalar(0); + if (dec.rows() == 1) return RealScalar(1); + const RealScalar inverse_matrix_norm = rcond_invmatrix_L1_norm_estimate(dec); + return (numext::is_exactly_zero(inverse_matrix_norm) ? RealScalar(0) + : (RealScalar(1) / inverse_matrix_norm) / matrix_norm); +} + +} // namespace internal + +} // namespace Eigen + +#endif diff --git a/dae-cpp/Eigen/src/Core/CoreEvaluators.h b/dae-cpp/Eigen/src/Core/CoreEvaluators.h new file mode 100644 index 0000000..c620600 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/CoreEvaluators.h @@ -0,0 +1,1666 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2011 Benoit Jacob +// Copyright (C) 2011-2014 Gael Guennebaud +// Copyright (C) 2011-2012 Jitse Niesen +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_COREEVALUATORS_H +#define EIGEN_COREEVALUATORS_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +// This class returns the evaluator kind from the expression storage kind. +// Default assumes index based accessors +template +struct storage_kind_to_evaluator_kind { + typedef IndexBased Kind; +}; + +// This class returns the evaluator shape from the expression storage kind. +// It can be Dense, Sparse, Triangular, Diagonal, SelfAdjoint, Band, etc. +template +struct storage_kind_to_shape; + +template <> +struct storage_kind_to_shape { + typedef DenseShape Shape; +}; +template <> +struct storage_kind_to_shape { + typedef SolverShape Shape; +}; +template <> +struct storage_kind_to_shape { + typedef PermutationShape Shape; +}; +template <> +struct storage_kind_to_shape { + typedef TranspositionsShape Shape; +}; + +// Evaluators have to be specialized with respect to various criteria such as: +// - storage/structure/shape +// - scalar type +// - etc. +// Therefore, we need specialization of evaluator providing additional template arguments for each kind of evaluators. +// We currently distinguish the following kind of evaluators: +// - unary_evaluator for expressions taking only one arguments (CwiseUnaryOp, CwiseUnaryView, Transpose, +// MatrixWrapper, ArrayWrapper, Reverse, Replicate) +// - binary_evaluator for expression taking two arguments (CwiseBinaryOp) +// - ternary_evaluator for expression taking three arguments (CwiseTernaryOp) +// - product_evaluator for linear algebra products (Product); special case of binary_evaluator because it requires +// additional tags for dispatching. +// - mapbase_evaluator for Map, Block, Ref +// - block_evaluator for Block (special dispatching to a mapbase_evaluator or unary_evaluator) + +template ::Kind, + typename Arg2Kind = typename evaluator_traits::Kind, + typename Arg3Kind = typename evaluator_traits::Kind, + typename Arg1Scalar = typename traits::Scalar, + typename Arg2Scalar = typename traits::Scalar, + typename Arg3Scalar = typename traits::Scalar> +struct ternary_evaluator; + +template ::Kind, + typename RhsKind = typename evaluator_traits::Kind, + typename LhsScalar = typename traits::Scalar, + typename RhsScalar = typename traits::Scalar> +struct binary_evaluator; + +template ::Kind, + typename Scalar = typename T::Scalar> +struct unary_evaluator; + +// evaluator_traits contains traits for evaluator + +template +struct evaluator_traits_base { + // by default, get evaluator kind and shape from storage + typedef typename storage_kind_to_evaluator_kind::StorageKind>::Kind Kind; + typedef typename storage_kind_to_shape::StorageKind>::Shape Shape; +}; + +// Default evaluator traits +template +struct evaluator_traits : public evaluator_traits_base {}; + +template ::Shape> +struct evaluator_assume_aliasing { + static const bool value = false; +}; + +// By default, we assume a unary expression: +template +struct evaluator : public unary_evaluator { + typedef unary_evaluator Base; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const T& xpr) : Base(xpr) {} +}; + +// TODO: Think about const-correctness +template +struct evaluator : evaluator { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const T& xpr) : evaluator(xpr) {} +}; + +// ---------- base class for all evaluators ---------- + +template +struct evaluator_base { + // TODO that's not very nice to have to propagate all these traits. They are currently only needed to handle + // outer,inner indices. + typedef traits ExpressionTraits; + + enum { Alignment = 0 }; + // noncopyable: + // Don't make this class inherit noncopyable as this kills EBO (Empty Base Optimization) + // and make complex evaluator much larger than then should do. + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator_base() {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~evaluator_base() {} + + private: + EIGEN_DEVICE_FUNC evaluator_base(const evaluator_base&); + EIGEN_DEVICE_FUNC const evaluator_base& operator=(const evaluator_base&); +}; + +// -------------------- Matrix and Array -------------------- +// +// evaluator is a common base class for the +// Matrix and Array evaluators. +// Here we directly specialize evaluator. This is not really a unary expression, and it is, by definition, dense, +// so no need for more sophisticated dispatching. + +// this helper permits to completely eliminate m_outerStride if it is known at compiletime. +template +class plainobjectbase_evaluator_data { + public: + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE plainobjectbase_evaluator_data(const Scalar* ptr, Index outerStride) + : data(ptr) { +#ifndef EIGEN_INTERNAL_DEBUGGING + EIGEN_UNUSED_VARIABLE(outerStride); +#endif + eigen_internal_assert(outerStride == OuterStride); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT { return OuterStride; } + const Scalar* data; +}; + +template +class plainobjectbase_evaluator_data { + public: + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE plainobjectbase_evaluator_data(const Scalar* ptr, Index outerStride) + : data(ptr), m_outerStride(outerStride) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index outerStride() const { return m_outerStride; } + const Scalar* data; + + protected: + Index m_outerStride; +}; + +template +struct evaluator > : evaluator_base { + typedef PlainObjectBase PlainObjectType; + typedef typename PlainObjectType::Scalar Scalar; + typedef typename PlainObjectType::CoeffReturnType CoeffReturnType; + + enum { + IsRowMajor = PlainObjectType::IsRowMajor, + IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime, + RowsAtCompileTime = PlainObjectType::RowsAtCompileTime, + ColsAtCompileTime = PlainObjectType::ColsAtCompileTime, + + CoeffReadCost = NumTraits::ReadCost, + Flags = traits::EvaluatorFlags, + Alignment = traits::Alignment + }; + enum { + // We do not need to know the outer stride for vectors + OuterStrideAtCompileTime = IsVectorAtCompileTime ? 0 + : int(IsRowMajor) ? ColsAtCompileTime + : RowsAtCompileTime + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator() : m_d(0, OuterStrideAtCompileTime) { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const PlainObjectType& m) + : m_d(m.data(), IsVectorAtCompileTime ? 0 : m.outerStride()) { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + if (IsRowMajor) + return m_d.data[row * m_d.outerStride() + col]; + else + return m_d.data[row + col * m_d.outerStride()]; + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { return m_d.data[index]; } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + if (IsRowMajor) + return const_cast(m_d.data)[row * m_d.outerStride() + col]; + else + return const_cast(m_d.data)[row + col * m_d.outerStride()]; + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { return const_cast(m_d.data)[index]; } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + if (IsRowMajor) + return ploadt(m_d.data + row * m_d.outerStride() + col); + else + return ploadt(m_d.data + row + col * m_d.outerStride()); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + return ploadt(m_d.data + index); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index row, Index col, const PacketType& x) { + if (IsRowMajor) + return pstoret(const_cast(m_d.data) + row * m_d.outerStride() + col, x); + else + return pstoret(const_cast(m_d.data) + row + col * m_d.outerStride(), x); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index index, const PacketType& x) { + return pstoret(const_cast(m_d.data) + index, x); + } + + protected: + plainobjectbase_evaluator_data m_d; +}; + +template +struct evaluator > + : evaluator > > { + typedef Matrix XprType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator() {} + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& m) + : evaluator >(m) {} +}; + +template +struct evaluator > + : evaluator > > { + typedef Array XprType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator() {} + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& m) + : evaluator >(m) {} +}; + +// -------------------- Transpose -------------------- + +template +struct unary_evaluator, IndexBased> : evaluator_base > { + typedef Transpose XprType; + + enum { + CoeffReadCost = evaluator::CoeffReadCost, + Flags = evaluator::Flags ^ RowMajorBit, + Alignment = evaluator::Alignment + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit unary_evaluator(const XprType& t) : m_argImpl(t.nestedExpression()) {} + + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_argImpl.coeff(col, row); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { return m_argImpl.coeff(index); } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { return m_argImpl.coeffRef(col, row); } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename XprType::Scalar& coeffRef(Index index) { + return m_argImpl.coeffRef(index); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + return m_argImpl.template packet(col, row); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + return m_argImpl.template packet(index); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index row, Index col, const PacketType& x) { + m_argImpl.template writePacket(col, row, x); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index index, const PacketType& x) { + m_argImpl.template writePacket(index, x); + } + + protected: + evaluator m_argImpl; +}; + +// -------------------- CwiseNullaryOp -------------------- +// Like Matrix and Array, this is not really a unary expression, so we directly specialize evaluator. +// Likewise, there is not need to more sophisticated dispatching here. + +template ::value, + bool has_unary = has_unary_operator::value, + bool has_binary = has_binary_operator::value> +struct nullary_wrapper { + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const { + return op(i, j); + } + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const { + return op(i); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const { + return op.template packetOp(i, j); + } + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const { + return op.template packetOp(i); + } +}; + +template +struct nullary_wrapper { + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType = 0, IndexType = 0) const { + return op(); + } + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType = 0, IndexType = 0) const { + return op.template packetOp(); + } +}; + +template +struct nullary_wrapper { + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j = 0) const { + return op(i, j); + } + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j = 0) const { + return op.template packetOp(i, j); + } +}; + +// We need the following specialization for vector-only functors assigned to a runtime vector, +// for instance, using linspace and assigning a RowVectorXd to a MatrixXd or even a row of a MatrixXd. +// In this case, i==0 and j is used for the actual iteration. +template +struct nullary_wrapper { + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const { + eigen_assert(i == 0 || j == 0); + return op(i + j); + } + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const { + eigen_assert(i == 0 || j == 0); + return op.template packetOp(i + j); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const { + return op(i); + } + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const { + return op.template packetOp(i); + } +}; + +template +struct nullary_wrapper {}; + +#if 0 && EIGEN_COMP_MSVC > 0 +// Disable this ugly workaround. This is now handled in traits::match, +// but this piece of code might still become handly if some other weird compilation +// erros pop up again. + +// MSVC exhibits a weird compilation error when +// compiling: +// Eigen::MatrixXf A = MatrixXf::Random(3,3); +// Ref R = 2.f*A; +// and that has_*ary_operator> have not been instantiated yet. +// The "problem" is that evaluator<2.f*A> is instantiated by traits::match<2.f*A> +// and at that time has_*ary_operator returns true regardless of T. +// Then nullary_wrapper is badly instantiated as nullary_wrapper<.,.,true,true,true>. +// The trick is thus to defer the proper instantiation of nullary_wrapper when coeff(), +// and packet() are really instantiated as implemented below: + +// This is a simple wrapper around Index to enforce the re-instantiation of +// has_*ary_operator when needed. +template struct nullary_wrapper_workaround_msvc { + nullary_wrapper_workaround_msvc(const T&); + operator T()const; +}; + +template +struct nullary_wrapper +{ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i, IndexType j) const { + return nullary_wrapper >::value, + has_unary_operator >::value, + has_binary_operator >::value>().operator()(op,i,j); + } + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(const NullaryOp& op, IndexType i) const { + return nullary_wrapper >::value, + has_unary_operator >::value, + has_binary_operator >::value>().operator()(op,i); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i, IndexType j) const { + return nullary_wrapper >::value, + has_unary_operator >::value, + has_binary_operator >::value>().template packetOp(op,i,j); + } + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(const NullaryOp& op, IndexType i) const { + return nullary_wrapper >::value, + has_unary_operator >::value, + has_binary_operator >::value>().template packetOp(op,i); + } +}; +#endif // MSVC workaround + +template +struct evaluator > + : evaluator_base > { + typedef CwiseNullaryOp XprType; + typedef internal::remove_all_t PlainObjectTypeCleaned; + + enum { + CoeffReadCost = internal::functor_traits::Cost, + + Flags = (evaluator::Flags & + (HereditaryBits | (functor_has_linear_access::ret ? LinearAccessBit : 0) | + (functor_traits::PacketAccess ? PacketAccessBit : 0))) | + (functor_traits::IsRepeatable ? 0 : EvalBeforeNestingBit), + Alignment = AlignedMax + }; + + EIGEN_DEVICE_FUNC explicit evaluator(const XprType& n) : m_functor(n.functor()), m_wrapper() { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::CoeffReturnType CoeffReturnType; + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(IndexType row, IndexType col) const { + return m_wrapper(m_functor, row, col); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(IndexType index) const { + return m_wrapper(m_functor, index); + } + + template + EIGEN_STRONG_INLINE PacketType packet(IndexType row, IndexType col) const { + return m_wrapper.template packetOp(m_functor, row, col); + } + + template + EIGEN_STRONG_INLINE PacketType packet(IndexType index) const { + return m_wrapper.template packetOp(m_functor, index); + } + + protected: + const NullaryOp m_functor; + const internal::nullary_wrapper m_wrapper; +}; + +// -------------------- CwiseUnaryOp -------------------- + +template +struct unary_evaluator, IndexBased> : evaluator_base > { + typedef CwiseUnaryOp XprType; + + enum { + CoeffReadCost = int(evaluator::CoeffReadCost) + int(functor_traits::Cost), + + Flags = evaluator::Flags & + (HereditaryBits | LinearAccessBit | (functor_traits::PacketAccess ? PacketAccessBit : 0)), + Alignment = evaluator::Alignment + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit unary_evaluator(const XprType& op) : m_d(op) { + EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits::Cost); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_d.func()(m_d.argImpl.coeff(row, col)); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + return m_d.func()(m_d.argImpl.coeff(index)); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + return m_d.func().packetOp(m_d.argImpl.template packet(row, col)); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + return m_d.func().packetOp(m_d.argImpl.template packet(index)); + } + + protected: + // this helper permits to completely eliminate the functor if it is empty + struct Data { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Data(const XprType& xpr) + : op(xpr.functor()), argImpl(xpr.nestedExpression()) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const UnaryOp& func() const { return op; } + UnaryOp op; + evaluator argImpl; + }; + + Data m_d; +}; + +// ----------------------- Casting --------------------- + +template +struct unary_evaluator, ArgType>, IndexBased> { + using CastOp = core_cast_op; + using XprType = CwiseUnaryOp; + + // Use the largest packet type by default + using SrcPacketType = typename packet_traits::type; + static constexpr int SrcPacketSize = unpacket_traits::size; + static constexpr int SrcPacketBytes = SrcPacketSize * sizeof(SrcType); + + enum { + CoeffReadCost = int(evaluator::CoeffReadCost) + int(functor_traits::Cost), + PacketAccess = functor_traits::PacketAccess, + ActualPacketAccessBit = PacketAccess ? PacketAccessBit : 0, + Flags = evaluator::Flags & (HereditaryBits | LinearAccessBit | ActualPacketAccessBit), + IsRowMajor = (evaluator::Flags & RowMajorBit), + Alignment = evaluator::Alignment + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit unary_evaluator(const XprType& xpr) + : m_argImpl(xpr.nestedExpression()), m_rows(xpr.rows()), m_cols(xpr.cols()) { + EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits::Cost); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + template + using AltSrcScalarOp = std::enable_if_t<(unpacket_traits::size < SrcPacketSize && + !find_packet_by_size::size>::value), + bool>; + template + using SrcPacketArgs1 = + std::enable_if_t<(find_packet_by_size::size>::value), bool>; + template + using SrcPacketArgs2 = std::enable_if_t<(unpacket_traits::size) == (2 * SrcPacketSize), bool>; + template + using SrcPacketArgs4 = std::enable_if_t<(unpacket_traits::size) == (4 * SrcPacketSize), bool>; + template + using SrcPacketArgs8 = std::enable_if_t<(unpacket_traits::size) == (8 * SrcPacketSize), bool>; + + template = true> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool check_array_bounds(Index, Index col, Index packetSize) const { + return col + packetSize <= cols(); + } + template = true> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool check_array_bounds(Index row, Index, Index packetSize) const { + return row + packetSize <= rows(); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool check_array_bounds(Index index, Index packetSize) const { + return index + packetSize <= size(); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE SrcType srcCoeff(Index row, Index col, Index offset) const { + Index actualRow = IsRowMajor ? row : row + offset; + Index actualCol = IsRowMajor ? col + offset : col; + return m_argImpl.coeff(actualRow, actualCol); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE SrcType srcCoeff(Index index, Index offset) const { + Index actualIndex = index + offset; + return m_argImpl.coeff(actualIndex); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DstType coeff(Index row, Index col) const { + return cast(srcCoeff(row, col, 0)); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DstType coeff(Index index) const { + return cast(srcCoeff(index, 0)); + } + + template + EIGEN_STRONG_INLINE PacketType srcPacket(Index row, Index col, Index offset) const { + constexpr int PacketSize = unpacket_traits::size; + Index actualRow = IsRowMajor ? row : row + (offset * PacketSize); + Index actualCol = IsRowMajor ? col + (offset * PacketSize) : col; + eigen_assert(check_array_bounds(actualRow, actualCol, PacketSize) && "Array index out of bounds"); + return m_argImpl.template packet(actualRow, actualCol); + } + template + EIGEN_STRONG_INLINE PacketType srcPacket(Index index, Index offset) const { + constexpr int PacketSize = unpacket_traits::size; + Index actualIndex = index + (offset * PacketSize); + eigen_assert(check_array_bounds(actualIndex, PacketSize) && "Array index out of bounds"); + return m_argImpl.template packet(actualIndex); + } + + // There is no source packet type with equal or fewer elements than DstPacketType. + // This is problematic as the evaluation loop may attempt to access data outside the bounds of the array. + // For example, consider the cast utilizing pcast with an array of size 4: {0.0f,1.0f,2.0f,3.0f}. + // The first iteration of the evaulation loop will load 16 bytes: {0.0f,1.0f,2.0f,3.0f} and cast to {0.0,1.0}, which + // is acceptable. The second iteration will load 16 bytes: {2.0f,3.0f,?,?}, which is outside the bounds of the array. + + // Instead, perform runtime check to determine if the load would access data outside the bounds of the array. + // If not, perform full load. Otherwise, revert to a scalar loop to perform a partial load. + // In either case, perform a vectorized cast of the source packet. + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index row, Index col) const { + constexpr int DstPacketSize = unpacket_traits::size; + constexpr int SrcBytesIncrement = DstPacketSize * sizeof(SrcType); + constexpr int SrcLoadMode = plain_enum_min(SrcBytesIncrement, LoadMode); + SrcPacketType src; + if (EIGEN_PREDICT_TRUE(check_array_bounds(row, col, SrcPacketSize))) { + src = srcPacket(row, col, 0); + } else { + Array srcArray; + for (size_t k = 0; k < DstPacketSize; k++) srcArray[k] = srcCoeff(row, col, k); + for (size_t k = DstPacketSize; k < SrcPacketSize; k++) srcArray[k] = SrcType(0); + src = pload(srcArray.data()); + } + return pcast(src); + } + // Use the source packet type with the same size as DstPacketType, if it exists + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index row, Index col) const { + constexpr int DstPacketSize = unpacket_traits::size; + using SizedSrcPacketType = typename find_packet_by_size::type; + constexpr int SrcBytesIncrement = DstPacketSize * sizeof(SrcType); + constexpr int SrcLoadMode = plain_enum_min(SrcBytesIncrement, LoadMode); + return pcast(srcPacket(row, col, 0)); + } + // unpacket_traits::size == 2 * SrcPacketSize + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index row, Index col) const { + constexpr int SrcLoadMode = plain_enum_min(SrcPacketBytes, LoadMode); + return pcast(srcPacket(row, col, 0), + srcPacket(row, col, 1)); + } + // unpacket_traits::size == 4 * SrcPacketSize + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index row, Index col) const { + constexpr int SrcLoadMode = plain_enum_min(SrcPacketBytes, LoadMode); + return pcast(srcPacket(row, col, 0), srcPacket(row, col, 1), + srcPacket(row, col, 2), + srcPacket(row, col, 3)); + } + // unpacket_traits::size == 8 * SrcPacketSize + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index row, Index col) const { + constexpr int SrcLoadMode = plain_enum_min(SrcPacketBytes, LoadMode); + return pcast( + srcPacket(row, col, 0), srcPacket(row, col, 1), srcPacket(row, col, 2), + srcPacket(row, col, 3), srcPacket(row, col, 4), srcPacket(row, col, 5), + srcPacket(row, col, 6), srcPacket(row, col, 7)); + } + + // Analagous routines for linear access. + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index index) const { + constexpr int DstPacketSize = unpacket_traits::size; + constexpr int SrcBytesIncrement = DstPacketSize * sizeof(SrcType); + constexpr int SrcLoadMode = plain_enum_min(SrcBytesIncrement, LoadMode); + SrcPacketType src; + if (EIGEN_PREDICT_TRUE(check_array_bounds(index, SrcPacketSize))) { + src = srcPacket(index, 0); + } else { + Array srcArray; + for (size_t k = 0; k < DstPacketSize; k++) srcArray[k] = srcCoeff(index, k); + for (size_t k = DstPacketSize; k < SrcPacketSize; k++) srcArray[k] = SrcType(0); + src = pload(srcArray.data()); + } + return pcast(src); + } + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index index) const { + constexpr int DstPacketSize = unpacket_traits::size; + using SizedSrcPacketType = typename find_packet_by_size::type; + constexpr int SrcBytesIncrement = DstPacketSize * sizeof(SrcType); + constexpr int SrcLoadMode = plain_enum_min(SrcBytesIncrement, LoadMode); + return pcast(srcPacket(index, 0)); + } + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index index) const { + constexpr int SrcLoadMode = plain_enum_min(SrcPacketBytes, LoadMode); + return pcast(srcPacket(index, 0), srcPacket(index, 1)); + } + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index index) const { + constexpr int SrcLoadMode = plain_enum_min(SrcPacketBytes, LoadMode); + return pcast(srcPacket(index, 0), srcPacket(index, 1), + srcPacket(index, 2), srcPacket(index, 3)); + } + template = true> + EIGEN_STRONG_INLINE DstPacketType packet(Index index) const { + constexpr int SrcLoadMode = plain_enum_min(SrcPacketBytes, LoadMode); + return pcast(srcPacket(index, 0), srcPacket(index, 1), + srcPacket(index, 2), srcPacket(index, 3), + srcPacket(index, 4), srcPacket(index, 5), + srcPacket(index, 6), srcPacket(index, 7)); + } + + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const { return m_rows; } + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const { return m_cols; } + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_rows * m_cols; } + + protected: + const evaluator m_argImpl; + const variable_if_dynamic m_rows; + const variable_if_dynamic m_cols; +}; + +// -------------------- CwiseTernaryOp -------------------- + +// this is a ternary expression +template +struct evaluator > + : public ternary_evaluator > { + typedef CwiseTernaryOp XprType; + typedef ternary_evaluator > Base; + + EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : Base(xpr) {} +}; + +template +struct ternary_evaluator, IndexBased, IndexBased> + : evaluator_base > { + typedef CwiseTernaryOp XprType; + + enum { + CoeffReadCost = int(evaluator::CoeffReadCost) + int(evaluator::CoeffReadCost) + + int(evaluator::CoeffReadCost) + int(functor_traits::Cost), + + Arg1Flags = evaluator::Flags, + Arg2Flags = evaluator::Flags, + Arg3Flags = evaluator::Flags, + SameType = is_same::value && + is_same::value, + StorageOrdersAgree = (int(Arg1Flags) & RowMajorBit) == (int(Arg2Flags) & RowMajorBit) && + (int(Arg1Flags) & RowMajorBit) == (int(Arg3Flags) & RowMajorBit), + Flags0 = (int(Arg1Flags) | int(Arg2Flags) | int(Arg3Flags)) & + (HereditaryBits | + (int(Arg1Flags) & int(Arg2Flags) & int(Arg3Flags) & + ((StorageOrdersAgree ? LinearAccessBit : 0) | + (functor_traits::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0)))), + Flags = (Flags0 & ~RowMajorBit) | (Arg1Flags & RowMajorBit), + Alignment = plain_enum_min(plain_enum_min(evaluator::Alignment, evaluator::Alignment), + evaluator::Alignment) + }; + + EIGEN_DEVICE_FUNC explicit ternary_evaluator(const XprType& xpr) : m_d(xpr) { + EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits::Cost); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_d.func()(m_d.arg1Impl.coeff(row, col), m_d.arg2Impl.coeff(row, col), m_d.arg3Impl.coeff(row, col)); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + return m_d.func()(m_d.arg1Impl.coeff(index), m_d.arg2Impl.coeff(index), m_d.arg3Impl.coeff(index)); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + return m_d.func().packetOp(m_d.arg1Impl.template packet(row, col), + m_d.arg2Impl.template packet(row, col), + m_d.arg3Impl.template packet(row, col)); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + return m_d.func().packetOp(m_d.arg1Impl.template packet(index), + m_d.arg2Impl.template packet(index), + m_d.arg3Impl.template packet(index)); + } + + protected: + // this helper permits to completely eliminate the functor if it is empty + struct Data { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Data(const XprType& xpr) + : op(xpr.functor()), arg1Impl(xpr.arg1()), arg2Impl(xpr.arg2()), arg3Impl(xpr.arg3()) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TernaryOp& func() const { return op; } + TernaryOp op; + evaluator arg1Impl; + evaluator arg2Impl; + evaluator arg3Impl; + }; + + Data m_d; +}; + +// -------------------- CwiseBinaryOp -------------------- + +// this is a binary expression +template +struct evaluator > : public binary_evaluator > { + typedef CwiseBinaryOp XprType; + typedef binary_evaluator > Base; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) : Base(xpr) {} +}; + +template +struct binary_evaluator, IndexBased, IndexBased> + : evaluator_base > { + typedef CwiseBinaryOp XprType; + + enum { + CoeffReadCost = + int(evaluator::CoeffReadCost) + int(evaluator::CoeffReadCost) + int(functor_traits::Cost), + + LhsFlags = evaluator::Flags, + RhsFlags = evaluator::Flags, + SameType = is_same::value, + StorageOrdersAgree = (int(LhsFlags) & RowMajorBit) == (int(RhsFlags) & RowMajorBit), + Flags0 = (int(LhsFlags) | int(RhsFlags)) & + (HereditaryBits | + (int(LhsFlags) & int(RhsFlags) & + ((StorageOrdersAgree ? LinearAccessBit : 0) | + (functor_traits::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0)))), + Flags = (Flags0 & ~RowMajorBit) | (LhsFlags & RowMajorBit), + Alignment = plain_enum_min(evaluator::Alignment, evaluator::Alignment) + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit binary_evaluator(const XprType& xpr) : m_d(xpr) { + EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits::Cost); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_d.func()(m_d.lhsImpl.coeff(row, col), m_d.rhsImpl.coeff(row, col)); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + return m_d.func()(m_d.lhsImpl.coeff(index), m_d.rhsImpl.coeff(index)); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + return m_d.func().packetOp(m_d.lhsImpl.template packet(row, col), + m_d.rhsImpl.template packet(row, col)); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + return m_d.func().packetOp(m_d.lhsImpl.template packet(index), + m_d.rhsImpl.template packet(index)); + } + + protected: + // this helper permits to completely eliminate the functor if it is empty + struct Data { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Data(const XprType& xpr) + : op(xpr.functor()), lhsImpl(xpr.lhs()), rhsImpl(xpr.rhs()) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const BinaryOp& func() const { return op; } + BinaryOp op; + evaluator lhsImpl; + evaluator rhsImpl; + }; + + Data m_d; +}; + +// -------------------- CwiseUnaryView -------------------- + +template +struct unary_evaluator, IndexBased> + : evaluator_base > { + typedef CwiseUnaryView XprType; + + enum { + CoeffReadCost = int(evaluator::CoeffReadCost) + int(functor_traits::Cost), + + Flags = (evaluator::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit)), + + Alignment = 0 // FIXME it is not very clear why alignment is necessarily lost... + }; + + EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& op) : m_d(op) { + EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits::Cost); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_d.func()(m_d.argImpl.coeff(row, col)); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + return m_d.func()(m_d.argImpl.coeff(index)); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + return m_d.func()(m_d.argImpl.coeffRef(row, col)); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { + return m_d.func()(m_d.argImpl.coeffRef(index)); + } + + protected: + // this helper permits to completely eliminate the functor if it is empty + struct Data { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Data(const XprType& xpr) + : op(xpr.functor()), argImpl(xpr.nestedExpression()) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const UnaryOp& func() const { return op; } + UnaryOp op; + evaluator argImpl; + }; + + Data m_d; +}; + +// -------------------- Map -------------------- + +// FIXME perhaps the PlainObjectType could be provided by Derived::PlainObject ? +// but that might complicate template specialization +template +struct mapbase_evaluator; + +template +struct mapbase_evaluator : evaluator_base { + typedef Derived XprType; + typedef typename XprType::PointerType PointerType; + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + enum { + IsRowMajor = XprType::RowsAtCompileTime, + ColsAtCompileTime = XprType::ColsAtCompileTime, + CoeffReadCost = NumTraits::ReadCost + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit mapbase_evaluator(const XprType& map) + : m_data(const_cast(map.data())), + m_innerStride(map.innerStride()), + m_outerStride(map.outerStride()) { + EIGEN_STATIC_ASSERT(check_implication((evaluator::Flags & PacketAccessBit) != 0, + internal::inner_stride_at_compile_time::ret == 1), + PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_data[col * colStride() + row * rowStride()]; + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + return m_data[index * m_innerStride.value()]; + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + return m_data[col * colStride() + row * rowStride()]; + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { return m_data[index * m_innerStride.value()]; } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + PointerType ptr = m_data + row * rowStride() + col * colStride(); + return internal::ploadt(ptr); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + return internal::ploadt(m_data + index * m_innerStride.value()); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index row, Index col, const PacketType& x) { + PointerType ptr = m_data + row * rowStride() + col * colStride(); + return internal::pstoret(ptr, x); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index index, const PacketType& x) { + internal::pstoret(m_data + index * m_innerStride.value(), x); + } + + protected: + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rowStride() const EIGEN_NOEXCEPT { + return XprType::IsRowMajor ? m_outerStride.value() : m_innerStride.value(); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index colStride() const EIGEN_NOEXCEPT { + return XprType::IsRowMajor ? m_innerStride.value() : m_outerStride.value(); + } + + PointerType m_data; + const internal::variable_if_dynamic m_innerStride; + const internal::variable_if_dynamic m_outerStride; +}; + +template +struct evaluator > + : public mapbase_evaluator, PlainObjectType> { + typedef Map XprType; + typedef typename XprType::Scalar Scalar; + // TODO: should check for smaller packet types once we can handle multi-sized packet types + typedef typename packet_traits::type PacketScalar; + + enum { + InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0 + ? int(PlainObjectType::InnerStrideAtCompileTime) + : int(StrideType::InnerStrideAtCompileTime), + OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0 + ? int(PlainObjectType::OuterStrideAtCompileTime) + : int(StrideType::OuterStrideAtCompileTime), + HasNoInnerStride = InnerStrideAtCompileTime == 1, + HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0, + HasNoStride = HasNoInnerStride && HasNoOuterStride, + IsDynamicSize = PlainObjectType::SizeAtCompileTime == Dynamic, + + PacketAccessMask = bool(HasNoInnerStride) ? ~int(0) : ~int(PacketAccessBit), + LinearAccessMask = + bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime) ? ~int(0) : ~int(LinearAccessBit), + Flags = int(evaluator::Flags) & (LinearAccessMask & PacketAccessMask), + + Alignment = int(MapOptions) & int(AlignedMask) + }; + + EIGEN_DEVICE_FUNC explicit evaluator(const XprType& map) : mapbase_evaluator(map) {} +}; + +// -------------------- Ref -------------------- + +template +struct evaluator > + : public mapbase_evaluator, PlainObjectType> { + typedef Ref XprType; + + enum { + Flags = evaluator >::Flags, + Alignment = evaluator >::Alignment + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& ref) + : mapbase_evaluator(ref) {} +}; + +// -------------------- Block -------------------- + +template ::ret> +struct block_evaluator; + +template +struct evaluator > + : block_evaluator { + typedef Block XprType; + typedef typename XprType::Scalar Scalar; + // TODO: should check for smaller packet types once we can handle multi-sized packet types + typedef typename packet_traits::type PacketScalar; + + enum { + CoeffReadCost = evaluator::CoeffReadCost, + + RowsAtCompileTime = traits::RowsAtCompileTime, + ColsAtCompileTime = traits::ColsAtCompileTime, + MaxRowsAtCompileTime = traits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = traits::MaxColsAtCompileTime, + + ArgTypeIsRowMajor = (int(evaluator::Flags) & RowMajorBit) != 0, + IsRowMajor = (MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1) ? 1 + : (MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1) ? 0 + : ArgTypeIsRowMajor, + HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor), + InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime), + InnerStrideAtCompileTime = HasSameStorageOrderAsArgType ? int(inner_stride_at_compile_time::ret) + : int(outer_stride_at_compile_time::ret), + OuterStrideAtCompileTime = HasSameStorageOrderAsArgType ? int(outer_stride_at_compile_time::ret) + : int(inner_stride_at_compile_time::ret), + MaskPacketAccessBit = (InnerStrideAtCompileTime == 1 || HasSameStorageOrderAsArgType) ? PacketAccessBit : 0, + + FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || + (InnerPanel && (evaluator::Flags & LinearAccessBit))) + ? LinearAccessBit + : 0, + FlagsRowMajorBit = XprType::Flags & RowMajorBit, + Flags0 = evaluator::Flags & ((HereditaryBits & ~RowMajorBit) | DirectAccessBit | MaskPacketAccessBit), + Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit, + + PacketAlignment = unpacket_traits::alignment, + Alignment0 = (InnerPanel && (OuterStrideAtCompileTime != Dynamic) && (OuterStrideAtCompileTime != 0) && + (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % int(PacketAlignment)) == 0)) + ? int(PacketAlignment) + : 0, + Alignment = plain_enum_min(evaluator::Alignment, Alignment0) + }; + typedef block_evaluator block_evaluator_type; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& block) : block_evaluator_type(block) { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } +}; + +// no direct-access => dispatch to a unary evaluator +template +struct block_evaluator + : unary_evaluator > { + typedef Block XprType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit block_evaluator(const XprType& block) + : unary_evaluator(block) {} +}; + +template +struct unary_evaluator, IndexBased> + : evaluator_base > { + typedef Block XprType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit unary_evaluator(const XprType& block) + : m_argImpl(block.nestedExpression()), + m_startRow(block.startRow()), + m_startCol(block.startCol()), + m_linear_offset(ForwardLinearAccess + ? (ArgType::IsRowMajor + ? block.startRow() * block.nestedExpression().cols() + block.startCol() + : block.startCol() * block.nestedExpression().rows() + block.startRow()) + : 0) {} + + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + enum { + RowsAtCompileTime = XprType::RowsAtCompileTime, + ForwardLinearAccess = (InnerPanel || int(XprType::IsRowMajor) == int(ArgType::IsRowMajor)) && + bool(evaluator::Flags & LinearAccessBit) + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_argImpl.coeff(m_startRow.value() + row, m_startCol.value() + col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + return linear_coeff_impl(index, bool_constant()); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + return m_argImpl.coeffRef(m_startRow.value() + row, m_startCol.value() + col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { + return linear_coeffRef_impl(index, bool_constant()); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + return m_argImpl.template packet(m_startRow.value() + row, m_startCol.value() + col); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + if (ForwardLinearAccess) + return m_argImpl.template packet(m_linear_offset.value() + index); + else + return packet(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index row, Index col, const PacketType& x) { + return m_argImpl.template writePacket(m_startRow.value() + row, m_startCol.value() + col, x); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index index, const PacketType& x) { + if (ForwardLinearAccess) + return m_argImpl.template writePacket(m_linear_offset.value() + index, x); + else + return writePacket(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0, + x); + } + + protected: + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType + linear_coeff_impl(Index index, internal::true_type /* ForwardLinearAccess */) const { + return m_argImpl.coeff(m_linear_offset.value() + index); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType + linear_coeff_impl(Index index, internal::false_type /* not ForwardLinearAccess */) const { + return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& linear_coeffRef_impl(Index index, + internal::true_type /* ForwardLinearAccess */) { + return m_argImpl.coeffRef(m_linear_offset.value() + index); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& linear_coeffRef_impl( + Index index, internal::false_type /* not ForwardLinearAccess */) { + return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0); + } + + evaluator m_argImpl; + const variable_if_dynamic m_startRow; + const variable_if_dynamic m_startCol; + const variable_if_dynamic m_linear_offset; +}; + +// TODO: This evaluator does not actually use the child evaluator; +// all action is via the data() as returned by the Block expression. + +template +struct block_evaluator + : mapbase_evaluator, + typename Block::PlainObject> { + typedef Block XprType; + typedef typename XprType::Scalar Scalar; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit block_evaluator(const XprType& block) + : mapbase_evaluator(block) { + eigen_internal_assert((internal::is_constant_evaluated() || + (std::uintptr_t(block.data()) % plain_enum_max(1, evaluator::Alignment)) == 0) && + "data is not aligned"); + } +}; + +// -------------------- Select -------------------- +// NOTE shall we introduce a ternary_evaluator? + +// TODO enable vectorization for Select +template +struct evaluator > + : evaluator_base > { + typedef Select XprType; + enum { + CoeffReadCost = evaluator::CoeffReadCost + + plain_enum_max(evaluator::CoeffReadCost, evaluator::CoeffReadCost), + + Flags = (unsigned int)evaluator::Flags & evaluator::Flags & HereditaryBits, + + Alignment = plain_enum_min(evaluator::Alignment, evaluator::Alignment) + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& select) + : m_conditionImpl(select.conditionMatrix()), m_thenImpl(select.thenMatrix()), m_elseImpl(select.elseMatrix()) { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + if (m_conditionImpl.coeff(row, col)) + return m_thenImpl.coeff(row, col); + else + return m_elseImpl.coeff(row, col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + if (m_conditionImpl.coeff(index)) + return m_thenImpl.coeff(index); + else + return m_elseImpl.coeff(index); + } + + protected: + evaluator m_conditionImpl; + evaluator m_thenImpl; + evaluator m_elseImpl; +}; + +// -------------------- Replicate -------------------- + +template +struct unary_evaluator > + : evaluator_base > { + typedef Replicate XprType; + typedef typename XprType::CoeffReturnType CoeffReturnType; + enum { Factor = (RowFactor == Dynamic || ColFactor == Dynamic) ? Dynamic : RowFactor * ColFactor }; + typedef typename internal::nested_eval::type ArgTypeNested; + typedef internal::remove_all_t ArgTypeNestedCleaned; + + enum { + CoeffReadCost = evaluator::CoeffReadCost, + LinearAccessMask = XprType::IsVectorAtCompileTime ? LinearAccessBit : 0, + Flags = (evaluator::Flags & (HereditaryBits | LinearAccessMask) & ~RowMajorBit) | + (traits::Flags & RowMajorBit), + + Alignment = evaluator::Alignment + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit unary_evaluator(const XprType& replicate) + : m_arg(replicate.nestedExpression()), + m_argImpl(m_arg), + m_rows(replicate.nestedExpression().rows()), + m_cols(replicate.nestedExpression().cols()) {} + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + // try to avoid using modulo; this is a pure optimization strategy + const Index actual_row = internal::traits::RowsAtCompileTime == 1 ? 0 + : RowFactor == 1 ? row + : row % m_rows.value(); + const Index actual_col = internal::traits::ColsAtCompileTime == 1 ? 0 + : ColFactor == 1 ? col + : col % m_cols.value(); + + return m_argImpl.coeff(actual_row, actual_col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + // try to avoid using modulo; this is a pure optimization strategy + const Index actual_index = internal::traits::RowsAtCompileTime == 1 + ? (ColFactor == 1 ? index : index % m_cols.value()) + : (RowFactor == 1 ? index : index % m_rows.value()); + + return m_argImpl.coeff(actual_index); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + const Index actual_row = internal::traits::RowsAtCompileTime == 1 ? 0 + : RowFactor == 1 ? row + : row % m_rows.value(); + const Index actual_col = internal::traits::ColsAtCompileTime == 1 ? 0 + : ColFactor == 1 ? col + : col % m_cols.value(); + + return m_argImpl.template packet(actual_row, actual_col); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + const Index actual_index = internal::traits::RowsAtCompileTime == 1 + ? (ColFactor == 1 ? index : index % m_cols.value()) + : (RowFactor == 1 ? index : index % m_rows.value()); + + return m_argImpl.template packet(actual_index); + } + + protected: + const ArgTypeNested m_arg; + evaluator m_argImpl; + const variable_if_dynamic m_rows; + const variable_if_dynamic m_cols; +}; + +// -------------------- MatrixWrapper and ArrayWrapper -------------------- +// +// evaluator_wrapper_base is a common base class for the +// MatrixWrapper and ArrayWrapper evaluators. + +template +struct evaluator_wrapper_base : evaluator_base { + typedef remove_all_t ArgType; + enum { + CoeffReadCost = evaluator::CoeffReadCost, + Flags = evaluator::Flags, + Alignment = evaluator::Alignment + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator_wrapper_base(const ArgType& arg) : m_argImpl(arg) {} + + typedef typename ArgType::Scalar Scalar; + typedef typename ArgType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_argImpl.coeff(row, col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { return m_argImpl.coeff(index); } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { return m_argImpl.coeffRef(row, col); } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { return m_argImpl.coeffRef(index); } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + return m_argImpl.template packet(row, col); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + return m_argImpl.template packet(index); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index row, Index col, const PacketType& x) { + m_argImpl.template writePacket(row, col, x); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index index, const PacketType& x) { + m_argImpl.template writePacket(index, x); + } + + protected: + evaluator m_argImpl; +}; + +template +struct unary_evaluator > : evaluator_wrapper_base > { + typedef MatrixWrapper XprType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit unary_evaluator(const XprType& wrapper) + : evaluator_wrapper_base >(wrapper.nestedExpression()) {} +}; + +template +struct unary_evaluator > : evaluator_wrapper_base > { + typedef ArrayWrapper XprType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit unary_evaluator(const XprType& wrapper) + : evaluator_wrapper_base >(wrapper.nestedExpression()) {} +}; + +// -------------------- Reverse -------------------- + +// defined in Reverse.h: +template +struct reverse_packet_cond; + +template +struct unary_evaluator > : evaluator_base > { + typedef Reverse XprType; + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + enum { + IsRowMajor = XprType::IsRowMajor, + IsColMajor = !IsRowMajor, + ReverseRow = (Direction == Vertical) || (Direction == BothDirections), + ReverseCol = (Direction == Horizontal) || (Direction == BothDirections), + ReversePacket = (Direction == BothDirections) || ((Direction == Vertical) && IsColMajor) || + ((Direction == Horizontal) && IsRowMajor), + + CoeffReadCost = evaluator::CoeffReadCost, + + // let's enable LinearAccess only with vectorization because of the product overhead + // FIXME enable DirectAccess with negative strides? + Flags0 = evaluator::Flags, + LinearAccess = + ((Direction == BothDirections) && (int(Flags0) & PacketAccessBit)) || + ((ReverseRow && XprType::ColsAtCompileTime == 1) || (ReverseCol && XprType::RowsAtCompileTime == 1)) + ? LinearAccessBit + : 0, + + Flags = int(Flags0) & (HereditaryBits | PacketAccessBit | LinearAccess), + + Alignment = 0 // FIXME in some rare cases, Alignment could be preserved, like a Vector4f. + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit unary_evaluator(const XprType& reverse) + : m_argImpl(reverse.nestedExpression()), + m_rows(ReverseRow ? reverse.nestedExpression().rows() : 1), + m_cols(ReverseCol ? reverse.nestedExpression().cols() : 1) {} + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + return m_argImpl.coeff(ReverseRow ? m_rows.value() - row - 1 : row, ReverseCol ? m_cols.value() - col - 1 : col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + return m_argImpl.coeffRef(ReverseRow ? m_rows.value() - row - 1 : row, ReverseCol ? m_cols.value() - col - 1 : col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { + return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + enum { + PacketSize = unpacket_traits::size, + OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1, + OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1 + }; + typedef internal::reverse_packet_cond reverse_packet; + return reverse_packet::run(m_argImpl.template packet( + ReverseRow ? m_rows.value() - row - OffsetRow : row, ReverseCol ? m_cols.value() - col - OffsetCol : col)); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index index) const { + enum { PacketSize = unpacket_traits::size }; + return preverse( + m_argImpl.template packet(m_rows.value() * m_cols.value() - index - PacketSize)); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index row, Index col, const PacketType& x) { + // FIXME we could factorize some code with packet(i,j) + enum { + PacketSize = unpacket_traits::size, + OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1, + OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1 + }; + typedef internal::reverse_packet_cond reverse_packet; + m_argImpl.template writePacket(ReverseRow ? m_rows.value() - row - OffsetRow : row, + ReverseCol ? m_cols.value() - col - OffsetCol : col, + reverse_packet::run(x)); + } + + template + EIGEN_STRONG_INLINE void writePacket(Index index, const PacketType& x) { + enum { PacketSize = unpacket_traits::size }; + m_argImpl.template writePacket(m_rows.value() * m_cols.value() - index - PacketSize, preverse(x)); + } + + protected: + evaluator m_argImpl; + + // If we do not reverse rows, then we do not need to know the number of rows; same for columns + // Nonetheless, in this case it is important to set to 1 such that the coeff(index) method works fine for vectors. + const variable_if_dynamic m_rows; + const variable_if_dynamic m_cols; +}; + +// -------------------- Diagonal -------------------- + +template +struct evaluator > : evaluator_base > { + typedef Diagonal XprType; + + enum { + CoeffReadCost = evaluator::CoeffReadCost, + + Flags = + (unsigned int)(evaluator::Flags & (HereditaryBits | DirectAccessBit) & ~RowMajorBit) | LinearAccessBit, + + Alignment = 0 + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& diagonal) + : m_argImpl(diagonal.nestedExpression()), m_index(diagonal.index()) {} + + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index) const { + return m_argImpl.coeff(row + rowOffset(), row + colOffset()); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + return m_argImpl.coeff(index + rowOffset(), index + colOffset()); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index) { + return m_argImpl.coeffRef(row + rowOffset(), row + colOffset()); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { + return m_argImpl.coeffRef(index + rowOffset(), index + colOffset()); + } + + protected: + evaluator m_argImpl; + const internal::variable_if_dynamicindex m_index; + + private: + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rowOffset() const { + return m_index.value() > 0 ? 0 : -m_index.value(); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index colOffset() const { + return m_index.value() > 0 ? m_index.value() : 0; + } +}; + +//---------------------------------------------------------------------- +// deprecated code +//---------------------------------------------------------------------- + +// -------------------- EvalToTemp -------------------- + +// expression class for evaluating nested expression to a temporary + +template +class EvalToTemp; + +template +struct traits > : public traits {}; + +template +class EvalToTemp : public dense_xpr_base >::type { + public: + typedef typename dense_xpr_base::type Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp) + + explicit EvalToTemp(const ArgType& arg) : m_arg(arg) {} + + const ArgType& arg() const { return m_arg; } + + EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_arg.rows(); } + + EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_arg.cols(); } + + private: + const ArgType& m_arg; +}; + +template +struct evaluator > : public evaluator { + typedef EvalToTemp XprType; + typedef typename ArgType::PlainObject PlainObject; + typedef evaluator Base; + + EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : m_result(xpr.arg()) { + internal::construct_at(this, m_result); + } + + // This constructor is used when nesting an EvalTo evaluator in another evaluator + EIGEN_DEVICE_FUNC evaluator(const ArgType& arg) : m_result(arg) { internal::construct_at(this, m_result); } + + protected: + PlainObject m_result; +}; + +} // namespace internal + +} // end namespace Eigen + +#endif // EIGEN_COREEVALUATORS_H diff --git a/dae-cpp/Eigen/src/Core/CoreIterators.h b/dae-cpp/Eigen/src/Core/CoreIterators.h new file mode 100644 index 0000000..f62cf23 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/CoreIterators.h @@ -0,0 +1,141 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2014 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_COREITERATORS_H +#define EIGEN_COREITERATORS_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core + */ + +namespace internal { + +template +class inner_iterator_selector; + +} + +/** \class InnerIterator + * \brief An InnerIterator allows to loop over the element of any matrix expression. + * + * \warning To be used with care because an evaluator is constructed every time an InnerIterator iterator is + * constructed. + * + * TODO: add a usage example + */ +template +class InnerIterator { + protected: + typedef internal::inner_iterator_selector::Kind> IteratorType; + typedef internal::evaluator EvaluatorType; + typedef typename internal::traits::Scalar Scalar; + + public: + /** Construct an iterator over the \a outerId -th row or column of \a xpr */ + InnerIterator(const XprType &xpr, const Index &outerId) : m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize()) {} + + /// \returns the value of the current coefficient. + EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); } + /** Increment the iterator \c *this to the next non-zero coefficient. + * Explicit zeros are not skipped over. To skip explicit zeros, see class SparseView + */ + EIGEN_STRONG_INLINE InnerIterator &operator++() { + m_iter.operator++(); + return *this; + } + EIGEN_STRONG_INLINE InnerIterator &operator+=(Index i) { + m_iter.operator+=(i); + return *this; + } + EIGEN_STRONG_INLINE InnerIterator operator+(Index i) { + InnerIterator result(*this); + result += i; + return result; + } + + /// \returns the column or row index of the current coefficient. + EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); } + /// \returns the row index of the current coefficient. + EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); } + /// \returns the column index of the current coefficient. + EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); } + /// \returns \c true if the iterator \c *this still references a valid coefficient. + EIGEN_STRONG_INLINE operator bool() const { return m_iter; } + + protected: + EvaluatorType m_eval; + IteratorType m_iter; + + private: + // If you get here, then you're not using the right InnerIterator type, e.g.: + // SparseMatrix A; + // SparseMatrix::InnerIterator it(A,0); + template + InnerIterator(const EigenBase &, Index outer); +}; + +namespace internal { + +// Generic inner iterator implementation for dense objects +template +class inner_iterator_selector { + protected: + typedef evaluator EvaluatorType; + typedef typename traits::Scalar Scalar; + enum { IsRowMajor = (XprType::Flags & RowMajorBit) == RowMajorBit }; + + public: + EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize) + : m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize) {} + + EIGEN_STRONG_INLINE Scalar value() const { + return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner) : m_eval.coeff(m_inner, m_outer); + } + + EIGEN_STRONG_INLINE inner_iterator_selector &operator++() { + m_inner++; + return *this; + } + + EIGEN_STRONG_INLINE Index index() const { return m_inner; } + inline Index row() const { return IsRowMajor ? m_outer : index(); } + inline Index col() const { return IsRowMajor ? index() : m_outer; } + + EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner >= 0; } + + protected: + const EvaluatorType &m_eval; + Index m_inner; + const Index m_outer; + const Index m_end; +}; + +// For iterator-based evaluator, inner-iterator is already implemented as +// evaluator<>::InnerIterator +template +class inner_iterator_selector : public evaluator::InnerIterator { + protected: + typedef typename evaluator::InnerIterator Base; + typedef evaluator EvaluatorType; + + public: + EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, + const Index & /*innerSize*/) + : Base(eval, outerId) {} +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_COREITERATORS_H diff --git a/dae-cpp/Eigen/src/Core/CwiseBinaryOp.h b/dae-cpp/Eigen/src/Core/CwiseBinaryOp.h new file mode 100644 index 0000000..aa79b60 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/CwiseBinaryOp.h @@ -0,0 +1,166 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2014 Gael Guennebaud +// Copyright (C) 2006-2008 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CWISE_BINARY_OP_H +#define EIGEN_CWISE_BINARY_OP_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits> { + // we must not inherit from traits since it has + // the potential to cause problems with MSVC + typedef remove_all_t Ancestor; + typedef typename traits::XprKind XprKind; + enum { + RowsAtCompileTime = traits::RowsAtCompileTime, + ColsAtCompileTime = traits::ColsAtCompileTime, + MaxRowsAtCompileTime = traits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = traits::MaxColsAtCompileTime + }; + + // even though we require Lhs and Rhs to have the same scalar type (see CwiseBinaryOp constructor), + // we still want to handle the case when the result type is different. + typedef typename result_of::type Scalar; + typedef typename cwise_promote_storage_type::StorageKind, typename traits::StorageKind, + BinaryOp>::ret StorageKind; + typedef typename promote_index_type::StorageIndex, typename traits::StorageIndex>::type + StorageIndex; + typedef typename Lhs::Nested LhsNested; + typedef typename Rhs::Nested RhsNested; + typedef std::remove_reference_t LhsNested_; + typedef std::remove_reference_t RhsNested_; + enum { + Flags = cwise_promote_storage_order::StorageKind, typename traits::StorageKind, + LhsNested_::Flags & RowMajorBit, RhsNested_::Flags & RowMajorBit>::value + }; +}; +} // end namespace internal + +template +class CwiseBinaryOpImpl; + +/** \class CwiseBinaryOp + * \ingroup Core_Module + * + * \brief Generic expression where a coefficient-wise binary operator is applied to two expressions + * + * \tparam BinaryOp template functor implementing the operator + * \tparam LhsType the type of the left-hand side + * \tparam RhsType the type of the right-hand side + * + * This class represents an expression where a coefficient-wise binary operator is applied to two expressions. + * It is the return type of binary operators, by which we mean only those binary operators where + * both the left-hand side and the right-hand side are Eigen expressions. + * For example, the return type of matrix1+matrix2 is a CwiseBinaryOp. + * + * Most of the time, this is the only way that it is used, so you typically don't have to name + * CwiseBinaryOp types explicitly. + * + * \sa MatrixBase::binaryExpr(const MatrixBase &,const CustomBinaryOp &) const, class CwiseUnaryOp, class + * CwiseNullaryOp + */ +template +class CwiseBinaryOp : public CwiseBinaryOpImpl::StorageKind, + typename internal::traits::StorageKind, BinaryOp>::ret>, + internal::no_assignment_operator { + public: + typedef internal::remove_all_t Functor; + typedef internal::remove_all_t Lhs; + typedef internal::remove_all_t Rhs; + + typedef typename CwiseBinaryOpImpl< + BinaryOp, LhsType, RhsType, + typename internal::cwise_promote_storage_type::StorageKind, + typename internal::traits::StorageKind, BinaryOp>::ret>::Base + Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp) + + EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp, typename Lhs::Scalar, typename Rhs::Scalar) + EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs) + + typedef typename internal::ref_selector::type LhsNested; + typedef typename internal::ref_selector::type RhsNested; + typedef std::remove_reference_t LhsNested_; + typedef std::remove_reference_t RhsNested_; + +#if EIGEN_COMP_MSVC + // Required for Visual Studio or the Copy constructor will probably not get inlined! + EIGEN_STRONG_INLINE CwiseBinaryOp(const CwiseBinaryOp&) = default; +#endif + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CwiseBinaryOp(const Lhs& aLhs, const Rhs& aRhs, + const BinaryOp& func = BinaryOp()) + : m_lhs(aLhs), m_rhs(aRhs), m_functor(func) { + eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols()); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { + // return the fixed size type if available to enable compile time optimizations + return internal::traits>::RowsAtCompileTime == Dynamic ? m_rhs.rows() + : m_lhs.rows(); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { + // return the fixed size type if available to enable compile time optimizations + return internal::traits>::ColsAtCompileTime == Dynamic ? m_rhs.cols() + : m_lhs.cols(); + } + + /** \returns the left hand side nested expression */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const LhsNested_& lhs() const { return m_lhs; } + /** \returns the right hand side nested expression */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const RhsNested_& rhs() const { return m_rhs; } + /** \returns the functor representing the binary operation */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const BinaryOp& functor() const { return m_functor; } + + protected: + LhsNested m_lhs; + RhsNested m_rhs; + const BinaryOp m_functor; +}; + +// Generic API dispatcher +template +class CwiseBinaryOpImpl : public internal::generic_xpr_base>::type { + public: + typedef typename internal::generic_xpr_base>::type Base; +}; + +/** replaces \c *this by \c *this - \a other. + * + * \returns a reference to \c *this + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::operator-=(const MatrixBase& other) { + call_assignment(derived(), other.derived(), internal::sub_assign_op()); + return derived(); +} + +/** replaces \c *this by \c *this + \a other. + * + * \returns a reference to \c *this + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::operator+=(const MatrixBase& other) { + call_assignment(derived(), other.derived(), internal::add_assign_op()); + return derived(); +} + +} // end namespace Eigen + +#endif // EIGEN_CWISE_BINARY_OP_H diff --git a/dae-cpp/Eigen/src/Core/CwiseNullaryOp.h b/dae-cpp/Eigen/src/Core/CwiseNullaryOp.h new file mode 100644 index 0000000..39c33cf --- /dev/null +++ b/dae-cpp/Eigen/src/Core/CwiseNullaryOp.h @@ -0,0 +1,971 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CWISE_NULLARY_OP_H +#define EIGEN_CWISE_NULLARY_OP_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits > : traits { + enum { Flags = traits::Flags & RowMajorBit }; +}; + +} // namespace internal + +/** \class CwiseNullaryOp + * \ingroup Core_Module + * + * \brief Generic expression of a matrix where all coefficients are defined by a functor + * + * \tparam NullaryOp template functor implementing the operator + * \tparam PlainObjectType the underlying plain matrix/array type + * + * This class represents an expression of a generic nullary operator. + * It is the return type of the Ones(), Zero(), Constant(), Identity() and Random() methods, + * and most of the time this is the only way it is used. + * + * However, if you want to write a function returning such an expression, you + * will need to use this class. + * + * The functor NullaryOp must expose one of the following method: + + +
\c operator()() if the procedural generation does not depend on the coefficient entries + (e.g., random numbers)
\c operator()(Index i)if the procedural generation makes + sense for vectors only and that it depends on the coefficient index \c i (e.g., linspace)
\c + operator()(Index i,Index j)if the procedural generation depends on the matrix coordinates \c i, \c j (e.g., + to generate a checkerboard with 0 and 1)
+ * It is also possible to expose the last two operators if the generation makes sense for matrices but can be optimized + for vectors. + * + * See DenseBase::NullaryExpr(Index,const CustomNullaryOp&) for an example binding + * C++11 random number generators. + * + * A nullary expression can also be used to implement custom sophisticated matrix manipulations + * that cannot be covered by the existing set of natively supported matrix manipulations. + * See this \ref TopicCustomizing_NullaryExpr "page" for some examples and additional explanations + * on the behavior of CwiseNullaryOp. + * + * \sa class CwiseUnaryOp, class CwiseBinaryOp, DenseBase::NullaryExpr + */ +template +class CwiseNullaryOp : public internal::dense_xpr_base >::type, + internal::no_assignment_operator { + public: + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(CwiseNullaryOp) + + EIGEN_DEVICE_FUNC CwiseNullaryOp(Index rows, Index cols, const NullaryOp& func = NullaryOp()) + : m_rows(rows), m_cols(cols), m_functor(func) { + eigen_assert(rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && cols >= 0 && + (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const { return m_rows.value(); } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const { return m_cols.value(); } + + /** \returns the functor representing the nullary operation */ + EIGEN_DEVICE_FUNC const NullaryOp& functor() const { return m_functor; } + + protected: + const internal::variable_if_dynamic m_rows; + const internal::variable_if_dynamic m_cols; + const NullaryOp m_functor; +}; + +/** \returns an expression of a matrix defined by a custom functor \a func + * + * The parameters \a rows and \a cols are the number of rows and of columns of + * the returned matrix. Must be compatible with this MatrixBase type. + * + * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, + * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used + * instead. + * + * The template parameter \a CustomNullaryOp is the type of the functor. + * + * \sa class CwiseNullaryOp + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE +#ifndef EIGEN_PARSED_BY_DOXYGEN + const CwiseNullaryOp::PlainObject> +#else + const CwiseNullaryOp +#endif + DenseBase::NullaryExpr(Index rows, Index cols, const CustomNullaryOp& func) { + return CwiseNullaryOp(rows, cols, func); +} + +/** \returns an expression of a matrix defined by a custom functor \a func + * + * The parameter \a size is the size of the returned vector. + * Must be compatible with this MatrixBase type. + * + * \only_for_vectors + * + * This variant is meant to be used for dynamic-size vector types. For fixed-size types, + * it is redundant to pass \a size as argument, so Zero() should be used + * instead. + * + * The template parameter \a CustomNullaryOp is the type of the functor. + * + * Here is an example with C++11 random generators: \include random_cpp11.cpp + * Output: \verbinclude random_cpp11.out + * + * \sa class CwiseNullaryOp + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE +#ifndef EIGEN_PARSED_BY_DOXYGEN + const CwiseNullaryOp::PlainObject> +#else + const CwiseNullaryOp +#endif + DenseBase::NullaryExpr(Index size, const CustomNullaryOp& func) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + if (RowsAtCompileTime == 1) + return CwiseNullaryOp(1, size, func); + else + return CwiseNullaryOp(size, 1, func); +} + +/** \returns an expression of a matrix defined by a custom functor \a func + * + * This variant is only for fixed-size DenseBase types. For dynamic-size types, you + * need to use the variants taking size arguments. + * + * The template parameter \a CustomNullaryOp is the type of the functor. + * + * \sa class CwiseNullaryOp + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE +#ifndef EIGEN_PARSED_BY_DOXYGEN + const CwiseNullaryOp::PlainObject> +#else + const CwiseNullaryOp +#endif + DenseBase::NullaryExpr(const CustomNullaryOp& func) { + return CwiseNullaryOp(RowsAtCompileTime, ColsAtCompileTime, func); +} + +/** \returns an expression of a constant matrix of value \a value + * + * The parameters \a rows and \a cols are the number of rows and of columns of + * the returned matrix. Must be compatible with this DenseBase type. + * + * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, + * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used + * instead. + * + * The template parameter \a CustomNullaryOp is the type of the functor. + * + * \sa class CwiseNullaryOp + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Constant(Index rows, Index cols, const Scalar& value) { + return DenseBase::NullaryExpr(rows, cols, internal::scalar_constant_op(value)); +} + +/** \returns an expression of a constant matrix of value \a value + * + * The parameter \a size is the size of the returned vector. + * Must be compatible with this DenseBase type. + * + * \only_for_vectors + * + * This variant is meant to be used for dynamic-size vector types. For fixed-size types, + * it is redundant to pass \a size as argument, so Zero() should be used + * instead. + * + * The template parameter \a CustomNullaryOp is the type of the functor. + * + * \sa class CwiseNullaryOp + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Constant(Index size, const Scalar& value) { + return DenseBase::NullaryExpr(size, internal::scalar_constant_op(value)); +} + +/** \returns an expression of a constant matrix of value \a value + * + * This variant is only for fixed-size DenseBase types. For dynamic-size types, you + * need to use the variants taking size arguments. + * + * The template parameter \a CustomNullaryOp is the type of the functor. + * + * \sa class CwiseNullaryOp + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType +DenseBase::Constant(const Scalar& value) { + EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) + return DenseBase::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, + internal::scalar_constant_op(value)); +} + +/** \deprecated because of accuracy loss. In Eigen 3.3, it is an alias for LinSpaced(Index,const Scalar&,const Scalar&) + * + * \only_for_vectors + * + * Example: \include DenseBase_LinSpaced_seq_deprecated.cpp + * Output: \verbinclude DenseBase_LinSpaced_seq_deprecated.out + * + * \sa LinSpaced(Index,const Scalar&, const Scalar&), setLinSpaced(Index,const Scalar&,const Scalar&) + */ +template +EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase< + Derived>::RandomAccessLinSpacedReturnType +DenseBase::LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return DenseBase::NullaryExpr(size, internal::linspaced_op(low, high, size)); +} + +/** \deprecated because of accuracy loss. In Eigen 3.3, it is an alias for LinSpaced(const Scalar&,const Scalar&) + * + * \sa LinSpaced(const Scalar&, const Scalar&) + */ +template +EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase< + Derived>::RandomAccessLinSpacedReturnType +DenseBase::LinSpaced(Sequential_t, const Scalar& low, const Scalar& high) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) + return DenseBase::NullaryExpr(Derived::SizeAtCompileTime, + internal::linspaced_op(low, high, Derived::SizeAtCompileTime)); +} + +/** + * \brief Sets a linearly spaced vector. + * + * The function generates 'size' equally spaced values in the closed interval [low,high]. + * When size is set to 1, a vector of length 1 containing 'high' is returned. + * + * \only_for_vectors + * + * Example: \include DenseBase_LinSpaced.cpp + * Output: \verbinclude DenseBase_LinSpaced.out + * + * For integer scalar types, an even spacing is possible if and only if the length of the range, + * i.e., \c high-low is a scalar multiple of \c size-1, or if \c size is a scalar multiple of the + * number of values \c high-low+1 (meaning each value can be repeated the same number of time). + * If one of these two considions is not satisfied, then \c high is lowered to the largest value + * satisfying one of this constraint. + * Here are some examples: + * + * Example: \include DenseBase_LinSpacedInt.cpp + * Output: \verbinclude DenseBase_LinSpacedInt.out + * + * \sa setLinSpaced(Index,const Scalar&,const Scalar&), CwiseNullaryOp + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::RandomAccessLinSpacedReturnType +DenseBase::LinSpaced(Index size, const Scalar& low, const Scalar& high) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return DenseBase::NullaryExpr(size, internal::linspaced_op(low, high, size)); +} + +/** + * \copydoc DenseBase::LinSpaced(Index, const Scalar&, const Scalar&) + * Special version for fixed size types which does not require the size parameter. + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::RandomAccessLinSpacedReturnType +DenseBase::LinSpaced(const Scalar& low, const Scalar& high) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) + return DenseBase::NullaryExpr(Derived::SizeAtCompileTime, + internal::linspaced_op(low, high, Derived::SizeAtCompileTime)); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::RandomAccessEqualSpacedReturnType +DenseBase::EqualSpaced(Index size, const Scalar& low, const Scalar& step) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return DenseBase::NullaryExpr(size, internal::equalspaced_op(low, step)); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::RandomAccessEqualSpacedReturnType +DenseBase::EqualSpaced(const Scalar& low, const Scalar& step) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return DenseBase::NullaryExpr(Derived::SizeAtCompileTime, internal::equalspaced_op(low, step)); +} + +/** \returns true if all coefficients in this matrix are approximately equal to \a val, to within precision \a prec */ +template +EIGEN_DEVICE_FUNC bool DenseBase::isApproxToConstant(const Scalar& val, const RealScalar& prec) const { + typename internal::nested_eval::type self(derived()); + for (Index j = 0; j < cols(); ++j) + for (Index i = 0; i < rows(); ++i) + if (!internal::isApprox(self.coeff(i, j), val, prec)) return false; + return true; +} + +/** This is just an alias for isApproxToConstant(). + * + * \returns true if all coefficients in this matrix are approximately equal to \a value, to within precision \a prec */ +template +EIGEN_DEVICE_FUNC bool DenseBase::isConstant(const Scalar& val, const RealScalar& prec) const { + return isApproxToConstant(val, prec); +} + +/** Alias for setConstant(): sets all coefficients in this expression to \a val. + * + * \sa setConstant(), Constant(), class CwiseNullaryOp + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void DenseBase::fill(const Scalar& val) { + setConstant(val); +} + +/** Sets all coefficients in this expression to value \a val. + * + * \sa fill(), setConstant(Index,const Scalar&), setConstant(Index,Index,const Scalar&), setZero(), setOnes(), + * Constant(), class CwiseNullaryOp, setZero(), setOnes() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::setConstant(const Scalar& val) { + return derived() = Constant(rows(), cols(), val); +} + +/** Resizes to the given \a size, and sets all coefficients in this expression to the given value \a val. + * + * \only_for_vectors + * + * Example: \include Matrix_setConstant_int.cpp + * Output: \verbinclude Matrix_setConstant_int.out + * + * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,Index,const Scalar&), class CwiseNullaryOp, + * MatrixBase::Constant(const Scalar&) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setConstant(Index size, const Scalar& val) { + resize(size); + return setConstant(val); +} + +/** Resizes to the given size, and sets all coefficients in this expression to the given value \a val. + * + * \param rows the new number of rows + * \param cols the new number of columns + * \param val the value to which all coefficients are set + * + * Example: \include Matrix_setConstant_int_int.cpp + * Output: \verbinclude Matrix_setConstant_int_int.out + * + * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, + * MatrixBase::Constant(const Scalar&) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setConstant(Index rows, Index cols, + const Scalar& val) { + resize(rows, cols); + return setConstant(val); +} + +/** Resizes to the given size, changing only the number of columns, and sets all + * coefficients in this expression to the given value \a val. For the parameter + * of type NoChange_t, just pass the special value \c NoChange. + * + * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, + * MatrixBase::Constant(const Scalar&) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setConstant(NoChange_t, Index cols, + const Scalar& val) { + return setConstant(rows(), cols, val); +} + +/** Resizes to the given size, changing only the number of rows, and sets all + * coefficients in this expression to the given value \a val. For the parameter + * of type NoChange_t, just pass the special value \c NoChange. + * + * \sa MatrixBase::setConstant(const Scalar&), setConstant(Index,const Scalar&), class CwiseNullaryOp, + * MatrixBase::Constant(const Scalar&) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setConstant(Index rows, NoChange_t, + const Scalar& val) { + return setConstant(rows, cols(), val); +} + +/** + * \brief Sets a linearly spaced vector. + * + * The function generates 'size' equally spaced values in the closed interval [low,high]. + * When size is set to 1, a vector of length 1 containing 'high' is returned. + * + * \only_for_vectors + * + * Example: \include DenseBase_setLinSpaced.cpp + * Output: \verbinclude DenseBase_setLinSpaced.out + * + * For integer scalar types, do not miss the explanations on the definition + * of \link LinSpaced(Index,const Scalar&,const Scalar&) even spacing \endlink. + * + * \sa LinSpaced(Index,const Scalar&,const Scalar&), CwiseNullaryOp + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::setLinSpaced(Index newSize, const Scalar& low, + const Scalar& high) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return derived() = Derived::NullaryExpr(newSize, internal::linspaced_op(low, high, newSize)); +} + +/** + * \brief Sets a linearly spaced vector. + * + * The function fills \c *this with equally spaced values in the closed interval [low,high]. + * When size is set to 1, a vector of length 1 containing 'high' is returned. + * + * \only_for_vectors + * + * For integer scalar types, do not miss the explanations on the definition + * of \link LinSpaced(Index,const Scalar&,const Scalar&) even spacing \endlink. + * + * \sa LinSpaced(Index,const Scalar&,const Scalar&), setLinSpaced(Index, const Scalar&, const Scalar&), CwiseNullaryOp + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::setLinSpaced(const Scalar& low, const Scalar& high) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return setLinSpaced(size(), low, high); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::setEqualSpaced(Index newSize, const Scalar& low, + const Scalar& step) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return derived() = Derived::NullaryExpr(newSize, internal::equalspaced_op(low, step)); +} +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::setEqualSpaced(const Scalar& low, + const Scalar& step) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return setEqualSpaced(size(), low, step); +} + +// zero: + +/** \returns an expression of a zero matrix. + * + * The parameters \a rows and \a cols are the number of rows and of columns of + * the returned matrix. Must be compatible with this MatrixBase type. + * + * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, + * it is redundant to pass \a rows and \a cols as arguments, so Zero() should be used + * instead. + * + * Example: \include MatrixBase_zero_int_int.cpp + * Output: \verbinclude MatrixBase_zero_int_int.out + * + * \sa Zero(), Zero(Index) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType DenseBase::Zero( + Index rows, Index cols) { + return Constant(rows, cols, Scalar(0)); +} + +/** \returns an expression of a zero vector. + * + * The parameter \a size is the size of the returned vector. + * Must be compatible with this MatrixBase type. + * + * \only_for_vectors + * + * This variant is meant to be used for dynamic-size vector types. For fixed-size types, + * it is redundant to pass \a size as argument, so Zero() should be used + * instead. + * + * Example: \include MatrixBase_zero_int.cpp + * Output: \verbinclude MatrixBase_zero_int.out + * + * \sa Zero(), Zero(Index,Index) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType DenseBase::Zero( + Index size) { + return Constant(size, Scalar(0)); +} + +/** \returns an expression of a fixed-size zero matrix or vector. + * + * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you + * need to use the variants taking size arguments. + * + * Example: \include MatrixBase_zero.cpp + * Output: \verbinclude MatrixBase_zero.out + * + * \sa Zero(Index), Zero(Index,Index) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType DenseBase::Zero() { + return Constant(Scalar(0)); +} + +/** \returns true if *this is approximately equal to the zero matrix, + * within the precision given by \a prec. + * + * Example: \include MatrixBase_isZero.cpp + * Output: \verbinclude MatrixBase_isZero.out + * + * \sa class CwiseNullaryOp, Zero() + */ +template +EIGEN_DEVICE_FUNC bool DenseBase::isZero(const RealScalar& prec) const { + typename internal::nested_eval::type self(derived()); + for (Index j = 0; j < cols(); ++j) + for (Index i = 0; i < rows(); ++i) + if (!internal::isMuchSmallerThan(self.coeff(i, j), static_cast(1), prec)) return false; + return true; +} + +/** Sets all coefficients in this expression to zero. + * + * Example: \include MatrixBase_setZero.cpp + * Output: \verbinclude MatrixBase_setZero.out + * + * \sa class CwiseNullaryOp, Zero() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::setZero() { + return setConstant(Scalar(0)); +} + +/** Resizes to the given \a size, and sets all coefficients in this expression to zero. + * + * \only_for_vectors + * + * Example: \include Matrix_setZero_int.cpp + * Output: \verbinclude Matrix_setZero_int.out + * + * \sa DenseBase::setZero(), setZero(Index,Index), class CwiseNullaryOp, DenseBase::Zero() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setZero(Index newSize) { + resize(newSize); + return setConstant(Scalar(0)); +} + +/** Resizes to the given size, and sets all coefficients in this expression to zero. + * + * \param rows the new number of rows + * \param cols the new number of columns + * + * Example: \include Matrix_setZero_int_int.cpp + * Output: \verbinclude Matrix_setZero_int_int.out + * + * \sa DenseBase::setZero(), setZero(Index), class CwiseNullaryOp, DenseBase::Zero() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setZero(Index rows, Index cols) { + resize(rows, cols); + return setConstant(Scalar(0)); +} + +/** Resizes to the given size, changing only the number of columns, and sets all + * coefficients in this expression to zero. For the parameter of type NoChange_t, + * just pass the special value \c NoChange. + * + * \sa DenseBase::setZero(), setZero(Index), setZero(Index, Index), setZero(Index, NoChange_t), class CwiseNullaryOp, + * DenseBase::Zero() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setZero(NoChange_t, Index cols) { + return setZero(rows(), cols); +} + +/** Resizes to the given size, changing only the number of rows, and sets all + * coefficients in this expression to zero. For the parameter of type NoChange_t, + * just pass the special value \c NoChange. + * + * \sa DenseBase::setZero(), setZero(Index), setZero(Index, Index), setZero(NoChange_t, Index), class CwiseNullaryOp, + * DenseBase::Zero() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setZero(Index rows, NoChange_t) { + return setZero(rows, cols()); +} + +// ones: + +/** \returns an expression of a matrix where all coefficients equal one. + * + * The parameters \a rows and \a cols are the number of rows and of columns of + * the returned matrix. Must be compatible with this MatrixBase type. + * + * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, + * it is redundant to pass \a rows and \a cols as arguments, so Ones() should be used + * instead. + * + * Example: \include MatrixBase_ones_int_int.cpp + * Output: \verbinclude MatrixBase_ones_int_int.out + * + * \sa Ones(), Ones(Index), isOnes(), class Ones + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType DenseBase::Ones( + Index rows, Index cols) { + return Constant(rows, cols, Scalar(1)); +} + +/** \returns an expression of a vector where all coefficients equal one. + * + * The parameter \a newSize is the size of the returned vector. + * Must be compatible with this MatrixBase type. + * + * \only_for_vectors + * + * This variant is meant to be used for dynamic-size vector types. For fixed-size types, + * it is redundant to pass \a size as argument, so Ones() should be used + * instead. + * + * Example: \include MatrixBase_ones_int.cpp + * Output: \verbinclude MatrixBase_ones_int.out + * + * \sa Ones(), Ones(Index,Index), isOnes(), class Ones + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType DenseBase::Ones( + Index newSize) { + return Constant(newSize, Scalar(1)); +} + +/** \returns an expression of a fixed-size matrix or vector where all coefficients equal one. + * + * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you + * need to use the variants taking size arguments. + * + * Example: \include MatrixBase_ones.cpp + * Output: \verbinclude MatrixBase_ones.out + * + * \sa Ones(Index), Ones(Index,Index), isOnes(), class Ones + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::ConstantReturnType DenseBase::Ones() { + return Constant(Scalar(1)); +} + +/** \returns true if *this is approximately equal to the matrix where all coefficients + * are equal to 1, within the precision given by \a prec. + * + * Example: \include MatrixBase_isOnes.cpp + * Output: \verbinclude MatrixBase_isOnes.out + * + * \sa class CwiseNullaryOp, Ones() + */ +template +EIGEN_DEVICE_FUNC bool DenseBase::isOnes(const RealScalar& prec) const { + return isApproxToConstant(Scalar(1), prec); +} + +/** Sets all coefficients in this expression to one. + * + * Example: \include MatrixBase_setOnes.cpp + * Output: \verbinclude MatrixBase_setOnes.out + * + * \sa class CwiseNullaryOp, Ones() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& DenseBase::setOnes() { + return setConstant(Scalar(1)); +} + +/** Resizes to the given \a newSize, and sets all coefficients in this expression to one. + * + * \only_for_vectors + * + * Example: \include Matrix_setOnes_int.cpp + * Output: \verbinclude Matrix_setOnes_int.out + * + * \sa MatrixBase::setOnes(), setOnes(Index,Index), class CwiseNullaryOp, MatrixBase::Ones() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setOnes(Index newSize) { + resize(newSize); + return setConstant(Scalar(1)); +} + +/** Resizes to the given size, and sets all coefficients in this expression to one. + * + * \param rows the new number of rows + * \param cols the new number of columns + * + * Example: \include Matrix_setOnes_int_int.cpp + * Output: \verbinclude Matrix_setOnes_int_int.out + * + * \sa MatrixBase::setOnes(), setOnes(Index), class CwiseNullaryOp, MatrixBase::Ones() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setOnes(Index rows, Index cols) { + resize(rows, cols); + return setConstant(Scalar(1)); +} + +/** Resizes to the given size, changing only the number of rows, and sets all + * coefficients in this expression to one. For the parameter of type NoChange_t, + * just pass the special value \c NoChange. + * + * \sa MatrixBase::setOnes(), setOnes(Index), setOnes(Index, Index), setOnes(NoChange_t, Index), class CwiseNullaryOp, + * MatrixBase::Ones() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setOnes(Index rows, NoChange_t) { + return setOnes(rows, cols()); +} + +/** Resizes to the given size, changing only the number of columns, and sets all + * coefficients in this expression to one. For the parameter of type NoChange_t, + * just pass the special value \c NoChange. + * + * \sa MatrixBase::setOnes(), setOnes(Index), setOnes(Index, Index), setOnes(Index, NoChange_t) class CwiseNullaryOp, + * MatrixBase::Ones() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& PlainObjectBase::setOnes(NoChange_t, Index cols) { + return setOnes(rows(), cols); +} + +// Identity: + +/** \returns an expression of the identity matrix (not necessarily square). + * + * The parameters \a rows and \a cols are the number of rows and of columns of + * the returned matrix. Must be compatible with this MatrixBase type. + * + * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, + * it is redundant to pass \a rows and \a cols as arguments, so Identity() should be used + * instead. + * + * Example: \include MatrixBase_identity_int_int.cpp + * Output: \verbinclude MatrixBase_identity_int_int.out + * + * \sa Identity(), setIdentity(), isIdentity() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::IdentityReturnType +MatrixBase::Identity(Index rows, Index cols) { + return DenseBase::NullaryExpr(rows, cols, internal::scalar_identity_op()); +} + +/** \returns an expression of the identity matrix (not necessarily square). + * + * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you + * need to use the variant taking size arguments. + * + * Example: \include MatrixBase_identity.cpp + * Output: \verbinclude MatrixBase_identity.out + * + * \sa Identity(Index,Index), setIdentity(), isIdentity() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::IdentityReturnType +MatrixBase::Identity() { + EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) + return MatrixBase::NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_identity_op()); +} + +/** \returns true if *this is approximately equal to the identity matrix + * (not necessarily square), + * within the precision given by \a prec. + * + * Example: \include MatrixBase_isIdentity.cpp + * Output: \verbinclude MatrixBase_isIdentity.out + * + * \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), setIdentity() + */ +template +bool MatrixBase::isIdentity(const RealScalar& prec) const { + typename internal::nested_eval::type self(derived()); + for (Index j = 0; j < cols(); ++j) { + for (Index i = 0; i < rows(); ++i) { + if (i == j) { + if (!internal::isApprox(self.coeff(i, j), static_cast(1), prec)) return false; + } else { + if (!internal::isMuchSmallerThan(self.coeff(i, j), static_cast(1), prec)) return false; + } + } + } + return true; +} + +namespace internal { + +template = 16)> +struct setIdentity_impl { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Derived& run(Derived& m) { + return m = Derived::Identity(m.rows(), m.cols()); + } +}; + +template +struct setIdentity_impl { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Derived& run(Derived& m) { + m.setZero(); + const Index size = numext::mini(m.rows(), m.cols()); + for (Index i = 0; i < size; ++i) m.coeffRef(i, i) = typename Derived::Scalar(1); + return m; + } +}; + +} // end namespace internal + +/** Writes the identity expression (not necessarily square) into *this. + * + * Example: \include MatrixBase_setIdentity.cpp + * Output: \verbinclude MatrixBase_setIdentity.out + * + * \sa class CwiseNullaryOp, Identity(), Identity(Index,Index), isIdentity() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::setIdentity() { + return internal::setIdentity_impl::run(derived()); +} + +/** \brief Resizes to the given size, and writes the identity expression (not necessarily square) into *this. + * + * \param rows the new number of rows + * \param cols the new number of columns + * + * Example: \include Matrix_setIdentity_int_int.cpp + * Output: \verbinclude Matrix_setIdentity_int_int.out + * + * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Identity() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::setIdentity(Index rows, Index cols) { + derived().resize(rows, cols); + return setIdentity(); +} + +/** \returns an expression of the i-th unit (basis) vector. + * + * \only_for_vectors + * + * \sa MatrixBase::Unit(Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::BasisReturnType MatrixBase::Unit( + Index newSize, Index i) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return BasisReturnType(SquareMatrixType::Identity(newSize, newSize), i); +} + +/** \returns an expression of the i-th unit (basis) vector. + * + * \only_for_vectors + * + * This variant is for fixed-size vector only. + * + * \sa MatrixBase::Unit(Index,Index), MatrixBase::UnitX(), MatrixBase::UnitY(), MatrixBase::UnitZ(), MatrixBase::UnitW() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::BasisReturnType MatrixBase::Unit( + Index i) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + return BasisReturnType(SquareMatrixType::Identity(), i); +} + +/** \returns an expression of the X axis unit vector (1{,0}^*) + * + * \only_for_vectors + * + * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), + * MatrixBase::UnitW() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::BasisReturnType MatrixBase::UnitX() { + return Derived::Unit(0); +} + +/** \returns an expression of the Y axis unit vector (0,1{,0}^*) + * + * \only_for_vectors + * + * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), + * MatrixBase::UnitW() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::BasisReturnType MatrixBase::UnitY() { + return Derived::Unit(1); +} + +/** \returns an expression of the Z axis unit vector (0,0,1{,0}^*) + * + * \only_for_vectors + * + * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), + * MatrixBase::UnitW() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::BasisReturnType MatrixBase::UnitZ() { + return Derived::Unit(2); +} + +/** \returns an expression of the W axis unit vector (0,0,0,1) + * + * \only_for_vectors + * + * \sa MatrixBase::Unit(Index,Index), MatrixBase::Unit(Index), MatrixBase::UnitY(), MatrixBase::UnitZ(), + * MatrixBase::UnitW() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::BasisReturnType MatrixBase::UnitW() { + return Derived::Unit(3); +} + +/** \brief Set the coefficients of \c *this to the i-th unit (basis) vector + * + * \param i index of the unique coefficient to be set to 1 + * + * \only_for_vectors + * + * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Unit(Index,Index) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::setUnit(Index i) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); + eigen_assert(i < size()); + derived().setZero(); + derived().coeffRef(i) = Scalar(1); + return derived(); +} + +/** \brief Resizes to the given \a newSize, and writes the i-th unit (basis) vector into *this. + * + * \param newSize the new size of the vector + * \param i index of the unique coefficient to be set to 1 + * + * \only_for_vectors + * + * \sa MatrixBase::setIdentity(), class CwiseNullaryOp, MatrixBase::Unit(Index,Index) + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& MatrixBase::setUnit(Index newSize, Index i) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); + eigen_assert(i < newSize); + derived().resize(newSize); + return setUnit(i); +} + +} // end namespace Eigen + +#endif // EIGEN_CWISE_NULLARY_OP_H diff --git a/dae-cpp/Eigen/src/Core/CwiseTernaryOp.h b/dae-cpp/Eigen/src/Core/CwiseTernaryOp.h new file mode 100644 index 0000000..9bb0d40 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/CwiseTernaryOp.h @@ -0,0 +1,171 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2014 Gael Guennebaud +// Copyright (C) 2006-2008 Benoit Jacob +// Copyright (C) 2016 Eugene Brevdo +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CWISE_TERNARY_OP_H +#define EIGEN_CWISE_TERNARY_OP_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits> { + // we must not inherit from traits since it has + // the potential to cause problems with MSVC + typedef remove_all_t Ancestor; + typedef typename traits::XprKind XprKind; + enum { + RowsAtCompileTime = traits::RowsAtCompileTime, + ColsAtCompileTime = traits::ColsAtCompileTime, + MaxRowsAtCompileTime = traits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = traits::MaxColsAtCompileTime + }; + + // even though we require Arg1, Arg2, and Arg3 to have the same scalar type + // (see CwiseTernaryOp constructor), + // we still want to handle the case when the result type is different. + typedef typename result_of::type Scalar; + + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::StorageIndex StorageIndex; + + typedef typename Arg1::Nested Arg1Nested; + typedef typename Arg2::Nested Arg2Nested; + typedef typename Arg3::Nested Arg3Nested; + typedef std::remove_reference_t Arg1Nested_; + typedef std::remove_reference_t Arg2Nested_; + typedef std::remove_reference_t Arg3Nested_; + enum { Flags = Arg1Nested_::Flags & RowMajorBit }; +}; +} // end namespace internal + +template +class CwiseTernaryOpImpl; + +/** \class CwiseTernaryOp + * \ingroup Core_Module + * + * \brief Generic expression where a coefficient-wise ternary operator is + * applied to two expressions + * + * \tparam TernaryOp template functor implementing the operator + * \tparam Arg1Type the type of the first argument + * \tparam Arg2Type the type of the second argument + * \tparam Arg3Type the type of the third argument + * + * This class represents an expression where a coefficient-wise ternary + * operator is applied to three expressions. + * It is the return type of ternary operators, by which we mean only those + * ternary operators where + * all three arguments are Eigen expressions. + * For example, the return type of betainc(matrix1, matrix2, matrix3) is a + * CwiseTernaryOp. + * + * Most of the time, this is the only way that it is used, so you typically + * don't have to name + * CwiseTernaryOp types explicitly. + * + * \sa MatrixBase::ternaryExpr(const MatrixBase &, const + * MatrixBase &, const CustomTernaryOp &) const, class CwiseBinaryOp, + * class CwiseUnaryOp, class CwiseNullaryOp + */ +template +class CwiseTernaryOp : public CwiseTernaryOpImpl::StorageKind>, + internal::no_assignment_operator { + public: + typedef internal::remove_all_t Arg1; + typedef internal::remove_all_t Arg2; + typedef internal::remove_all_t Arg3; + + // require the sizes to match + EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg2) + EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Arg1, Arg3) + + // The index types should match + EIGEN_STATIC_ASSERT((internal::is_same::StorageKind, + typename internal::traits::StorageKind>::value), + STORAGE_KIND_MUST_MATCH) + EIGEN_STATIC_ASSERT((internal::is_same::StorageKind, + typename internal::traits::StorageKind>::value), + STORAGE_KIND_MUST_MATCH) + + typedef typename CwiseTernaryOpImpl::StorageKind>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseTernaryOp) + + typedef typename internal::ref_selector::type Arg1Nested; + typedef typename internal::ref_selector::type Arg2Nested; + typedef typename internal::ref_selector::type Arg3Nested; + typedef std::remove_reference_t Arg1Nested_; + typedef std::remove_reference_t Arg2Nested_; + typedef std::remove_reference_t Arg3Nested_; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CwiseTernaryOp(const Arg1& a1, const Arg2& a2, const Arg3& a3, + const TernaryOp& func = TernaryOp()) + : m_arg1(a1), m_arg2(a2), m_arg3(a3), m_functor(func) { + eigen_assert(a1.rows() == a2.rows() && a1.cols() == a2.cols() && a1.rows() == a3.rows() && a1.cols() == a3.cols()); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const { + // return the fixed size type if available to enable compile time + // optimizations + if (internal::traits>::RowsAtCompileTime == Dynamic && + internal::traits>::RowsAtCompileTime == Dynamic) + return m_arg3.rows(); + else if (internal::traits>::RowsAtCompileTime == Dynamic && + internal::traits>::RowsAtCompileTime == Dynamic) + return m_arg2.rows(); + else + return m_arg1.rows(); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const { + // return the fixed size type if available to enable compile time + // optimizations + if (internal::traits>::ColsAtCompileTime == Dynamic && + internal::traits>::ColsAtCompileTime == Dynamic) + return m_arg3.cols(); + else if (internal::traits>::ColsAtCompileTime == Dynamic && + internal::traits>::ColsAtCompileTime == Dynamic) + return m_arg2.cols(); + else + return m_arg1.cols(); + } + + /** \returns the first argument nested expression */ + EIGEN_DEVICE_FUNC const Arg1Nested_& arg1() const { return m_arg1; } + /** \returns the first argument nested expression */ + EIGEN_DEVICE_FUNC const Arg2Nested_& arg2() const { return m_arg2; } + /** \returns the third argument nested expression */ + EIGEN_DEVICE_FUNC const Arg3Nested_& arg3() const { return m_arg3; } + /** \returns the functor representing the ternary operation */ + EIGEN_DEVICE_FUNC const TernaryOp& functor() const { return m_functor; } + + protected: + Arg1Nested m_arg1; + Arg2Nested m_arg2; + Arg3Nested m_arg3; + const TernaryOp m_functor; +}; + +// Generic API dispatcher +template +class CwiseTernaryOpImpl : public internal::generic_xpr_base>::type { + public: + typedef typename internal::generic_xpr_base>::type Base; +}; + +} // end namespace Eigen + +#endif // EIGEN_CWISE_TERNARY_OP_H diff --git a/dae-cpp/Eigen/src/Core/CwiseUnaryOp.h b/dae-cpp/Eigen/src/Core/CwiseUnaryOp.h new file mode 100644 index 0000000..42ed459 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/CwiseUnaryOp.h @@ -0,0 +1,91 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2014 Gael Guennebaud +// Copyright (C) 2006-2008 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CWISE_UNARY_OP_H +#define EIGEN_CWISE_UNARY_OP_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits > : traits { + typedef typename result_of::type Scalar; + typedef typename XprType::Nested XprTypeNested; + typedef std::remove_reference_t XprTypeNested_; + enum { Flags = XprTypeNested_::Flags & RowMajorBit }; +}; +} // namespace internal + +template +class CwiseUnaryOpImpl; + +/** \class CwiseUnaryOp + * \ingroup Core_Module + * + * \brief Generic expression where a coefficient-wise unary operator is applied to an expression + * + * \tparam UnaryOp template functor implementing the operator + * \tparam XprType the type of the expression to which we are applying the unary operator + * + * This class represents an expression where a unary operator is applied to an expression. + * It is the return type of all operations taking exactly 1 input expression, regardless of the + * presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix + * is considered unary, because only the right-hand side is an expression, and its + * return type is a specialization of CwiseUnaryOp. + * + * Most of the time, this is the only way that it is used, so you typically don't have to name + * CwiseUnaryOp types explicitly. + * + * \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp + */ +template +class CwiseUnaryOp : public CwiseUnaryOpImpl::StorageKind>, + internal::no_assignment_operator { + public: + typedef typename CwiseUnaryOpImpl::StorageKind>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp) + typedef typename internal::ref_selector::type XprTypeNested; + typedef internal::remove_all_t NestedExpression; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) + : m_xpr(xpr), m_functor(func) {} + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_xpr.rows(); } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_xpr.cols(); } + + /** \returns the functor representing the unary operation */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const UnaryOp& functor() const { return m_functor; } + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all_t& nestedExpression() const { + return m_xpr; + } + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::remove_all_t& nestedExpression() { return m_xpr; } + + protected: + XprTypeNested m_xpr; + const UnaryOp m_functor; +}; + +// Generic API dispatcher +template +class CwiseUnaryOpImpl : public internal::generic_xpr_base >::type { + public: + typedef typename internal::generic_xpr_base >::type Base; +}; + +} // end namespace Eigen + +#endif // EIGEN_CWISE_UNARY_OP_H diff --git a/dae-cpp/Eigen/src/Core/CwiseUnaryView.h b/dae-cpp/Eigen/src/Core/CwiseUnaryView.h new file mode 100644 index 0000000..49b1410 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/CwiseUnaryView.h @@ -0,0 +1,167 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CWISE_UNARY_VIEW_H +#define EIGEN_CWISE_UNARY_VIEW_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits > : traits { + typedef typename result_of::Scalar&)>::type1 ScalarRef; + static_assert(std::is_reference::value, "Views must return a reference type."); + typedef remove_all_t Scalar; + typedef typename MatrixType::Nested MatrixTypeNested; + typedef remove_all_t MatrixTypeNested_; + enum { + FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, + Flags = + traits::Flags & + (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions + MatrixTypeInnerStride = inner_stride_at_compile_time::ret, + // need to cast the sizeof's from size_t to int explicitly, otherwise: + // "error: no integral type can represent all of the enumerator values + InnerStrideAtCompileTime = + StrideType::InnerStrideAtCompileTime == 0 + ? (MatrixTypeInnerStride == Dynamic + ? int(Dynamic) + : int(MatrixTypeInnerStride) * int(sizeof(typename traits::Scalar) / sizeof(Scalar))) + : int(StrideType::InnerStrideAtCompileTime), + + OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0 + ? (outer_stride_at_compile_time::ret == Dynamic + ? int(Dynamic) + : outer_stride_at_compile_time::ret * + int(sizeof(typename traits::Scalar) / sizeof(Scalar))) + : int(StrideType::OuterStrideAtCompileTime) + }; +}; + +// Generic API dispatcher +template ::value> +class CwiseUnaryViewImpl : public generic_xpr_base >::type { + public: + typedef typename generic_xpr_base >::type Base; +}; + +template +class CwiseUnaryViewImpl + : public dense_xpr_base >::type { + public: + typedef CwiseUnaryView Derived; + typedef typename dense_xpr_base >::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Derived) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl) + + EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeffRef(0)); } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const { + return StrideType::InnerStrideAtCompileTime != 0 ? int(StrideType::InnerStrideAtCompileTime) + : derived().nestedExpression().innerStride() * + sizeof(typename traits::Scalar) / sizeof(Scalar); + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const { + return StrideType::OuterStrideAtCompileTime != 0 ? int(StrideType::OuterStrideAtCompileTime) + : derived().nestedExpression().outerStride() * + sizeof(typename traits::Scalar) / sizeof(Scalar); + } + + protected: + EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl) + + // Allow const access to coeffRef for the case of direct access being enabled. + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { + return internal::evaluator(derived()).coeffRef(index); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index row, Index col) const { + return internal::evaluator(derived()).coeffRef(row, col); + } +}; + +template +class CwiseUnaryViewImpl + : public CwiseUnaryViewImpl { + public: + typedef CwiseUnaryViewImpl Base; + typedef CwiseUnaryView Derived; + EIGEN_DENSE_PUBLIC_INTERFACE(Derived) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl) + + using Base::data; + EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + return internal::evaluator(derived()).coeffRef(row, col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { + return internal::evaluator(derived()).coeffRef(index); + } + + protected: + EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl) +}; + +} // namespace internal + +/** \class CwiseUnaryView + * \ingroup Core_Module + * + * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector + * + * \tparam ViewOp template functor implementing the view + * \tparam MatrixType the type of the matrix we are applying the unary operator + * + * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector. + * It is the return type of real() and imag(), and most of the time this is the only way it is used. + * + * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp + */ +template +class CwiseUnaryView : public internal::CwiseUnaryViewImpl::StorageKind> { + public: + typedef typename internal::CwiseUnaryViewImpl::StorageKind>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView) + typedef typename internal::ref_selector::non_const_type MatrixTypeNested; + typedef internal::remove_all_t NestedExpression; + + explicit EIGEN_DEVICE_FUNC inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp()) + : m_matrix(mat), m_functor(func) {} + + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView) + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); } + + /** \returns the functor representing unary operation */ + EIGEN_DEVICE_FUNC const ViewOp& functor() const { return m_functor; } + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC const internal::remove_all_t& nestedExpression() const { return m_matrix; } + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC std::remove_reference_t& nestedExpression() { return m_matrix; } + + protected: + MatrixTypeNested m_matrix; + ViewOp m_functor; +}; + +} // namespace Eigen + +#endif // EIGEN_CWISE_UNARY_VIEW_H diff --git a/dae-cpp/Eigen/src/Core/DenseBase.h b/dae-cpp/Eigen/src/Core/DenseBase.h new file mode 100644 index 0000000..5ab54ef --- /dev/null +++ b/dae-cpp/Eigen/src/Core/DenseBase.h @@ -0,0 +1,645 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2007-2010 Benoit Jacob +// Copyright (C) 2008-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_DENSEBASE_H +#define EIGEN_DENSEBASE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +// The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type. +EIGEN_STATIC_ASSERT(NumTraits::IsSigned, THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE) + +/** \class DenseBase + * \ingroup Core_Module + * + * \brief Base class for all dense matrices, vectors, and arrays + * + * This class is the base that is inherited by all dense objects (matrix, vector, arrays, + * and related expression types). The common Eigen API for dense objects is contained in this class. + * + * \tparam Derived is the derived type, e.g., a matrix type or an expression. + * + * This class can be extended with the help of the plugin mechanism described on the page + * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_DENSEBASE_PLUGIN. + * + * \sa \blank \ref TopicClassHierarchy + */ +template +class DenseBase +#ifndef EIGEN_PARSED_BY_DOXYGEN + : public DenseCoeffsBase::value> +#else + : public DenseCoeffsBase +#endif // not EIGEN_PARSED_BY_DOXYGEN +{ + public: + /** Inner iterator type to iterate over the coefficients of a row or column. + * \sa class InnerIterator + */ + typedef Eigen::InnerIterator InnerIterator; + + typedef typename internal::traits::StorageKind StorageKind; + + /** + * \brief The type used to store indices + * \details This typedef is relevant for types that store multiple indices such as + * PermutationMatrix or Transpositions, otherwise it defaults to Eigen::Index + * \sa \blank \ref TopicPreprocessorDirectives, Eigen::Index, SparseMatrixBase. + */ + typedef typename internal::traits::StorageIndex StorageIndex; + + /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex, etc. */ + typedef typename internal::traits::Scalar Scalar; + + /** The numeric type of the expression' coefficients, e.g. float, double, int or std::complex, etc. + * + * It is an alias for the Scalar type */ + typedef Scalar value_type; + + typedef typename NumTraits::Real RealScalar; + typedef DenseCoeffsBase::value> Base; + + using Base::coeff; + using Base::coeffByOuterInner; + using Base::colIndexByOuterInner; + using Base::cols; + using Base::const_cast_derived; + using Base::derived; + using Base::rowIndexByOuterInner; + using Base::rows; + using Base::size; + using Base::operator(); + using Base::operator[]; + using Base::colStride; + using Base::innerStride; + using Base::outerStride; + using Base::rowStride; + using Base::stride; + using Base::w; + using Base::x; + using Base::y; + using Base::z; + typedef typename Base::CoeffReturnType CoeffReturnType; + + enum { + + RowsAtCompileTime = internal::traits::RowsAtCompileTime, + /**< The number of rows at compile-time. This is just a copy of the value provided + * by the \a Derived type. If a value is not known at compile-time, + * it is set to the \a Dynamic constant. + * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */ + + ColsAtCompileTime = internal::traits::ColsAtCompileTime, + /**< The number of columns at compile-time. This is just a copy of the value provided + * by the \a Derived type. If a value is not known at compile-time, + * it is set to the \a Dynamic constant. + * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ + + SizeAtCompileTime = (internal::size_of_xpr_at_compile_time::ret), + /**< This is equal to the number of coefficients, i.e. the number of + * rows times the number of columns, or to \a Dynamic if this is not + * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ + + MaxRowsAtCompileTime = internal::traits::MaxRowsAtCompileTime, + /**< This value is equal to the maximum possible number of rows that this expression + * might have. If this expression might have an arbitrarily high number of rows, + * this value is set to \a Dynamic. + * + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime + */ + + MaxColsAtCompileTime = internal::traits::MaxColsAtCompileTime, + /**< This value is equal to the maximum possible number of columns that this expression + * might have. If this expression might have an arbitrarily high number of columns, + * this value is set to \a Dynamic. + * + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime + */ + + MaxSizeAtCompileTime = internal::size_at_compile_time(internal::traits::MaxRowsAtCompileTime, + internal::traits::MaxColsAtCompileTime), + /**< This value is equal to the maximum possible number of coefficients that this expression + * might have. If this expression might have an arbitrarily high number of coefficients, + * this value is set to \a Dynamic. + * + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime + */ + + IsVectorAtCompileTime = + internal::traits::RowsAtCompileTime == 1 || internal::traits::ColsAtCompileTime == 1, + /**< This is set to true if either the number of rows or the number of + * columns is known at compile-time to be equal to 1. Indeed, in that case, + * we are dealing with a column-vector (if there is only one column) or with + * a row-vector (if there is only one row). */ + + NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 + : bool(IsVectorAtCompileTime) ? 1 + : 2, + /**< This value is equal to Tensor::NumDimensions, i.e. 0 for scalars, 1 for vectors, + * and 2 for matrices. + */ + + Flags = internal::traits::Flags, + /**< This stores expression \ref flags flags which may or may not be inherited by new expressions + * constructed from this one. See the \ref flags "list of flags". + */ + + IsRowMajor = int(Flags) & RowMajorBit, /**< True if this expression has row-major storage order. */ + + InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime) + : int(IsRowMajor) ? int(ColsAtCompileTime) + : int(RowsAtCompileTime), + + InnerStrideAtCompileTime = internal::inner_stride_at_compile_time::ret, + OuterStrideAtCompileTime = internal::outer_stride_at_compile_time::ret + }; + + typedef typename internal::find_best_packet::type PacketScalar; + + enum { IsPlainObjectBase = 0 }; + + /** The plain matrix type corresponding to this expression. + * \sa PlainObject */ + typedef Matrix::Scalar, internal::traits::RowsAtCompileTime, + internal::traits::ColsAtCompileTime, + AutoAlign | (internal::traits::Flags & RowMajorBit ? RowMajor : ColMajor), + internal::traits::MaxRowsAtCompileTime, internal::traits::MaxColsAtCompileTime> + PlainMatrix; + + /** The plain array type corresponding to this expression. + * \sa PlainObject */ + typedef Array::Scalar, internal::traits::RowsAtCompileTime, + internal::traits::ColsAtCompileTime, + AutoAlign | (internal::traits::Flags & RowMajorBit ? RowMajor : ColMajor), + internal::traits::MaxRowsAtCompileTime, internal::traits::MaxColsAtCompileTime> + PlainArray; + + /** \brief The plain matrix or array type corresponding to this expression. + * + * This is not necessarily exactly the return type of eval(). In the case of plain matrices, + * the return type of eval() is a const reference to a matrix, not a matrix! It is however guaranteed + * that the return type of eval() is either PlainObject or const PlainObject&. + */ + typedef std::conditional_t::XprKind, MatrixXpr>::value, + PlainMatrix, PlainArray> + PlainObject; + + /** \returns the outer size. + * + * \note For a vector, this returns just 1. For a matrix (non-vector), this is the major dimension + * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of columns for a + * column-major matrix, and the number of rows for a row-major matrix. */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const { + return IsVectorAtCompileTime ? 1 : int(IsRowMajor) ? this->rows() : this->cols(); + } + + /** \returns the inner size. + * + * \note For a vector, this is just the size. For a matrix (non-vector), this is the minor dimension + * with respect to the \ref TopicStorageOrders "storage order", i.e., the number of rows for a + * column-major matrix, and the number of columns for a row-major matrix. */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerSize() const { + return IsVectorAtCompileTime ? this->size() : int(IsRowMajor) ? this->cols() : this->rows(); + } + + /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are + * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and + * does nothing else. + */ + EIGEN_DEVICE_FUNC void resize(Index newSize) { + EIGEN_ONLY_USED_FOR_DEBUG(newSize); + eigen_assert(newSize == this->size() && "DenseBase::resize() does not actually allow to resize."); + } + /** Only plain matrices/arrays, not expressions, may be resized; therefore the only useful resize methods are + * Matrix::resize() and Array::resize(). The present method only asserts that the new size equals the old size, and + * does nothing else. + */ + EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { + EIGEN_ONLY_USED_FOR_DEBUG(rows); + EIGEN_ONLY_USED_FOR_DEBUG(cols); + eigen_assert(rows == this->rows() && cols == this->cols() && + "DenseBase::resize() does not actually allow to resize."); + } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** \internal Represents a matrix with all coefficients equal to one another*/ + typedef CwiseNullaryOp, PlainObject> ConstantReturnType; + /** \internal \deprecated Represents a vector with linearly spaced coefficients that allows sequential access only. */ + EIGEN_DEPRECATED typedef CwiseNullaryOp, PlainObject> SequentialLinSpacedReturnType; + /** \internal Represents a vector with linearly spaced coefficients that allows random access. */ + typedef CwiseNullaryOp, PlainObject> RandomAccessLinSpacedReturnType; + /** \internal Represents a vector with equally spaced coefficients that allows random access. */ + typedef CwiseNullaryOp, PlainObject> RandomAccessEqualSpacedReturnType; + /** \internal the return type of MatrixBase::eigenvalues() */ + typedef Matrix::Scalar>::Real, + internal::traits::ColsAtCompileTime, 1> + EigenvaluesReturnType; + +#endif // not EIGEN_PARSED_BY_DOXYGEN + + /** Copies \a other into *this. \returns a reference to *this. */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const DenseBase& other); + + /** Special case of the template operator=, in order to prevent the compiler + * from generating a default operator= (issue hit with g++ 4.1) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const DenseBase& other); + + template + EIGEN_DEVICE_FUNC Derived& operator=(const EigenBase& other); + + template + EIGEN_DEVICE_FUNC Derived& operator+=(const EigenBase& other); + + template + EIGEN_DEVICE_FUNC Derived& operator-=(const EigenBase& other); + + template + EIGEN_DEVICE_FUNC Derived& operator=(const ReturnByValue& func); + + /** \internal + * Copies \a other into *this without evaluating other. \returns a reference to *this. */ + template + /** \deprecated */ + EIGEN_DEPRECATED EIGEN_DEVICE_FUNC Derived& lazyAssign(const DenseBase& other); + + EIGEN_DEVICE_FUNC CommaInitializer operator<<(const Scalar& s); + + template + /** \deprecated it now returns \c *this */ + EIGEN_DEPRECATED const Derived& flagged() const { + return derived(); + } + + template + EIGEN_DEVICE_FUNC CommaInitializer operator<<(const DenseBase& other); + + typedef Transpose TransposeReturnType; + EIGEN_DEVICE_FUNC TransposeReturnType transpose(); + typedef Transpose ConstTransposeReturnType; + EIGEN_DEVICE_FUNC const ConstTransposeReturnType transpose() const; + EIGEN_DEVICE_FUNC void transposeInPlace(); + + EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(Index rows, Index cols, const Scalar& value); + EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(Index size, const Scalar& value); + EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(const Scalar& value); + + EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, + const Scalar& low, + const Scalar& high); + EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, + const Scalar& low, + const Scalar& high); + + EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Index size, const Scalar& low, + const Scalar& high); + EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(const Scalar& low, const Scalar& high); + + EIGEN_DEVICE_FUNC static const RandomAccessEqualSpacedReturnType EqualSpaced(Index size, const Scalar& low, + const Scalar& step); + EIGEN_DEVICE_FUNC static const RandomAccessEqualSpacedReturnType EqualSpaced(const Scalar& low, const Scalar& step); + + template + EIGEN_DEVICE_FUNC static const CwiseNullaryOp NullaryExpr(Index rows, Index cols, + const CustomNullaryOp& func); + template + EIGEN_DEVICE_FUNC static const CwiseNullaryOp NullaryExpr(Index size, + const CustomNullaryOp& func); + template + EIGEN_DEVICE_FUNC static const CwiseNullaryOp NullaryExpr(const CustomNullaryOp& func); + + EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index rows, Index cols); + EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(Index size); + EIGEN_DEVICE_FUNC static const ConstantReturnType Zero(); + EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index rows, Index cols); + EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(Index size); + EIGEN_DEVICE_FUNC static const ConstantReturnType Ones(); + + EIGEN_DEVICE_FUNC void fill(const Scalar& value); + EIGEN_DEVICE_FUNC Derived& setConstant(const Scalar& value); + EIGEN_DEVICE_FUNC Derived& setLinSpaced(Index size, const Scalar& low, const Scalar& high); + EIGEN_DEVICE_FUNC Derived& setLinSpaced(const Scalar& low, const Scalar& high); + EIGEN_DEVICE_FUNC Derived& setEqualSpaced(Index size, const Scalar& low, const Scalar& step); + EIGEN_DEVICE_FUNC Derived& setEqualSpaced(const Scalar& low, const Scalar& step); + EIGEN_DEVICE_FUNC Derived& setZero(); + EIGEN_DEVICE_FUNC Derived& setOnes(); + EIGEN_DEVICE_FUNC Derived& setRandom(); + + template + EIGEN_DEVICE_FUNC bool isApprox(const DenseBase& other, + const RealScalar& prec = NumTraits::dummy_precision()) const; + EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const RealScalar& other, + const RealScalar& prec = NumTraits::dummy_precision()) const; + template + EIGEN_DEVICE_FUNC bool isMuchSmallerThan(const DenseBase& other, + const RealScalar& prec = NumTraits::dummy_precision()) const; + + EIGEN_DEVICE_FUNC bool isApproxToConstant(const Scalar& value, + const RealScalar& prec = NumTraits::dummy_precision()) const; + EIGEN_DEVICE_FUNC bool isConstant(const Scalar& value, + const RealScalar& prec = NumTraits::dummy_precision()) const; + EIGEN_DEVICE_FUNC bool isZero(const RealScalar& prec = NumTraits::dummy_precision()) const; + EIGEN_DEVICE_FUNC bool isOnes(const RealScalar& prec = NumTraits::dummy_precision()) const; + + EIGEN_DEVICE_FUNC inline bool hasNaN() const; + EIGEN_DEVICE_FUNC inline bool allFinite() const; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*=(const Scalar& other); + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator/=(const Scalar& other); + + typedef internal::add_const_on_value_type_t::type> EvalReturnType; + /** \returns the matrix or vector obtained by evaluating this expression. + * + * Notice that in the case of a plain matrix or vector (not an expression) this function just returns + * a const reference, in order to avoid a useless copy. + * + * \warning Be careful with eval() and the auto C++ keyword, as detailed in this \link TopicPitfalls_auto_keyword page + * \endlink. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvalReturnType eval() const { + // Even though MSVC does not honor strong inlining when the return type + // is a dynamic matrix, we desperately need strong inlining for fixed + // size types on MSVC. + return typename internal::eval::type(derived()); + } + + /** swaps *this with the expression \a other. + * + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(const DenseBase& other) { + EIGEN_STATIC_ASSERT(!OtherDerived::IsPlainObjectBase, THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); + eigen_assert(rows() == other.rows() && cols() == other.cols()); + call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op()); + } + + /** swaps *this with the matrix or array \a other. + * + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(PlainObjectBase& other) { + eigen_assert(rows() == other.rows() && cols() == other.cols()); + call_assignment(derived(), other.derived(), internal::swap_assign_op()); + } + + EIGEN_DEVICE_FUNC inline const NestByValue nestByValue() const; + EIGEN_DEVICE_FUNC inline const ForceAlignedAccess forceAlignedAccess() const; + EIGEN_DEVICE_FUNC inline ForceAlignedAccess forceAlignedAccess(); + template + EIGEN_DEVICE_FUNC inline const std::conditional_t, Derived&> + forceAlignedAccessIf() const; + template + EIGEN_DEVICE_FUNC inline std::conditional_t, Derived&> forceAlignedAccessIf(); + + EIGEN_DEVICE_FUNC Scalar sum() const; + EIGEN_DEVICE_FUNC Scalar mean() const; + EIGEN_DEVICE_FUNC Scalar trace() const; + + EIGEN_DEVICE_FUNC Scalar prod() const; + + template + EIGEN_DEVICE_FUNC typename internal::traits::Scalar minCoeff() const; + template + EIGEN_DEVICE_FUNC typename internal::traits::Scalar maxCoeff() const; + + // By default, the fastest version with undefined NaN propagation semantics is + // used. + // TODO(rmlarsen): Replace with default template argument when we move to + // c++11 or beyond. + EIGEN_DEVICE_FUNC inline typename internal::traits::Scalar minCoeff() const { + return minCoeff(); + } + EIGEN_DEVICE_FUNC inline typename internal::traits::Scalar maxCoeff() const { + return maxCoeff(); + } + + template + EIGEN_DEVICE_FUNC typename internal::traits::Scalar minCoeff(IndexType* row, IndexType* col) const; + template + EIGEN_DEVICE_FUNC typename internal::traits::Scalar maxCoeff(IndexType* row, IndexType* col) const; + template + EIGEN_DEVICE_FUNC typename internal::traits::Scalar minCoeff(IndexType* index) const; + template + EIGEN_DEVICE_FUNC typename internal::traits::Scalar maxCoeff(IndexType* index) const; + + // TODO(rmlarsen): Replace these methods with a default template argument. + template + EIGEN_DEVICE_FUNC inline typename internal::traits::Scalar minCoeff(IndexType* row, IndexType* col) const { + return minCoeff(row, col); + } + template + EIGEN_DEVICE_FUNC inline typename internal::traits::Scalar maxCoeff(IndexType* row, IndexType* col) const { + return maxCoeff(row, col); + } + template + EIGEN_DEVICE_FUNC inline typename internal::traits::Scalar minCoeff(IndexType* index) const { + return minCoeff(index); + } + template + EIGEN_DEVICE_FUNC inline typename internal::traits::Scalar maxCoeff(IndexType* index) const { + return maxCoeff(index); + } + + template + EIGEN_DEVICE_FUNC Scalar redux(const BinaryOp& func) const; + + template + EIGEN_DEVICE_FUNC void visit(Visitor& func) const; + + /** \returns a WithFormat proxy object allowing to print a matrix the with given + * format \a fmt. + * + * See class IOFormat for some examples. + * + * \sa class IOFormat, class WithFormat + */ + inline const WithFormat format(const IOFormat& fmt) const { return WithFormat(derived(), fmt); } + + /** \returns the unique coefficient of a 1x1 expression */ + EIGEN_DEVICE_FUNC CoeffReturnType value() const { + EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) eigen_assert(this->rows() == 1 && this->cols() == 1); + return derived().coeff(0, 0); + } + + EIGEN_DEVICE_FUNC bool all() const; + EIGEN_DEVICE_FUNC bool any() const; + EIGEN_DEVICE_FUNC Index count() const; + + typedef VectorwiseOp RowwiseReturnType; + typedef const VectorwiseOp ConstRowwiseReturnType; + typedef VectorwiseOp ColwiseReturnType; + typedef const VectorwiseOp ConstColwiseReturnType; + + /** \returns a VectorwiseOp wrapper of *this for broadcasting and partial reductions + * + * Example: \include MatrixBase_rowwise.cpp + * Output: \verbinclude MatrixBase_rowwise.out + * + * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting + */ + // Code moved here due to a CUDA compiler bug + EIGEN_DEVICE_FUNC inline ConstRowwiseReturnType rowwise() const { return ConstRowwiseReturnType(derived()); } + EIGEN_DEVICE_FUNC RowwiseReturnType rowwise(); + + /** \returns a VectorwiseOp wrapper of *this broadcasting and partial reductions + * + * Example: \include MatrixBase_colwise.cpp + * Output: \verbinclude MatrixBase_colwise.out + * + * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting + */ + EIGEN_DEVICE_FUNC inline ConstColwiseReturnType colwise() const { return ConstColwiseReturnType(derived()); } + EIGEN_DEVICE_FUNC ColwiseReturnType colwise(); + + typedef CwiseNullaryOp, PlainObject> RandomReturnType; + static const RandomReturnType Random(Index rows, Index cols); + static const RandomReturnType Random(Index size); + static const RandomReturnType Random(); + + template + inline EIGEN_DEVICE_FUNC + CwiseTernaryOp::Scalar, + typename DenseBase::Scalar, Scalar>, + ThenDerived, ElseDerived, Derived> + select(const DenseBase& thenMatrix, const DenseBase& elseMatrix) const; + + template + inline EIGEN_DEVICE_FUNC + CwiseTernaryOp::Scalar, + typename DenseBase::Scalar, Scalar>, + ThenDerived, typename DenseBase::ConstantReturnType, Derived> + select(const DenseBase& thenMatrix, const typename DenseBase::Scalar& elseScalar) const; + + template + inline EIGEN_DEVICE_FUNC + CwiseTernaryOp::Scalar, + typename DenseBase::Scalar, Scalar>, + typename DenseBase::ConstantReturnType, ElseDerived, Derived> + select(const typename DenseBase::Scalar& thenScalar, const DenseBase& elseMatrix) const; + + template + RealScalar lpNorm() const; + + template + EIGEN_DEVICE_FUNC const Replicate replicate() const; + /** + * \return an expression of the replication of \c *this + * + * Example: \include MatrixBase_replicate_int_int.cpp + * Output: \verbinclude MatrixBase_replicate_int_int.out + * + * \sa VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate + */ + // Code moved here due to a CUDA compiler bug + EIGEN_DEVICE_FUNC const Replicate replicate(Index rowFactor, Index colFactor) const { + return Replicate(derived(), rowFactor, colFactor); + } + + typedef Reverse ReverseReturnType; + typedef const Reverse ConstReverseReturnType; + EIGEN_DEVICE_FUNC ReverseReturnType reverse(); + /** This is the const version of reverse(). */ + // Code moved here due to a CUDA compiler bug + EIGEN_DEVICE_FUNC ConstReverseReturnType reverse() const { return ConstReverseReturnType(derived()); } + EIGEN_DEVICE_FUNC void reverseInPlace(); + +#ifdef EIGEN_PARSED_BY_DOXYGEN + /** STL-like RandomAccessIterator + * iterator type as returned by the begin() and end() methods. + */ + typedef random_access_iterator_type iterator; + /** This is the const version of iterator (aka read-only) */ + typedef random_access_iterator_type const_iterator; +#else + typedef std::conditional_t<(Flags & DirectAccessBit) == DirectAccessBit, + internal::pointer_based_stl_iterator, + internal::generic_randaccess_stl_iterator > + iterator_type; + + typedef std::conditional_t<(Flags & DirectAccessBit) == DirectAccessBit, + internal::pointer_based_stl_iterator, + internal::generic_randaccess_stl_iterator > + const_iterator_type; + + // Stl-style iterators are supported only for vectors. + + typedef std::conditional_t iterator; + + typedef std::conditional_t const_iterator; +#endif + + inline iterator begin(); + inline const_iterator begin() const; + inline const_iterator cbegin() const; + inline iterator end(); + inline const_iterator end() const; + inline const_iterator cend() const; + +#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase +#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL +#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND) +#define EIGEN_DOC_UNARY_ADDONS(X, Y) +#include "../plugins/CommonCwiseUnaryOps.inc" +#include "../plugins/BlockMethods.inc" +#include "../plugins/IndexedViewMethods.inc" +#include "../plugins/ReshapedMethods.inc" +#ifdef EIGEN_DENSEBASE_PLUGIN +#include EIGEN_DENSEBASE_PLUGIN +#endif +#undef EIGEN_CURRENT_STORAGE_BASE_CLASS +#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL +#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF +#undef EIGEN_DOC_UNARY_ADDONS + + // disable the use of evalTo for dense objects with a nice compilation error + template + EIGEN_DEVICE_FUNC inline void evalTo(Dest&) const { + EIGEN_STATIC_ASSERT((internal::is_same::value), + THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS); + } + + protected: + EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase) + /** Default constructor. Do nothing. */ + EIGEN_DEVICE_FUNC constexpr DenseBase() { + /* Just checks for self-consistency of the flags. + * Only do it when debugging Eigen, as this borders on paranoia and could slow compilation down + */ +#ifdef EIGEN_INTERNAL_DEBUGGING + EIGEN_STATIC_ASSERT( + (internal::check_implication(MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1, int(IsRowMajor)) && + internal::check_implication(MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1, int(!IsRowMajor))), + INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION) +#endif + } + + private: + EIGEN_DEVICE_FUNC explicit DenseBase(int); + EIGEN_DEVICE_FUNC DenseBase(int, int); + template + EIGEN_DEVICE_FUNC explicit DenseBase(const DenseBase&); +}; + +} // end namespace Eigen + +#endif // EIGEN_DENSEBASE_H diff --git a/dae-cpp/Eigen/src/Core/DenseCoeffsBase.h b/dae-cpp/Eigen/src/Core/DenseCoeffsBase.h new file mode 100644 index 0000000..48c6d73 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/DenseCoeffsBase.h @@ -0,0 +1,568 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2010 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_DENSECOEFFSBASE_H +#define EIGEN_DENSECOEFFSBASE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct add_const_on_value_type_if_arithmetic { + typedef std::conditional_t::value, T, add_const_on_value_type_t> type; +}; +} // namespace internal + +/** \brief Base class providing read-only coefficient access to matrices and arrays. + * \ingroup Core_Module + * \tparam Derived Type of the derived class + * + * \note #ReadOnlyAccessors Constant indicating read-only access + * + * This class defines the \c operator() \c const function and friends, which can be used to read specific + * entries of a matrix or array. + * + * \sa DenseCoeffsBase, DenseCoeffsBase, + * \ref TopicClassHierarchy + */ +template +class DenseCoeffsBase : public EigenBase { + public: + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::Scalar Scalar; + typedef typename internal::packet_traits::type PacketScalar; + + // Explanation for this CoeffReturnType typedef. + // - This is the return type of the coeff() method. + // - The LvalueBit means exactly that we can offer a coeffRef() method, which means exactly that we can get references + // to coeffs, which means exactly that we can have coeff() return a const reference (as opposed to returning a value). + // - The is_arithmetic check is required since "const int", "const double", etc. will cause warnings on some systems + // while the declaration of "const T", where T is a non arithmetic type does not. Always returning "const Scalar&" is + // not possible, since the underlying expressions might not offer a valid address the reference could be referring to. + typedef std::conditional_t::Flags& LvalueBit), const Scalar&, + std::conditional_t::value, Scalar, const Scalar>> + CoeffReturnType; + + typedef typename internal::add_const_on_value_type_if_arithmetic::type>::type + PacketReturnType; + + typedef EigenBase Base; + using Base::cols; + using Base::derived; + using Base::rows; + using Base::size; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) const { + return int(Derived::RowsAtCompileTime) == 1 ? 0 + : int(Derived::ColsAtCompileTime) == 1 ? inner + : int(Derived::Flags) & RowMajorBit ? outer + : inner; + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) const { + return int(Derived::ColsAtCompileTime) == 1 ? 0 + : int(Derived::RowsAtCompileTime) == 1 ? inner + : int(Derived::Flags) & RowMajorBit ? inner + : outer; + } + + /** Short version: don't use this function, use + * \link operator()(Index,Index) const \endlink instead. + * + * Long version: this function is similar to + * \link operator()(Index,Index) const \endlink, but without the assertion. + * Use this for limiting the performance cost of debugging code when doing + * repeated coefficient access. Only use this when it is guaranteed that the + * parameters \a row and \a col are in range. + * + * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this + * function equivalent to \link operator()(Index,Index) const \endlink. + * + * \sa operator()(Index,Index) const, coeffRef(Index,Index), coeff(Index) const + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); + return internal::evaluator(derived()).coeff(row, col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const { + return coeff(rowIndexByOuterInner(outer, inner), colIndexByOuterInner(outer, inner)); + } + + /** \returns the coefficient at given the given row and column. + * + * \sa operator()(Index,Index), operator[](Index) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType operator()(Index row, Index col) const { + eigen_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); + return coeff(row, col); + } + + /** Short version: don't use this function, use + * \link operator[](Index) const \endlink instead. + * + * Long version: this function is similar to + * \link operator[](Index) const \endlink, but without the assertion. + * Use this for limiting the performance cost of debugging code when doing + * repeated coefficient access. Only use this when it is guaranteed that the + * parameter \a index is in range. + * + * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this + * function equivalent to \link operator[](Index) const \endlink. + * + * \sa operator[](Index) const, coeffRef(Index), coeff(Index,Index) const + */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { + EIGEN_STATIC_ASSERT(internal::evaluator::Flags & LinearAccessBit, + THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS) + eigen_internal_assert(index >= 0 && index < size()); + return internal::evaluator(derived()).coeff(index); + } + + /** \returns the coefficient at given index. + * + * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit. + * + * \sa operator[](Index), operator()(Index,Index) const, x() const, y() const, + * z() const, w() const + */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType operator[](Index index) const { + EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime, + THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD) + eigen_assert(index >= 0 && index < size()); + return coeff(index); + } + + /** \returns the coefficient at given index. + * + * This is synonymous to operator[](Index) const. + * + * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit. + * + * \sa operator[](Index), operator()(Index,Index) const, x() const, y() const, + * z() const, w() const + */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType operator()(Index index) const { + eigen_assert(index >= 0 && index < size()); + return coeff(index); + } + + /** equivalent to operator[](0). */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType x() const { return (*this)[0]; } + + /** equivalent to operator[](1). */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType y() const { + EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 2, OUT_OF_RANGE_ACCESS); + return (*this)[1]; + } + + /** equivalent to operator[](2). */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType z() const { + EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 3, OUT_OF_RANGE_ACCESS); + return (*this)[2]; + } + + /** equivalent to operator[](3). */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType w() const { + EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 4, OUT_OF_RANGE_ACCESS); + return (*this)[3]; + } + + /** \internal + * \returns the packet of coefficients starting at the given row and column. It is your responsibility + * to ensure that a packet really starts there. This method is only available on expressions having the + * PacketAccessBit. + * + * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select + * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets + * starting at an address which is a multiple of the packet size. + */ + + template + EIGEN_STRONG_INLINE PacketReturnType packet(Index row, Index col) const { + typedef typename internal::packet_traits::type DefaultPacketType; + eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); + return internal::evaluator(derived()).template packet(row, col); + } + + /** \internal */ + template + EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner(Index outer, Index inner) const { + return packet(rowIndexByOuterInner(outer, inner), colIndexByOuterInner(outer, inner)); + } + + /** \internal + * \returns the packet of coefficients starting at the given index. It is your responsibility + * to ensure that a packet really starts there. This method is only available on expressions having the + * PacketAccessBit and the LinearAccessBit. + * + * The \a LoadMode parameter may have the value \a #Aligned or \a #Unaligned. Its effect is to select + * the appropriate vectorization instruction. Aligned access is faster, but is only possible for packets + * starting at an address which is a multiple of the packet size. + */ + + template + EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const { + EIGEN_STATIC_ASSERT(internal::evaluator::Flags & LinearAccessBit, + THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS) + typedef typename internal::packet_traits::type DefaultPacketType; + eigen_internal_assert(index >= 0 && index < size()); + return internal::evaluator(derived()).template packet(index); + } + + protected: + // explanation: DenseBase is doing "using ..." on the methods from DenseCoeffsBase. + // But some methods are only available in the DirectAccess case. + // So we add dummy methods here with these names, so that "using... " doesn't fail. + // It's not private so that the child class DenseBase can access them, and it's not public + // either since it's an implementation detail, so has to be protected. + void coeffRef(); + void coeffRefByOuterInner(); + void writePacket(); + void writePacketByOuterInner(); + void copyCoeff(); + void copyCoeffByOuterInner(); + void copyPacket(); + void copyPacketByOuterInner(); + void stride(); + void innerStride(); + void outerStride(); + void rowStride(); + void colStride(); +}; + +/** \brief Base class providing read/write coefficient access to matrices and arrays. + * \ingroup Core_Module + * \tparam Derived Type of the derived class + * + * \note #WriteAccessors Constant indicating read/write access + * + * This class defines the non-const \c operator() function and friends, which can be used to write specific + * entries of a matrix or array. This class inherits DenseCoeffsBase which + * defines the const variant for reading specific entries. + * + * \sa DenseCoeffsBase, \ref TopicClassHierarchy + */ +template +class DenseCoeffsBase : public DenseCoeffsBase { + public: + typedef DenseCoeffsBase Base; + + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::Scalar Scalar; + typedef typename internal::packet_traits::type PacketScalar; + typedef typename NumTraits::Real RealScalar; + + using Base::coeff; + using Base::colIndexByOuterInner; + using Base::cols; + using Base::derived; + using Base::rowIndexByOuterInner; + using Base::rows; + using Base::size; + using Base::operator[]; + using Base::operator(); + using Base::w; + using Base::x; + using Base::y; + using Base::z; + + /** Short version: don't use this function, use + * \link operator()(Index,Index) \endlink instead. + * + * Long version: this function is similar to + * \link operator()(Index,Index) \endlink, but without the assertion. + * Use this for limiting the performance cost of debugging code when doing + * repeated coefficient access. Only use this when it is guaranteed that the + * parameters \a row and \a col are in range. + * + * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this + * function equivalent to \link operator()(Index,Index) \endlink. + * + * \sa operator()(Index,Index), coeff(Index, Index) const, coeffRef(Index) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + eigen_internal_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); + return internal::evaluator(derived()).coeffRef(row, col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRefByOuterInner(Index outer, Index inner) { + return coeffRef(rowIndexByOuterInner(outer, inner), colIndexByOuterInner(outer, inner)); + } + + /** \returns a reference to the coefficient at given the given row and column. + * + * \sa operator[](Index) + */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index row, Index col) { + eigen_assert(row >= 0 && row < rows() && col >= 0 && col < cols()); + return coeffRef(row, col); + } + + /** Short version: don't use this function, use + * \link operator[](Index) \endlink instead. + * + * Long version: this function is similar to + * \link operator[](Index) \endlink, but without the assertion. + * Use this for limiting the performance cost of debugging code when doing + * repeated coefficient access. Only use this when it is guaranteed that the + * parameters \a row and \a col are in range. + * + * If EIGEN_INTERNAL_DEBUGGING is defined, an assertion will be made, making this + * function equivalent to \link operator[](Index) \endlink. + * + * \sa operator[](Index), coeff(Index) const, coeffRef(Index,Index) + */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { + EIGEN_STATIC_ASSERT(internal::evaluator::Flags & LinearAccessBit, + THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS) + eigen_internal_assert(index >= 0 && index < size()); + return internal::evaluator(derived()).coeffRef(index); + } + + /** \returns a reference to the coefficient at given index. + * + * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit. + * + * \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w() + */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator[](Index index) { + EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime, + THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD) + eigen_assert(index >= 0 && index < size()); + return coeffRef(index); + } + + /** \returns a reference to the coefficient at given index. + * + * This is synonymous to operator[](Index). + * + * This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit. + * + * \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w() + */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& operator()(Index index) { + eigen_assert(index >= 0 && index < size()); + return coeffRef(index); + } + + /** equivalent to operator[](0). */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& x() { return (*this)[0]; } + + /** equivalent to operator[](1). */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& y() { + EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 2, OUT_OF_RANGE_ACCESS); + return (*this)[1]; + } + + /** equivalent to operator[](2). */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& z() { + EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 3, OUT_OF_RANGE_ACCESS); + return (*this)[2]; + } + + /** equivalent to operator[](3). */ + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& w() { + EIGEN_STATIC_ASSERT(Derived::SizeAtCompileTime == -1 || Derived::SizeAtCompileTime >= 4, OUT_OF_RANGE_ACCESS); + return (*this)[3]; + } +}; + +/** \brief Base class providing direct read-only coefficient access to matrices and arrays. + * \ingroup Core_Module + * \tparam Derived Type of the derived class + * + * \note #DirectAccessors Constant indicating direct access + * + * This class defines functions to work with strides which can be used to access entries directly. This class + * inherits DenseCoeffsBase which defines functions to access entries read-only using + * \c operator() . + * + * \sa \blank \ref TopicClassHierarchy + */ +template +class DenseCoeffsBase : public DenseCoeffsBase { + public: + typedef DenseCoeffsBase Base; + typedef typename internal::traits::Scalar Scalar; + typedef typename NumTraits::Real RealScalar; + + using Base::cols; + using Base::derived; + using Base::rows; + using Base::size; + + /** \returns the pointer increment between two consecutive elements within a slice in the inner direction. + * + * \sa outerStride(), rowStride(), colStride() + */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const { return derived().innerStride(); } + + /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns + * in a column-major matrix). + * + * \sa innerStride(), rowStride(), colStride() + */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const { return derived().outerStride(); } + + // FIXME shall we remove it ? + EIGEN_CONSTEXPR inline Index stride() const { return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); } + + /** \returns the pointer increment between two consecutive rows. + * + * \sa innerStride(), outerStride(), colStride() + */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rowStride() const { + return Derived::IsRowMajor ? outerStride() : innerStride(); + } + + /** \returns the pointer increment between two consecutive columns. + * + * \sa innerStride(), outerStride(), rowStride() + */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index colStride() const { + return Derived::IsRowMajor ? innerStride() : outerStride(); + } +}; + +/** \brief Base class providing direct read/write coefficient access to matrices and arrays. + * \ingroup Core_Module + * \tparam Derived Type of the derived class + * + * \note #DirectWriteAccessors Constant indicating direct access + * + * This class defines functions to work with strides which can be used to access entries directly. This class + * inherits DenseCoeffsBase which defines functions to access entries read/write using + * \c operator(). + * + * \sa \blank \ref TopicClassHierarchy + */ +template +class DenseCoeffsBase : public DenseCoeffsBase { + public: + typedef DenseCoeffsBase Base; + typedef typename internal::traits::Scalar Scalar; + typedef typename NumTraits::Real RealScalar; + + using Base::cols; + using Base::derived; + using Base::rows; + using Base::size; + + /** \returns the pointer increment between two consecutive elements within a slice in the inner direction. + * + * \sa outerStride(), rowStride(), colStride() + */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { return derived().innerStride(); } + + /** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns + * in a column-major matrix). + * + * \sa innerStride(), rowStride(), colStride() + */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { return derived().outerStride(); } + + // FIXME shall we remove it ? + EIGEN_CONSTEXPR inline Index stride() const EIGEN_NOEXCEPT { + return Derived::IsVectorAtCompileTime ? innerStride() : outerStride(); + } + + /** \returns the pointer increment between two consecutive rows. + * + * \sa innerStride(), outerStride(), colStride() + */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rowStride() const EIGEN_NOEXCEPT { + return Derived::IsRowMajor ? outerStride() : innerStride(); + } + + /** \returns the pointer increment between two consecutive columns. + * + * \sa innerStride(), outerStride(), rowStride() + */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index colStride() const EIGEN_NOEXCEPT { + return Derived::IsRowMajor ? innerStride() : outerStride(); + } +}; + +namespace internal { + +template +struct first_aligned_impl { + static EIGEN_CONSTEXPR inline Index run(const Derived&) EIGEN_NOEXCEPT { return 0; } +}; + +template +struct first_aligned_impl { + static inline Index run(const Derived& m) { return internal::first_aligned(m.data(), m.size()); } +}; + +/** \internal \returns the index of the first element of the array stored by \a m that is properly aligned with respect + * to \a Alignment for vectorization. + * + * \tparam Alignment requested alignment in Bytes. + * + * There is also the variant first_aligned(const Scalar*, Integer) defined in Memory.h. See it for more + * documentation. + */ +template +static inline Index first_aligned(const DenseBase& m) { + enum { ReturnZero = (int(evaluator::Alignment) >= Alignment) || !(Derived::Flags & DirectAccessBit) }; + return first_aligned_impl::run(m.derived()); +} + +template +static inline Index first_default_aligned(const DenseBase& m) { + typedef typename Derived::Scalar Scalar; + typedef typename packet_traits::type DefaultPacketType; + return internal::first_aligned::alignment), Derived>(m); +} + +template ::ret> +struct inner_stride_at_compile_time { + enum { ret = traits::InnerStrideAtCompileTime }; +}; + +template +struct inner_stride_at_compile_time { + enum { ret = 0 }; +}; + +template ::ret> +struct outer_stride_at_compile_time { + enum { ret = traits::OuterStrideAtCompileTime }; +}; + +template +struct outer_stride_at_compile_time { + enum { ret = 0 }; +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_DENSECOEFFSBASE_H diff --git a/dae-cpp/Eigen/src/Core/DenseStorage.h b/dae-cpp/Eigen/src/Core/DenseStorage.h new file mode 100644 index 0000000..f616939 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/DenseStorage.h @@ -0,0 +1,650 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2006-2009 Benoit Jacob +// Copyright (C) 2010-2013 Hauke Heibel +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_MATRIXSTORAGE_H +#define EIGEN_MATRIXSTORAGE_H + +#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN +#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) \ + X; \ + EIGEN_DENSE_STORAGE_CTOR_PLUGIN; +#else +#define EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(X) +#endif + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +struct constructor_without_unaligned_array_assert {}; + +template +EIGEN_DEVICE_FUNC constexpr void check_static_allocation_size() { +// if EIGEN_STACK_ALLOCATION_LIMIT is defined to 0, then no limit +#if EIGEN_STACK_ALLOCATION_LIMIT + EIGEN_STATIC_ASSERT(Size * sizeof(T) <= EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG); +#endif +} + +/** \internal + * Static array. If the MatrixOrArrayOptions require auto-alignment, the array will be automatically aligned: + * to 16 bytes boundary if the total size is a multiple of 16 bytes. + */ +template ::value> +struct plain_array { + T array[Size]; + + EIGEN_DEVICE_FUNC constexpr plain_array() { check_static_allocation_size(); } + + EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) { + check_static_allocation_size(); + } +}; + +#if defined(EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT) +#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) +#else +#define EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(sizemask) \ + eigen_assert((internal::is_constant_evaluated() || (std::uintptr_t(array) & (sizemask)) == 0) && \ + "this assertion is explained here: " \ + "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" \ + " **** READ THIS WEB PAGE !!! ****"); +#endif + +template +struct plain_array { + EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size]; + + EIGEN_DEVICE_FUNC constexpr plain_array() { + EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(7); + check_static_allocation_size(); + } + + EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) { + check_static_allocation_size(); + } +}; + +template +struct plain_array { + EIGEN_ALIGN_TO_BOUNDARY(16) T array[Size]; + + EIGEN_DEVICE_FUNC constexpr plain_array() { + EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15); + check_static_allocation_size(); + } + + EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) { + check_static_allocation_size(); + } +}; + +template +struct plain_array { + EIGEN_ALIGN_TO_BOUNDARY(32) T array[Size]; + + EIGEN_DEVICE_FUNC constexpr plain_array() { + EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(31); + check_static_allocation_size(); + } + + EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) { + check_static_allocation_size(); + } +}; + +template +struct plain_array { + EIGEN_ALIGN_TO_BOUNDARY(64) T array[Size]; + + EIGEN_DEVICE_FUNC constexpr plain_array() { + EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(63); + check_static_allocation_size(); + } + + EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) { + check_static_allocation_size(); + } +}; + +template +struct plain_array { + T array[1]; + EIGEN_DEVICE_FUNC constexpr plain_array() {} + EIGEN_DEVICE_FUNC constexpr plain_array(constructor_without_unaligned_array_assert) {} +}; + +struct plain_array_helper { + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void copy( + const plain_array& src, const Eigen::Index size, + plain_array& dst) { + smart_copy(src.array, src.array + size, dst.array); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static void swap(plain_array& a, + const Eigen::Index a_size, + plain_array& b, + const Eigen::Index b_size) { + if (a_size < b_size) { + std::swap_ranges(b.array, b.array + a_size, a.array); + smart_move(b.array + a_size, b.array + b_size, a.array + a_size); + } else if (a_size > b_size) { + std::swap_ranges(a.array, a.array + b_size, b.array); + smart_move(a.array + b_size, a.array + a_size, b.array + b_size); + } else { + std::swap_ranges(a.array, a.array + a_size, b.array); + } + } +}; + +} // end namespace internal + +/** \internal + * + * \class DenseStorage + * \ingroup Core_Module + * + * \brief Stores the data of a matrix + * + * This class stores the data of fixed-size, dynamic-size or mixed matrices + * in a way as compact as possible. + * + * \sa Matrix + */ +template +class DenseStorage; + +// purely fixed-size matrix +template +class DenseStorage { + internal::plain_array m_data; + + public: + constexpr EIGEN_DEVICE_FUNC DenseStorage(){EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN( + Index size = + Size)} EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) + : m_data(internal::constructor_without_unaligned_array_assert()) {} +#if defined(EIGEN_DENSE_STORAGE_CTOR_PLUGIN) + EIGEN_DEVICE_FUNC constexpr DenseStorage(const DenseStorage& other) + : m_data(other.m_data){EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = Size)} +#else + EIGEN_DEVICE_FUNC constexpr DenseStorage(const DenseStorage&) = default; +#endif + EIGEN_DEVICE_FUNC constexpr DenseStorage + & + operator=(const DenseStorage&) = default; + EIGEN_DEVICE_FUNC constexpr DenseStorage(DenseStorage&&) = default; + EIGEN_DEVICE_FUNC constexpr DenseStorage& operator=(DenseStorage&&) = default; + EIGEN_DEVICE_FUNC constexpr DenseStorage(Index size, Index rows, Index cols) { + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) + eigen_internal_assert(size == rows * cols && rows == Rows_ && cols == Cols_); + EIGEN_UNUSED_VARIABLE(size); + EIGEN_UNUSED_VARIABLE(rows); + EIGEN_UNUSED_VARIABLE(cols); + } + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { numext::swap(m_data, other.m_data); } + EIGEN_DEVICE_FUNC static constexpr Index rows(void) EIGEN_NOEXCEPT { return Rows_; } + EIGEN_DEVICE_FUNC static constexpr Index cols(void) EIGEN_NOEXCEPT { return Cols_; } + EIGEN_DEVICE_FUNC constexpr void conservativeResize(Index, Index, Index) {} + EIGEN_DEVICE_FUNC constexpr void resize(Index, Index, Index) {} + EIGEN_DEVICE_FUNC constexpr const T* data() const { return m_data.array; } + EIGEN_DEVICE_FUNC constexpr T* data() { return m_data.array; } +}; + +// null matrix +template +class DenseStorage { + public: + static_assert(Rows_ * Cols_ == 0, "The fixed number of rows times columns must equal the storage size."); + EIGEN_DEVICE_FUNC constexpr DenseStorage() {} + EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) {} + EIGEN_DEVICE_FUNC constexpr DenseStorage(const DenseStorage&) {} + EIGEN_DEVICE_FUNC constexpr DenseStorage& operator=(const DenseStorage&) { return *this; } + EIGEN_DEVICE_FUNC constexpr DenseStorage(Index, Index, Index) {} + EIGEN_DEVICE_FUNC constexpr void swap(DenseStorage&) {} + EIGEN_DEVICE_FUNC static constexpr Index rows(void) EIGEN_NOEXCEPT { return Rows_; } + EIGEN_DEVICE_FUNC static constexpr Index cols(void) EIGEN_NOEXCEPT { return Cols_; } + EIGEN_DEVICE_FUNC constexpr void conservativeResize(Index, Index, Index) {} + EIGEN_DEVICE_FUNC constexpr void resize(Index, Index, Index) {} + EIGEN_DEVICE_FUNC constexpr const T* data() const { return 0; } + EIGEN_DEVICE_FUNC constexpr T* data() { return 0; } +}; + +// more specializations for null matrices; these are necessary to resolve ambiguities +template +class DenseStorage { + Index m_rows; + Index m_cols; + + public: + EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0), m_cols(0) {} + EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {} + EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_rows(other.m_rows), m_cols(other.m_cols) {} + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + m_rows = other.m_rows; + m_cols = other.m_cols; + return *this; + } + EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index cols) : m_rows(rows), m_cols(cols) { + eigen_assert(m_rows * m_cols == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { + numext::swap(m_rows, other.m_rows); + numext::swap(m_cols, other.m_cols); + } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_rows; } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_cols; } + EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index cols) { + m_rows = rows; + m_cols = cols; + eigen_assert(m_rows * m_cols == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index cols) { + m_rows = rows; + m_cols = cols; + eigen_assert(m_rows * m_cols == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC const T* data() const { return nullptr; } + EIGEN_DEVICE_FUNC T* data() { return nullptr; } +}; + +template +class DenseStorage { + Index m_cols; + + public: + EIGEN_DEVICE_FUNC DenseStorage() : m_cols(0) {} + EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {} + EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_cols(other.m_cols) {} + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + m_cols = other.m_cols; + return *this; + } + EIGEN_DEVICE_FUNC DenseStorage(Index, Index, Index cols) : m_cols(cols) { + eigen_assert(Rows_ * m_cols == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { numext::swap(m_cols, other.m_cols); } + EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index rows(void) EIGEN_NOEXCEPT { return Rows_; } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols(void) const EIGEN_NOEXCEPT { return m_cols; } + EIGEN_DEVICE_FUNC void conservativeResize(Index, Index, Index cols) { + m_cols = cols; + eigen_assert(Rows_ * m_cols == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC void resize(Index, Index, Index cols) { + m_cols = cols; + eigen_assert(Rows_ * m_cols == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC const T* data() const { return nullptr; } + EIGEN_DEVICE_FUNC T* data() { return nullptr; } +}; + +template +class DenseStorage { + Index m_rows; + + public: + EIGEN_DEVICE_FUNC DenseStorage() : m_rows(0) {} + EIGEN_DEVICE_FUNC explicit DenseStorage(internal::constructor_without_unaligned_array_assert) : DenseStorage() {} + EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) : m_rows(other.m_rows) {} + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + m_rows = other.m_rows; + return *this; + } + EIGEN_DEVICE_FUNC DenseStorage(Index, Index rows, Index) : m_rows(rows) { + eigen_assert(m_rows * Cols_ == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { numext::swap(m_rows, other.m_rows); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows(void) const EIGEN_NOEXCEPT { return m_rows; } + EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Index cols(void) EIGEN_NOEXCEPT { return Cols_; } + EIGEN_DEVICE_FUNC void conservativeResize(Index, Index rows, Index) { + m_rows = rows; + eigen_assert(m_rows * Cols_ == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC void resize(Index, Index rows, Index) { + m_rows = rows; + eigen_assert(m_rows * Cols_ == 0 && "The number of rows times columns must equal the storage size."); + } + EIGEN_DEVICE_FUNC const T* data() const { return nullptr; } + EIGEN_DEVICE_FUNC T* data() { return nullptr; } +}; + +// dynamic-size matrix with fixed-size storage +template +class DenseStorage { + internal::plain_array m_data; + Index m_rows; + Index m_cols; + + public: + EIGEN_DEVICE_FUNC constexpr DenseStorage() : m_data(), m_rows(0), m_cols(0) {} + EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) + : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0), m_cols(0) {} + EIGEN_DEVICE_FUNC constexpr DenseStorage(const DenseStorage& other) + : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows), m_cols(other.m_cols) { + internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data); + } + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + if (this != &other) { + m_rows = other.m_rows; + m_cols = other.m_cols; + internal::plain_array_helper::copy(other.m_data, m_rows * m_cols, m_data); + } + return *this; + } + EIGEN_DEVICE_FUNC constexpr DenseStorage(Index, Index rows, Index cols) : m_rows(rows), m_cols(cols) {} + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { + internal::plain_array_helper::swap(m_data, m_rows * m_cols, other.m_data, other.m_rows * other.m_cols); + numext::swap(m_rows, other.m_rows); + numext::swap(m_cols, other.m_cols); + } + EIGEN_DEVICE_FUNC constexpr Index rows() const { return m_rows; } + EIGEN_DEVICE_FUNC constexpr Index cols() const { return m_cols; } + EIGEN_DEVICE_FUNC constexpr void conservativeResize(Index, Index rows, Index cols) { + m_rows = rows; + m_cols = cols; + } + EIGEN_DEVICE_FUNC constexpr void resize(Index, Index rows, Index cols) { + m_rows = rows; + m_cols = cols; + } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return m_data.array; } + EIGEN_DEVICE_FUNC constexpr T* data() { return m_data.array; } +}; + +// dynamic-size matrix with fixed-size storage and fixed width +template +class DenseStorage { + internal::plain_array m_data; + Index m_rows; + + public: + EIGEN_DEVICE_FUNC constexpr DenseStorage() : m_rows(0) {} + EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) + : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {} + EIGEN_DEVICE_FUNC constexpr DenseStorage(const DenseStorage& other) + : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(other.m_rows) { + internal::plain_array_helper::copy(other.m_data, m_rows * Cols_, m_data); + } + + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + if (this != &other) { + m_rows = other.m_rows; + internal::plain_array_helper::copy(other.m_data, m_rows * Cols_, m_data); + } + return *this; + } + EIGEN_DEVICE_FUNC constexpr DenseStorage(Index, Index rows, Index) : m_rows(rows) {} + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { + internal::plain_array_helper::swap(m_data, m_rows * Cols_, other.m_data, other.m_rows * Cols_); + numext::swap(m_rows, other.m_rows); + } + EIGEN_DEVICE_FUNC constexpr Index rows(void) const EIGEN_NOEXCEPT { return m_rows; } + EIGEN_DEVICE_FUNC constexpr Index cols(void) const EIGEN_NOEXCEPT { return Cols_; } + EIGEN_DEVICE_FUNC constexpr void conservativeResize(Index, Index rows, Index) { m_rows = rows; } + EIGEN_DEVICE_FUNC constexpr void resize(Index, Index rows, Index) { m_rows = rows; } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return m_data.array; } + EIGEN_DEVICE_FUNC constexpr T* data() { return m_data.array; } +}; + +// dynamic-size matrix with fixed-size storage and fixed height +template +class DenseStorage { + internal::plain_array m_data; + Index m_cols; + + public: + EIGEN_DEVICE_FUNC constexpr DenseStorage() : m_cols(0) {} + EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) + : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {} + EIGEN_DEVICE_FUNC constexpr DenseStorage(const DenseStorage& other) + : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(other.m_cols) { + internal::plain_array_helper::copy(other.m_data, Rows_ * m_cols, m_data); + } + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + if (this != &other) { + m_cols = other.m_cols; + internal::plain_array_helper::copy(other.m_data, Rows_ * m_cols, m_data); + } + return *this; + } + EIGEN_DEVICE_FUNC DenseStorage(Index, Index, Index cols) : m_cols(cols) {} + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { + internal::plain_array_helper::swap(m_data, Rows_ * m_cols, other.m_data, Rows_ * other.m_cols); + numext::swap(m_cols, other.m_cols); + } + EIGEN_DEVICE_FUNC constexpr Index rows(void) const EIGEN_NOEXCEPT { return Rows_; } + EIGEN_DEVICE_FUNC constexpr Index cols(void) const EIGEN_NOEXCEPT { return m_cols; } + EIGEN_DEVICE_FUNC constexpr void conservativeResize(Index, Index, Index cols) { m_cols = cols; } + EIGEN_DEVICE_FUNC constexpr void resize(Index, Index, Index cols) { m_cols = cols; } + EIGEN_DEVICE_FUNC constexpr const T* data() const { return m_data.array; } + EIGEN_DEVICE_FUNC constexpr T* data() { return m_data.array; } +}; + +// purely dynamic matrix. +template +class DenseStorage { + T* m_data; + Index m_rows; + Index m_cols; + + public: + EIGEN_DEVICE_FUNC constexpr DenseStorage() : m_data(0), m_rows(0), m_cols(0) {} + EIGEN_DEVICE_FUNC explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) + : m_data(0), m_rows(0), m_cols(0) {} + EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) + : m_data(internal::conditional_aligned_new_auto(size)), + m_rows(rows), + m_cols(cols) { + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) + eigen_internal_assert(size == rows * cols && rows >= 0 && cols >= 0); + } + EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) + : m_data(internal::conditional_aligned_new_auto(other.m_rows * other.m_cols)), + m_rows(other.m_rows), + m_cols(other.m_cols) { + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows * m_cols) + internal::smart_copy(other.m_data, other.m_data + other.m_rows * other.m_cols, m_data); + } + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + if (this != &other) { + DenseStorage tmp(other); + this->swap(tmp); + } + return *this; + } + EIGEN_DEVICE_FUNC DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT : m_data(std::move(other.m_data)), + m_rows(std::move(other.m_rows)), + m_cols(std::move(other.m_cols)) { + other.m_data = nullptr; + other.m_rows = 0; + other.m_cols = 0; + } + EIGEN_DEVICE_FUNC DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT { + numext::swap(m_data, other.m_data); + numext::swap(m_rows, other.m_rows); + numext::swap(m_cols, other.m_cols); + return *this; + } + EIGEN_DEVICE_FUNC ~DenseStorage() { + internal::conditional_aligned_delete_auto(m_data, m_rows * m_cols); + } + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { + numext::swap(m_data, other.m_data); + numext::swap(m_rows, other.m_rows); + numext::swap(m_cols, other.m_cols); + } + EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT { return m_rows; } + EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT { return m_cols; } + void conservativeResize(Index size, Index rows, Index cols) { + m_data = + internal::conditional_aligned_realloc_new_auto(m_data, size, m_rows * m_cols); + m_rows = rows; + m_cols = cols; + } + EIGEN_DEVICE_FUNC void resize(Index size, Index rows, Index cols) { + if (size != m_rows * m_cols) { + internal::conditional_aligned_delete_auto(m_data, m_rows * m_cols); + if (size > 0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative + m_data = internal::conditional_aligned_new_auto(size); + else + m_data = 0; + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) + } + m_rows = rows; + m_cols = cols; + } + EIGEN_DEVICE_FUNC const T* data() const { return m_data; } + EIGEN_DEVICE_FUNC T* data() { return m_data; } +}; + +// matrix with dynamic width and fixed height (so that matrix has dynamic size). +template +class DenseStorage { + T* m_data; + Index m_cols; + + public: + EIGEN_DEVICE_FUNC constexpr DenseStorage() : m_data(0), m_cols(0) {} + explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {} + EIGEN_DEVICE_FUNC DenseStorage(Index size, Index rows, Index cols) + : m_data(internal::conditional_aligned_new_auto(size)), m_cols(cols) { + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) + eigen_internal_assert(size == rows * cols && rows == Rows_ && cols >= 0); + EIGEN_UNUSED_VARIABLE(rows); + } + EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) + : m_data(internal::conditional_aligned_new_auto(Rows_ * other.m_cols)), + m_cols(other.m_cols) { + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_cols * Rows_) + internal::smart_copy(other.m_data, other.m_data + Rows_ * m_cols, m_data); + } + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + if (this != &other) { + DenseStorage tmp(other); + this->swap(tmp); + } + return *this; + } + EIGEN_DEVICE_FUNC DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT : m_data(std::move(other.m_data)), + m_cols(std::move(other.m_cols)) { + other.m_data = nullptr; + other.m_cols = 0; + } + EIGEN_DEVICE_FUNC DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT { + numext::swap(m_data, other.m_data); + numext::swap(m_cols, other.m_cols); + return *this; + } + EIGEN_DEVICE_FUNC ~DenseStorage() { + internal::conditional_aligned_delete_auto(m_data, Rows_ * m_cols); + } + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { + numext::swap(m_data, other.m_data); + numext::swap(m_cols, other.m_cols); + } + EIGEN_DEVICE_FUNC static constexpr Index rows(void) EIGEN_NOEXCEPT { return Rows_; } + EIGEN_DEVICE_FUNC Index cols(void) const EIGEN_NOEXCEPT { return m_cols; } + EIGEN_DEVICE_FUNC void conservativeResize(Index size, Index, Index cols) { + m_data = + internal::conditional_aligned_realloc_new_auto(m_data, size, Rows_ * m_cols); + m_cols = cols; + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index, Index cols) { + if (size != Rows_ * m_cols) { + internal::conditional_aligned_delete_auto(m_data, Rows_ * m_cols); + if (size > 0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative + m_data = internal::conditional_aligned_new_auto(size); + else + m_data = 0; + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) + } + m_cols = cols; + } + EIGEN_DEVICE_FUNC const T* data() const { return m_data; } + EIGEN_DEVICE_FUNC T* data() { return m_data; } +}; + +// matrix with dynamic height and fixed width (so that matrix has dynamic size). +template +class DenseStorage { + T* m_data; + Index m_rows; + + public: + EIGEN_DEVICE_FUNC constexpr DenseStorage() : m_data(0), m_rows(0) {} + explicit constexpr DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {} + EIGEN_DEVICE_FUNC constexpr DenseStorage(Index size, Index rows, Index cols) + : m_data(internal::conditional_aligned_new_auto(size)), m_rows(rows) { + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) + eigen_internal_assert(size == rows * cols && rows >= 0 && cols == Cols_); + EIGEN_UNUSED_VARIABLE(cols); + } + EIGEN_DEVICE_FUNC DenseStorage(const DenseStorage& other) + : m_data(internal::conditional_aligned_new_auto(other.m_rows * Cols_)), + m_rows(other.m_rows) { + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN(Index size = m_rows * Cols_) + internal::smart_copy(other.m_data, other.m_data + other.m_rows * Cols_, m_data); + } + EIGEN_DEVICE_FUNC DenseStorage& operator=(const DenseStorage& other) { + if (this != &other) { + DenseStorage tmp(other); + this->swap(tmp); + } + return *this; + } + EIGEN_DEVICE_FUNC DenseStorage(DenseStorage&& other) EIGEN_NOEXCEPT : m_data(std::move(other.m_data)), + m_rows(std::move(other.m_rows)) { + other.m_data = nullptr; + other.m_rows = 0; + } + EIGEN_DEVICE_FUNC DenseStorage& operator=(DenseStorage&& other) EIGEN_NOEXCEPT { + numext::swap(m_data, other.m_data); + numext::swap(m_rows, other.m_rows); + return *this; + } + EIGEN_DEVICE_FUNC ~DenseStorage() { + internal::conditional_aligned_delete_auto(m_data, Cols_ * m_rows); + } + EIGEN_DEVICE_FUNC void swap(DenseStorage& other) { + numext::swap(m_data, other.m_data); + numext::swap(m_rows, other.m_rows); + } + EIGEN_DEVICE_FUNC Index rows(void) const EIGEN_NOEXCEPT { return m_rows; } + EIGEN_DEVICE_FUNC static constexpr Index cols(void) { return Cols_; } + void conservativeResize(Index size, Index rows, Index) { + m_data = + internal::conditional_aligned_realloc_new_auto(m_data, size, m_rows * Cols_); + m_rows = rows; + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index size, Index rows, Index) { + if (size != m_rows * Cols_) { + internal::conditional_aligned_delete_auto(m_data, Cols_ * m_rows); + if (size > 0) // >0 and not simply !=0 to let the compiler knows that size cannot be negative + m_data = internal::conditional_aligned_new_auto(size); + else + m_data = 0; + EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN({}) + } + m_rows = rows; + } + EIGEN_DEVICE_FUNC const T* data() const { return m_data; } + EIGEN_DEVICE_FUNC T* data() { return m_data; } +}; + +} // end namespace Eigen + +#endif // EIGEN_MATRIX_H diff --git a/dae-cpp/Eigen/src/Core/Diagonal.h b/dae-cpp/Eigen/src/Core/Diagonal.h new file mode 100644 index 0000000..8d27857 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Diagonal.h @@ -0,0 +1,221 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2007-2009 Benoit Jacob +// Copyright (C) 2009-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_DIAGONAL_H +#define EIGEN_DIAGONAL_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class Diagonal + * \ingroup Core_Module + * + * \brief Expression of a diagonal/subdiagonal/superdiagonal in a matrix + * + * \tparam MatrixType the type of the object in which we are taking a sub/main/super diagonal + * \tparam DiagIndex the index of the sub/super diagonal. The default is 0 and it means the main diagonal. + * A positive value means a superdiagonal, a negative value means a subdiagonal. + * You can also use DynamicIndex so the index can be set at runtime. + * + * The matrix is not required to be square. + * + * This class represents an expression of the main diagonal, or any sub/super diagonal + * of a square matrix. It is the return type of MatrixBase::diagonal() and MatrixBase::diagonal(Index) and most of the + * time this is the only way it is used. + * + * \sa MatrixBase::diagonal(), MatrixBase::diagonal(Index) + */ + +namespace internal { +template +struct traits > : traits { + typedef typename ref_selector::type MatrixTypeNested; + typedef std::remove_reference_t MatrixTypeNested_; + typedef typename MatrixType::StorageKind StorageKind; + enum { + RowsAtCompileTime = (int(DiagIndex) == DynamicIndex || int(MatrixType::SizeAtCompileTime) == Dynamic) + ? Dynamic + : (plain_enum_min(MatrixType::RowsAtCompileTime - plain_enum_max(-DiagIndex, 0), + MatrixType::ColsAtCompileTime - plain_enum_max(DiagIndex, 0))), + ColsAtCompileTime = 1, + MaxRowsAtCompileTime = + int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic + : DiagIndex == DynamicIndex + ? min_size_prefer_fixed(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) + : (plain_enum_min(MatrixType::MaxRowsAtCompileTime - plain_enum_max(-DiagIndex, 0), + MatrixType::MaxColsAtCompileTime - plain_enum_max(DiagIndex, 0))), + MaxColsAtCompileTime = 1, + MaskLvalueBit = is_lvalue::value ? LvalueBit : 0, + Flags = (unsigned int)MatrixTypeNested_::Flags & (RowMajorBit | MaskLvalueBit | DirectAccessBit) & + ~RowMajorBit, // FIXME DirectAccessBit should not be handled by expressions + MatrixTypeOuterStride = outer_stride_at_compile_time::ret, + InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride + 1, + OuterStrideAtCompileTime = 0 + }; +}; +} // namespace internal + +template +class Diagonal : public internal::dense_xpr_base >::type { + public: + enum { DiagIndex = DiagIndex_ }; + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Diagonal) + + EIGEN_DEVICE_FUNC explicit inline Diagonal(MatrixType& matrix, Index a_index = DiagIndex) + : m_matrix(matrix), m_index(a_index) { + eigen_assert(a_index <= m_matrix.cols() && -a_index <= m_matrix.rows()); + } + + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal) + + EIGEN_DEVICE_FUNC inline Index rows() const { + return m_index.value() < 0 ? numext::mini(m_matrix.cols(), m_matrix.rows() + m_index.value()) + : numext::mini(m_matrix.rows(), m_matrix.cols() - m_index.value()); + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return 1; } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { + return m_matrix.outerStride() + 1; + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { return 0; } + + typedef std::conditional_t::value, Scalar, const Scalar> ScalarWithConstIfNotLvalue; + + EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { return &(m_matrix.coeffRef(rowOffset(), colOffset())); } + EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(m_matrix.coeffRef(rowOffset(), colOffset())); } + + EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index) { + EIGEN_STATIC_ASSERT_LVALUE(MatrixType) + return m_matrix.coeffRef(row + rowOffset(), row + colOffset()); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index row, Index) const { + return m_matrix.coeffRef(row + rowOffset(), row + colOffset()); + } + + EIGEN_DEVICE_FUNC inline CoeffReturnType coeff(Index row, Index) const { + return m_matrix.coeff(row + rowOffset(), row + colOffset()); + } + + EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index idx) { + EIGEN_STATIC_ASSERT_LVALUE(MatrixType) + return m_matrix.coeffRef(idx + rowOffset(), idx + colOffset()); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index idx) const { + return m_matrix.coeffRef(idx + rowOffset(), idx + colOffset()); + } + + EIGEN_DEVICE_FUNC inline CoeffReturnType coeff(Index idx) const { + return m_matrix.coeff(idx + rowOffset(), idx + colOffset()); + } + + EIGEN_DEVICE_FUNC inline const internal::remove_all_t& nestedExpression() const { + return m_matrix; + } + + EIGEN_DEVICE_FUNC inline Index index() const { return m_index.value(); } + + protected: + typename internal::ref_selector::non_const_type m_matrix; + const internal::variable_if_dynamicindex m_index; + + private: + // some compilers may fail to optimize std::max etc in case of compile-time constants... + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index absDiagIndex() const EIGEN_NOEXCEPT { + return m_index.value() > 0 ? m_index.value() : -m_index.value(); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rowOffset() const EIGEN_NOEXCEPT { + return m_index.value() > 0 ? 0 : -m_index.value(); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index colOffset() const EIGEN_NOEXCEPT { + return m_index.value() > 0 ? m_index.value() : 0; + } + // trigger a compile-time error if someone try to call packet + template + typename MatrixType::PacketReturnType packet(Index) const; + template + typename MatrixType::PacketReturnType packet(Index, Index) const; +}; + +/** \returns an expression of the main diagonal of the matrix \c *this + * + * \c *this is not required to be square. + * + * Example: \include MatrixBase_diagonal.cpp + * Output: \verbinclude MatrixBase_diagonal.out + * + * \sa class Diagonal */ +template +EIGEN_DEVICE_FUNC inline typename MatrixBase::DiagonalReturnType MatrixBase::diagonal() { + return DiagonalReturnType(derived()); +} + +/** This is the const version of diagonal(). */ +template +EIGEN_DEVICE_FUNC inline const typename MatrixBase::ConstDiagonalReturnType MatrixBase::diagonal() + const { + return ConstDiagonalReturnType(derived()); +} + +/** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this + * + * \c *this is not required to be square. + * + * The template parameter \a DiagIndex represent a super diagonal if \a DiagIndex > 0 + * and a sub diagonal otherwise. \a DiagIndex == 0 is equivalent to the main diagonal. + * + * Example: \include MatrixBase_diagonal_int.cpp + * Output: \verbinclude MatrixBase_diagonal_int.out + * + * \sa MatrixBase::diagonal(), class Diagonal */ +template +EIGEN_DEVICE_FUNC inline Diagonal MatrixBase::diagonal(Index index) { + return Diagonal(derived(), index); +} + +/** This is the const version of diagonal(Index). */ +template +EIGEN_DEVICE_FUNC inline const Diagonal MatrixBase::diagonal(Index index) const { + return Diagonal(derived(), index); +} + +/** \returns an expression of the \a DiagIndex-th sub or super diagonal of the matrix \c *this + * + * \c *this is not required to be square. + * + * The template parameter \a DiagIndex represent a super diagonal if \a DiagIndex > 0 + * and a sub diagonal otherwise. \a DiagIndex == 0 is equivalent to the main diagonal. + * + * Example: \include MatrixBase_diagonal_template_int.cpp + * Output: \verbinclude MatrixBase_diagonal_template_int.out + * + * \sa MatrixBase::diagonal(), class Diagonal */ +template +template +EIGEN_DEVICE_FUNC inline Diagonal MatrixBase::diagonal() { + return Diagonal(derived()); +} + +/** This is the const version of diagonal(). */ +template +template +EIGEN_DEVICE_FUNC inline const Diagonal MatrixBase::diagonal() const { + return Diagonal(derived()); +} + +} // end namespace Eigen + +#endif // EIGEN_DIAGONAL_H diff --git a/dae-cpp/Eigen/src/Core/DiagonalMatrix.h b/dae-cpp/Eigen/src/Core/DiagonalMatrix.h new file mode 100644 index 0000000..fd61bb7 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/DiagonalMatrix.h @@ -0,0 +1,414 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// Copyright (C) 2007-2009 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_DIAGONALMATRIX_H +#define EIGEN_DIAGONALMATRIX_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class DiagonalBase + * \ingroup Core_Module + * + * \brief Base class for diagonal matrices and expressions + * + * This is the base class that is inherited by diagonal matrix and related expression + * types, which internally use a vector for storing the diagonal entries. Diagonal + * types always represent square matrices. + * + * \tparam Derived is the derived type, a DiagonalMatrix or DiagonalWrapper. + * + * \sa class DiagonalMatrix, class DiagonalWrapper + */ +template +class DiagonalBase : public EigenBase { + public: + typedef typename internal::traits::DiagonalVectorType DiagonalVectorType; + typedef typename DiagonalVectorType::Scalar Scalar; + typedef typename DiagonalVectorType::RealScalar RealScalar; + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::StorageIndex StorageIndex; + + enum { + RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, + ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, + MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime, + MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime, + IsVectorAtCompileTime = 0, + Flags = NoPreferredStorageOrderBit + }; + + typedef Matrix + DenseMatrixType; + typedef DenseMatrixType DenseType; + typedef DiagonalMatrix + PlainObject; + + /** \returns a reference to the derived object. */ + EIGEN_DEVICE_FUNC inline const Derived& derived() const { return *static_cast(this); } + /** \returns a const reference to the derived object. */ + EIGEN_DEVICE_FUNC inline Derived& derived() { return *static_cast(this); } + + /** + * Constructs a dense matrix from \c *this. Note, this directly returns a dense matrix type, + * not an expression. + * \returns A dense matrix, with its diagonal entries set from the the derived object. */ + EIGEN_DEVICE_FUNC DenseMatrixType toDenseMatrix() const { return derived(); } + + /** \returns a reference to the derived object's vector of diagonal coefficients. */ + EIGEN_DEVICE_FUNC inline const DiagonalVectorType& diagonal() const { return derived().diagonal(); } + /** \returns a const reference to the derived object's vector of diagonal coefficients. */ + EIGEN_DEVICE_FUNC inline DiagonalVectorType& diagonal() { return derived().diagonal(); } + + /** \returns the value of the coefficient as if \c *this was a dense matrix. */ + EIGEN_DEVICE_FUNC inline Scalar coeff(Index row, Index col) const { + eigen_assert(row >= 0 && col >= 0 && row < rows() && col <= cols()); + return row == col ? diagonal().coeff(row) : Scalar(0); + } + + /** \returns the number of rows. */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const { return diagonal().size(); } + /** \returns the number of columns. */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const { return diagonal().size(); } + + /** \returns the diagonal matrix product of \c *this by the dense matrix, \a matrix */ + template + EIGEN_DEVICE_FUNC const Product operator*( + const MatrixBase& matrix) const { + return Product(derived(), matrix.derived()); + } + + template + using DiagonalProductReturnType = DiagonalWrapper; + + /** \returns the diagonal matrix product of \c *this by the diagonal matrix \a other */ + template + EIGEN_DEVICE_FUNC const DiagonalProductReturnType operator*( + const DiagonalBase& other) const { + return diagonal().cwiseProduct(other.diagonal()).asDiagonal(); + } + + using DiagonalInverseReturnType = + DiagonalWrapper, const DiagonalVectorType>>; + + /** \returns the inverse \c *this. Computed as the coefficient-wise inverse of the diagonal. */ + EIGEN_DEVICE_FUNC inline const DiagonalInverseReturnType inverse() const { + return diagonal().cwiseInverse().asDiagonal(); + } + + using DiagonalScaleReturnType = + DiagonalWrapper; + + /** \returns the product of \c *this by the scalar \a scalar */ + EIGEN_DEVICE_FUNC inline const DiagonalScaleReturnType operator*(const Scalar& scalar) const { + return (diagonal() * scalar).asDiagonal(); + } + + using ScaleDiagonalReturnType = + DiagonalWrapper; + + /** \returns the product of a scalar and the diagonal matrix \a other */ + EIGEN_DEVICE_FUNC friend inline const ScaleDiagonalReturnType operator*(const Scalar& scalar, + const DiagonalBase& other) { + return (scalar * other.diagonal()).asDiagonal(); + } + + template + using DiagonalSumReturnType = DiagonalWrapper; + + /** \returns the sum of \c *this and the diagonal matrix \a other */ + template + EIGEN_DEVICE_FUNC inline const DiagonalSumReturnType operator+( + const DiagonalBase& other) const { + return (diagonal() + other.diagonal()).asDiagonal(); + } + + template + using DiagonalDifferenceReturnType = DiagonalWrapper; + + /** \returns the difference of \c *this and the diagonal matrix \a other */ + template + EIGEN_DEVICE_FUNC inline const DiagonalDifferenceReturnType operator-( + const DiagonalBase& other) const { + return (diagonal() - other.diagonal()).asDiagonal(); + } +}; + +/** \class DiagonalMatrix + * \ingroup Core_Module + * + * \brief Represents a diagonal matrix with its storage + * + * \tparam Scalar_ the type of coefficients + * \tparam SizeAtCompileTime the dimension of the matrix, or Dynamic + * \tparam MaxSizeAtCompileTime the dimension of the matrix, or Dynamic. This parameter is optional and defaults + * to SizeAtCompileTime. Most of the time, you do not need to specify it. + * + * \sa class DiagonalBase, class DiagonalWrapper + */ + +namespace internal { +template +struct traits> + : traits> { + typedef Matrix DiagonalVectorType; + typedef DiagonalShape StorageKind; + enum { Flags = LvalueBit | NoPreferredStorageOrderBit | NestByRefBit }; +}; +} // namespace internal +template +class DiagonalMatrix : public DiagonalBase> { + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef typename internal::traits::DiagonalVectorType DiagonalVectorType; + typedef const DiagonalMatrix& Nested; + typedef Scalar_ Scalar; + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::StorageIndex StorageIndex; +#endif + + protected: + DiagonalVectorType m_diagonal; + + public: + /** const version of diagonal(). */ + EIGEN_DEVICE_FUNC inline const DiagonalVectorType& diagonal() const { return m_diagonal; } + /** \returns a reference to the stored vector of diagonal coefficients. */ + EIGEN_DEVICE_FUNC inline DiagonalVectorType& diagonal() { return m_diagonal; } + + /** Default constructor without initialization */ + EIGEN_DEVICE_FUNC inline DiagonalMatrix() {} + + /** Constructs a diagonal matrix with given dimension */ + EIGEN_DEVICE_FUNC explicit inline DiagonalMatrix(Index dim) : m_diagonal(dim) {} + + /** 2D constructor. */ + EIGEN_DEVICE_FUNC inline DiagonalMatrix(const Scalar& x, const Scalar& y) : m_diagonal(x, y) {} + + /** 3D constructor. */ + EIGEN_DEVICE_FUNC inline DiagonalMatrix(const Scalar& x, const Scalar& y, const Scalar& z) : m_diagonal(x, y, z) {} + + /** \brief Construct a diagonal matrix with fixed size from an arbitrary number of coefficients. + * + * \warning To construct a diagonal matrix of fixed size, the number of values passed to this + * constructor must match the fixed dimension of \c *this. + * + * \sa DiagonalMatrix(const Scalar&, const Scalar&) + * \sa DiagonalMatrix(const Scalar&, const Scalar&, const Scalar&) + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DiagonalMatrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, + const ArgTypes&... args) + : m_diagonal(a0, a1, a2, args...) {} + + /** \brief Constructs a DiagonalMatrix and initializes it by elements given by an initializer list of initializer + * lists \cpp11 + */ + EIGEN_DEVICE_FUNC explicit EIGEN_STRONG_INLINE DiagonalMatrix( + const std::initializer_list>& list) + : m_diagonal(list) {} + + /** \brief Constructs a DiagonalMatrix from an r-value diagonal vector type */ + EIGEN_DEVICE_FUNC explicit inline DiagonalMatrix(DiagonalVectorType&& diag) : m_diagonal(std::move(diag)) {} + + /** Copy constructor. */ + template + EIGEN_DEVICE_FUNC inline DiagonalMatrix(const DiagonalBase& other) : m_diagonal(other.diagonal()) {} + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** copy constructor. prevent a default copy constructor from hiding the other templated constructor */ + inline DiagonalMatrix(const DiagonalMatrix& other) : m_diagonal(other.diagonal()) {} +#endif + + /** generic constructor from expression of the diagonal coefficients */ + template + EIGEN_DEVICE_FUNC explicit inline DiagonalMatrix(const MatrixBase& other) : m_diagonal(other) {} + + /** Copy operator. */ + template + EIGEN_DEVICE_FUNC DiagonalMatrix& operator=(const DiagonalBase& other) { + m_diagonal = other.diagonal(); + return *this; + } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** This is a special case of the templated operator=. Its purpose is to + * prevent a default operator= from hiding the templated operator=. + */ + EIGEN_DEVICE_FUNC DiagonalMatrix& operator=(const DiagonalMatrix& other) { + m_diagonal = other.diagonal(); + return *this; + } +#endif + + typedef DiagonalWrapper, DiagonalVectorType>> + InitializeReturnType; + + /** Initializes a diagonal matrix of size SizeAtCompileTime with coefficients set to zero */ + EIGEN_DEVICE_FUNC static const InitializeReturnType Zero() { return DiagonalVectorType::Zero().asDiagonal(); } + /** Initializes a diagonal matrix of size dim with coefficients set to zero */ + EIGEN_DEVICE_FUNC static const InitializeReturnType Zero(Index size) { + return DiagonalVectorType::Zero(size).asDiagonal(); + } + /** Initializes a identity matrix of size SizeAtCompileTime */ + EIGEN_DEVICE_FUNC static const InitializeReturnType Identity() { return DiagonalVectorType::Ones().asDiagonal(); } + /** Initializes a identity matrix of size dim */ + EIGEN_DEVICE_FUNC static const InitializeReturnType Identity(Index size) { + return DiagonalVectorType::Ones(size).asDiagonal(); + } + + /** Resizes to given size. */ + EIGEN_DEVICE_FUNC inline void resize(Index size) { m_diagonal.resize(size); } + /** Sets all coefficients to zero. */ + EIGEN_DEVICE_FUNC inline void setZero() { m_diagonal.setZero(); } + /** Resizes and sets all coefficients to zero. */ + EIGEN_DEVICE_FUNC inline void setZero(Index size) { m_diagonal.setZero(size); } + /** Sets this matrix to be the identity matrix of the current size. */ + EIGEN_DEVICE_FUNC inline void setIdentity() { m_diagonal.setOnes(); } + /** Sets this matrix to be the identity matrix of the given size. */ + EIGEN_DEVICE_FUNC inline void setIdentity(Index size) { m_diagonal.setOnes(size); } +}; + +/** \class DiagonalWrapper + * \ingroup Core_Module + * + * \brief Expression of a diagonal matrix + * + * \tparam DiagonalVectorType_ the type of the vector of diagonal coefficients + * + * This class is an expression of a diagonal matrix, but not storing its own vector of diagonal coefficients, + * instead wrapping an existing vector expression. It is the return type of MatrixBase::asDiagonal() + * and most of the time this is the only way that it is used. + * + * \sa class DiagonalMatrix, class DiagonalBase, MatrixBase::asDiagonal() + */ + +namespace internal { +template +struct traits> { + typedef DiagonalVectorType_ DiagonalVectorType; + typedef typename DiagonalVectorType::Scalar Scalar; + typedef typename DiagonalVectorType::StorageIndex StorageIndex; + typedef DiagonalShape StorageKind; + typedef typename traits::XprKind XprKind; + enum { + RowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, + ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime, + MaxRowsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime, + MaxColsAtCompileTime = DiagonalVectorType::MaxSizeAtCompileTime, + Flags = (traits::Flags & LvalueBit) | NoPreferredStorageOrderBit + }; +}; +} // namespace internal + +template +class DiagonalWrapper : public DiagonalBase>, internal::no_assignment_operator { + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef DiagonalVectorType_ DiagonalVectorType; + typedef DiagonalWrapper Nested; +#endif + + /** Constructor from expression of diagonal coefficients to wrap. */ + EIGEN_DEVICE_FUNC explicit inline DiagonalWrapper(DiagonalVectorType& a_diagonal) : m_diagonal(a_diagonal) {} + + /** \returns a const reference to the wrapped expression of diagonal coefficients. */ + EIGEN_DEVICE_FUNC const DiagonalVectorType& diagonal() const { return m_diagonal; } + + protected: + typename DiagonalVectorType::Nested m_diagonal; +}; + +/** \returns a pseudo-expression of a diagonal matrix with *this as vector of diagonal coefficients + * + * \only_for_vectors + * + * Example: \include MatrixBase_asDiagonal.cpp + * Output: \verbinclude MatrixBase_asDiagonal.out + * + * \sa class DiagonalWrapper, class DiagonalMatrix, diagonal(), isDiagonal() + **/ +template +EIGEN_DEVICE_FUNC inline const DiagonalWrapper MatrixBase::asDiagonal() const { + return DiagonalWrapper(derived()); +} + +/** \returns true if *this is approximately equal to a diagonal matrix, + * within the precision given by \a prec. + * + * Example: \include MatrixBase_isDiagonal.cpp + * Output: \verbinclude MatrixBase_isDiagonal.out + * + * \sa asDiagonal() + */ +template +bool MatrixBase::isDiagonal(const RealScalar& prec) const { + if (cols() != rows()) return false; + RealScalar maxAbsOnDiagonal = static_cast(-1); + for (Index j = 0; j < cols(); ++j) { + RealScalar absOnDiagonal = numext::abs(coeff(j, j)); + if (absOnDiagonal > maxAbsOnDiagonal) maxAbsOnDiagonal = absOnDiagonal; + } + for (Index j = 0; j < cols(); ++j) + for (Index i = 0; i < j; ++i) { + if (!internal::isMuchSmallerThan(coeff(i, j), maxAbsOnDiagonal, prec)) return false; + if (!internal::isMuchSmallerThan(coeff(j, i), maxAbsOnDiagonal, prec)) return false; + } + return true; +} + +namespace internal { + +template <> +struct storage_kind_to_shape { + typedef DiagonalShape Shape; +}; + +struct Diagonal2Dense {}; + +template <> +struct AssignmentKind { + typedef Diagonal2Dense Kind; +}; + +// Diagonal matrix to Dense assignment +template +struct Assignment { + static void run(DstXprType& dst, const SrcXprType& src, + const internal::assign_op& /*func*/) { + Index dstRows = src.rows(); + Index dstCols = src.cols(); + if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols); + + dst.setZero(); + dst.diagonal() = src.diagonal(); + } + + static void run(DstXprType& dst, const SrcXprType& src, + const internal::add_assign_op& /*func*/) { + dst.diagonal() += src.diagonal(); + } + + static void run(DstXprType& dst, const SrcXprType& src, + const internal::sub_assign_op& /*func*/) { + dst.diagonal() -= src.diagonal(); + } +}; + +} // namespace internal + +} // end namespace Eigen + +#endif // EIGEN_DIAGONALMATRIX_H diff --git a/dae-cpp/Eigen/src/Core/DiagonalProduct.h b/dae-cpp/Eigen/src/Core/DiagonalProduct.h new file mode 100644 index 0000000..bd0feea --- /dev/null +++ b/dae-cpp/Eigen/src/Core/DiagonalProduct.h @@ -0,0 +1,30 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2007-2009 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_DIAGONALPRODUCT_H +#define EIGEN_DIAGONALPRODUCT_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \returns the diagonal matrix product of \c *this by the diagonal matrix \a diagonal. + */ +template +template +EIGEN_DEVICE_FUNC inline const Product MatrixBase::operator*( + const DiagonalBase &a_diagonal) const { + return Product(derived(), a_diagonal.derived()); +} + +} // end namespace Eigen + +#endif // EIGEN_DIAGONALPRODUCT_H diff --git a/dae-cpp/Eigen/src/Core/Dot.h b/dae-cpp/Eigen/src/Core/Dot.h new file mode 100644 index 0000000..82eb9c7 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Dot.h @@ -0,0 +1,289 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2008, 2010 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_DOT_H +#define EIGEN_DOT_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +// helper function for dot(). The problem is that if we put that in the body of dot(), then upon calling dot +// with mismatched types, the compiler emits errors about failing to instantiate cwiseProduct BEFORE +// looking at the static assertions. Thus this is a trick to get better compile errors. +template +struct dot_nocheck { + typedef scalar_conj_product_op::Scalar, typename traits::Scalar> conj_prod; + typedef typename conj_prod::result_type ResScalar; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static ResScalar run(const MatrixBase& a, const MatrixBase& b) { + return a.template binaryExpr(b).sum(); + } +}; + +template +struct dot_nocheck { + typedef scalar_conj_product_op::Scalar, typename traits::Scalar> conj_prod; + typedef typename conj_prod::result_type ResScalar; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE static ResScalar run(const MatrixBase& a, const MatrixBase& b) { + return a.transpose().template binaryExpr(b).sum(); + } +}; + +} // end namespace internal + +/** \fn MatrixBase::dot + * \returns the dot product of *this with other. + * + * \only_for_vectors + * + * \note If the scalar type is complex numbers, then this function returns the hermitian + * (sesquilinear) dot product, conjugate-linear in the first variable and linear in the + * second variable. + * + * \sa squaredNorm(), norm() + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + typename ScalarBinaryOpTraits::Scalar, + typename internal::traits::Scalar>::ReturnType + MatrixBase::dot(const MatrixBase& other) const { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) + EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived, OtherDerived) +#if !(defined(EIGEN_NO_STATIC_ASSERT) && defined(EIGEN_NO_DEBUG)) + EIGEN_CHECK_BINARY_COMPATIBILIY( + Eigen::internal::scalar_conj_product_op, Scalar, + typename OtherDerived::Scalar); +#endif + + eigen_assert(size() == other.size()); + + return internal::dot_nocheck::run(*this, other); +} + +//---------- implementation of L2 norm and related functions ---------- + +/** \returns, for vectors, the squared \em l2 norm of \c *this, and for matrices the squared Frobenius norm. + * In both cases, it consists in the sum of the square of all the matrix entries. + * For vectors, this is also equals to the dot product of \c *this with itself. + * + * \sa dot(), norm(), lpNorm() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename NumTraits::Scalar>::Real +MatrixBase::squaredNorm() const { + return numext::real((*this).cwiseAbs2().sum()); +} + +/** \returns, for vectors, the \em l2 norm of \c *this, and for matrices the Frobenius norm. + * In both cases, it consists in the square root of the sum of the square of all the matrix entries. + * For vectors, this is also equals to the square root of the dot product of \c *this with itself. + * + * \sa lpNorm(), dot(), squaredNorm() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename NumTraits::Scalar>::Real +MatrixBase::norm() const { + return numext::sqrt(squaredNorm()); +} + +/** \returns an expression of the quotient of \c *this by its own norm. + * + * \warning If the input vector is too small (i.e., this->norm()==0), + * then this function returns a copy of the input. + * + * \only_for_vectors + * + * \sa norm(), normalize() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::PlainObject MatrixBase::normalized() + const { + typedef typename internal::nested_eval::type Nested_; + Nested_ n(derived()); + RealScalar z = n.squaredNorm(); + // NOTE: after extensive benchmarking, this conditional does not impact performance, at least on recent x86 CPU + if (z > RealScalar(0)) + return n / numext::sqrt(z); + else + return n; +} + +/** Normalizes the vector, i.e. divides it by its own norm. + * + * \only_for_vectors + * + * \warning If the input vector is too small (i.e., this->norm()==0), then \c *this is left unchanged. + * + * \sa norm(), normalized() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void MatrixBase::normalize() { + RealScalar z = squaredNorm(); + // NOTE: after extensive benchmarking, this conditional does not impact performance, at least on recent x86 CPU + if (z > RealScalar(0)) derived() /= numext::sqrt(z); +} + +/** \returns an expression of the quotient of \c *this by its own norm while avoiding underflow and overflow. + * + * \only_for_vectors + * + * This method is analogue to the normalized() method, but it reduces the risk of + * underflow and overflow when computing the norm. + * + * \warning If the input vector is too small (i.e., this->norm()==0), + * then this function returns a copy of the input. + * + * \sa stableNorm(), stableNormalize(), normalized() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename MatrixBase::PlainObject +MatrixBase::stableNormalized() const { + typedef typename internal::nested_eval::type Nested_; + Nested_ n(derived()); + RealScalar w = n.cwiseAbs().maxCoeff(); + RealScalar z = (n / w).squaredNorm(); + if (z > RealScalar(0)) + return n / (numext::sqrt(z) * w); + else + return n; +} + +/** Normalizes the vector while avoid underflow and overflow + * + * \only_for_vectors + * + * This method is analogue to the normalize() method, but it reduces the risk of + * underflow and overflow when computing the norm. + * + * \warning If the input vector is too small (i.e., this->norm()==0), then \c *this is left unchanged. + * + * \sa stableNorm(), stableNormalized(), normalize() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void MatrixBase::stableNormalize() { + RealScalar w = cwiseAbs().maxCoeff(); + RealScalar z = (derived() / w).squaredNorm(); + if (z > RealScalar(0)) derived() /= numext::sqrt(z) * w; +} + +//---------- implementation of other norms ---------- + +namespace internal { + +template +struct lpNorm_selector { + typedef typename NumTraits::Scalar>::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const MatrixBase& m) { + EIGEN_USING_STD(pow) + return pow(m.cwiseAbs().array().pow(p).sum(), RealScalar(1) / p); + } +}; + +template +struct lpNorm_selector { + EIGEN_DEVICE_FUNC static inline typename NumTraits::Scalar>::Real run( + const MatrixBase& m) { + return m.cwiseAbs().sum(); + } +}; + +template +struct lpNorm_selector { + EIGEN_DEVICE_FUNC static inline typename NumTraits::Scalar>::Real run( + const MatrixBase& m) { + return m.norm(); + } +}; + +template +struct lpNorm_selector { + typedef typename NumTraits::Scalar>::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const MatrixBase& m) { + if (Derived::SizeAtCompileTime == 0 || (Derived::SizeAtCompileTime == Dynamic && m.size() == 0)) + return RealScalar(0); + return m.cwiseAbs().maxCoeff(); + } +}; + +} // end namespace internal + +/** \returns the \b coefficient-wise \f$ \ell^p \f$ norm of \c *this, that is, returns the p-th root of the sum of the + * p-th powers of the absolute values of the coefficients of \c *this. If \a p is the special value \a Eigen::Infinity, + * this function returns the \f$ \ell^\infty \f$ norm, that is the maximum of the absolute values of the coefficients of + * \c *this. + * + * In all cases, if \c *this is empty, then the value 0 is returned. + * + * \note For matrices, this function does not compute the operator-norm. That is, if \c *this is a matrix, then its + * coefficients are interpreted as a 1D vector. Nonetheless, you can easily compute the 1-norm and \f$\infty\f$-norm + * matrix operator norms using \link TutorialReductionsVisitorsBroadcastingReductionsNorm partial reductions \endlink. + * + * \sa norm() + */ +template +template +#ifndef EIGEN_PARSED_BY_DOXYGEN +EIGEN_DEVICE_FUNC inline typename NumTraits::Scalar>::Real +#else +EIGEN_DEVICE_FUNC MatrixBase::RealScalar +#endif +MatrixBase::lpNorm() const { + return internal::lpNorm_selector::run(*this); +} + +//---------- implementation of isOrthogonal / isUnitary ---------- + +/** \returns true if *this is approximately orthogonal to \a other, + * within the precision given by \a prec. + * + * Example: \include MatrixBase_isOrthogonal.cpp + * Output: \verbinclude MatrixBase_isOrthogonal.out + */ +template +template +bool MatrixBase::isOrthogonal(const MatrixBase& other, const RealScalar& prec) const { + typename internal::nested_eval::type nested(derived()); + typename internal::nested_eval::type otherNested(other.derived()); + return numext::abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm(); +} + +/** \returns true if *this is approximately an unitary matrix, + * within the precision given by \a prec. In the case where the \a Scalar + * type is real numbers, a unitary matrix is an orthogonal matrix, whence the name. + * + * \note This can be used to check whether a family of vectors forms an orthonormal basis. + * Indeed, \c m.isUnitary() returns true if and only if the columns (equivalently, the rows) of m form an + * orthonormal basis. + * + * Example: \include MatrixBase_isUnitary.cpp + * Output: \verbinclude MatrixBase_isUnitary.out + */ +template +bool MatrixBase::isUnitary(const RealScalar& prec) const { + typename internal::nested_eval::type self(derived()); + for (Index i = 0; i < cols(); ++i) { + if (!internal::isApprox(self.col(i).squaredNorm(), static_cast(1), prec)) return false; + for (Index j = 0; j < i; ++j) + if (!internal::isMuchSmallerThan(self.col(i).dot(self.col(j)), static_cast(1), prec)) return false; + } + return true; +} + +} // end namespace Eigen + +#endif // EIGEN_DOT_H diff --git a/dae-cpp/Eigen/src/Core/EigenBase.h b/dae-cpp/Eigen/src/Core/EigenBase.h new file mode 100644 index 0000000..f485016 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/EigenBase.h @@ -0,0 +1,144 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Benoit Jacob +// Copyright (C) 2009 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_EIGENBASE_H +#define EIGEN_EIGENBASE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class EigenBase + * \ingroup Core_Module + * + * Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T). + * + * In other words, an EigenBase object is an object that can be copied into a MatrixBase. + * + * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc. + * + * Notice that this class is trivial, it is only used to disambiguate overloaded functions. + * + * \sa \blank \ref TopicClassHierarchy + */ +template +struct EigenBase { + // typedef typename internal::plain_matrix_type::type PlainObject; + + /** \brief The interface type of indices + * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE. + * \sa StorageIndex, \ref TopicPreprocessorDirectives. + * DEPRECATED: Since Eigen 3.3, its usage is deprecated. Use Eigen::Index instead. + * Deprecation is not marked with a doxygen comment because there are too many existing usages to add the deprecation + * attribute. + */ + typedef Eigen::Index Index; + + // FIXME is it needed? + typedef typename internal::traits::StorageKind StorageKind; + + /** \returns a reference to the derived object */ + EIGEN_DEVICE_FUNC Derived& derived() { return *static_cast(this); } + /** \returns a const reference to the derived object */ + EIGEN_DEVICE_FUNC const Derived& derived() const { return *static_cast(this); } + + EIGEN_DEVICE_FUNC inline Derived& const_cast_derived() const { + return *static_cast(const_cast(this)); + } + EIGEN_DEVICE_FUNC inline const Derived& const_derived() const { return *static_cast(this); } + + /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return derived().rows(); } + /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return derived().cols(); } + /** \returns the number of coefficients, which is rows()*cols(). + * \sa rows(), cols(), SizeAtCompileTime. */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index size() const EIGEN_NOEXCEPT { return rows() * cols(); } + + /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */ + template + EIGEN_DEVICE_FUNC inline void evalTo(Dest& dst) const { + derived().evalTo(dst); + } + + /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */ + template + EIGEN_DEVICE_FUNC inline void addTo(Dest& dst) const { + // This is the default implementation, + // derived class can reimplement it in a more optimized way. + typename Dest::PlainObject res(rows(), cols()); + evalTo(res); + dst += res; + } + + /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */ + template + EIGEN_DEVICE_FUNC inline void subTo(Dest& dst) const { + // This is the default implementation, + // derived class can reimplement it in a more optimized way. + typename Dest::PlainObject res(rows(), cols()); + evalTo(res); + dst -= res; + } + + /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */ + template + EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const { + // This is the default implementation, + // derived class can reimplement it in a more optimized way. + dst = dst * this->derived(); + } + + /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */ + template + EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const { + // This is the default implementation, + // derived class can reimplement it in a more optimized way. + dst = this->derived() * dst; + } +}; + +/*************************************************************************** + * Implementation of matrix base methods + ***************************************************************************/ + +/** \brief Copies the generic expression \a other into *this. + * + * \details The expression must provide a (templated) evalTo(Derived& dst) const + * function which does the actual job. In practice, this allows any user to write + * its own special matrix without having to modify MatrixBase + * + * \returns a reference to *this. + */ +template +template +EIGEN_DEVICE_FUNC Derived& DenseBase::operator=(const EigenBase& other) { + call_assignment(derived(), other.derived()); + return derived(); +} + +template +template +EIGEN_DEVICE_FUNC Derived& DenseBase::operator+=(const EigenBase& other) { + call_assignment(derived(), other.derived(), internal::add_assign_op()); + return derived(); +} + +template +template +EIGEN_DEVICE_FUNC Derived& DenseBase::operator-=(const EigenBase& other) { + call_assignment(derived(), other.derived(), internal::sub_assign_op()); + return derived(); +} + +} // end namespace Eigen + +#endif // EIGEN_EIGENBASE_H diff --git a/dae-cpp/Eigen/src/Core/ForceAlignedAccess.h b/dae-cpp/Eigen/src/Core/ForceAlignedAccess.h new file mode 100644 index 0000000..a91b0da --- /dev/null +++ b/dae-cpp/Eigen/src/Core/ForceAlignedAccess.h @@ -0,0 +1,131 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_FORCEALIGNEDACCESS_H +#define EIGEN_FORCEALIGNEDACCESS_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class ForceAlignedAccess + * \ingroup Core_Module + * + * \brief Enforce aligned packet loads and stores regardless of what is requested + * + * \param ExpressionType the type of the object of which we are forcing aligned packet access + * + * This class is the return type of MatrixBase::forceAlignedAccess() + * and most of the time this is the only way it is used. + * + * \sa MatrixBase::forceAlignedAccess() + */ + +namespace internal { +template +struct traits> : public traits {}; +} // namespace internal + +template +class ForceAlignedAccess : public internal::dense_xpr_base>::type { + public: + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess) + + EIGEN_DEVICE_FUNC explicit inline ForceAlignedAccess(const ExpressionType& matrix) : m_expression(matrix) {} + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { + return m_expression.outerStride(); + } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { + return m_expression.innerStride(); + } + + EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index row, Index col) const { + return m_expression.coeff(row, col); + } + + EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col) { + return m_expression.const_cast_derived().coeffRef(row, col); + } + + EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const { return m_expression.coeff(index); } + + EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index) { return m_expression.const_cast_derived().coeffRef(index); } + + template + inline const PacketScalar packet(Index row, Index col) const { + return m_expression.template packet(row, col); + } + + template + inline void writePacket(Index row, Index col, const PacketScalar& x) { + m_expression.const_cast_derived().template writePacket(row, col, x); + } + + template + inline const PacketScalar packet(Index index) const { + return m_expression.template packet(index); + } + + template + inline void writePacket(Index index, const PacketScalar& x) { + m_expression.const_cast_derived().template writePacket(index, x); + } + + EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; } + + protected: + const ExpressionType& m_expression; + + private: + ForceAlignedAccess& operator=(const ForceAlignedAccess&); +}; + +/** \returns an expression of *this with forced aligned access + * \sa forceAlignedAccessIf(),class ForceAlignedAccess + */ +template +inline const ForceAlignedAccess MatrixBase::forceAlignedAccess() const { + return ForceAlignedAccess(derived()); +} + +/** \returns an expression of *this with forced aligned access + * \sa forceAlignedAccessIf(), class ForceAlignedAccess + */ +template +inline ForceAlignedAccess MatrixBase::forceAlignedAccess() { + return ForceAlignedAccess(derived()); +} + +/** \returns an expression of *this with forced aligned access if \a Enable is true. + * \sa forceAlignedAccess(), class ForceAlignedAccess + */ +template +template +inline add_const_on_value_type_t, Derived&>> +MatrixBase::forceAlignedAccessIf() const { + return derived(); // FIXME This should not work but apparently is never used +} + +/** \returns an expression of *this with forced aligned access if \a Enable is true. + * \sa forceAlignedAccess(), class ForceAlignedAccess + */ +template +template +inline std::conditional_t, Derived&> MatrixBase::forceAlignedAccessIf() { + return derived(); // FIXME This should not work but apparently is never used +} + +} // end namespace Eigen + +#endif // EIGEN_FORCEALIGNEDACCESS_H diff --git a/dae-cpp/Eigen/src/Core/Fuzzy.h b/dae-cpp/Eigen/src/Core/Fuzzy.h new file mode 100644 index 0000000..ed6b4ff --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Fuzzy.h @@ -0,0 +1,132 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2008 Benoit Jacob +// Copyright (C) 2008 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_FUZZY_H +#define EIGEN_FUZZY_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template ::IsInteger> +struct isApprox_selector { + EIGEN_DEVICE_FUNC static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) { + typename internal::nested_eval::type nested(x); + typename internal::nested_eval::type otherNested(y); + return (nested.matrix() - otherNested.matrix()).cwiseAbs2().sum() <= + prec * prec * numext::mini(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum()); + } +}; + +template +struct isApprox_selector { + EIGEN_DEVICE_FUNC static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar&) { + return x.matrix() == y.matrix(); + } +}; + +template ::IsInteger> +struct isMuchSmallerThan_object_selector { + EIGEN_DEVICE_FUNC static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) { + return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum(); + } +}; + +template +struct isMuchSmallerThan_object_selector { + EIGEN_DEVICE_FUNC static bool run(const Derived& x, const OtherDerived&, const typename Derived::RealScalar&) { + return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix(); + } +}; + +template ::IsInteger> +struct isMuchSmallerThan_scalar_selector { + EIGEN_DEVICE_FUNC static bool run(const Derived& x, const typename Derived::RealScalar& y, + const typename Derived::RealScalar& prec) { + return x.cwiseAbs2().sum() <= numext::abs2(prec * y); + } +}; + +template +struct isMuchSmallerThan_scalar_selector { + EIGEN_DEVICE_FUNC static bool run(const Derived& x, const typename Derived::RealScalar&, + const typename Derived::RealScalar&) { + return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix(); + } +}; + +} // end namespace internal + +/** \returns \c true if \c *this is approximately equal to \a other, within the precision + * determined by \a prec. + * + * \note The fuzzy compares are done multiplicatively. Two vectors \f$ v \f$ and \f$ w \f$ + * are considered to be approximately equal within precision \f$ p \f$ if + * \f[ \Vert v - w \Vert \leqslant p\,\min(\Vert v\Vert, \Vert w\Vert). \f] + * For matrices, the comparison is done using the Hilbert-Schmidt norm (aka Frobenius norm + * L2 norm). + * + * \note Because of the multiplicativeness of this comparison, one can't use this function + * to check whether \c *this is approximately equal to the zero matrix or vector. + * Indeed, \c isApprox(zero) returns false unless \c *this itself is exactly the zero matrix + * or vector. If you want to test whether \c *this is zero, use internal::isMuchSmallerThan(const + * RealScalar&, RealScalar) instead. + * + * \sa internal::isMuchSmallerThan(const RealScalar&, RealScalar) const + */ +template +template +EIGEN_DEVICE_FUNC bool DenseBase::isApprox(const DenseBase& other, + const RealScalar& prec) const { + return internal::isApprox_selector::run(derived(), other.derived(), prec); +} + +/** \returns \c true if the norm of \c *this is much smaller than \a other, + * within the precision determined by \a prec. + * + * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is + * considered to be much smaller than \f$ x \f$ within precision \f$ p \f$ if + * \f[ \Vert v \Vert \leqslant p\,\vert x\vert. \f] + * + * For matrices, the comparison is done using the Hilbert-Schmidt norm. For this reason, + * the value of the reference scalar \a other should come from the Hilbert-Schmidt norm + * of a reference matrix of same dimensions. + * + * \sa isApprox(), isMuchSmallerThan(const DenseBase&, RealScalar) const + */ +template +EIGEN_DEVICE_FUNC bool DenseBase::isMuchSmallerThan(const typename NumTraits::Real& other, + const RealScalar& prec) const { + return internal::isMuchSmallerThan_scalar_selector::run(derived(), other, prec); +} + +/** \returns \c true if the norm of \c *this is much smaller than the norm of \a other, + * within the precision determined by \a prec. + * + * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is + * considered to be much smaller than a vector \f$ w \f$ within precision \f$ p \f$ if + * \f[ \Vert v \Vert \leqslant p\,\Vert w\Vert. \f] + * For matrices, the comparison is done using the Hilbert-Schmidt norm. + * + * \sa isApprox(), isMuchSmallerThan(const RealScalar&, RealScalar) const + */ +template +template +EIGEN_DEVICE_FUNC bool DenseBase::isMuchSmallerThan(const DenseBase& other, + const RealScalar& prec) const { + return internal::isMuchSmallerThan_object_selector::run(derived(), other.derived(), prec); +} + +} // end namespace Eigen + +#endif // EIGEN_FUZZY_H diff --git a/dae-cpp/Eigen/src/Core/GeneralProduct.h b/dae-cpp/Eigen/src/Core/GeneralProduct.h new file mode 100644 index 0000000..1220073 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/GeneralProduct.h @@ -0,0 +1,519 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2008 Benoit Jacob +// Copyright (C) 2008-2011 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_GENERAL_PRODUCT_H +#define EIGEN_GENERAL_PRODUCT_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +enum { Large = 2, Small = 3 }; + +// Define the threshold value to fallback from the generic matrix-matrix product +// implementation (heavy) to the lightweight coeff-based product one. +// See generic_product_impl +// in products/GeneralMatrixMatrix.h for more details. +// TODO This threshold should also be used in the compile-time selector below. +#ifndef EIGEN_GEMM_TO_COEFFBASED_THRESHOLD +// This default value has been obtained on a Haswell architecture. +#define EIGEN_GEMM_TO_COEFFBASED_THRESHOLD 20 +#endif + +namespace internal { + +template +struct product_type_selector; + +template +struct product_size_category { + enum { +#ifndef EIGEN_GPU_COMPILE_PHASE + is_large = MaxSize == Dynamic || Size >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD || + (Size == Dynamic && MaxSize >= EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD), +#else + is_large = 0, +#endif + value = is_large ? Large + : Size == 1 ? 1 + : Small + }; +}; + +template +struct product_type { + typedef remove_all_t Lhs_; + typedef remove_all_t Rhs_; + enum { + MaxRows = traits::MaxRowsAtCompileTime, + Rows = traits::RowsAtCompileTime, + MaxCols = traits::MaxColsAtCompileTime, + Cols = traits::ColsAtCompileTime, + MaxDepth = min_size_prefer_fixed(traits::MaxColsAtCompileTime, traits::MaxRowsAtCompileTime), + Depth = min_size_prefer_fixed(traits::ColsAtCompileTime, traits::RowsAtCompileTime) + }; + + // the splitting into different lines of code here, introducing the _select enums and the typedef below, + // is to work around an internal compiler error with gcc 4.1 and 4.2. + private: + enum { + rows_select = product_size_category::value, + cols_select = product_size_category::value, + depth_select = product_size_category::value + }; + typedef product_type_selector selector; + + public: + enum { value = selector::ret, ret = selector::ret }; +#ifdef EIGEN_DEBUG_PRODUCT + static void debug() { + EIGEN_DEBUG_VAR(Rows); + EIGEN_DEBUG_VAR(Cols); + EIGEN_DEBUG_VAR(Depth); + EIGEN_DEBUG_VAR(rows_select); + EIGEN_DEBUG_VAR(cols_select); + EIGEN_DEBUG_VAR(depth_select); + EIGEN_DEBUG_VAR(value); + } +#endif +}; + +/* The following allows to select the kind of product at compile time + * based on the three dimensions of the product. + * This is a compile time mapping from {1,Small,Large}^3 -> {product types} */ +// FIXME I'm not sure the current mapping is the ideal one. +template +struct product_type_selector { + enum { ret = OuterProduct }; +}; +template +struct product_type_selector { + enum { ret = LazyCoeffBasedProductMode }; +}; +template +struct product_type_selector<1, N, 1> { + enum { ret = LazyCoeffBasedProductMode }; +}; +template +struct product_type_selector<1, 1, Depth> { + enum { ret = InnerProduct }; +}; +template <> +struct product_type_selector<1, 1, 1> { + enum { ret = InnerProduct }; +}; +template <> +struct product_type_selector { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector<1, Small, Small> { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = LazyCoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = LazyCoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = LazyCoeffBasedProductMode }; +}; +template <> +struct product_type_selector<1, Large, Small> { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector<1, Large, Large> { + enum { ret = GemvProduct }; +}; +template <> +struct product_type_selector<1, Small, Large> { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = GemvProduct }; +}; +template <> +struct product_type_selector { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = GemmProduct }; +}; +template <> +struct product_type_selector { + enum { ret = GemmProduct }; +}; +template <> +struct product_type_selector { + enum { ret = GemmProduct }; +}; +template <> +struct product_type_selector { + enum { ret = GemmProduct }; +}; +template <> +struct product_type_selector { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = CoeffBasedProductMode }; +}; +template <> +struct product_type_selector { + enum { ret = GemmProduct }; +}; + +} // end namespace internal + +/*********************************************************************** + * Implementation of Inner Vector Vector Product + ***********************************************************************/ + +// FIXME : maybe the "inner product" could return a Scalar +// instead of a 1x1 matrix ?? +// Pro: more natural for the user +// Cons: this could be a problem if in a meta unrolled algorithm a matrix-matrix +// product ends up to a row-vector times col-vector product... To tackle this use +// case, we could have a specialization for Block with: operator=(Scalar x); + +/*********************************************************************** + * Implementation of Outer Vector Vector Product + ***********************************************************************/ + +/*********************************************************************** + * Implementation of General Matrix Vector Product + ***********************************************************************/ + +/* According to the shape/flags of the matrix we have to distinghish 3 different cases: + * 1 - the matrix is col-major, BLAS compatible and M is large => call fast BLAS-like colmajor routine + * 2 - the matrix is row-major, BLAS compatible and N is large => call fast BLAS-like rowmajor routine + * 3 - all other cases are handled using a simple loop along the outer-storage direction. + * Therefore we need a lower level meta selector. + * Furthermore, if the matrix is the rhs, then the product has to be transposed. + */ +namespace internal { + +template +struct gemv_dense_selector; + +} // end namespace internal + +namespace internal { + +template +struct gemv_static_vector_if; + +template +struct gemv_static_vector_if { + EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { + eigen_internal_assert(false && "should never be called"); + return 0; + } +}; + +template +struct gemv_static_vector_if { + EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* data() { return 0; } +}; + +template +struct gemv_static_vector_if { +#if EIGEN_MAX_STATIC_ALIGN_BYTES != 0 + internal::plain_array + m_data; + EIGEN_STRONG_INLINE Scalar* data() { return m_data.array; } +#else + // Some architectures cannot align on the stack, + // => let's manually enforce alignment by allocating more data and return the address of the first aligned element. + internal::plain_array< + Scalar, internal::min_size_prefer_fixed(Size, MaxSize) + EIGEN_MAX_ALIGN_BYTES, 0> + m_data; + EIGEN_STRONG_INLINE Scalar* data() { + return reinterpret_cast((std::uintptr_t(m_data.array) & ~(std::size_t(EIGEN_MAX_ALIGN_BYTES - 1))) + EIGEN_MAX_ALIGN_BYTES); + } +#endif +}; + +// The vector is on the left => transposition +template +struct gemv_dense_selector { + template + static void run(const Lhs& lhs, const Rhs& rhs, Dest& dest, const typename Dest::Scalar& alpha) { + Transpose destT(dest); + enum { OtherStorageOrder = StorageOrder == RowMajor ? ColMajor : RowMajor }; + gemv_dense_selector::run(rhs.transpose(), lhs.transpose(), destT, + alpha); + } +}; + +template <> +struct gemv_dense_selector { + template + static inline void run(const Lhs& lhs, const Rhs& rhs, Dest& dest, const typename Dest::Scalar& alpha) { + typedef typename Lhs::Scalar LhsScalar; + typedef typename Rhs::Scalar RhsScalar; + typedef typename Dest::Scalar ResScalar; + + typedef internal::blas_traits LhsBlasTraits; + typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; + typedef internal::blas_traits RhsBlasTraits; + typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; + + typedef Map, plain_enum_min(AlignedMax, internal::packet_traits::size)> + MappedDest; + + ActualLhsType actualLhs = LhsBlasTraits::extract(lhs); + ActualRhsType actualRhs = RhsBlasTraits::extract(rhs); + + ResScalar actualAlpha = combine_scalar_factors(alpha, lhs, rhs); + + // make sure Dest is a compile-time vector type (bug 1166) + typedef std::conditional_t ActualDest; + + enum { + // FIXME find a way to allow an inner stride on the result if packet_traits::size==1 + // on, the other hand it is good for the cache to pack the vector anyways... + EvalToDestAtCompileTime = (ActualDest::InnerStrideAtCompileTime == 1), + ComplexByReal = (NumTraits::IsComplex) && (!NumTraits::IsComplex), + MightCannotUseDest = ((!EvalToDestAtCompileTime) || ComplexByReal) && (ActualDest::MaxSizeAtCompileTime != 0) + }; + + typedef const_blas_data_mapper LhsMapper; + typedef const_blas_data_mapper RhsMapper; + RhsScalar compatibleAlpha = get_factor::run(actualAlpha); + + if (!MightCannotUseDest) { + // shortcut if we are sure to be able to use dest directly, + // this ease the compiler to generate cleaner and more optimzized code for most common cases + general_matrix_vector_product::run(actualLhs.rows(), actualLhs.cols(), + LhsMapper(actualLhs.data(), + actualLhs.outerStride()), + RhsMapper(actualRhs.data(), + actualRhs.innerStride()), + dest.data(), 1, compatibleAlpha); + } else { + gemv_static_vector_if + static_dest; + + const bool alphaIsCompatible = (!ComplexByReal) || (numext::is_exactly_zero(numext::imag(actualAlpha))); + const bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible; + + ei_declare_aligned_stack_constructed_variable(ResScalar, actualDestPtr, dest.size(), + evalToDest ? dest.data() : static_dest.data()); + + if (!evalToDest) { +#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN + Index size = dest.size(); + EIGEN_DENSE_STORAGE_CTOR_PLUGIN +#endif + if (!alphaIsCompatible) { + MappedDest(actualDestPtr, dest.size()).setZero(); + compatibleAlpha = RhsScalar(1); + } else + MappedDest(actualDestPtr, dest.size()) = dest; + } + + general_matrix_vector_product::run(actualLhs.rows(), actualLhs.cols(), + LhsMapper(actualLhs.data(), + actualLhs.outerStride()), + RhsMapper(actualRhs.data(), + actualRhs.innerStride()), + actualDestPtr, 1, compatibleAlpha); + + if (!evalToDest) { + if (!alphaIsCompatible) + dest.matrix() += actualAlpha * MappedDest(actualDestPtr, dest.size()); + else + dest = MappedDest(actualDestPtr, dest.size()); + } + } + } +}; + +template <> +struct gemv_dense_selector { + template + static void run(const Lhs& lhs, const Rhs& rhs, Dest& dest, const typename Dest::Scalar& alpha) { + typedef typename Lhs::Scalar LhsScalar; + typedef typename Rhs::Scalar RhsScalar; + typedef typename Dest::Scalar ResScalar; + + typedef internal::blas_traits LhsBlasTraits; + typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType; + typedef internal::blas_traits RhsBlasTraits; + typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType; + typedef internal::remove_all_t ActualRhsTypeCleaned; + + std::add_const_t actualLhs = LhsBlasTraits::extract(lhs); + std::add_const_t actualRhs = RhsBlasTraits::extract(rhs); + + ResScalar actualAlpha = combine_scalar_factors(alpha, lhs, rhs); + + enum { + // FIXME find a way to allow an inner stride on the result if packet_traits::size==1 + // on, the other hand it is good for the cache to pack the vector anyways... + DirectlyUseRhs = + ActualRhsTypeCleaned::InnerStrideAtCompileTime == 1 || ActualRhsTypeCleaned::MaxSizeAtCompileTime == 0 + }; + + gemv_static_vector_if + static_rhs; + + ei_declare_aligned_stack_constructed_variable( + RhsScalar, actualRhsPtr, actualRhs.size(), + DirectlyUseRhs ? const_cast(actualRhs.data()) : static_rhs.data()); + + if (!DirectlyUseRhs) { +#ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN + Index size = actualRhs.size(); + EIGEN_DENSE_STORAGE_CTOR_PLUGIN +#endif + Map(actualRhsPtr, actualRhs.size()) = actualRhs; + } + + typedef const_blas_data_mapper LhsMapper; + typedef const_blas_data_mapper RhsMapper; + general_matrix_vector_product:: + run(actualLhs.rows(), actualLhs.cols(), LhsMapper(actualLhs.data(), actualLhs.outerStride()), + RhsMapper(actualRhsPtr, 1), dest.data(), + dest.col(0).innerStride(), // NOTE if dest is not a vector at compile-time, then dest.innerStride() might + // be wrong. (bug 1166) + actualAlpha); + } +}; + +template <> +struct gemv_dense_selector { + template + static void run(const Lhs& lhs, const Rhs& rhs, Dest& dest, const typename Dest::Scalar& alpha) { + EIGEN_STATIC_ASSERT((!nested_eval::Evaluate), + EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE); + // TODO if rhs is large enough it might be beneficial to make sure that dest is sequentially stored in memory, + // otherwise use a temp + typename nested_eval::type actual_rhs(rhs); + const Index size = rhs.rows(); + for (Index k = 0; k < size; ++k) dest += (alpha * actual_rhs.coeff(k)) * lhs.col(k); + } +}; + +template <> +struct gemv_dense_selector { + template + static void run(const Lhs& lhs, const Rhs& rhs, Dest& dest, const typename Dest::Scalar& alpha) { + EIGEN_STATIC_ASSERT((!nested_eval::Evaluate), + EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE); + typename nested_eval::type actual_rhs(rhs); + const Index rows = dest.rows(); + for (Index i = 0; i < rows; ++i) + dest.coeffRef(i) += alpha * (lhs.row(i).cwiseProduct(actual_rhs.transpose())).sum(); + } +}; + +} // end namespace internal + +/*************************************************************************** + * Implementation of matrix base methods + ***************************************************************************/ + +/** \returns the matrix product of \c *this and \a other. + * + * \note If instead of the matrix product you want the coefficient-wise product, see Cwise::operator*(). + * + * \sa lazyProduct(), operator*=(const MatrixBase&), Cwise::operator*() + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Product MatrixBase::operator*( + const MatrixBase& other) const { + // A note regarding the function declaration: In MSVC, this function will sometimes + // not be inlined since DenseStorage is an unwindable object for dynamic + // matrices and product types are holding a member to store the result. + // Thus it does not help tagging this function with EIGEN_STRONG_INLINE. + enum { + ProductIsValid = Derived::ColsAtCompileTime == Dynamic || OtherDerived::RowsAtCompileTime == Dynamic || + int(Derived::ColsAtCompileTime) == int(OtherDerived::RowsAtCompileTime), + AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime, + SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived, OtherDerived) + }; + // note to the lost user: + // * for a dot product use: v1.dot(v2) + // * for a coeff-wise product use: v1.cwiseProduct(v2) + EIGEN_STATIC_ASSERT( + ProductIsValid || !(AreVectors && SameSizes), + INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS) + EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors), + INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION) + EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) +#ifdef EIGEN_DEBUG_PRODUCT + internal::product_type::debug(); +#endif + + return Product(derived(), other.derived()); +} + +/** \returns an expression of the matrix product of \c *this and \a other without implicit evaluation. + * + * The returned product will behave like any other expressions: the coefficients of the product will be + * computed once at a time as requested. This might be useful in some extremely rare cases when only + * a small and no coherent fraction of the result's coefficients have to be computed. + * + * \warning This version of the matrix product can be much much slower. So use it only if you know + * what you are doing and that you measured a true speed improvement. + * + * \sa operator*(const MatrixBase&) + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Product +MatrixBase::lazyProduct(const MatrixBase& other) const { + enum { + ProductIsValid = Derived::ColsAtCompileTime == Dynamic || OtherDerived::RowsAtCompileTime == Dynamic || + int(Derived::ColsAtCompileTime) == int(OtherDerived::RowsAtCompileTime), + AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime, + SameSizes = EIGEN_PREDICATE_SAME_MATRIX_SIZE(Derived, OtherDerived) + }; + // note to the lost user: + // * for a dot product use: v1.dot(v2) + // * for a coeff-wise product use: v1.cwiseProduct(v2) + EIGEN_STATIC_ASSERT( + ProductIsValid || !(AreVectors && SameSizes), + INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS) + EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors), + INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION) + EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) + + return Product(derived(), other.derived()); +} + +} // end namespace Eigen + +#endif // EIGEN_PRODUCT_H diff --git a/dae-cpp/Eigen/src/Core/GenericPacketMath.h b/dae-cpp/Eigen/src/Core/GenericPacketMath.h new file mode 100644 index 0000000..58a197f --- /dev/null +++ b/dae-cpp/Eigen/src/Core/GenericPacketMath.h @@ -0,0 +1,1515 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2006-2008 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_GENERIC_PACKET_MATH_H +#define EIGEN_GENERIC_PACKET_MATH_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +/** \internal + * \file GenericPacketMath.h + * + * Default implementation for types not supported by the vectorization. + * In practice these functions are provided to make easier the writing + * of generic vectorized code. + */ + +#ifndef EIGEN_DEBUG_ALIGNED_LOAD +#define EIGEN_DEBUG_ALIGNED_LOAD +#endif + +#ifndef EIGEN_DEBUG_UNALIGNED_LOAD +#define EIGEN_DEBUG_UNALIGNED_LOAD +#endif + +#ifndef EIGEN_DEBUG_ALIGNED_STORE +#define EIGEN_DEBUG_ALIGNED_STORE +#endif + +#ifndef EIGEN_DEBUG_UNALIGNED_STORE +#define EIGEN_DEBUG_UNALIGNED_STORE +#endif + +struct default_packet_traits { + enum { + // Ops that are implemented for most types. + HasAdd = 1, + HasSub = 1, + HasShift = 1, + HasMul = 1, + HasNegate = 1, + HasAbs = 1, + HasAbs2 = 1, + HasMin = 1, + HasMax = 1, + HasConj = 1, + HasSetLinear = 1, + HasSign = 1, + + HasArg = 0, + HasAbsDiff = 0, + HasBlend = 0, + // This flag is used to indicate whether packet comparison is supported. + // pcmp_eq, pcmp_lt and pcmp_le should be defined for it to be true. + HasCmp = 0, + HasRound = 0, + HasRint = 0, + HasFloor = 0, + HasCeil = 0, + + HasDiv = 0, + HasReciprocal = 0, + HasSqrt = 0, + HasRsqrt = 0, + HasExp = 0, + HasExpm1 = 0, + HasLog = 0, + HasLog1p = 0, + HasLog10 = 0, + HasPow = 0, + HasSin = 0, + HasCos = 0, + HasTan = 0, + HasASin = 0, + HasACos = 0, + HasATan = 0, + HasATanh = 0, + HasSinh = 0, + HasCosh = 0, + HasTanh = 0, + HasLGamma = 0, + HasDiGamma = 0, + HasZeta = 0, + HasPolygamma = 0, + HasErf = 0, + HasErfc = 0, + HasNdtri = 0, + HasBessel = 0, + HasIGamma = 0, + HasIGammaDerA = 0, + HasGammaSampleDerAlpha = 0, + HasIGammac = 0, + HasBetaInc = 0 + }; +}; + +template +struct packet_traits : default_packet_traits { + typedef T type; + typedef T half; + enum { + Vectorizable = 0, + size = 1, + AlignedOnScalar = 0, + }; + enum { + HasAdd = 0, + HasSub = 0, + HasMul = 0, + HasNegate = 0, + HasAbs = 0, + HasAbs2 = 0, + HasMin = 0, + HasMax = 0, + HasConj = 0, + HasSetLinear = 0 + }; +}; + +template +struct packet_traits : packet_traits {}; + +template +struct unpacket_traits { + typedef T type; + typedef T half; + enum { size = 1, alignment = 1, vectorizable = false, masked_load_available = false, masked_store_available = false }; +}; + +template +struct unpacket_traits : unpacket_traits {}; + +/** \internal A convenience utility for determining if the type is a scalar. + * This is used to enable some generic packet implementations. + */ +template +struct is_scalar { + using Scalar = typename unpacket_traits::type; + enum { value = internal::is_same::value }; +}; + +// automatically and succinctly define combinations of pcast when +// 1) the packets are the same type, or +// 2) the packets differ only in sign. +// In both of these cases, preinterpret (bit_cast) is equivalent to pcast (static_cast) +template ::value && is_scalar::value> +struct is_degenerate_helper : is_same {}; +template <> +struct is_degenerate_helper : std::true_type {}; +template <> +struct is_degenerate_helper : std::true_type {}; +template <> +struct is_degenerate_helper : std::true_type {}; +template <> +struct is_degenerate_helper : std::true_type {}; + +template +struct is_degenerate_helper { + using SrcScalar = typename unpacket_traits::type; + static constexpr int SrcSize = unpacket_traits::size; + using TgtScalar = typename unpacket_traits::type; + static constexpr int TgtSize = unpacket_traits::size; + static constexpr bool value = is_degenerate_helper::value && (SrcSize == TgtSize); +}; + +// is_degenerate::value == is_degenerate::value +template +struct is_degenerate { + static constexpr bool value = + is_degenerate_helper::value || is_degenerate_helper::value; +}; + +template +struct is_half { + using Scalar = typename unpacket_traits::type; + static constexpr int Size = unpacket_traits::size; + using DefaultPacket = typename packet_traits::type; + static constexpr int DefaultSize = unpacket_traits::size; + static constexpr bool value = Size < DefaultSize; +}; + +template +struct type_casting_traits { + enum { + VectorizedCast = + is_degenerate::value && packet_traits::Vectorizable && packet_traits::Vectorizable, + SrcCoeffRatio = 1, + TgtCoeffRatio = 1 + }; +}; + +// provides a succint template to define vectorized casting traits with respect to the largest accessible packet types +template +struct vectorized_type_casting_traits { + enum : int { + DefaultSrcPacketSize = packet_traits::size, + DefaultTgtPacketSize = packet_traits::size, + VectorizedCast = 1, + SrcCoeffRatio = plain_enum_max(DefaultTgtPacketSize / DefaultSrcPacketSize, 1), + TgtCoeffRatio = plain_enum_max(DefaultSrcPacketSize / DefaultTgtPacketSize, 1) + }; +}; + +/** \internal Wrapper to ensure that multiple packet types can map to the same + same underlying vector type. */ +template +struct eigen_packet_wrapper { + EIGEN_ALWAYS_INLINE operator T&() { return m_val; } + EIGEN_ALWAYS_INLINE operator const T&() const { return m_val; } + EIGEN_ALWAYS_INLINE eigen_packet_wrapper() = default; + EIGEN_ALWAYS_INLINE eigen_packet_wrapper(const T& v) : m_val(v) {} + EIGEN_ALWAYS_INLINE eigen_packet_wrapper& operator=(const T& v) { + m_val = v; + return *this; + } + + T m_val; +}; + +template ::value> +struct preinterpret_generic; + +template +struct preinterpret_generic { + // the packets are not the same, attempt scalar bit_cast + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Target run(const Packet& a) { + return numext::bit_cast(a); + } +}; + +template +struct preinterpret_generic { + // the packets are the same type: do nothing + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet& a) { return a; } +}; + +/** \internal \returns reinterpret_cast(a) */ +template +EIGEN_DEVICE_FUNC inline Target preinterpret(const Packet& a) { + return preinterpret_generic::run(a); +} + +template ::value, + bool TgtIsHalf = is_half::value> +struct pcast_generic; + +template +struct pcast_generic { + // the packets are not degenerate: attempt scalar static_cast + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket run(const SrcPacket& a) { + return cast_impl::run(a); + } +}; + +template +struct pcast_generic { + // the packets are the same: do nothing + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet& a) { return a; } +}; + +template +struct pcast_generic { + // the packets are degenerate: preinterpret is equivalent to pcast + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket run(const SrcPacket& a) { return preinterpret(a); } +}; + +/** \internal \returns static_cast(a) (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline TgtPacket pcast(const SrcPacket& a) { + return pcast_generic::run(a); +} +template +EIGEN_DEVICE_FUNC inline TgtPacket pcast(const SrcPacket& a, const SrcPacket& b) { + return pcast_generic::run(a, b); +} +template +EIGEN_DEVICE_FUNC inline TgtPacket pcast(const SrcPacket& a, const SrcPacket& b, const SrcPacket& c, + const SrcPacket& d) { + return pcast_generic::run(a, b, c, d); +} +template +EIGEN_DEVICE_FUNC inline TgtPacket pcast(const SrcPacket& a, const SrcPacket& b, const SrcPacket& c, const SrcPacket& d, + const SrcPacket& e, const SrcPacket& f, const SrcPacket& g, + const SrcPacket& h) { + return pcast_generic::run(a, b, c, d, e, f, g, h); +} + +template +struct pcast_generic { + // TgtPacket is a half packet of some other type + // perform cast and truncate result + using DefaultTgtPacket = typename is_half::DefaultPacket; + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket run(const SrcPacket& a) { + return preinterpret(pcast(a)); + } +}; + +/** \internal \returns a + b (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet padd(const Packet& a, const Packet& b) { + return a + b; +} +// Avoid compiler warning for boolean algebra. +template <> +EIGEN_DEVICE_FUNC inline bool padd(const bool& a, const bool& b) { + return a || b; +} + +/** \internal \returns a packet version of \a *from, (un-aligned masked add) + * There is no generic implementation. We only have implementations for specialized + * cases. Generic case should not be called. + */ +template +EIGEN_DEVICE_FUNC inline std::enable_if_t::masked_fpops_available, Packet> padd( + const Packet& a, const Packet& b, typename unpacket_traits::mask_t umask); + +/** \internal \returns a - b (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet psub(const Packet& a, const Packet& b) { + return a - b; +} + +/** \internal \returns -a (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pnegate(const Packet& a) { + return -a; +} + +template <> +EIGEN_DEVICE_FUNC inline bool pnegate(const bool& a) { + return !a; +} + +/** \internal \returns conj(a) (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pconj(const Packet& a) { + return numext::conj(a); +} + +/** \internal \returns a * b (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pmul(const Packet& a, const Packet& b) { + return a * b; +} +// Avoid compiler warning for boolean algebra. +template <> +EIGEN_DEVICE_FUNC inline bool pmul(const bool& a, const bool& b) { + return a && b; +} + +/** \internal \returns a / b (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pdiv(const Packet& a, const Packet& b) { + return a / b; +} + +// In the generic case, memset to all one bits. +template +struct ptrue_impl { + static EIGEN_DEVICE_FUNC inline Packet run(const Packet& /*a*/) { + Packet b; + memset(static_cast(&b), 0xff, sizeof(Packet)); + return b; + } +}; + +// For booleans, we can only directly set a valid `bool` value to avoid UB. +template <> +struct ptrue_impl { + static EIGEN_DEVICE_FUNC inline bool run(const bool& /*a*/) { return true; } +}; + +// For non-trivial scalars, set to Scalar(1) (i.e. a non-zero value). +// Although this is technically not a valid bitmask, the scalar path for pselect +// uses a comparison to zero, so this should still work in most cases. We don't +// have another option, since the scalar type requires initialization. +template +struct ptrue_impl::value && NumTraits::RequireInitialization>> { + static EIGEN_DEVICE_FUNC inline T run(const T& /*a*/) { return T(1); } +}; + +/** \internal \returns one bits. */ +template +EIGEN_DEVICE_FUNC inline Packet ptrue(const Packet& a) { + return ptrue_impl::run(a); +} + +// In the general case, memset to zero. +template +struct pzero_impl { + static EIGEN_DEVICE_FUNC inline Packet run(const Packet& /*a*/) { + Packet b; + memset(static_cast(&b), 0x00, sizeof(Packet)); + return b; + } +}; + +// For scalars, explicitly set to Scalar(0), since the underlying representation +// for zero may not consist of all-zero bits. +template +struct pzero_impl::value>> { + static EIGEN_DEVICE_FUNC inline T run(const T& /*a*/) { return T(0); } +}; + +/** \internal \returns packet of zeros */ +template +EIGEN_DEVICE_FUNC inline Packet pzero(const Packet& a) { + return pzero_impl::run(a); +} + +/** \internal \returns a <= b as a bit mask */ +template +EIGEN_DEVICE_FUNC inline Packet pcmp_le(const Packet& a, const Packet& b) { + return a <= b ? ptrue(a) : pzero(a); +} + +/** \internal \returns a < b as a bit mask */ +template +EIGEN_DEVICE_FUNC inline Packet pcmp_lt(const Packet& a, const Packet& b) { + return a < b ? ptrue(a) : pzero(a); +} + +/** \internal \returns a == b as a bit mask */ +template +EIGEN_DEVICE_FUNC inline Packet pcmp_eq(const Packet& a, const Packet& b) { + return a == b ? ptrue(a) : pzero(a); +} + +/** \internal \returns a < b or a==NaN or b==NaN as a bit mask */ +template +EIGEN_DEVICE_FUNC inline Packet pcmp_lt_or_nan(const Packet& a, const Packet& b) { + return a >= b ? pzero(a) : ptrue(a); +} + +template +struct bit_and { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const { return a & b; } +}; + +template +struct bit_or { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const { return a | b; } +}; + +template +struct bit_xor { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const { return a ^ b; } +}; + +template +struct bit_not { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE T operator()(const T& a) const { return ~a; } +}; + +template <> +struct bit_and { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE bool operator()(const bool& a, const bool& b) const { + return a && b; + } +}; + +template <> +struct bit_or { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE bool operator()(const bool& a, const bool& b) const { + return a || b; + } +}; + +template <> +struct bit_xor { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE bool operator()(const bool& a, const bool& b) const { + return a != b; + } +}; + +template <> +struct bit_not { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR EIGEN_ALWAYS_INLINE bool operator()(const bool& a) const { return !a; } +}; + +// Use operators &, |, ^, ~. +template +struct operator_bitwise_helper { + EIGEN_DEVICE_FUNC static inline T bitwise_and(const T& a, const T& b) { return bit_and()(a, b); } + EIGEN_DEVICE_FUNC static inline T bitwise_or(const T& a, const T& b) { return bit_or()(a, b); } + EIGEN_DEVICE_FUNC static inline T bitwise_xor(const T& a, const T& b) { return bit_xor()(a, b); } + EIGEN_DEVICE_FUNC static inline T bitwise_not(const T& a) { return bit_not()(a); } +}; + +// Apply binary operations byte-by-byte +template +struct bytewise_bitwise_helper { + EIGEN_DEVICE_FUNC static inline T bitwise_and(const T& a, const T& b) { + return binary(a, b, bit_and()); + } + EIGEN_DEVICE_FUNC static inline T bitwise_or(const T& a, const T& b) { return binary(a, b, bit_or()); } + EIGEN_DEVICE_FUNC static inline T bitwise_xor(const T& a, const T& b) { + return binary(a, b, bit_xor()); + } + EIGEN_DEVICE_FUNC static inline T bitwise_not(const T& a) { return unary(a, bit_not()); } + + private: + template + EIGEN_DEVICE_FUNC static inline T unary(const T& a, Op op) { + const unsigned char* a_ptr = reinterpret_cast(&a); + T c; + unsigned char* c_ptr = reinterpret_cast(&c); + for (size_t i = 0; i < sizeof(T); ++i) { + *c_ptr++ = op(*a_ptr++); + } + return c; + } + + template + EIGEN_DEVICE_FUNC static inline T binary(const T& a, const T& b, Op op) { + const unsigned char* a_ptr = reinterpret_cast(&a); + const unsigned char* b_ptr = reinterpret_cast(&b); + T c; + unsigned char* c_ptr = reinterpret_cast(&c); + for (size_t i = 0; i < sizeof(T); ++i) { + *c_ptr++ = op(*a_ptr++, *b_ptr++); + } + return c; + } +}; + +// In the general case, use byte-by-byte manipulation. +template +struct bitwise_helper : public bytewise_bitwise_helper {}; + +// For integers or non-trivial scalars, use binary operators. +template +struct bitwise_helper::value && + (NumTraits::IsInteger || NumTraits::RequireInitialization)>> + : public operator_bitwise_helper {}; + +/** \internal \returns the bitwise and of \a a and \a b */ +template +EIGEN_DEVICE_FUNC inline Packet pand(const Packet& a, const Packet& b) { + return bitwise_helper::bitwise_and(a, b); +} + +/** \internal \returns the bitwise or of \a a and \a b */ +template +EIGEN_DEVICE_FUNC inline Packet por(const Packet& a, const Packet& b) { + return bitwise_helper::bitwise_or(a, b); +} + +/** \internal \returns the bitwise xor of \a a and \a b */ +template +EIGEN_DEVICE_FUNC inline Packet pxor(const Packet& a, const Packet& b) { + return bitwise_helper::bitwise_xor(a, b); +} + +/** \internal \returns the bitwise not of \a a */ +template +EIGEN_DEVICE_FUNC inline Packet pnot(const Packet& a) { + return bitwise_helper::bitwise_not(a); +} + +/** \internal \returns the bitwise and of \a a and not \a b */ +template +EIGEN_DEVICE_FUNC inline Packet pandnot(const Packet& a, const Packet& b) { + return pand(a, pnot(b)); +} + +/** \internal \returns isnan(a) */ +template +EIGEN_DEVICE_FUNC inline Packet pisnan(const Packet& a) { + return pandnot(ptrue(a), pcmp_eq(a, a)); +} + +// In the general case, use bitwise select. +template +struct pselect_impl { + static EIGEN_DEVICE_FUNC inline Packet run(const Packet& mask, const Packet& a, const Packet& b) { + return por(pand(a, mask), pandnot(b, mask)); + } +}; + +// For scalars, use ternary select. +template +struct pselect_impl::value>> { + static EIGEN_DEVICE_FUNC inline Packet run(const Packet& mask, const Packet& a, const Packet& b) { + return numext::equal_strict(mask, Packet(0)) ? b : a; + } +}; + +/** \internal \returns \a or \b for each field in packet according to \mask */ +template +EIGEN_DEVICE_FUNC inline Packet pselect(const Packet& mask, const Packet& a, const Packet& b) { + return pselect_impl::run(mask, a, b); +} + +template <> +EIGEN_DEVICE_FUNC inline bool pselect(const bool& cond, const bool& a, const bool& b) { + return cond ? a : b; +} + +/** \internal \returns the min or of \a a and \a b (coeff-wise) + If either \a a or \a b are NaN, the result is implementation defined. */ +template +struct pminmax_impl { + template + static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) { + return op(a, b); + } +}; + +/** \internal \returns the min or max of \a a and \a b (coeff-wise) + If either \a a or \a b are NaN, NaN is returned. */ +template <> +struct pminmax_impl { + template + static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) { + Packet not_nan_mask_a = pcmp_eq(a, a); + Packet not_nan_mask_b = pcmp_eq(b, b); + return pselect(not_nan_mask_a, pselect(not_nan_mask_b, op(a, b), b), a); + } +}; + +/** \internal \returns the min or max of \a a and \a b (coeff-wise) + If both \a a and \a b are NaN, NaN is returned. + Equivalent to std::fmin(a, b). */ +template <> +struct pminmax_impl { + template + static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a, const Packet& b, Op op) { + Packet not_nan_mask_a = pcmp_eq(a, a); + Packet not_nan_mask_b = pcmp_eq(b, b); + return pselect(not_nan_mask_a, pselect(not_nan_mask_b, op(a, b), a), b); + } +}; + +#define EIGEN_BINARY_OP_NAN_PROPAGATION(Type, Func) [](const Type& a, const Type& b) { return Func(a, b); } + +/** \internal \returns the min of \a a and \a b (coeff-wise). + If \a a or \b b is NaN, the return value is implementation defined. */ +template +EIGEN_DEVICE_FUNC inline Packet pmin(const Packet& a, const Packet& b) { + return numext::mini(a, b); +} + +/** \internal \returns the min of \a a and \a b (coeff-wise). + NaNPropagation determines the NaN propagation semantics. */ +template +EIGEN_DEVICE_FUNC inline Packet pmin(const Packet& a, const Packet& b) { + return pminmax_impl::run(a, b, EIGEN_BINARY_OP_NAN_PROPAGATION(Packet, (pmin))); +} + +/** \internal \returns the max of \a a and \a b (coeff-wise) + If \a a or \b b is NaN, the return value is implementation defined. */ +template +EIGEN_DEVICE_FUNC inline Packet pmax(const Packet& a, const Packet& b) { + return numext::maxi(a, b); +} + +/** \internal \returns the max of \a a and \a b (coeff-wise). + NaNPropagation determines the NaN propagation semantics. */ +template +EIGEN_DEVICE_FUNC inline Packet pmax(const Packet& a, const Packet& b) { + return pminmax_impl::run(a, b, EIGEN_BINARY_OP_NAN_PROPAGATION(Packet, (pmax))); +} + +/** \internal \returns the absolute value of \a a */ +template +EIGEN_DEVICE_FUNC inline Packet pabs(const Packet& a) { + return numext::abs(a); +} +template <> +EIGEN_DEVICE_FUNC inline unsigned int pabs(const unsigned int& a) { + return a; +} +template <> +EIGEN_DEVICE_FUNC inline unsigned long pabs(const unsigned long& a) { + return a; +} +template <> +EIGEN_DEVICE_FUNC inline unsigned long long pabs(const unsigned long long& a) { + return a; +} + +/** \internal \returns the addsub value of \a a,b */ +template +EIGEN_DEVICE_FUNC inline Packet paddsub(const Packet& a, const Packet& b) { + return pselect(peven_mask(a), padd(a, b), psub(a, b)); +} + +/** \internal \returns the phase angle of \a a */ +template +EIGEN_DEVICE_FUNC inline Packet parg(const Packet& a) { + using numext::arg; + return arg(a); +} + +/** \internal \returns \a a arithmetically shifted by N bits to the right */ +template +EIGEN_DEVICE_FUNC inline int parithmetic_shift_right(const int& a) { + return a >> N; +} +template +EIGEN_DEVICE_FUNC inline long int parithmetic_shift_right(const long int& a) { + return a >> N; +} + +/** \internal \returns \a a logically shifted by N bits to the right */ +template +EIGEN_DEVICE_FUNC inline int plogical_shift_right(const int& a) { + return static_cast(static_cast(a) >> N); +} +template +EIGEN_DEVICE_FUNC inline long int plogical_shift_right(const long int& a) { + return static_cast(static_cast(a) >> N); +} + +/** \internal \returns \a a shifted by N bits to the left */ +template +EIGEN_DEVICE_FUNC inline int plogical_shift_left(const int& a) { + return a << N; +} +template +EIGEN_DEVICE_FUNC inline long int plogical_shift_left(const long int& a) { + return a << N; +} + +/** \internal \returns the significant and exponent of the underlying floating point numbers + * See https://en.cppreference.com/w/cpp/numeric/math/frexp + */ +template +EIGEN_DEVICE_FUNC inline Packet pfrexp(const Packet& a, Packet& exponent) { + int exp; + EIGEN_USING_STD(frexp); + Packet result = static_cast(frexp(a, &exp)); + exponent = static_cast(exp); + return result; +} + +/** \internal \returns a * 2^((int)exponent) + * See https://en.cppreference.com/w/cpp/numeric/math/ldexp + */ +template +EIGEN_DEVICE_FUNC inline Packet pldexp(const Packet& a, const Packet& exponent) { + EIGEN_USING_STD(ldexp) + return static_cast(ldexp(a, static_cast(exponent))); +} + +/** \internal \returns the min of \a a and \a b (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pabsdiff(const Packet& a, const Packet& b) { + return pselect(pcmp_lt(a, b), psub(b, a), psub(a, b)); +} + +/** \internal \returns a packet version of \a *from, from must be properly aligned */ +template +EIGEN_DEVICE_FUNC inline Packet pload(const typename unpacket_traits::type* from) { + return *from; +} + +/** \internal \returns n elements of a packet version of \a *from, from must be properly aligned + * offset indicates the starting element in which to load and + * offset + n <= unpacket_traits::size + * All elements before offset and after the last element loaded will initialized with zero */ +template +EIGEN_DEVICE_FUNC inline Packet pload_partial(const typename unpacket_traits::type* from, const Index n, + const Index offset = 0) { + const Index packet_size = unpacket_traits::size; + eigen_assert(n + offset <= packet_size && "number of elements plus offset will read past end of packet"); + typedef typename unpacket_traits::type Scalar; + EIGEN_ALIGN_MAX Scalar elements[packet_size] = {Scalar(0)}; + for (Index i = offset; i < numext::mini(n + offset, packet_size); i++) { + elements[i] = from[i - offset]; + } + return pload(elements); +} + +/** \internal \returns a packet version of \a *from, (un-aligned load) */ +template +EIGEN_DEVICE_FUNC inline Packet ploadu(const typename unpacket_traits::type* from) { + return *from; +} + +/** \internal \returns n elements of a packet version of \a *from, (un-aligned load) + * All elements after the last element loaded will initialized with zero */ +template +EIGEN_DEVICE_FUNC inline Packet ploadu_partial(const typename unpacket_traits::type* from, const Index n, + const Index offset = 0) { + const Index packet_size = unpacket_traits::size; + eigen_assert(n + offset <= packet_size && "number of elements plus offset will read past end of packet"); + typedef typename unpacket_traits::type Scalar; + EIGEN_ALIGN_MAX Scalar elements[packet_size] = {Scalar(0)}; + for (Index i = offset; i < numext::mini(n + offset, packet_size); i++) { + elements[i] = from[i - offset]; + } + return pload(elements); +} + +/** \internal \returns a packet version of \a *from, (un-aligned masked load) + * There is no generic implementation. We only have implementations for specialized + * cases. Generic case should not be called. + */ +template +EIGEN_DEVICE_FUNC inline std::enable_if_t::masked_load_available, Packet> ploadu( + const typename unpacket_traits::type* from, typename unpacket_traits::mask_t umask); + +/** \internal \returns a packet with constant coefficients \a a, e.g.: (a,a,a,a) */ +template +EIGEN_DEVICE_FUNC inline Packet pset1(const typename unpacket_traits::type& a) { + return a; +} + +/** \internal \returns a packet with constant coefficients set from bits */ +template +EIGEN_DEVICE_FUNC inline Packet pset1frombits(BitsType a); + +/** \internal \returns a packet with constant coefficients \a a[0], e.g.: (a[0],a[0],a[0],a[0]) */ +template +EIGEN_DEVICE_FUNC inline Packet pload1(const typename unpacket_traits::type* a) { + return pset1(*a); +} + +/** \internal \returns a packet with elements of \a *from duplicated. + * For instance, for a packet of 8 elements, 4 scalars will be read from \a *from and + * duplicated to form: {from[0],from[0],from[1],from[1],from[2],from[2],from[3],from[3]} + * Currently, this function is only used for scalar * complex products. + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet ploaddup(const typename unpacket_traits::type* from) { + return *from; +} + +/** \internal \returns a packet with elements of \a *from quadrupled. + * For instance, for a packet of 8 elements, 2 scalars will be read from \a *from and + * replicated to form: {from[0],from[0],from[0],from[0],from[1],from[1],from[1],from[1]} + * Currently, this function is only used in matrix products. + * For packet-size smaller or equal to 4, this function is equivalent to pload1 + */ +template +EIGEN_DEVICE_FUNC inline Packet ploadquad(const typename unpacket_traits::type* from) { + return pload1(from); +} + +/** \internal equivalent to + * \code + * a0 = pload1(a+0); + * a1 = pload1(a+1); + * a2 = pload1(a+2); + * a3 = pload1(a+3); + * \endcode + * \sa pset1, pload1, ploaddup, pbroadcast2 + */ +template +EIGEN_DEVICE_FUNC inline void pbroadcast4(const typename unpacket_traits::type* a, Packet& a0, Packet& a1, + Packet& a2, Packet& a3) { + a0 = pload1(a + 0); + a1 = pload1(a + 1); + a2 = pload1(a + 2); + a3 = pload1(a + 3); +} + +/** \internal equivalent to + * \code + * a0 = pload1(a+0); + * a1 = pload1(a+1); + * \endcode + * \sa pset1, pload1, ploaddup, pbroadcast4 + */ +template +EIGEN_DEVICE_FUNC inline void pbroadcast2(const typename unpacket_traits::type* a, Packet& a0, Packet& a1) { + a0 = pload1(a + 0); + a1 = pload1(a + 1); +} + +/** \internal \brief Returns a packet with coefficients (a,a+1,...,a+packet_size-1). */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet plset(const typename unpacket_traits::type& a) { + return a; +} + +/** \internal \returns a packet with constant coefficients \a a, e.g.: (x, 0, x, 0), + where x is the value of all 1-bits. */ +template +EIGEN_DEVICE_FUNC inline Packet peven_mask(const Packet& /*a*/) { + typedef typename unpacket_traits::type Scalar; + const size_t n = unpacket_traits::size; + EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) Scalar elements[n]; + for (size_t i = 0; i < n; ++i) { + memset(elements + i, ((i & 1) == 0 ? 0xff : 0), sizeof(Scalar)); + } + return ploadu(elements); +} + +/** \internal copy the packet \a from to \a *to, \a to must be properly aligned */ +template +EIGEN_DEVICE_FUNC inline void pstore(Scalar* to, const Packet& from) { + (*to) = from; +} + +/** \internal copy n elements of the packet \a from to \a *to, \a to must be properly aligned + * offset indicates the starting element in which to store and + * offset + n <= unpacket_traits::size */ +template +EIGEN_DEVICE_FUNC inline void pstore_partial(Scalar* to, const Packet& from, const Index n, const Index offset = 0) { + const Index packet_size = unpacket_traits::size; + eigen_assert(n + offset <= packet_size && "number of elements plus offset will write past end of packet"); + EIGEN_ALIGN_MAX Scalar elements[packet_size]; + pstore(elements, from); + for (Index i = 0; i < numext::mini(n, packet_size - offset); i++) { + to[i] = elements[i + offset]; + } +} + +/** \internal copy the packet \a from to \a *to, (un-aligned store) */ +template +EIGEN_DEVICE_FUNC inline void pstoreu(Scalar* to, const Packet& from) { + (*to) = from; +} + +/** \internal copy n elements of the packet \a from to \a *to, (un-aligned store) */ +template +EIGEN_DEVICE_FUNC inline void pstoreu_partial(Scalar* to, const Packet& from, const Index n, const Index offset = 0) { + const Index packet_size = unpacket_traits::size; + eigen_assert(n + offset <= packet_size && "number of elements plus offset will write past end of packet"); + EIGEN_ALIGN_MAX Scalar elements[packet_size]; + pstore(elements, from); + for (Index i = 0; i < numext::mini(n, packet_size - offset); i++) { + to[i] = elements[i + offset]; + } +} + +/** \internal copy the packet \a from to \a *to, (un-aligned store with a mask) + * There is no generic implementation. We only have implementations for specialized + * cases. Generic case should not be called. + */ +template +EIGEN_DEVICE_FUNC inline std::enable_if_t::masked_store_available, void> pstoreu( + Scalar* to, const Packet& from, typename unpacket_traits::mask_t umask); + +template +EIGEN_DEVICE_FUNC inline Packet pgather(const Scalar* from, Index /*stride*/) { + return ploadu(from); +} + +template +EIGEN_DEVICE_FUNC inline Packet pgather_partial(const Scalar* from, Index stride, const Index n) { + const Index packet_size = unpacket_traits::size; + EIGEN_ALIGN_MAX Scalar elements[packet_size] = {Scalar(0)}; + for (Index i = 0; i < numext::mini(n, packet_size); i++) { + elements[i] = from[i * stride]; + } + return pload(elements); +} + +template +EIGEN_DEVICE_FUNC inline void pscatter(Scalar* to, const Packet& from, Index /*stride*/) { + pstore(to, from); +} + +template +EIGEN_DEVICE_FUNC inline void pscatter_partial(Scalar* to, const Packet& from, Index stride, const Index n) { + const Index packet_size = unpacket_traits::size; + EIGEN_ALIGN_MAX Scalar elements[packet_size]; + pstore(elements, from); + for (Index i = 0; i < numext::mini(n, packet_size); i++) { + to[i * stride] = elements[i]; + } +} + +/** \internal tries to do cache prefetching of \a addr */ +template +EIGEN_DEVICE_FUNC inline void prefetch(const Scalar* addr) { +#if defined(EIGEN_HIP_DEVICE_COMPILE) + // do nothing +#elif defined(EIGEN_CUDA_ARCH) +#if defined(__LP64__) || EIGEN_OS_WIN64 + // 64-bit pointer operand constraint for inlined asm + asm(" prefetch.L1 [ %1 ];" : "=l"(addr) : "l"(addr)); +#else + // 32-bit pointer operand constraint for inlined asm + asm(" prefetch.L1 [ %1 ];" : "=r"(addr) : "r"(addr)); +#endif +#elif (!EIGEN_COMP_MSVC) && (EIGEN_COMP_GNUC || EIGEN_COMP_CLANG || EIGEN_COMP_ICC) + __builtin_prefetch(addr); +#endif +} + +/** \internal \returns the reversed elements of \a a*/ +template +EIGEN_DEVICE_FUNC inline Packet preverse(const Packet& a) { + return a; +} + +/** \internal \returns \a a with real and imaginary part flipped (for complex type only) */ +template +EIGEN_DEVICE_FUNC inline Packet pcplxflip(const Packet& a) { + return Packet(numext::imag(a), numext::real(a)); +} + +/************************** + * Special math functions + ***************************/ + +/** \internal \returns the sine of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin(const Packet& a) { + EIGEN_USING_STD(sin); + return sin(a); +} + +/** \internal \returns the cosine of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcos(const Packet& a) { + EIGEN_USING_STD(cos); + return cos(a); +} + +/** \internal \returns the tan of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptan(const Packet& a) { + EIGEN_USING_STD(tan); + return tan(a); +} + +/** \internal \returns the arc sine of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasin(const Packet& a) { + EIGEN_USING_STD(asin); + return asin(a); +} + +/** \internal \returns the arc cosine of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pacos(const Packet& a) { + EIGEN_USING_STD(acos); + return acos(a); +} + +/** \internal \returns the hyperbolic sine of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psinh(const Packet& a) { + EIGEN_USING_STD(sinh); + return sinh(a); +} + +/** \internal \returns the hyperbolic cosine of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcosh(const Packet& a) { + EIGEN_USING_STD(cosh); + return cosh(a); +} + +/** \internal \returns the arc tangent of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet patan(const Packet& a) { + EIGEN_USING_STD(atan); + return atan(a); +} + +/** \internal \returns the hyperbolic tan of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptanh(const Packet& a) { + EIGEN_USING_STD(tanh); + return tanh(a); +} + +/** \internal \returns the arc tangent of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet patanh(const Packet& a) { + EIGEN_USING_STD(atanh); + return atanh(a); +} + +/** \internal \returns the exp of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp(const Packet& a) { + EIGEN_USING_STD(exp); + return exp(a); +} + +/** \internal \returns the expm1 of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexpm1(const Packet& a) { + return numext::expm1(a); +} + +/** \internal \returns the log of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog(const Packet& a) { + EIGEN_USING_STD(log); + return log(a); +} + +/** \internal \returns the log1p of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog1p(const Packet& a) { + return numext::log1p(a); +} + +/** \internal \returns the log10 of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog10(const Packet& a) { + EIGEN_USING_STD(log10); + return log10(a); +} + +/** \internal \returns the log10 of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog2(const Packet& a) { + typedef typename internal::unpacket_traits::type Scalar; + return pmul(pset1(Scalar(EIGEN_LOG2E)), plog(a)); +} + +/** \internal \returns the square-root of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psqrt(const Packet& a) { + return numext::sqrt(a); +} + +/** \internal \returns the cube-root of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcbrt(const Packet& a) { + return numext::cbrt(a); +} + +/** \internal \returns the rounded value of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pround(const Packet& a) { + using numext::round; + return round(a); +} + +/** \internal \returns the floor of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pfloor(const Packet& a) { + using numext::floor; + return floor(a); +} + +/** \internal \returns the rounded value of \a a (coeff-wise) with current + * rounding mode */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet print(const Packet& a) { + using numext::rint; + return rint(a); +} + +/** \internal \returns the ceil of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pceil(const Packet& a) { + using numext::ceil; + return ceil(a); +} + +template +struct psign_impl { + static EIGEN_DEVICE_FUNC inline Packet run(const Packet& a) { return numext::sign(a); } +}; + +/** \internal \returns the sign of \a a (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet psign(const Packet& a) { + return psign_impl::run(a); +} + +template <> +EIGEN_DEVICE_FUNC inline bool psign(const bool& a) { + return a; +} + +/** \internal \returns the first element of a packet */ +template +EIGEN_DEVICE_FUNC inline typename unpacket_traits::type pfirst(const Packet& a) { + return a; +} + +/** \internal \returns the sum of the elements of upper and lower half of \a a if \a a is larger than 4. + * For a packet {a0, a1, a2, a3, a4, a5, a6, a7}, it returns a half packet {a0+a4, a1+a5, a2+a6, a3+a7} + * For packet-size smaller or equal to 4, this boils down to a noop. + */ +template +EIGEN_DEVICE_FUNC inline std::conditional_t<(unpacket_traits::size % 8) == 0, + typename unpacket_traits::half, Packet> +predux_half_dowto4(const Packet& a) { + return a; +} + +// Slow generic implementation of Packet reduction. +template +EIGEN_DEVICE_FUNC inline typename unpacket_traits::type predux_helper(const Packet& a, Op op) { + typedef typename unpacket_traits::type Scalar; + const size_t n = unpacket_traits::size; + EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) Scalar elements[n]; + pstoreu(elements, a); + for (size_t k = n / 2; k > 0; k /= 2) { + for (size_t i = 0; i < k; ++i) { + elements[i] = op(elements[i], elements[i + k]); + } + } + return elements[0]; +} + +/** \internal \returns the sum of the elements of \a a*/ +template +EIGEN_DEVICE_FUNC inline typename unpacket_traits::type predux(const Packet& a) { + return a; +} + +/** \internal \returns the product of the elements of \a a */ +template +EIGEN_DEVICE_FUNC inline typename unpacket_traits::type predux_mul(const Packet& a) { + typedef typename unpacket_traits::type Scalar; + return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmul))); +} + +/** \internal \returns the min of the elements of \a a */ +template +EIGEN_DEVICE_FUNC inline typename unpacket_traits::type predux_min(const Packet& a) { + typedef typename unpacket_traits::type Scalar; + return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmin))); +} + +template +EIGEN_DEVICE_FUNC inline typename unpacket_traits::type predux_min(const Packet& a) { + typedef typename unpacket_traits::type Scalar; + return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmin))); +} + +/** \internal \returns the min of the elements of \a a */ +template +EIGEN_DEVICE_FUNC inline typename unpacket_traits::type predux_max(const Packet& a) { + typedef typename unpacket_traits::type Scalar; + return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmax))); +} + +template +EIGEN_DEVICE_FUNC inline typename unpacket_traits::type predux_max(const Packet& a) { + typedef typename unpacket_traits::type Scalar; + return predux_helper(a, EIGEN_BINARY_OP_NAN_PROPAGATION(Scalar, (pmax))); +} + +#undef EIGEN_BINARY_OP_NAN_PROPAGATION + +/** \internal \returns true if all coeffs of \a a means "true" + * It is supposed to be called on values returned by pcmp_*. + */ +// not needed yet +// template EIGEN_DEVICE_FUNC inline bool predux_all(const Packet& a) +// { return bool(a); } + +/** \internal \returns true if any coeffs of \a a means "true" + * It is supposed to be called on values returned by pcmp_*. + */ +template +EIGEN_DEVICE_FUNC inline bool predux_any(const Packet& a) { + // Dirty but generic implementation where "true" is assumed to be non 0 and all the sames. + // It is expected that "true" is either: + // - Scalar(1) + // - bits full of ones (NaN for floats), + // - or first bit equals to 1 (1 for ints, smallest denormal for floats). + // For all these cases, taking the sum is just fine, and this boils down to a no-op for scalars. + typedef typename unpacket_traits::type Scalar; + return numext::not_equal_strict(predux(a), Scalar(0)); +} + +/*************************************************************************** + * The following functions might not have to be overwritten for vectorized types + ***************************************************************************/ + +// FMA instructions. +/** \internal \returns a * b + c (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pmadd(const Packet& a, const Packet& b, const Packet& c) { + return padd(pmul(a, b), c); +} + +/** \internal \returns a * b - c (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pmsub(const Packet& a, const Packet& b, const Packet& c) { + return psub(pmul(a, b), c); +} + +/** \internal \returns -(a * b) + c (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pnmadd(const Packet& a, const Packet& b, const Packet& c) { + return padd(pnegate(pmul(a, b)), c); +} + +/** \internal \returns -(a * b) - c (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet pnmsub(const Packet& a, const Packet& b, const Packet& c) { + return psub(pnegate(pmul(a, b)), c); +} + +/** \internal copy a packet with constant coefficient \a a (e.g., [a,a,a,a]) to \a *to. \a to must be 16 bytes aligned + */ +// NOTE: this function must really be templated on the packet type (think about different packet types for the same +// scalar type) +template +inline void pstore1(typename unpacket_traits::type* to, const typename unpacket_traits::type& a) { + pstore(to, pset1(a)); +} + +/** \internal \returns a packet version of \a *from. + * The pointer \a from must be aligned on a \a Alignment bytes boundary. */ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt(const typename unpacket_traits::type* from) { + if (Alignment >= unpacket_traits::alignment) + return pload(from); + else + return ploadu(from); +} + +/** \internal \returns n elements of a packet version of \a *from. + * The pointer \a from must be aligned on a \a Alignment bytes boundary. */ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt_partial(const typename unpacket_traits::type* from, + const Index n, const Index offset = 0) { + if (Alignment >= unpacket_traits::alignment) + return pload_partial(from, n, offset); + else + return ploadu_partial(from, n, offset); +} + +/** \internal copy the packet \a from to \a *to. + * The pointer \a from must be aligned on a \a Alignment bytes boundary. */ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret(Scalar* to, const Packet& from) { + if (Alignment >= unpacket_traits::alignment) + pstore(to, from); + else + pstoreu(to, from); +} + +/** \internal copy n elements of the packet \a from to \a *to. + * The pointer \a from must be aligned on a \a Alignment bytes boundary. */ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void pstoret_partial(Scalar* to, const Packet& from, const Index n, + const Index offset = 0) { + if (Alignment >= unpacket_traits::alignment) + pstore_partial(to, from, n, offset); + else + pstoreu_partial(to, from, n, offset); +} + +/** \internal \returns a packet version of \a *from. + * Unlike ploadt, ploadt_ro takes advantage of the read-only memory path on the + * hardware if available to speedup the loading of data that won't be modified + * by the current computation. + */ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet ploadt_ro(const typename unpacket_traits::type* from) { + return ploadt(from); +} + +/*************************************************************************** + * Fast complex products (GCC generates a function call which is very slow) + ***************************************************************************/ + +// Eigen+CUDA does not support complexes. +#if !defined(EIGEN_GPUCC) + +template <> +inline std::complex pmul(const std::complex& a, const std::complex& b) { + return std::complex(a.real() * b.real() - a.imag() * b.imag(), a.imag() * b.real() + a.real() * b.imag()); +} + +template <> +inline std::complex pmul(const std::complex& a, const std::complex& b) { + return std::complex(a.real() * b.real() - a.imag() * b.imag(), a.imag() * b.real() + a.real() * b.imag()); +} + +#endif + +/*************************************************************************** + * PacketBlock, that is a collection of N packets where the number of words + * in the packet is a multiple of N. + ***************************************************************************/ +template ::size> +struct PacketBlock { + Packet packet[N]; +}; + +template +EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock& /*kernel*/) { + // Nothing to do in the scalar case, i.e. a 1x1 matrix. +} + +/*************************************************************************** + * Selector, i.e. vector of N boolean values used to select (i.e. blend) + * words from 2 packets. + ***************************************************************************/ +template +struct Selector { + bool select[N]; +}; + +template +EIGEN_DEVICE_FUNC inline Packet pblend(const Selector::size>& ifPacket, + const Packet& thenPacket, const Packet& elsePacket) { + return ifPacket.select[0] ? thenPacket : elsePacket; +} + +/** \internal \returns 1 / a (coeff-wise) */ +template +EIGEN_DEVICE_FUNC inline Packet preciprocal(const Packet& a) { + using Scalar = typename unpacket_traits::type; + return pdiv(pset1(Scalar(1)), a); +} + +/** \internal \returns the reciprocal square-root of \a a (coeff-wise) */ +template +EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet prsqrt(const Packet& a) { + return preciprocal(psqrt(a)); +} + +template ::value, + bool IsInteger = NumTraits::type>::IsInteger> +struct psignbit_impl; +template +struct psignbit_impl { + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static constexpr Packet run(const Packet& a) { return numext::signbit(a); } +}; +template +struct psignbit_impl { + // generic implementation if not specialized in PacketMath.h + // slower than arithmetic shift + typedef typename unpacket_traits::type Scalar; + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static Packet run(const Packet& a) { + const Packet cst_pos_one = pset1(Scalar(1)); + const Packet cst_neg_one = pset1(Scalar(-1)); + return pcmp_eq(por(pand(a, cst_neg_one), cst_pos_one), cst_neg_one); + } +}; +template +struct psignbit_impl { + // generic implementation for integer packets + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static constexpr Packet run(const Packet& a) { return pcmp_lt(a, pzero(a)); } +}; +/** \internal \returns the sign bit of \a a as a bitmask*/ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE constexpr Packet psignbit(const Packet& a) { + return psignbit_impl::run(a); +} + +/** \internal \returns the 2-argument arc tangent of \a y and \a x (coeff-wise) */ +template ::value, int> = 0> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet patan2(const Packet& y, const Packet& x) { + return numext::atan2(y, x); +} + +/** \internal \returns the 2-argument arc tangent of \a y and \a x (coeff-wise) */ +template ::value, int> = 0> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet patan2(const Packet& y, const Packet& x) { + typedef typename internal::unpacket_traits::type Scalar; + + // See https://en.cppreference.com/w/cpp/numeric/math/atan2 + // for how corner cases are supposed to be handled according to the + // IEEE floating-point standard (IEC 60559). + const Packet kSignMask = pset1(-Scalar(0)); + const Packet kZero = pzero(x); + const Packet kOne = pset1(Scalar(1)); + const Packet kPi = pset1(Scalar(EIGEN_PI)); + + const Packet x_has_signbit = psignbit(x); + const Packet y_signmask = pand(y, kSignMask); + const Packet x_signmask = pand(x, kSignMask); + const Packet result_signmask = pxor(y_signmask, x_signmask); + const Packet shift = por(pand(x_has_signbit, kPi), y_signmask); + + const Packet x_and_y_are_same = pcmp_eq(pabs(x), pabs(y)); + const Packet x_and_y_are_zero = pcmp_eq(por(x, y), kZero); + + Packet arg = pdiv(y, x); + arg = pselect(x_and_y_are_same, por(kOne, result_signmask), arg); + arg = pselect(x_and_y_are_zero, result_signmask, arg); + + Packet result = patan(arg); + result = padd(result, shift); + return result; +} + +/** \internal \returns the argument of \a a as a complex number */ +template ::value, int> = 0> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet pcarg(const Packet& a) { + return Packet(numext::arg(a)); +} + +/** \internal \returns the argument of \a a as a complex number */ +template ::value, int> = 0> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet pcarg(const Packet& a) { + EIGEN_STATIC_ASSERT(NumTraits::type>::IsComplex, + THIS METHOD IS FOR COMPLEX TYPES ONLY) + using RealPacket = typename unpacket_traits::as_real; + // a // r i r i ... + RealPacket aflip = pcplxflip(a).v; // i r i r ... + RealPacket result = patan2(aflip, a.v); // atan2 crap atan2 crap ... + return (Packet)pand(result, peven_mask(result)); // atan2 0 atan2 0 ... +} + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_GENERIC_PACKET_MATH_H diff --git a/dae-cpp/Eigen/src/Core/GlobalFunctions.h b/dae-cpp/Eigen/src/Core/GlobalFunctions.h new file mode 100644 index 0000000..f0ae5a8 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/GlobalFunctions.h @@ -0,0 +1,226 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2010-2016 Gael Guennebaud +// Copyright (C) 2010 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_GLOBAL_FUNCTIONS_H +#define EIGEN_GLOBAL_FUNCTIONS_H + +#ifdef EIGEN_PARSED_BY_DOXYGEN + +#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME, FUNCTOR, DOC_OP, DOC_DETAILS) \ + /** \returns an expression of the coefficient-wise DOC_OP of \a x \ + \ \ + DOC_DETAILS \ + \ \ + \sa Math functions, class CwiseUnaryOp \ + */ \ + template \ + inline const Eigen::CwiseUnaryOp, const Derived> NAME( \ + const Eigen::ArrayBase& x); + +#else + +#define EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(NAME, FUNCTOR, DOC_OP, DOC_DETAILS) \ + template \ + inline const Eigen::CwiseUnaryOp, const Derived>(NAME)( \ + const Eigen::ArrayBase& x) { \ + return Eigen::CwiseUnaryOp, const Derived>(x.derived()); \ + } + +#endif // EIGEN_PARSED_BY_DOXYGEN + +#define EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(NAME, FUNCTOR) \ + \ + template \ + struct NAME##_retval > { \ + typedef const Eigen::CwiseUnaryOp, const Derived> type; \ + }; \ + template \ + struct NAME##_impl > { \ + static inline typename NAME##_retval >::type run(const Eigen::ArrayBase& x) { \ + return typename NAME##_retval >::type(x.derived()); \ + } \ + }; + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real, scalar_real_op, real part,\sa ArrayBase::real) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(imag, scalar_imag_op, imaginary part,\sa ArrayBase::imag) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(conj, scalar_conjugate_op, complex conjugate,\sa ArrayBase::conjugate) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(inverse, scalar_inverse_op, inverse,\sa ArrayBase::inverse) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sin, scalar_sin_op, sine,\sa ArrayBase::sin) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cos, scalar_cos_op, cosine,\sa ArrayBase::cos) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tan, scalar_tan_op, tangent,\sa ArrayBase::tan) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atan, scalar_atan_op, arc - tangent,\sa ArrayBase::atan) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asin, scalar_asin_op, arc - sine,\sa ArrayBase::asin) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acos, scalar_acos_op, arc - consine,\sa ArrayBase::acos) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh, scalar_sinh_op, hyperbolic sine,\sa ArrayBase::sinh) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh, scalar_cosh_op, hyperbolic cosine,\sa ArrayBase::cosh) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh, scalar_tanh_op, hyperbolic tangent,\sa ArrayBase::tanh) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asinh, scalar_asinh_op, inverse hyperbolic sine,\sa ArrayBase::asinh) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acosh, scalar_acosh_op, inverse hyperbolic cosine,\sa ArrayBase::acosh) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atanh, scalar_atanh_op, inverse hyperbolic tangent,\sa ArrayBase::atanh) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(logistic, scalar_logistic_op, logistic function,\sa ArrayBase::logistic) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma, scalar_lgamma_op, + natural logarithm of the gamma function,\sa ArrayBase::lgamma) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma, scalar_digamma_op, derivative of lgamma,\sa ArrayBase::digamma) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf, scalar_erf_op, error function,\sa ArrayBase::erf) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erfc, scalar_erfc_op, complement error function,\sa ArrayBase::erfc) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ndtri, scalar_ndtri_op, inverse normal distribution function,\sa ArrayBase::ndtri) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(exp, scalar_exp_op, exponential,\sa ArrayBase::exp) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(expm1, scalar_expm1_op, exponential of a value minus 1,\sa ArrayBase::expm1) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log, scalar_log_op, natural logarithm,\sa Eigen::log10 DOXCOMMA ArrayBase::log) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log1p, scalar_log1p_op, natural logarithm of 1 plus the value,\sa ArrayBase::log1p) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log10, scalar_log10_op, base 10 logarithm,\sa Eigen::log DOXCOMMA ArrayBase::log10) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(log2, scalar_log2_op, base 2 logarithm,\sa Eigen::log DOXCOMMA ArrayBase::log2) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs, scalar_abs_op, absolute value,\sa ArrayBase::abs DOXCOMMA MatrixBase::cwiseAbs) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(abs2, scalar_abs2_op, + squared absolute value,\sa ArrayBase::abs2 DOXCOMMA MatrixBase::cwiseAbs2) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(arg, scalar_arg_op, complex argument,\sa ArrayBase::arg DOXCOMMA MatrixBase::cwiseArg) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(carg, scalar_carg_op, + complex argument, \sa ArrayBase::carg DOXCOMMA MatrixBase::cwiseCArg) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sqrt, scalar_sqrt_op, square root,\sa ArrayBase::sqrt DOXCOMMA MatrixBase::cwiseSqrt) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cbrt, scalar_cbrt_op, cube root,\sa ArrayBase::cbrt DOXCOMMA MatrixBase::cwiseCbrt) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(rsqrt, scalar_rsqrt_op, reciprocal square root,\sa ArrayBase::rsqrt) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(square, scalar_square_op, + square(power 2),\sa Eigen::abs2 DOXCOMMA Eigen::pow DOXCOMMA ArrayBase::square) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cube, scalar_cube_op, cube(power 3),\sa Eigen::pow DOXCOMMA ArrayBase::cube) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(rint, scalar_rint_op, + nearest integer,\sa Eigen::floor DOXCOMMA Eigen::ceil DOXCOMMA ArrayBase::round) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round, scalar_round_op, + nearest integer,\sa Eigen::floor DOXCOMMA Eigen::ceil DOXCOMMA ArrayBase::round) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY( + floor, scalar_floor_op, nearest integer not greater than the giben value,\sa Eigen::ceil DOXCOMMA ArrayBase::floor) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY( + ceil, scalar_ceil_op, nearest integer not less than the giben value,\sa Eigen::floor DOXCOMMA ArrayBase::ceil) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY( + isnan, scalar_isnan_op, not -a - number test,\sa Eigen::isinf DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isnan) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY( + isinf, scalar_isinf_op, infinite value test,\sa Eigen::isnan DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isinf) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite, scalar_isfinite_op, + finite value test,\sa Eigen::isinf DOXCOMMA Eigen::isnan DOXCOMMA ArrayBase::isfinite) +EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sign, scalar_sign_op, sign(or 0),\sa ArrayBase::sign) + +template +using GlobalUnaryPowReturnType = std::enable_if_t< + !internal::is_arithmetic::Real>::value && + internal::is_arithmetic::Real>::value, + CwiseUnaryOp, const Derived> >; + +/** \returns an expression of the coefficient-wise power of \a x to the given constant \a exponent. + * + * \tparam ScalarExponent is the scalar type of \a exponent. It must be compatible with the scalar type of the given + * expression (\c Derived::Scalar). + * + * \sa ArrayBase::pow() + * + * \relates ArrayBase + */ +#ifdef EIGEN_PARSED_BY_DOXYGEN +template +EIGEN_DEVICE_FUNC inline const GlobalUnaryPowReturnType pow(const Eigen::ArrayBase& x, + const ScalarExponent& exponent); +#else +template +EIGEN_DEVICE_FUNC inline const GlobalUnaryPowReturnType pow(const Eigen::ArrayBase& x, + const ScalarExponent& exponent) { + return GlobalUnaryPowReturnType( + x.derived(), internal::scalar_unary_pow_op(exponent)); +} +#endif + +/** \returns an expression of the coefficient-wise power of \a x to the given array of \a exponents. + * + * This function computes the coefficient-wise power. + * + * Example: \include Cwise_array_power_array.cpp + * Output: \verbinclude Cwise_array_power_array.out + * + * \sa ArrayBase::pow() + * + * \relates ArrayBase + */ +template +inline const Eigen::CwiseBinaryOp< + Eigen::internal::scalar_pow_op, const Derived, + const ExponentDerived> +pow(const Eigen::ArrayBase& x, const Eigen::ArrayBase& exponents) { + return Eigen::CwiseBinaryOp< + Eigen::internal::scalar_pow_op, const Derived, + const ExponentDerived>(x.derived(), exponents.derived()); +} + +/** \returns an expression of the coefficient-wise power of the scalar \a x to the given array of \a exponents. + * + * This function computes the coefficient-wise power between a scalar and an array of exponents. + * + * \tparam Scalar is the scalar type of \a x. It must be compatible with the scalar type of the given array expression + * (\c Derived::Scalar). + * + * Example: \include Cwise_scalar_power_array.cpp + * Output: \verbinclude Cwise_scalar_power_array.out + * + * \sa ArrayBase::pow() + * + * \relates ArrayBase + */ +#ifdef EIGEN_PARSED_BY_DOXYGEN +template +inline const CwiseBinaryOp, Constant, Derived> pow( + const Scalar& x, const Eigen::ArrayBase& x); +#else +template +EIGEN_DEVICE_FUNC inline const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE( + typename internal::promote_scalar_arg::type, + Derived, pow) pow(const Scalar& x, const Eigen::ArrayBase& exponents) { + typedef + typename internal::promote_scalar_arg::type + PromotedScalar; + return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedScalar, Derived, pow)( + typename internal::plain_constant_type::type( + exponents.derived().rows(), exponents.derived().cols(), internal::scalar_constant_op(x)), + exponents.derived()); +} +#endif + +/** \returns an expression of the coefficient-wise atan2(\a x, \a y). \a x and \a y must be of the same type. + * + * This function computes the coefficient-wise atan2(). + * + * \sa ArrayBase::atan2() + * + * \relates ArrayBase + */ +template +inline const std::enable_if_t< + std::is_same::value, + Eigen::CwiseBinaryOp, + const LhsDerived, const RhsDerived> > +atan2(const Eigen::ArrayBase& x, const Eigen::ArrayBase& exponents) { + return Eigen::CwiseBinaryOp< + Eigen::internal::scalar_atan2_op, const LhsDerived, + const RhsDerived>(x.derived(), exponents.derived()); +} + +namespace internal { +EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(real, scalar_real_op) +EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(imag, scalar_imag_op) +EIGEN_ARRAY_DECLARE_GLOBAL_EIGEN_UNARY(abs2, scalar_abs2_op) +} // namespace internal +} // namespace Eigen + +// TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, +// internal::isApprox...) + +#endif // EIGEN_GLOBAL_FUNCTIONS_H diff --git a/dae-cpp/Eigen/src/Core/IO.h b/dae-cpp/Eigen/src/Core/IO.h new file mode 100644 index 0000000..ca5f247 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/IO.h @@ -0,0 +1,233 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2008 Benoit Jacob +// Copyright (C) 2008 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_IO_H +#define EIGEN_IO_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +enum { DontAlignCols = 1 }; +enum { StreamPrecision = -1, FullPrecision = -2 }; + +namespace internal { +template +std::ostream& print_matrix(std::ostream& s, const Derived& _m, const IOFormat& fmt); +} + +/** \class IOFormat + * \ingroup Core_Module + * + * \brief Stores a set of parameters controlling the way matrices are printed + * + * List of available parameters: + * - \b precision number of digits for floating point values, or one of the special constants \c StreamPrecision and \c + * FullPrecision. The default is the special value \c StreamPrecision which means to use the stream's own precision + * setting, as set for instance using \c cout.precision(3). The other special value \c FullPrecision means that the + * number of digits will be computed to match the full precision of each floating-point type. + * - \b flags an OR-ed combination of flags, the default value is 0, the only currently available flag is \c + * DontAlignCols which allows to disable the alignment of columns, resulting in faster code. + * - \b coeffSeparator string printed between two coefficients of the same row + * - \b rowSeparator string printed between two rows + * - \b rowPrefix string printed at the beginning of each row + * - \b rowSuffix string printed at the end of each row + * - \b matPrefix string printed at the beginning of the matrix + * - \b matSuffix string printed at the end of the matrix + * - \b fill character printed to fill the empty space in aligned columns + * + * Example: \include IOFormat.cpp + * Output: \verbinclude IOFormat.out + * + * \sa DenseBase::format(), class WithFormat + */ +struct IOFormat { + /** Default constructor, see class IOFormat for the meaning of the parameters */ + IOFormat(int _precision = StreamPrecision, int _flags = 0, const std::string& _coeffSeparator = " ", + const std::string& _rowSeparator = "\n", const std::string& _rowPrefix = "", + const std::string& _rowSuffix = "", const std::string& _matPrefix = "", const std::string& _matSuffix = "", + const char _fill = ' ') + : matPrefix(_matPrefix), + matSuffix(_matSuffix), + rowPrefix(_rowPrefix), + rowSuffix(_rowSuffix), + rowSeparator(_rowSeparator), + rowSpacer(""), + coeffSeparator(_coeffSeparator), + fill(_fill), + precision(_precision), + flags(_flags) { + // TODO check if rowPrefix, rowSuffix or rowSeparator contains a newline + // don't add rowSpacer if columns are not to be aligned + if ((flags & DontAlignCols)) return; + int i = int(matSuffix.length()) - 1; + while (i >= 0 && matSuffix[i] != '\n') { + rowSpacer += ' '; + i--; + } + } + std::string matPrefix, matSuffix; + std::string rowPrefix, rowSuffix, rowSeparator, rowSpacer; + std::string coeffSeparator; + char fill; + int precision; + int flags; +}; + +/** \class WithFormat + * \ingroup Core_Module + * + * \brief Pseudo expression providing matrix output with given format + * + * \tparam ExpressionType the type of the object on which IO stream operations are performed + * + * This class represents an expression with stream operators controlled by a given IOFormat. + * It is the return type of DenseBase::format() + * and most of the time this is the only way it is used. + * + * See class IOFormat for some examples. + * + * \sa DenseBase::format(), class IOFormat + */ +template +class WithFormat { + public: + WithFormat(const ExpressionType& matrix, const IOFormat& format) : m_matrix(matrix), m_format(format) {} + + friend std::ostream& operator<<(std::ostream& s, const WithFormat& wf) { + return internal::print_matrix(s, wf.m_matrix.eval(), wf.m_format); + } + + protected: + typename ExpressionType::Nested m_matrix; + IOFormat m_format; +}; + +namespace internal { + +// NOTE: This helper is kept for backward compatibility with previous code specializing +// this internal::significant_decimals_impl structure. In the future we should directly +// call max_digits10(). +template +struct significant_decimals_impl { + static inline int run() { return NumTraits::max_digits10(); } +}; + +/** \internal + * print the matrix \a _m to the output stream \a s using the output format \a fmt */ +template +std::ostream& print_matrix(std::ostream& s, const Derived& _m, const IOFormat& fmt) { + using internal::is_same; + + if (_m.size() == 0) { + s << fmt.matPrefix << fmt.matSuffix; + return s; + } + + typename Derived::Nested m = _m; + typedef typename Derived::Scalar Scalar; + typedef std::conditional_t::value || is_same::value || + is_same::value || is_same::value, + int, + std::conditional_t >::value || + is_same >::value || + is_same >::value || + is_same >::value, + std::complex, const Scalar&> > + PrintType; + + Index width = 0; + + std::streamsize explicit_precision; + if (fmt.precision == StreamPrecision) { + explicit_precision = 0; + } else if (fmt.precision == FullPrecision) { + if (NumTraits::IsInteger) { + explicit_precision = 0; + } else { + explicit_precision = significant_decimals_impl::run(); + } + } else { + explicit_precision = fmt.precision; + } + + std::streamsize old_precision = 0; + if (explicit_precision) old_precision = s.precision(explicit_precision); + + bool align_cols = !(fmt.flags & DontAlignCols); + if (align_cols) { + // compute the largest width + for (Index j = 0; j < m.cols(); ++j) + for (Index i = 0; i < m.rows(); ++i) { + std::stringstream sstr; + sstr.copyfmt(s); + sstr << static_cast(m.coeff(i, j)); + width = std::max(width, Index(sstr.str().length())); + } + } + std::streamsize old_width = s.width(); + char old_fill_character = s.fill(); + s << fmt.matPrefix; + for (Index i = 0; i < m.rows(); ++i) { + if (i) s << fmt.rowSpacer; + s << fmt.rowPrefix; + if (width) { + s.fill(fmt.fill); + s.width(width); + } + s << static_cast(m.coeff(i, 0)); + for (Index j = 1; j < m.cols(); ++j) { + s << fmt.coeffSeparator; + if (width) { + s.fill(fmt.fill); + s.width(width); + } + s << static_cast(m.coeff(i, j)); + } + s << fmt.rowSuffix; + if (i < m.rows() - 1) s << fmt.rowSeparator; + } + s << fmt.matSuffix; + if (explicit_precision) s.precision(old_precision); + if (width) { + s.fill(old_fill_character); + s.width(old_width); + } + return s; +} + +} // end namespace internal + +/** \relates DenseBase + * + * Outputs the matrix, to the given stream. + * + * If you wish to print the matrix with a format different than the default, use DenseBase::format(). + * + * It is also possible to change the default format by defining EIGEN_DEFAULT_IO_FORMAT before including Eigen headers. + * If not defined, this will automatically be defined to Eigen::IOFormat(), that is the Eigen::IOFormat with default + * parameters. + * + * \sa DenseBase::format() + */ +template +std::ostream& operator<<(std::ostream& s, const DenseBase& m) { + return internal::print_matrix(s, m.eval(), EIGEN_DEFAULT_IO_FORMAT); +} + +template +std::ostream& operator<<(std::ostream& s, const DiagonalBase& m) { + return internal::print_matrix(s, m.derived(), EIGEN_DEFAULT_IO_FORMAT); +} + +} // end namespace Eigen + +#endif // EIGEN_IO_H diff --git a/dae-cpp/Eigen/src/Core/IndexedView.h b/dae-cpp/Eigen/src/Core/IndexedView.h new file mode 100644 index 0000000..b90ecb1 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/IndexedView.h @@ -0,0 +1,316 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2017 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_INDEXED_VIEW_H +#define EIGEN_INDEXED_VIEW_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +struct traits> : traits { + enum { + RowsAtCompileTime = int(array_size::value), + ColsAtCompileTime = int(array_size::value), + MaxRowsAtCompileTime = RowsAtCompileTime, + MaxColsAtCompileTime = ColsAtCompileTime, + + XprTypeIsRowMajor = (int(traits::Flags) & RowMajorBit) != 0, + IsRowMajor = (MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1) ? 1 + : (MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1) ? 0 + : XprTypeIsRowMajor, + + RowIncr = int(get_compile_time_incr::value), + ColIncr = int(get_compile_time_incr::value), + InnerIncr = IsRowMajor ? ColIncr : RowIncr, + OuterIncr = IsRowMajor ? RowIncr : ColIncr, + + HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor), + XprInnerStride = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time::ret) + : int(outer_stride_at_compile_time::ret), + XprOuterstride = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time::ret) + : int(inner_stride_at_compile_time::ret), + + InnerSize = XprTypeIsRowMajor ? ColsAtCompileTime : RowsAtCompileTime, + IsBlockAlike = InnerIncr == 1 && OuterIncr == 1, + IsInnerPannel = HasSameStorageOrderAsXprType && + is_same, std::conditional_t>::value, + + InnerStrideAtCompileTime = + InnerIncr < 0 || InnerIncr == DynamicIndex || XprInnerStride == Dynamic || InnerIncr == UndefinedIncr + ? Dynamic + : XprInnerStride * InnerIncr, + OuterStrideAtCompileTime = + OuterIncr < 0 || OuterIncr == DynamicIndex || XprOuterstride == Dynamic || OuterIncr == UndefinedIncr + ? Dynamic + : XprOuterstride * OuterIncr, + + ReturnAsScalar = is_same::value && is_same::value, + ReturnAsBlock = (!ReturnAsScalar) && IsBlockAlike, + ReturnAsIndexedView = (!ReturnAsScalar) && (!ReturnAsBlock), + + // FIXME we deal with compile-time strides if and only if we have DirectAccessBit flag, + // but this is too strict regarding negative strides... + DirectAccessMask = + (int(InnerIncr) != UndefinedIncr && int(OuterIncr) != UndefinedIncr && InnerIncr >= 0 && OuterIncr >= 0) + ? DirectAccessBit + : 0, + FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, + FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, + FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, + Flags = (traits::Flags & (HereditaryBits | DirectAccessMask)) | FlagsLvalueBit | FlagsRowMajorBit | + FlagsLinearAccessBit + }; + + typedef Block BlockType; +}; + +template +class IndexedViewImpl; + +} // namespace internal + +/** \class IndexedView + * \ingroup Core_Module + * + * \brief Expression of a non-sequential sub-matrix defined by arbitrary sequences of row and column indices + * + * \tparam XprType the type of the expression in which we are taking the intersections of sub-rows and sub-columns + * \tparam RowIndices the type of the object defining the sequence of row indices + * \tparam ColIndices the type of the object defining the sequence of column indices + * + * This class represents an expression of a sub-matrix (or sub-vector) defined as the intersection + * of sub-sets of rows and columns, that are themself defined by generic sequences of row indices \f$ + * \{r_0,r_1,..r_{m-1}\} \f$ and column indices \f$ \{c_0,c_1,..c_{n-1} \}\f$. Let \f$ A \f$ be the nested matrix, then + * the resulting matrix \f$ B \f$ has \c m rows and \c n columns, and its entries are given by: \f$ B(i,j) = A(r_i,c_j) + * \f$. + * + * The \c RowIndices and \c ColIndices types must be compatible with the following API: + * \code + * operator[](Index) const; + * Index size() const; + * \endcode + * + * Typical supported types thus include: + * - std::vector + * - std::valarray + * - std::array + * - Eigen::ArrayXi + * - decltype(ArrayXi::LinSpaced(...)) + * - Any view/expressions of the previous types + * - Eigen::ArithmeticSequence + * - Eigen::internal::AllRange (helper for Eigen::placeholders::all) + * - Eigen::internal::SingleRange (helper for single index) + * - etc. + * + * In typical usages of %Eigen, this class should never be used directly. It is the return type of + * DenseBase::operator()(const RowIndices&, const ColIndices&). + * + * \sa class Block + */ +template +class IndexedView + : public internal::IndexedViewImpl::StorageKind, + (internal::traits>::Flags & + DirectAccessBit) != 0> { + public: + typedef typename internal::IndexedViewImpl< + XprType, RowIndices, ColIndices, typename internal::traits::StorageKind, + (internal::traits>::Flags & DirectAccessBit) != 0> + Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(IndexedView) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedView) + + template + IndexedView(XprType& xpr, const T0& rowIndices, const T1& colIndices) : Base(xpr, rowIndices, colIndices) {} +}; + +namespace internal { + +// Generic API dispatcher +template +class IndexedViewImpl : public internal::generic_xpr_base>::type { + public: + typedef typename internal::generic_xpr_base>::type Base; + typedef typename internal::ref_selector::non_const_type MatrixTypeNested; + typedef internal::remove_all_t NestedExpression; + typedef typename XprType::Scalar Scalar; + + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedViewImpl) + + template + IndexedViewImpl(XprType& xpr, const T0& rowIndices, const T1& colIndices) + : m_xpr(xpr), m_rowIndices(rowIndices), m_colIndices(colIndices) {} + + /** \returns number of rows */ + Index rows() const { return internal::index_list_size(m_rowIndices); } + + /** \returns number of columns */ + Index cols() const { return internal::index_list_size(m_colIndices); } + + /** \returns the nested expression */ + const internal::remove_all_t& nestedExpression() const { return m_xpr; } + + /** \returns the nested expression */ + std::remove_reference_t& nestedExpression() { return m_xpr; } + + /** \returns a const reference to the object storing/generating the row indices */ + const RowIndices& rowIndices() const { return m_rowIndices; } + + /** \returns a const reference to the object storing/generating the column indices */ + const ColIndices& colIndices() const { return m_colIndices; } + + constexpr Scalar& coeffRef(Index rowId, Index colId) { + return nestedExpression().coeffRef(m_rowIndices[rowId], m_colIndices[colId]); + } + + constexpr const Scalar& coeffRef(Index rowId, Index colId) const { + return nestedExpression().coeffRef(m_rowIndices[rowId], m_colIndices[colId]); + } + + protected: + MatrixTypeNested m_xpr; + RowIndices m_rowIndices; + ColIndices m_colIndices; +}; + +template +class IndexedViewImpl + : public IndexedViewImpl { + public: + using Base = internal::IndexedViewImpl::StorageKind, false>; + using Derived = IndexedView; + + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedViewImpl) + + template + IndexedViewImpl(XprType& xpr, const T0& rowIndices, const T1& colIndices) : Base(xpr, rowIndices, colIndices) {} + + Index rowIncrement() const { + if (traits::RowIncr != DynamicIndex && traits::RowIncr != UndefinedIncr) { + return traits::RowIncr; + } + return get_runtime_incr(this->rowIndices()); + } + Index colIncrement() const { + if (traits::ColIncr != DynamicIndex && traits::ColIncr != UndefinedIncr) { + return traits::ColIncr; + } + return get_runtime_incr(this->colIndices()); + } + + Index innerIncrement() const { return traits::IsRowMajor ? colIncrement() : rowIncrement(); } + + Index outerIncrement() const { return traits::IsRowMajor ? rowIncrement() : colIncrement(); } + + std::decay_t* data() { + Index row_offset = this->rowIndices()[0] * this->nestedExpression().rowStride(); + Index col_offset = this->colIndices()[0] * this->nestedExpression().colStride(); + return this->nestedExpression().data() + row_offset + col_offset; + } + + const std::decay_t* data() const { + Index row_offset = this->rowIndices()[0] * this->nestedExpression().rowStride(); + Index col_offset = this->colIndices()[0] * this->nestedExpression().colStride(); + return this->nestedExpression().data() + row_offset + col_offset; + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { + if (traits::InnerStrideAtCompileTime != Dynamic) { + return traits::InnerStrideAtCompileTime; + } + return innerIncrement() * this->nestedExpression().innerStride(); + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { + if (traits::OuterStrideAtCompileTime != Dynamic) { + return traits::OuterStrideAtCompileTime; + } + return outerIncrement() * this->nestedExpression().outerStride(); + } +}; + +template +struct unary_evaluator, IndexBased> + : evaluator_base> { + typedef IndexedView XprType; + + enum { + CoeffReadCost = evaluator::CoeffReadCost /* TODO + cost of row/col index */, + + FlagsLinearAccessBit = + (traits::RowsAtCompileTime == 1 || traits::ColsAtCompileTime == 1) ? LinearAccessBit : 0, + + FlagsRowMajorBit = traits::FlagsRowMajorBit, + + Flags = (evaluator::Flags & (HereditaryBits & ~RowMajorBit /*| LinearAccessBit | DirectAccessBit*/)) | + FlagsLinearAccessBit | FlagsRowMajorBit, + + Alignment = 0 + }; + + EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr) { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { + eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() && + m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols()); + return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() && + m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols()); + return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + Index row = XprType::RowsAtCompileTime == 1 ? 0 : index; + Index col = XprType::RowsAtCompileTime == 1 ? index : 0; + eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() && + m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols()); + return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeffRef(Index index) const { + Index row = XprType::RowsAtCompileTime == 1 ? 0 : index; + Index col = XprType::RowsAtCompileTime == 1 ? index : 0; + eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() && + m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols()); + return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index index) const { + Index row = XprType::RowsAtCompileTime == 1 ? 0 : index; + Index col = XprType::RowsAtCompileTime == 1 ? index : 0; + eigen_assert(m_xpr.rowIndices()[row] >= 0 && m_xpr.rowIndices()[row] < m_xpr.nestedExpression().rows() && + m_xpr.colIndices()[col] >= 0 && m_xpr.colIndices()[col] < m_xpr.nestedExpression().cols()); + return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]); + } + + protected: + evaluator m_argImpl; + const XprType& m_xpr; +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_INDEXED_VIEW_H diff --git a/dae-cpp/Eigen/src/Core/InternalHeaderCheck.h b/dae-cpp/Eigen/src/Core/InternalHeaderCheck.h new file mode 100644 index 0000000..1cea572 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/InternalHeaderCheck.h @@ -0,0 +1,3 @@ +#ifndef EIGEN_CORE_MODULE_H +#error "Please include Eigen/Core instead of including headers inside the src directory directly." +#endif diff --git a/dae-cpp/Eigen/src/Core/Inverse.h b/dae-cpp/Eigen/src/Core/Inverse.h new file mode 100644 index 0000000..cfb3b20 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Inverse.h @@ -0,0 +1,108 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2014-2019 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_INVERSE_H +#define EIGEN_INVERSE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +template +class InverseImpl; + +namespace internal { + +template +struct traits > : traits { + typedef typename XprType::PlainObject PlainObject; + typedef traits BaseTraits; + enum { Flags = BaseTraits::Flags & RowMajorBit }; +}; + +} // end namespace internal + +/** \class Inverse + * + * \brief Expression of the inverse of another expression + * + * \tparam XprType the type of the expression we are taking the inverse + * + * This class represents an abstract expression of A.inverse() + * and most of the time this is the only way it is used. + * + */ +template +class Inverse : public InverseImpl::StorageKind> { + public: + typedef typename XprType::StorageIndex StorageIndex; + typedef typename XprType::Scalar Scalar; + typedef typename internal::ref_selector::type XprTypeNested; + typedef internal::remove_all_t XprTypeNestedCleaned; + typedef typename internal::ref_selector::type Nested; + typedef internal::remove_all_t NestedExpression; + + explicit EIGEN_DEVICE_FUNC Inverse(const XprType& xpr) : m_xpr(xpr) {} + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_xpr.cols(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_xpr.rows(); } + + EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; } + + protected: + XprTypeNested m_xpr; +}; + +// Generic API dispatcher +template +class InverseImpl : public internal::generic_xpr_base >::type { + public: + typedef typename internal::generic_xpr_base >::type Base; + typedef typename XprType::Scalar Scalar; + + private: + Scalar coeff(Index row, Index col) const; + Scalar coeff(Index i) const; +}; + +namespace internal { + +/** \internal + * \brief Default evaluator for Inverse expression. + * + * This default evaluator for Inverse expression simply evaluate the inverse into a temporary + * by a call to internal::call_assignment_no_alias. + * Therefore, inverse implementers only have to specialize Assignment, ...> for + * there own nested expression. + * + * \sa class Inverse + */ +template +struct unary_evaluator > : public evaluator::PlainObject> { + typedef Inverse InverseType; + typedef typename InverseType::PlainObject PlainObject; + typedef evaluator Base; + + enum { Flags = Base::Flags | EvalBeforeNestingBit }; + + unary_evaluator(const InverseType& inv_xpr) : m_result(inv_xpr.rows(), inv_xpr.cols()) { + internal::construct_at(this, m_result); + internal::call_assignment_no_alias(m_result, inv_xpr); + } + + protected: + PlainObject m_result; +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_INVERSE_H diff --git a/dae-cpp/Eigen/src/Core/Map.h b/dae-cpp/Eigen/src/Core/Map.h new file mode 100644 index 0000000..df7b7ca --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Map.h @@ -0,0 +1,153 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2007-2010 Benoit Jacob +// Copyright (C) 2008 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_MAP_H +#define EIGEN_MAP_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits > : public traits { + typedef traits TraitsBase; + enum { + PlainObjectTypeInnerSize = ((traits::Flags & RowMajorBit) == RowMajorBit) + ? PlainObjectType::ColsAtCompileTime + : PlainObjectType::RowsAtCompileTime, + + InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0 + ? int(PlainObjectType::InnerStrideAtCompileTime) + : int(StrideType::InnerStrideAtCompileTime), + OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0 + ? (InnerStrideAtCompileTime == Dynamic || PlainObjectTypeInnerSize == Dynamic + ? Dynamic + : int(InnerStrideAtCompileTime) * int(PlainObjectTypeInnerSize)) + : int(StrideType::OuterStrideAtCompileTime), + Alignment = int(MapOptions) & int(AlignedMask), + Flags0 = TraitsBase::Flags & (~NestByRefBit), + Flags = is_lvalue::value ? int(Flags0) : (int(Flags0) & ~LvalueBit) + }; + + private: + enum { Options }; // Expressions don't have Options +}; +} // namespace internal + +/** \class Map + * \ingroup Core_Module + * + * \brief A matrix or vector expression mapping an existing array of data. + * + * \tparam PlainObjectType the equivalent matrix type of the mapped data + * \tparam MapOptions specifies the pointer alignment in bytes. It can be: \c #Aligned128, \c #Aligned64, \c #Aligned32, + * \c #Aligned16, \c #Aligned8 or \c #Unaligned. The default is \c #Unaligned. \tparam StrideType optionally specifies + * strides. By default, Map assumes the memory layout of an ordinary, contiguous array. This can be overridden by + * specifying strides. The type passed here must be a specialization of the Stride template, see examples below. + * + * This class represents a matrix or vector expression mapping an existing array of data. + * It can be used to let Eigen interface without any overhead with non-Eigen data structures, + * such as plain C arrays or structures from other libraries. By default, it assumes that the + * data is laid out contiguously in memory. You can however override this by explicitly specifying + * inner and outer strides. + * + * Here's an example of simply mapping a contiguous array as a \ref TopicStorageOrders "column-major" matrix: + * \include Map_simple.cpp + * Output: \verbinclude Map_simple.out + * + * If you need to map non-contiguous arrays, you can do so by specifying strides: + * + * Here's an example of mapping an array as a vector, specifying an inner stride, that is, the pointer + * increment between two consecutive coefficients. Here, we're specifying the inner stride as a compile-time + * fixed value. + * \include Map_inner_stride.cpp + * Output: \verbinclude Map_inner_stride.out + * + * Here's an example of mapping an array while specifying an outer stride. Here, since we're mapping + * as a column-major matrix, 'outer stride' means the pointer increment between two consecutive columns. + * Here, we're specifying the outer stride as a runtime parameter. Note that here \c OuterStride<> is + * a short version of \c OuterStride because the default template parameter of OuterStride + * is \c Dynamic + * \include Map_outer_stride.cpp + * Output: \verbinclude Map_outer_stride.out + * + * For more details and for an example of specifying both an inner and an outer stride, see class Stride. + * + * \b Tip: to change the array of data mapped by a Map object, you can use the C++ + * placement new syntax: + * + * Example: \include Map_placement_new.cpp + * Output: \verbinclude Map_placement_new.out + * + * This class is the return type of PlainObjectBase::Map() but can also be used directly. + * + * \sa PlainObjectBase::Map(), \ref TopicStorageOrders + */ +template +class Map : public MapBase > { + public: + typedef MapBase Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Map) + + typedef typename Base::PointerType PointerType; + typedef PointerType PointerArgType; + EIGEN_DEVICE_FUNC inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const { + return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1; + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const { + return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer() + : internal::traits::OuterStrideAtCompileTime != Dynamic + ? Index(internal::traits::OuterStrideAtCompileTime) + : IsVectorAtCompileTime ? (this->size() * innerStride()) + : int(Flags) & RowMajorBit ? (this->cols() * innerStride()) + : (this->rows() * innerStride()); + } + + /** Constructor in the fixed-size case. + * + * \param dataPtr pointer to the array to map + * \param stride optional Stride object, passing the strides. + */ + EIGEN_DEVICE_FUNC explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType()) + : Base(cast_to_pointer_type(dataPtr)), m_stride(stride) {} + + /** Constructor in the dynamic-size vector case. + * + * \param dataPtr pointer to the array to map + * \param size the size of the vector expression + * \param stride optional Stride object, passing the strides. + */ + EIGEN_DEVICE_FUNC inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType()) + : Base(cast_to_pointer_type(dataPtr), size), m_stride(stride) {} + + /** Constructor in the dynamic-size matrix case. + * + * \param dataPtr pointer to the array to map + * \param rows the number of rows of the matrix expression + * \param cols the number of columns of the matrix expression + * \param stride optional Stride object, passing the strides. + */ + EIGEN_DEVICE_FUNC inline Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType& stride = StrideType()) + : Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride) {} + + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map) + + protected: + StrideType m_stride; +}; + +} // end namespace Eigen + +#endif // EIGEN_MAP_H diff --git a/dae-cpp/Eigen/src/Core/MapBase.h b/dae-cpp/Eigen/src/Core/MapBase.h new file mode 100644 index 0000000..da95b5c --- /dev/null +++ b/dae-cpp/Eigen/src/Core/MapBase.h @@ -0,0 +1,283 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2007-2010 Benoit Jacob +// Copyright (C) 2008 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_MAPBASE_H +#define EIGEN_MAPBASE_H + +#define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \ + EIGEN_STATIC_ASSERT((int(internal::evaluator::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \ + YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT) + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \ingroup Core_Module + * + * \brief Base class for dense Map and Block expression with direct access + * + * This base class provides the const low-level accessors (e.g. coeff, coeffRef) of dense + * Map and Block objects with direct access. + * Typical users do not have to directly deal with this class. + * + * This class can be extended by through the macro plugin \c EIGEN_MAPBASE_PLUGIN. + * See \link TopicCustomizing_Plugins customizing Eigen \endlink for details. + * + * The \c Derived class has to provide the following two methods describing the memory layout: + * \code Index innerStride() const; \endcode + * \code Index outerStride() const; \endcode + * + * \sa class Map, class Block + */ +template +class MapBase : public internal::dense_xpr_base::type { + public: + typedef typename internal::dense_xpr_base::type Base; + enum { + RowsAtCompileTime = internal::traits::RowsAtCompileTime, + ColsAtCompileTime = internal::traits::ColsAtCompileTime, + InnerStrideAtCompileTime = internal::traits::InnerStrideAtCompileTime, + SizeAtCompileTime = Base::SizeAtCompileTime + }; + + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::Scalar Scalar; + typedef typename internal::packet_traits::type PacketScalar; + typedef typename NumTraits::Real RealScalar; + typedef std::conditional_t::value), Scalar*, const Scalar*> PointerType; + + using Base::derived; + // using Base::RowsAtCompileTime; + // using Base::ColsAtCompileTime; + // using Base::SizeAtCompileTime; + using Base::Flags; + using Base::IsRowMajor; + using Base::IsVectorAtCompileTime; + using Base::MaxColsAtCompileTime; + using Base::MaxRowsAtCompileTime; + using Base::MaxSizeAtCompileTime; + + using Base::coeff; + using Base::coeffRef; + using Base::cols; + using Base::eval; + using Base::lazyAssign; + using Base::rows; + using Base::size; + + using Base::colStride; + using Base::innerStride; + using Base::outerStride; + using Base::rowStride; + + // bug 217 - compile error on ICC 11.1 + using Base::operator=; + + typedef typename Base::CoeffReturnType CoeffReturnType; + + /** \copydoc DenseBase::rows() */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_rows.value(); } + /** \copydoc DenseBase::cols() */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_cols.value(); } + + /** Returns a pointer to the first coefficient of the matrix or vector. + * + * \note When addressing this data, make sure to honor the strides returned by innerStride() and outerStride(). + * + * \sa innerStride(), outerStride() + */ + EIGEN_DEVICE_FUNC inline const Scalar* data() const { return m_data; } + + /** \copydoc PlainObjectBase::coeff(Index,Index) const */ + EIGEN_DEVICE_FUNC inline const Scalar& coeff(Index rowId, Index colId) const { + return m_data[colId * colStride() + rowId * rowStride()]; + } + + /** \copydoc PlainObjectBase::coeff(Index) const */ + EIGEN_DEVICE_FUNC inline const Scalar& coeff(Index index) const { + EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) + return m_data[index * innerStride()]; + } + + /** \copydoc PlainObjectBase::coeffRef(Index,Index) const */ + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const { + return this->m_data[colId * colStride() + rowId * rowStride()]; + } + + /** \copydoc PlainObjectBase::coeffRef(Index) const */ + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { + EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) + return this->m_data[index * innerStride()]; + } + + /** \internal */ + template + inline PacketScalar packet(Index rowId, Index colId) const { + return internal::ploadt(m_data + (colId * colStride() + rowId * rowStride())); + } + + /** \internal */ + template + inline PacketScalar packet(Index index) const { + EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) + return internal::ploadt(m_data + index * innerStride()); + } + + /** \internal Constructor for fixed size matrices or vectors */ + EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) + : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime) { + EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) + checkSanity(); + } + + /** \internal Constructor for dynamically sized vectors */ + EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) + : m_data(dataPtr), + m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)), + m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime)) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + eigen_assert(vecSize >= 0); + eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize); + checkSanity(); + } + + /** \internal Constructor for dynamically sized matrices */ + EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) + : m_data(dataPtr), m_rows(rows), m_cols(cols) { + eigen_assert((dataPtr == 0) || (rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) && + cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols))); + checkSanity(); + } + +#ifdef EIGEN_MAPBASE_PLUGIN +#include EIGEN_MAPBASE_PLUGIN +#endif + + protected: + EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase) + EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase) + + template + EIGEN_DEVICE_FUNC void checkSanity(std::enable_if_t<(internal::traits::Alignment > 0), void*> = 0) const { +// Temporary macro to allow scalars to not be properly aligned. This is while we sort out failures +// in TensorFlow Lite that are currently relying on this UB. +#ifndef EIGEN_ALLOW_UNALIGNED_SCALARS + // Pointer must be aligned to the Scalar type, otherwise we get UB. + eigen_assert((std::uintptr_t(m_data) % alignof(Scalar) == 0) && "data is not scalar-aligned"); +#endif +#if EIGEN_MAX_ALIGN_BYTES > 0 + // innerStride() is not set yet when this function is called, so we optimistically assume the lowest plausible + // value: + const Index minInnerStride = InnerStrideAtCompileTime == Dynamic ? 1 : Index(InnerStrideAtCompileTime); + EIGEN_ONLY_USED_FOR_DEBUG(minInnerStride); + eigen_assert((((std::uintptr_t(m_data) % internal::traits::Alignment) == 0) || + (cols() * rows() * minInnerStride * sizeof(Scalar)) < internal::traits::Alignment) && + "data is not aligned"); +#endif + } + + template + EIGEN_DEVICE_FUNC void checkSanity(std::enable_if_t::Alignment == 0, void*> = 0) const { +#ifndef EIGEN_ALLOW_UNALIGNED_SCALARS + // Pointer must be aligned to the Scalar type, otherwise we get UB. + eigen_assert((std::uintptr_t(m_data) % alignof(Scalar) == 0) && "data is not scalar-aligned"); +#endif + } + + PointerType m_data; + const internal::variable_if_dynamic m_rows; + const internal::variable_if_dynamic m_cols; +}; + +/** \ingroup Core_Module + * + * \brief Base class for non-const dense Map and Block expression with direct access + * + * This base class provides the non-const low-level accessors (e.g. coeff and coeffRef) of + * dense Map and Block objects with direct access. + * It inherits MapBase which defines the const variant for reading specific entries. + * + * \sa class Map, class Block + */ +template +class MapBase : public MapBase { + typedef MapBase ReadOnlyMapBase; + + public: + typedef MapBase Base; + + typedef typename Base::Scalar Scalar; + typedef typename Base::PacketScalar PacketScalar; + typedef typename Base::StorageIndex StorageIndex; + typedef typename Base::PointerType PointerType; + + using Base::coeff; + using Base::coeffRef; + using Base::cols; + using Base::derived; + using Base::rows; + using Base::size; + + using Base::colStride; + using Base::innerStride; + using Base::outerStride; + using Base::rowStride; + + typedef std::conditional_t::value, Scalar, const Scalar> ScalarWithConstIfNotLvalue; + + EIGEN_DEVICE_FUNC inline const Scalar* data() const { return this->m_data; } + EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue* data() { + return this->m_data; + } // no const-cast here so non-const-correct code will give a compile error + + EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col) { + return this->m_data[col * colStride() + row * rowStride()]; + } + + EIGEN_DEVICE_FUNC inline ScalarWithConstIfNotLvalue& coeffRef(Index index) { + EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) + return this->m_data[index * innerStride()]; + } + + template + inline void writePacket(Index row, Index col, const PacketScalar& val) { + internal::pstoret(this->m_data + (col * colStride() + row * rowStride()), val); + } + + template + inline void writePacket(Index index, const PacketScalar& val) { + EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) + internal::pstoret(this->m_data + index * innerStride(), val); + } + + EIGEN_DEVICE_FUNC explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {} + EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {} + EIGEN_DEVICE_FUNC inline MapBase(PointerType dataPtr, Index rows, Index cols) : Base(dataPtr, rows, cols) {} + + EIGEN_DEVICE_FUNC Derived& operator=(const MapBase& other) { + ReadOnlyMapBase::Base::operator=(other); + return derived(); + } + + // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base, + // see bugs 821 and 920. + using ReadOnlyMapBase::Base::operator=; + + protected: + EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase) + EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase) +}; + +#undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS + +} // end namespace Eigen + +#endif // EIGEN_MAPBASE_H diff --git a/dae-cpp/Eigen/src/Core/MathFunctions.h b/dae-cpp/Eigen/src/Core/MathFunctions.h new file mode 100644 index 0000000..3f28068 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/MathFunctions.h @@ -0,0 +1,2047 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2010 Benoit Jacob +// Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_MATHFUNCTIONS_H +#define EIGEN_MATHFUNCTIONS_H + +// TODO this should better be moved to NumTraits +// Source: WolframAlpha +#define EIGEN_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406L +#define EIGEN_LOG2E 1.442695040888963407359924681001892137426645954152985934135449406931109219L +#define EIGEN_LN2 0.693147180559945309417232121458176568075500134360255254120680009493393621L + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +/** \internal \class global_math_functions_filtering_base + * + * What it does: + * Defines a typedef 'type' as follows: + * - if type T has a member typedef Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl, then + * global_math_functions_filtering_base::type is a typedef for it. + * - otherwise, global_math_functions_filtering_base::type is a typedef for T. + * + * How it's used: + * To allow to defined the global math functions (like sin...) in certain cases, like the Array expressions. + * When you do sin(array1+array2), the object array1+array2 has a complicated expression type, all what you want to know + * is that it inherits ArrayBase. So we implement a partial specialization of sin_impl for ArrayBase. + * So we must make sure to use sin_impl > and not sin_impl, otherwise our partial + * specialization won't be used. How does sin know that? That's exactly what global_math_functions_filtering_base tells + * it. + * + * How it's implemented: + * SFINAE in the style of enable_if. Highly susceptible of breaking compilers. With GCC, it sure does work, but if you + * replace the typename dummy by an integer template parameter, it doesn't work anymore! + */ + +template +struct global_math_functions_filtering_base { + typedef T type; +}; + +template +struct always_void { + typedef void type; +}; + +template +struct global_math_functions_filtering_base< + T, typename always_void::type> { + typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type; +}; + +#define EIGEN_MATHFUNC_IMPL(func, scalar) \ + Eigen::internal::func##_impl::type> +#define EIGEN_MATHFUNC_RETVAL(func, scalar) \ + typename Eigen::internal::func##_retval< \ + typename Eigen::internal::global_math_functions_filtering_base::type>::type + +/**************************************************************************** + * Implementation of real * + ****************************************************************************/ + +template ::IsComplex> +struct real_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { return x; } +}; + +template +struct real_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { + using std::real; + return real(x); + } +}; + +template +struct real_impl : real_default_impl {}; + +#if defined(EIGEN_GPU_COMPILE_PHASE) +template +struct real_impl> { + typedef T RealScalar; + EIGEN_DEVICE_FUNC static inline T run(const std::complex& x) { return x.real(); } +}; +#endif + +template +struct real_retval { + typedef typename NumTraits::Real type; +}; + +/**************************************************************************** + * Implementation of imag * + ****************************************************************************/ + +template ::IsComplex> +struct imag_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar&) { return RealScalar(0); } +}; + +template +struct imag_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { + using std::imag; + return imag(x); + } +}; + +template +struct imag_impl : imag_default_impl {}; + +#if defined(EIGEN_GPU_COMPILE_PHASE) +template +struct imag_impl> { + typedef T RealScalar; + EIGEN_DEVICE_FUNC static inline T run(const std::complex& x) { return x.imag(); } +}; +#endif + +template +struct imag_retval { + typedef typename NumTraits::Real type; +}; + +/**************************************************************************** + * Implementation of real_ref * + ****************************************************************************/ + +template +struct real_ref_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar& run(Scalar& x) { return reinterpret_cast(&x)[0]; } + EIGEN_DEVICE_FUNC static inline const RealScalar& run(const Scalar& x) { + return reinterpret_cast(&x)[0]; + } +}; + +template +struct real_ref_retval { + typedef typename NumTraits::Real& type; +}; + +/**************************************************************************** + * Implementation of imag_ref * + ****************************************************************************/ + +template +struct imag_ref_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar& run(Scalar& x) { return reinterpret_cast(&x)[1]; } + EIGEN_DEVICE_FUNC static inline const RealScalar& run(const Scalar& x) { + return reinterpret_cast(&x)[1]; + } +}; + +template +struct imag_ref_default_impl { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline Scalar run(Scalar&) { return Scalar(0); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline const Scalar run(const Scalar&) { return Scalar(0); } +}; + +template +struct imag_ref_impl : imag_ref_default_impl::IsComplex> {}; + +template +struct imag_ref_retval { + typedef typename NumTraits::Real& type; +}; + +/**************************************************************************** + * Implementation of conj * + ****************************************************************************/ + +template ::IsComplex> +struct conj_default_impl { + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x) { return x; } +}; + +template +struct conj_default_impl { + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x) { + using std::conj; + return conj(x); + } +}; + +template ::IsComplex> +struct conj_impl : conj_default_impl {}; + +template +struct conj_retval { + typedef Scalar type; +}; + +/**************************************************************************** + * Implementation of abs2 * + ****************************************************************************/ + +template +struct abs2_impl_default { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { return x * x; } +}; + +template +struct abs2_impl_default // IsComplex +{ + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { return x.real() * x.real() + x.imag() * x.imag(); } +}; + +template +struct abs2_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { + return abs2_impl_default::IsComplex>::run(x); + } +}; + +template +struct abs2_retval { + typedef typename NumTraits::Real type; +}; + +/**************************************************************************** + * Implementation of sqrt/rsqrt * + ****************************************************************************/ + +template +struct sqrt_impl { + EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE Scalar run(const Scalar& x) { + EIGEN_USING_STD(sqrt); + return sqrt(x); + } +}; + +// Complex sqrt defined in MathFunctionsImpl.h. +template +EIGEN_DEVICE_FUNC std::complex complex_sqrt(const std::complex& a_x); + +// Custom implementation is faster than `std::sqrt`, works on +// GPU, and correctly handles special cases (unlike MSVC). +template +struct sqrt_impl> { + EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE std::complex run(const std::complex& x) { + return complex_sqrt(x); + } +}; + +template +struct sqrt_retval { + typedef Scalar type; +}; + +// Default implementation relies on numext::sqrt, at bottom of file. +template +struct rsqrt_impl; + +// Complex rsqrt defined in MathFunctionsImpl.h. +template +EIGEN_DEVICE_FUNC std::complex complex_rsqrt(const std::complex& a_x); + +template +struct rsqrt_impl> { + EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE std::complex run(const std::complex& x) { + return complex_rsqrt(x); + } +}; + +template +struct rsqrt_retval { + typedef Scalar type; +}; + +/**************************************************************************** + * Implementation of norm1 * + ****************************************************************************/ + +template +struct norm1_default_impl; + +template +struct norm1_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { + EIGEN_USING_STD(abs); + return abs(x.real()) + abs(x.imag()); + } +}; + +template +struct norm1_default_impl { + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x) { + EIGEN_USING_STD(abs); + return abs(x); + } +}; + +template +struct norm1_impl : norm1_default_impl::IsComplex> {}; + +template +struct norm1_retval { + typedef typename NumTraits::Real type; +}; + +/**************************************************************************** + * Implementation of hypot * + ****************************************************************************/ + +template +struct hypot_impl; + +template +struct hypot_retval { + typedef typename NumTraits::Real type; +}; + +/**************************************************************************** + * Implementation of cast * + ****************************************************************************/ + +template +struct cast_impl { + EIGEN_DEVICE_FUNC static inline NewType run(const OldType& x) { return static_cast(x); } +}; + +template +struct cast_impl { + EIGEN_DEVICE_FUNC static inline bool run(const OldType& x) { return x != OldType(0); } +}; + +// Casting from S -> Complex leads to an implicit conversion from S to T, +// generating warnings on clang. Here we explicitly cast the real component. +template +struct cast_impl::IsComplex && NumTraits::IsComplex>> { + EIGEN_DEVICE_FUNC static inline NewType run(const OldType& x) { + typedef typename NumTraits::Real NewReal; + return static_cast(static_cast(x)); + } +}; + +// here, for once, we're plainly returning NewType: we don't want cast to do weird things. + +template +EIGEN_DEVICE_FUNC inline NewType cast(const OldType& x) { + return cast_impl::run(x); +} + +/**************************************************************************** + * Implementation of arg * + ****************************************************************************/ + +// Visual Studio 2017 has a bug where arg(float) returns 0 for negative inputs. +// This seems to be fixed in VS 2019. +#if (!EIGEN_COMP_MSVC || EIGEN_COMP_MSVC >= 1920) +// std::arg is only defined for types of std::complex, or integer types or float/double/long double +template ::IsComplex || is_integral::value || + is_same::value || is_same::value || + is_same::value> +struct arg_default_impl; + +template +struct arg_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { + // There is no official ::arg on device in CUDA/HIP, so we always need to use std::arg. + using std::arg; + return static_cast(arg(x)); + } +}; + +// Must be non-complex floating-point type (e.g. half/bfloat16). +template +struct arg_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { + return (x < Scalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0); + } +}; +#else +template ::IsComplex> +struct arg_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { + return (x < RealScalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0); + } +}; + +template +struct arg_default_impl { + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC static inline RealScalar run(const Scalar& x) { + EIGEN_USING_STD(arg); + return arg(x); + } +}; +#endif +template +struct arg_impl : arg_default_impl {}; + +template +struct arg_retval { + typedef typename NumTraits::Real type; +}; + +/**************************************************************************** + * Implementation of expm1 * + ****************************************************************************/ + +// This implementation is based on GSL Math's expm1. +namespace std_fallback { +// fallback expm1 implementation in case there is no expm1(Scalar) function in namespace of Scalar, +// or that there is no suitable std::expm1 function available. Implementation +// attributed to Kahan. See: http://www.plunk.org/~hatch/rightway.php. +template +EIGEN_DEVICE_FUNC inline Scalar expm1(const Scalar& x) { + EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) + typedef typename NumTraits::Real RealScalar; + + EIGEN_USING_STD(exp); + Scalar u = exp(x); + if (numext::equal_strict(u, Scalar(1))) { + return x; + } + Scalar um1 = u - RealScalar(1); + if (numext::equal_strict(um1, Scalar(-1))) { + return RealScalar(-1); + } + + EIGEN_USING_STD(log); + Scalar logu = log(u); + return numext::equal_strict(u, logu) ? u : (u - RealScalar(1)) * x / logu; +} +} // namespace std_fallback + +template +struct expm1_impl { + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x) { + EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) + EIGEN_USING_STD(expm1); + return expm1(x); + } +}; + +template +struct expm1_retval { + typedef Scalar type; +}; + +/**************************************************************************** + * Implementation of log * + ****************************************************************************/ + +// Complex log defined in MathFunctionsImpl.h. +template +EIGEN_DEVICE_FUNC std::complex complex_log(const std::complex& z); + +template +struct log_impl { + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x) { + EIGEN_USING_STD(log); + return static_cast(log(x)); + } +}; + +template +struct log_impl> { + EIGEN_DEVICE_FUNC static inline std::complex run(const std::complex& z) { return complex_log(z); } +}; + +/**************************************************************************** + * Implementation of log1p * + ****************************************************************************/ + +namespace std_fallback { +// fallback log1p implementation in case there is no log1p(Scalar) function in namespace of Scalar, +// or that there is no suitable std::log1p function available +template +EIGEN_DEVICE_FUNC inline Scalar log1p(const Scalar& x) { + EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) + typedef typename NumTraits::Real RealScalar; + EIGEN_USING_STD(log); + Scalar x1p = RealScalar(1) + x; + Scalar log_1p = log_impl::run(x1p); + const bool is_small = numext::equal_strict(x1p, Scalar(1)); + const bool is_inf = numext::equal_strict(x1p, log_1p); + return (is_small || is_inf) ? x : x * (log_1p / (x1p - RealScalar(1))); +} +} // namespace std_fallback + +template +struct log1p_impl { + EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) + + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x) { + EIGEN_USING_STD(log1p); + return log1p(x); + } +}; + +// Specialization for complex types that are not supported by std::log1p. +template +struct log1p_impl> { + EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar) + + EIGEN_DEVICE_FUNC static inline std::complex run(const std::complex& x) { + return std_fallback::log1p(x); + } +}; + +template +struct log1p_retval { + typedef Scalar type; +}; + +/**************************************************************************** + * Implementation of pow * + ****************************************************************************/ + +template ::IsInteger && NumTraits::IsInteger> +struct pow_impl { + // typedef Scalar retval; + typedef typename ScalarBinaryOpTraits>::ReturnType + result_type; + static EIGEN_DEVICE_FUNC inline result_type run(const ScalarX& x, const ScalarY& y) { + EIGEN_USING_STD(pow); + return pow(x, y); + } +}; + +template +struct pow_impl { + typedef ScalarX result_type; + static EIGEN_DEVICE_FUNC inline ScalarX run(ScalarX x, ScalarY y) { + ScalarX res(1); + eigen_assert(!NumTraits::IsSigned || y >= 0); + if (y & 1) res *= x; + y >>= 1; + while (y) { + x *= x; + if (y & 1) res *= x; + y >>= 1; + } + return res; + } +}; + +enum { meta_floor_log2_terminate, meta_floor_log2_move_up, meta_floor_log2_move_down, meta_floor_log2_bogus }; + +template +struct meta_floor_log2_selector { + enum { + middle = (lower + upper) / 2, + value = (upper <= lower + 1) ? int(meta_floor_log2_terminate) + : (n < (1 << middle)) ? int(meta_floor_log2_move_down) + : (n == 0) ? int(meta_floor_log2_bogus) + : int(meta_floor_log2_move_up) + }; +}; + +template ::value> +struct meta_floor_log2 {}; + +template +struct meta_floor_log2 { + enum { value = meta_floor_log2::middle>::value }; +}; + +template +struct meta_floor_log2 { + enum { value = meta_floor_log2::middle, upper>::value }; +}; + +template +struct meta_floor_log2 { + enum { value = (n >= ((unsigned int)(1) << (lower + 1))) ? lower + 1 : lower }; +}; + +template +struct meta_floor_log2 { + // no value, error at compile time +}; + +template +struct count_bits_impl { + static_assert(std::is_integral::value && std::is_unsigned::value, + "BitsType must be an unsigned integer"); + + static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + int n = CHAR_BIT * sizeof(BitsType); + int shift = n / 2; + while (bits > 0 && shift > 0) { + BitsType y = bits >> shift; + if (y > 0) { + n -= shift; + bits = y; + } + shift /= 2; + } + if (shift == 0) { + --n; + } + return n; + } + + static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + int n = CHAR_BIT * sizeof(BitsType); + int shift = n / 2; + while (bits > 0 && shift > 0) { + BitsType y = bits << shift; + if (y > 0) { + n -= shift; + bits = y; + } + shift /= 2; + } + if (shift == 0) { + --n; + } + return n; + } +}; + +// Count leading zeros. +template +EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + return count_bits_impl::clz(bits); +} + +// Count trailing zeros. +template +EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + return count_bits_impl::ctz(bits); +} + +#if EIGEN_COMP_GNUC || EIGEN_COMP_CLANG + +template +struct count_bits_impl> { + static constexpr int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); + static_assert(std::is_integral::value, "BitsType must be a built-in integer"); + static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + static constexpr int kLeadingBitsOffset = (sizeof(unsigned int) - sizeof(BitsType)) * CHAR_BIT; + return bits == 0 ? kNumBits : __builtin_clz(static_cast(bits)) - kLeadingBitsOffset; + } + + static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + return bits == 0 ? kNumBits : __builtin_ctz(static_cast(bits)); + } +}; + +template +struct count_bits_impl< + BitsType, std::enable_if_t> { + static constexpr int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); + static_assert(std::is_integral::value, "BitsType must be a built-in integer"); + static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + static constexpr int kLeadingBitsOffset = (sizeof(unsigned long) - sizeof(BitsType)) * CHAR_BIT; + return bits == 0 ? kNumBits : __builtin_clzl(static_cast(bits)) - kLeadingBitsOffset; + } + + static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + return bits == 0 ? kNumBits : __builtin_ctzl(static_cast(bits)); + } +}; + +template +struct count_bits_impl> { + static constexpr int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); + static_assert(std::is_integral::value, "BitsType must be a built-in integer"); + static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + static constexpr int kLeadingBitsOffset = (sizeof(unsigned long long) - sizeof(BitsType)) * CHAR_BIT; + return bits == 0 ? kNumBits : __builtin_clzll(static_cast(bits)) - kLeadingBitsOffset; + } + + static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + return bits == 0 ? kNumBits : __builtin_ctzll(static_cast(bits)); + } +}; + +#elif EIGEN_COMP_MSVC + +template +struct count_bits_impl> { + static constexpr int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); + static_assert(std::is_integral::value, "BitsType must be a built-in integer"); + static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + unsigned long out; + _BitScanReverse(&out, static_cast(bits)); + return bits == 0 ? kNumBits : (kNumBits - 1) - static_cast(out); + } + + static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + unsigned long out; + _BitScanForward(&out, static_cast(bits)); + return bits == 0 ? kNumBits : static_cast(out); + } +}; + +#ifdef _WIN64 + +template +struct count_bits_impl< + BitsType, std::enable_if_t> { + static constexpr int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); + static_assert(std::is_integral::value, "BitsType must be a built-in integer"); + static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + unsigned long out; + _BitScanReverse64(&out, static_cast(bits)); + return bits == 0 ? kNumBits : (kNumBits - 1) - static_cast(out); + } + + static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + unsigned long out; + _BitScanForward64(&out, static_cast(bits)); + return bits == 0 ? kNumBits : static_cast(out); + } +}; + +#endif // _WIN64 + +#endif // EIGEN_COMP_GNUC || EIGEN_COMP_CLANG + +template +int log2_ceil(BitsType x) { + int n = CHAR_BIT * sizeof(BitsType) - clz(x); + bool powerOfTwo = (x & (x - 1)) == 0; + return x == 0 ? 0 : powerOfTwo ? n - 1 : n; +} + +template +int log2_floor(BitsType x) { + int n = CHAR_BIT * sizeof(BitsType) - clz(x); + return x == 0 ? 0 : n - 1; +} + +/**************************************************************************** + * Implementation of random * + ****************************************************************************/ + +// return a Scalar filled with numRandomBits beginning from the least significant bit +template +Scalar getRandomBits(int numRandomBits) { + using BitsType = typename numext::get_integer_by_size::unsigned_type; + enum : int { + StdRandBits = meta_floor_log2<(unsigned int)(RAND_MAX) + 1>::value, + ScalarBits = sizeof(Scalar) * CHAR_BIT + }; + eigen_assert((numRandomBits >= 0) && (numRandomBits <= ScalarBits)); + const BitsType mask = BitsType(-1) >> ((ScalarBits - numRandomBits) & (ScalarBits - 1)); + BitsType randomBits = BitsType(0); + for (int shift = 0; shift < numRandomBits; shift += StdRandBits) { + int r = std::rand(); + randomBits |= static_cast(r) << shift; + } + // clear the excess bits + randomBits &= mask; + return numext::bit_cast(randomBits); +} + +template +struct random_default_impl {}; + +template +struct random_impl : random_default_impl::IsComplex, NumTraits::IsInteger> {}; + +template +struct random_retval { + typedef Scalar type; +}; + +template +inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y); +template +inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(); + +template +struct random_default_impl { + using BitsType = typename numext::get_integer_by_size::unsigned_type; + static EIGEN_DEVICE_FUNC inline Scalar run(const Scalar& x, const Scalar& y, int numRandomBits) { + Scalar half_x = Scalar(0.5) * x; + Scalar half_y = Scalar(0.5) * y; + Scalar result = (half_x + half_y) + (half_y - half_x) * run(numRandomBits); + // result is in the half-open interval [x, y) -- provided that x < y + return result; + } + static EIGEN_DEVICE_FUNC inline Scalar run(const Scalar& x, const Scalar& y) { + const int mantissa_bits = NumTraits::digits() - 1; + return run(x, y, mantissa_bits); + } + static EIGEN_DEVICE_FUNC inline Scalar run(int numRandomBits) { + const int mantissa_bits = NumTraits::digits() - 1; + eigen_assert(numRandomBits >= 0 && numRandomBits <= mantissa_bits); + BitsType randomBits = getRandomBits(numRandomBits); + // if fewer than MantissaBits is requested, shift them to the left + randomBits <<= (mantissa_bits - numRandomBits); + // randomBits is in the half-open interval [2,4) + randomBits |= numext::bit_cast(Scalar(2)); + // result is in the half-open interval [-1,1) + Scalar result = numext::bit_cast(randomBits) - Scalar(3); + return result; + } + static EIGEN_DEVICE_FUNC inline Scalar run() { + const int mantissa_bits = NumTraits::digits() - 1; + return run(mantissa_bits); + } +}; + +// TODO: fix this for PPC +template +struct random_longdouble_impl { + enum : int { + Size = sizeof(long double), + MantissaBits = NumTraits::digits() - 1, + LowBits = MantissaBits > 64 ? 64 : MantissaBits, + HighBits = MantissaBits > 64 ? MantissaBits - 64 : 0 + }; + static EIGEN_DEVICE_FUNC inline long double run() { + EIGEN_USING_STD(memcpy) + uint64_t randomBits[2]; + long double result = 2.0L; + memcpy(&randomBits, &result, Size); + randomBits[0] |= getRandomBits(LowBits); + randomBits[1] |= getRandomBits(HighBits); + memcpy(&result, &randomBits, Size); + result -= 3.0L; + return result; + } +}; + +// GPUs treat long double as double. +#ifndef EIGEN_GPU_COMPILE_PHASE +template <> +struct random_longdouble_impl { + using Impl = random_impl; + static EIGEN_DEVICE_FUNC inline long double run() { return static_cast(Impl::run()); } +}; + +template <> +struct random_impl { + static EIGEN_DEVICE_FUNC inline long double run(const long double& x, const long double& y) { + long double half_x = 0.5L * x; + long double half_y = 0.5L * y; + long double result = (half_x + half_y) + (half_y - half_x) * run(); + return result; + } + static EIGEN_DEVICE_FUNC inline long double run() { return random_longdouble_impl<>::run(); } +}; +#endif + +template +struct random_default_impl { + using BitsType = typename numext::get_integer_by_size::unsigned_type; + enum : int { ScalarBits = sizeof(Scalar) * CHAR_BIT }; + static EIGEN_DEVICE_FUNC inline Scalar run(const Scalar& x, const Scalar& y) { + if (y <= x) return x; + const BitsType range = static_cast(y) - static_cast(x) + 1; + // handle edge case where [x,y] spans the entire range of Scalar + if (range == 0) return getRandomBits(ScalarBits); + // calculate the number of random bits needed to fill range + const int numRandomBits = log2_ceil(range); + BitsType randomBits; + do { + randomBits = getRandomBits(numRandomBits); + // if the random draw is outside [0, range), try again (rejection sampling) + // in the worst-case scenario, the probability of rejection is: 1/2 - 1/2^numRandomBits < 50% + } while (randomBits >= range); + // Avoid overflow in the case where `x` is negative and there is a large range so + // `randomBits` would also be negative if cast to `Scalar` first. + Scalar result = static_cast(static_cast(x) + randomBits); + return result; + } + + static EIGEN_DEVICE_FUNC inline Scalar run() { +#ifdef EIGEN_MAKING_DOCS + return run(Scalar(NumTraits::IsSigned ? -10 : 0), Scalar(10)); +#else + return getRandomBits(ScalarBits); +#endif + } +}; + +template <> +struct random_impl { + static EIGEN_DEVICE_FUNC inline bool run(const bool& x, const bool& y) { + if (y <= x) return x; + return run(); + } + static EIGEN_DEVICE_FUNC inline bool run() { return getRandomBits(1) ? true : false; } +}; + +template +struct random_default_impl { + static EIGEN_DEVICE_FUNC inline Scalar run(const Scalar& x, const Scalar& y) { + return Scalar(random(x.real(), y.real()), random(x.imag(), y.imag())); + } + static EIGEN_DEVICE_FUNC inline Scalar run() { + typedef typename NumTraits::Real RealScalar; + return Scalar(random(), random()); + } +}; + +template +inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar& x, const Scalar& y) { + return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(x, y); +} + +template +inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random() { + return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(); +} + +// Implementation of is* functions + +template +EIGEN_DEVICE_FUNC std::enable_if_t::has_infinity || std::numeric_limits::has_quiet_NaN || + std::numeric_limits::has_signaling_NaN), + bool> +isfinite_impl(const T&) { + return true; +} + +template +EIGEN_DEVICE_FUNC std::enable_if_t<(std::numeric_limits::has_infinity || std::numeric_limits::has_quiet_NaN || + std::numeric_limits::has_signaling_NaN) && + (!NumTraits::IsComplex), + bool> +isfinite_impl(const T& x) { + EIGEN_USING_STD(isfinite); + return isfinite EIGEN_NOT_A_MACRO(x); +} + +template +EIGEN_DEVICE_FUNC std::enable_if_t::has_infinity, bool> isinf_impl(const T&) { + return false; +} + +template +EIGEN_DEVICE_FUNC std::enable_if_t<(std::numeric_limits::has_infinity && !NumTraits::IsComplex), bool> isinf_impl( + const T& x) { + EIGEN_USING_STD(isinf); + return isinf EIGEN_NOT_A_MACRO(x); +} + +template +EIGEN_DEVICE_FUNC + std::enable_if_t::has_quiet_NaN || std::numeric_limits::has_signaling_NaN), bool> + isnan_impl(const T&) { + return false; +} + +template +EIGEN_DEVICE_FUNC std::enable_if_t< + (std::numeric_limits::has_quiet_NaN || std::numeric_limits::has_signaling_NaN) && (!NumTraits::IsComplex), + bool> +isnan_impl(const T& x) { + EIGEN_USING_STD(isnan); + return isnan EIGEN_NOT_A_MACRO(x); +} + +// The following overload are defined at the end of this file +template +EIGEN_DEVICE_FUNC bool isfinite_impl(const std::complex& x); +template +EIGEN_DEVICE_FUNC bool isnan_impl(const std::complex& x); +template +EIGEN_DEVICE_FUNC bool isinf_impl(const std::complex& x); +template +EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS T ptanh_float(const T& a_x); + +/**************************************************************************** + * Implementation of sign * + ****************************************************************************/ +template ::IsComplex != 0), + bool IsInteger = (NumTraits::IsInteger != 0)> +struct sign_impl { + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& a) { return Scalar((a > Scalar(0)) - (a < Scalar(0))); } +}; + +template +struct sign_impl { + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& a) { + return (isnan_impl)(a) ? a : Scalar((a > Scalar(0)) - (a < Scalar(0))); + } +}; + +template +struct sign_impl { + EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& a) { + using real_type = typename NumTraits::Real; + EIGEN_USING_STD(abs); + real_type aa = abs(a); + if (aa == real_type(0)) return Scalar(0); + aa = real_type(1) / aa; + return Scalar(a.real() * aa, a.imag() * aa); + } +}; + +// The sign function for bool is the identity. +template <> +struct sign_impl { + EIGEN_DEVICE_FUNC static inline bool run(const bool& a) { return a; } +}; + +template +struct sign_retval { + typedef Scalar type; +}; + +template ::type>::IsInteger> +struct nearest_integer_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_floor(const Scalar& x) { + EIGEN_USING_STD(floor) return floor(x); + } + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_ceil(const Scalar& x) { + EIGEN_USING_STD(ceil) return ceil(x); + } + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_rint(const Scalar& x) { + EIGEN_USING_STD(rint) return rint(x); + } + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_round(const Scalar& x) { + EIGEN_USING_STD(round) return round(x); + } +}; +template +struct nearest_integer_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_floor(const Scalar& x) { return x; } + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_ceil(const Scalar& x) { return x; } + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_rint(const Scalar& x) { return x; } + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_round(const Scalar& x) { return x; } +}; + +} // end namespace internal + +/**************************************************************************** + * Generic math functions * + ****************************************************************************/ + +namespace numext { + +#if (!defined(EIGEN_GPUCC) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC)) +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T& x, const T& y) { + EIGEN_USING_STD(min) + return min EIGEN_NOT_A_MACRO(x, y); +} + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y) { + EIGEN_USING_STD(max) + return max EIGEN_NOT_A_MACRO(x, y); +} +#else +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T& x, const T& y) { + return y < x ? y : x; +} +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float mini(const float& x, const float& y) { + return fminf(x, y); +} +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double mini(const double& x, const double& y) { + return fmin(x, y); +} + +#ifndef EIGEN_GPU_COMPILE_PHASE +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE long double mini(const long double& x, const long double& y) { +#if defined(EIGEN_HIPCC) + // no "fminl" on HIP yet + return (x < y) ? x : y; +#else + return fminl(x, y); +#endif +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y) { + return x < y ? y : x; +} +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float maxi(const float& x, const float& y) { + return fmaxf(x, y); +} +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double maxi(const double& x, const double& y) { + return fmax(x, y); +} +#ifndef EIGEN_GPU_COMPILE_PHASE +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE long double maxi(const long double& x, const long double& y) { +#if defined(EIGEN_HIPCC) + // no "fmaxl" on HIP yet + return (x > y) ? x : y; +#else + return fmaxl(x, y); +#endif +} +#endif +#endif + +#if defined(SYCL_DEVICE_ONLY) + +#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_long) +#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_long) +#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong) +#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong) +#define SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(NAME, FUNC) \ + SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \ + SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) +#define SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(NAME, FUNC) \ + SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \ + SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) +#define SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(NAME, FUNC) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \ + SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_double) +#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(NAME, FUNC) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \ + SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_double) +#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(NAME, FUNC, RET_TYPE) \ + SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_float) \ + SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_double) + +#define SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \ + template <> \ + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE& x) { \ + return cl::sycl::FUNC(x); \ + } + +#define SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, TYPE) SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, TYPE, TYPE) + +#define SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE1, ARG_TYPE2) \ + template <> \ + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE1& x, const ARG_TYPE2& y) { \ + return cl::sycl::FUNC(x, y); \ + } + +#define SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \ + SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE, ARG_TYPE) + +#define SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, TYPE) SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, TYPE, TYPE) + +SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(mini, min) +SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(mini, fmin) +SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(maxi, max) +SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(maxi, fmax) + +#endif + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(real, Scalar) real(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x); +} + +template +EIGEN_DEVICE_FUNC inline internal::add_const_on_value_type_t real_ref( + const Scalar& x) { + return internal::real_ref_impl::run(x); +} + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x) { + return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x); +} + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) imag(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x); +} + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(arg, Scalar) arg(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(arg, Scalar)::run(x); +} + +template +EIGEN_DEVICE_FUNC inline internal::add_const_on_value_type_t imag_ref( + const Scalar& x) { + return internal::imag_ref_impl::run(x); +} + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x) { + return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x); +} + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) conj(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x); +} + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(sign, Scalar) sign(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(sign, Scalar)::run(x); +} + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x); +} + +EIGEN_DEVICE_FUNC inline bool abs2(bool x) { return x; } + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T absdiff(const T& x, const T& y) { + return x > y ? x - y : y - x; +} +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float absdiff(const float& x, const float& y) { + return fabsf(x - y); +} +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double absdiff(const double& x, const double& y) { + return fabs(x - y); +} + +// HIP and CUDA do not support long double. +#ifndef EIGEN_GPU_COMPILE_PHASE +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE long double absdiff(const long double& x, const long double& y) { + return fabsl(x - y); +} +#endif + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x); +} + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(const Scalar& x, const Scalar& y) { + return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(hypot, hypot) +#endif + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(log1p, Scalar) log1p(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(log1p, Scalar)::run(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log1p, log1p) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float log1p(const float& x) { + return ::log1pf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double log1p(const double& x) { + return ::log1p(x); +} +#endif + +template +EIGEN_DEVICE_FUNC inline typename internal::pow_impl::result_type pow(const ScalarX& x, + const ScalarY& y) { + return internal::pow_impl::run(x, y); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(pow, pow) +#endif + +template +EIGEN_DEVICE_FUNC bool(isnan)(const T& x) { + return internal::isnan_impl(x); +} +template +EIGEN_DEVICE_FUNC bool(isinf)(const T& x) { + return internal::isinf_impl(x); +} +template +EIGEN_DEVICE_FUNC bool(isfinite)(const T& x) { + return internal::isfinite_impl(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isnan, isnan, bool) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isinf, isinf, bool) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isfinite, isfinite, bool) +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar rint(const Scalar& x) { + return internal::nearest_integer_impl::run_rint(x); +} + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar round(const Scalar& x) { + return internal::nearest_integer_impl::run_round(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(round, round) +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar(floor)(const Scalar& x) { + return internal::nearest_integer_impl::run_floor(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(floor, floor) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float floor(const float& x) { + return ::floorf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double floor(const double& x) { + return ::floor(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar(ceil)(const Scalar& x) { + return internal::nearest_integer_impl::run_ceil(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(ceil, ceil) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float ceil(const float& x) { + return ::ceilf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double ceil(const double& x) { + return ::ceil(x); +} +#endif + +// Integer division with rounding up. +// T is assumed to be an integer type with a>=0, and b>0 +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE EIGEN_CONSTEXPR T div_ceil(T a, T b) { + EIGEN_STATIC_ASSERT((NumTraits::IsInteger), THIS FUNCTION IS FOR INTEGER TYPES) + eigen_assert(a >= 0); + eigen_assert(b > 0); + // Note: This form is used because it cannot overflow. + return a == 0 ? 0 : (a - 1) / b + 1; +} + +/** Log base 2 for 32 bits positive integers. + * Conveniently returns 0 for x==0. */ +inline int log2(int x) { + eigen_assert(x >= 0); + unsigned int v(x); + static const int table[32] = {0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, + 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31}; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + return table[(v * 0x07C4ACDDU) >> 27]; +} + +/** \returns the square root of \a x. + * + * It is essentially equivalent to + * \code using std::sqrt; return sqrt(x); \endcode + * but slightly faster for float/double and some compilers (e.g., gcc), thanks to + * specializations when SSE is enabled. + * + * It's usage is justified in performance critical functions, like norm/normalize. + */ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE EIGEN_MATHFUNC_RETVAL(sqrt, Scalar) sqrt(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(sqrt, Scalar)::run(x); +} + +// Boolean specialization, avoids implicit float to bool conversion (-Wimplicit-conversion-floating-point-to-bool). +template <> +EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC bool sqrt(const bool& x) { + return x; +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sqrt, sqrt) +#endif + +/** \returns the cube root of \a x. **/ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T cbrt(const T& x) { + EIGEN_USING_STD(cbrt); + return static_cast(cbrt(x)); +} + +/** \returns the reciprocal square root of \a x. **/ +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T rsqrt(const T& x) { + return internal::rsqrt_impl::run(x); +} + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T log(const T& x) { + return internal::log_impl::run(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log, log) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float log(const float& x) { + return ::logf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double log(const double& x) { + return ::log(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE + std::enable_if_t::IsSigned || NumTraits::IsComplex, typename NumTraits::Real> + abs(const T& x) { + EIGEN_USING_STD(abs); + return abs(x); +} + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE + std::enable_if_t::IsSigned || NumTraits::IsComplex), typename NumTraits::Real> + abs(const T& x) { + return x; +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(abs, abs) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(abs, fabs) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float abs(const float& x) { + return ::fabsf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double abs(const double& x) { + return ::fabs(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float abs(const std::complex& x) { + return ::hypotf(x.real(), x.imag()); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double abs(const std::complex& x) { + return ::hypot(x.real(), x.imag()); +} +#endif + +template ::IsInteger, bool IsSigned = NumTraits::IsSigned> +struct signbit_impl; +template +struct signbit_impl { + static constexpr size_t Size = sizeof(Scalar); + static constexpr size_t Shift = (CHAR_BIT * Size) - 1; + using intSize_t = typename get_integer_by_size::signed_type; + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static Scalar run(const Scalar& x) { + intSize_t a = bit_cast(x); + a = a >> Shift; + Scalar result = bit_cast(a); + return result; + } +}; +template +struct signbit_impl { + static constexpr size_t Size = sizeof(Scalar); + static constexpr size_t Shift = (CHAR_BIT * Size) - 1; + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static constexpr Scalar run(const Scalar& x) { return x >> Shift; } +}; +template +struct signbit_impl { + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static constexpr Scalar run(const Scalar&) { return Scalar(0); } +}; +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static constexpr Scalar signbit(const Scalar& x) { + return signbit_impl::run(x); +} + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T exp(const T& x) { + EIGEN_USING_STD(exp); + return exp(x); +} + +// MSVC screws up some edge-cases for std::exp(complex). +#ifdef EIGEN_COMP_MSVC +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE std::complex exp(const std::complex& x) { + EIGEN_USING_STD(exp); + // If z is (x,±∞) (for any finite x), the result is (NaN,NaN) and FE_INVALID is raised. + // If z is (x,NaN) (for any finite x), the result is (NaN,NaN) and FE_INVALID may be raised. + if ((isfinite)(real_ref(x)) && !(isfinite)(imag_ref(x))) { + return std::complex(NumTraits::quiet_NaN(), NumTraits::quiet_NaN()); + } + // If z is (+∞,±∞), the result is (±∞,NaN) and FE_INVALID is raised (the sign of the real part is unspecified) + // If z is (+∞,NaN), the result is (±∞,NaN) (the sign of the real part is unspecified) + if ((real_ref(x) == NumTraits::infinity() && !(isfinite)(imag_ref(x)))) { + return std::complex(NumTraits::infinity(), NumTraits::quiet_NaN()); + } + return exp(x); +} +#endif + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(exp, exp) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float exp(const float& x) { + return ::expf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double exp(const double& x) { + return ::exp(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE std::complex exp(const std::complex& x) { + float com = ::expf(x.real()); + float res_real = com * ::cosf(x.imag()); + float res_imag = com * ::sinf(x.imag()); + return std::complex(res_real, res_imag); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE std::complex exp(const std::complex& x) { + double com = ::exp(x.real()); + double res_real = com * ::cos(x.imag()); + double res_imag = com * ::sin(x.imag()); + return std::complex(res_real, res_imag); +} +#endif + +template +EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(expm1, Scalar) expm1(const Scalar& x) { + return EIGEN_MATHFUNC_IMPL(expm1, Scalar)::run(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(expm1, expm1) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float expm1(const float& x) { + return ::expm1f(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double expm1(const double& x) { + return ::expm1(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T cos(const T& x) { + EIGEN_USING_STD(cos); + return cos(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cos, cos) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float cos(const float& x) { + return ::cosf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double cos(const double& x) { + return ::cos(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T sin(const T& x) { + EIGEN_USING_STD(sin); + return sin(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sin, sin) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float sin(const float& x) { + return ::sinf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double sin(const double& x) { + return ::sin(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T tan(const T& x) { + EIGEN_USING_STD(tan); + return tan(x); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tan, tan) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float tan(const float& x) { + return ::tanf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double tan(const double& x) { + return ::tan(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T acos(const T& x) { + EIGEN_USING_STD(acos); + return acos(x); +} + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T acosh(const T& x) { + EIGEN_USING_STD(acosh); + return static_cast(acosh(x)); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acos, acos) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acosh, acosh) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float acos(const float& x) { + return ::acosf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double acos(const double& x) { + return ::acos(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T asin(const T& x) { + EIGEN_USING_STD(asin); + return asin(x); +} + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T asinh(const T& x) { + EIGEN_USING_STD(asinh); + return static_cast(asinh(x)); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asin, asin) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asinh, asinh) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float asin(const float& x) { + return ::asinf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double asin(const double& x) { + return ::asin(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T atan(const T& x) { + EIGEN_USING_STD(atan); + return static_cast(atan(x)); +} + +template ::IsComplex, int> = 0> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T atan2(const T& y, const T& x) { + EIGEN_USING_STD(atan2); + return static_cast(atan2(y, x)); +} + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T atanh(const T& x) { + EIGEN_USING_STD(atanh); + return static_cast(atanh(x)); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atan, atan) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atanh, atanh) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float atan(const float& x) { + return ::atanf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double atan(const double& x) { + return ::atan(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T cosh(const T& x) { + EIGEN_USING_STD(cosh); + return static_cast(cosh(x)); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cosh, cosh) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float cosh(const float& x) { + return ::coshf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double cosh(const double& x) { + return ::cosh(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T sinh(const T& x) { + EIGEN_USING_STD(sinh); + return static_cast(sinh(x)); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sinh, sinh) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float sinh(const float& x) { + return ::sinhf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double sinh(const double& x) { + return ::sinh(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T tanh(const T& x) { + EIGEN_USING_STD(tanh); + return tanh(x); +} + +#if (!defined(EIGEN_GPUCC)) && EIGEN_FAST_MATH && !defined(SYCL_DEVICE_ONLY) +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float tanh(float x) { return internal::ptanh_float(x); } +#endif + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tanh, tanh) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float tanh(const float& x) { + return ::tanhf(x); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double tanh(const double& x) { + return ::tanh(x); +} +#endif + +template +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T fmod(const T& a, const T& b) { + EIGEN_USING_STD(fmod); + return fmod(a, b); +} + +#if defined(SYCL_DEVICE_ONLY) +SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(fmod, fmod) +#endif + +#if defined(EIGEN_GPUCC) +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float fmod(const float& a, const float& b) { + return ::fmodf(a, b); +} + +template <> +EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double fmod(const double& a, const double& b) { + return ::fmod(a, b); +} +#endif + +#if defined(SYCL_DEVICE_ONLY) +#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY +#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY +#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY +#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY +#undef SYCL_SPECIALIZE_INTEGER_TYPES_BINARY +#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY +#undef SYCL_SPECIALIZE_FLOATING_TYPES_BINARY +#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY +#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE +#undef SYCL_SPECIALIZE_GEN_UNARY_FUNC +#undef SYCL_SPECIALIZE_UNARY_FUNC +#undef SYCL_SPECIALIZE_GEN1_BINARY_FUNC +#undef SYCL_SPECIALIZE_GEN2_BINARY_FUNC +#undef SYCL_SPECIALIZE_BINARY_FUNC +#endif + +} // end namespace numext + +namespace internal { + +template +EIGEN_DEVICE_FUNC bool isfinite_impl(const std::complex& x) { + return (numext::isfinite)(numext::real(x)) && (numext::isfinite)(numext::imag(x)); +} + +template +EIGEN_DEVICE_FUNC bool isnan_impl(const std::complex& x) { + return (numext::isnan)(numext::real(x)) || (numext::isnan)(numext::imag(x)); +} + +template +EIGEN_DEVICE_FUNC bool isinf_impl(const std::complex& x) { + return ((numext::isinf)(numext::real(x)) || (numext::isinf)(numext::imag(x))) && (!(numext::isnan)(x)); +} + +/**************************************************************************** + * Implementation of fuzzy comparisons * + ****************************************************************************/ + +template +struct scalar_fuzzy_default_impl {}; + +template +struct scalar_fuzzy_default_impl { + typedef typename NumTraits::Real RealScalar; + template + EIGEN_DEVICE_FUNC static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, + const RealScalar& prec) { + return numext::abs(x) <= numext::abs(y) * prec; + } + EIGEN_DEVICE_FUNC static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec) { + return numext::abs(x - y) <= numext::mini(numext::abs(x), numext::abs(y)) * prec; + } + EIGEN_DEVICE_FUNC static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar& prec) { + return x <= y || isApprox(x, y, prec); + } +}; + +template +struct scalar_fuzzy_default_impl { + typedef typename NumTraits::Real RealScalar; + template + EIGEN_DEVICE_FUNC static inline bool isMuchSmallerThan(const Scalar& x, const Scalar&, const RealScalar&) { + return x == Scalar(0); + } + EIGEN_DEVICE_FUNC static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar&) { return x == y; } + EIGEN_DEVICE_FUNC static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar&) { + return x <= y; + } +}; + +template +struct scalar_fuzzy_default_impl { + typedef typename NumTraits::Real RealScalar; + template + EIGEN_DEVICE_FUNC static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, + const RealScalar& prec) { + return numext::abs2(x) <= numext::abs2(y) * prec * prec; + } + EIGEN_DEVICE_FUNC static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec) { + return numext::abs2(x - y) <= numext::mini(numext::abs2(x), numext::abs2(y)) * prec * prec; + } +}; + +template +struct scalar_fuzzy_impl + : scalar_fuzzy_default_impl::IsComplex, NumTraits::IsInteger> {}; + +template +EIGEN_DEVICE_FUNC inline bool isMuchSmallerThan( + const Scalar& x, const OtherScalar& y, + const typename NumTraits::Real& precision = NumTraits::dummy_precision()) { + return scalar_fuzzy_impl::template isMuchSmallerThan(x, y, precision); +} + +template +EIGEN_DEVICE_FUNC inline bool isApprox( + const Scalar& x, const Scalar& y, + const typename NumTraits::Real& precision = NumTraits::dummy_precision()) { + return scalar_fuzzy_impl::isApprox(x, y, precision); +} + +template +EIGEN_DEVICE_FUNC inline bool isApproxOrLessThan( + const Scalar& x, const Scalar& y, + const typename NumTraits::Real& precision = NumTraits::dummy_precision()) { + return scalar_fuzzy_impl::isApproxOrLessThan(x, y, precision); +} + +/****************************************** +*** The special case of the bool type *** +******************************************/ + +template <> +struct scalar_fuzzy_impl { + typedef bool RealScalar; + + template + EIGEN_DEVICE_FUNC static inline bool isMuchSmallerThan(const bool& x, const bool&, const bool&) { + return !x; + } + + EIGEN_DEVICE_FUNC static inline bool isApprox(bool x, bool y, bool) { return x == y; } + + EIGEN_DEVICE_FUNC static inline bool isApproxOrLessThan(const bool& x, const bool& y, const bool&) { + return (!x) || y; + } +}; + +} // end namespace internal + +// Default implementations that rely on other numext implementations +namespace internal { + +// Specialization for complex types that are not supported by std::expm1. +template +struct expm1_impl> { + EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar) + + EIGEN_DEVICE_FUNC static inline std::complex run(const std::complex& x) { + RealScalar xr = x.real(); + RealScalar xi = x.imag(); + // expm1(z) = exp(z) - 1 + // = exp(x + i * y) - 1 + // = exp(x) * (cos(y) + i * sin(y)) - 1 + // = exp(x) * cos(y) - 1 + i * exp(x) * sin(y) + // Imag(expm1(z)) = exp(x) * sin(y) + // Real(expm1(z)) = exp(x) * cos(y) - 1 + // = exp(x) * cos(y) - 1. + // = expm1(x) + exp(x) * (cos(y) - 1) + // = expm1(x) + exp(x) * (2 * sin(y / 2) ** 2) + RealScalar erm1 = numext::expm1(xr); + RealScalar er = erm1 + RealScalar(1.); + RealScalar sin2 = numext::sin(xi / RealScalar(2.)); + sin2 = sin2 * sin2; + RealScalar s = numext::sin(xi); + RealScalar real_part = erm1 - RealScalar(2.) * er * sin2; + return std::complex(real_part, er * s); + } +}; + +template +struct rsqrt_impl { + EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE T run(const T& x) { return T(1) / numext::sqrt(x); } +}; + +#if defined(EIGEN_GPU_COMPILE_PHASE) +template +struct conj_impl, true> { + EIGEN_DEVICE_FUNC static inline std::complex run(const std::complex& x) { + return std::complex(numext::real(x), -numext::imag(x)); + } +}; +#endif + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_MATHFUNCTIONS_H diff --git a/dae-cpp/Eigen/src/Core/MathFunctionsImpl.h b/dae-cpp/Eigen/src/Core/MathFunctionsImpl.h new file mode 100644 index 0000000..689c6d8 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/MathFunctionsImpl.h @@ -0,0 +1,262 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) +// Copyright (C) 2016 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_MATHFUNCTIONSIMPL_H +#define EIGEN_MATHFUNCTIONSIMPL_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +/** \internal Fast reciprocal using Newton-Raphson's method. + + Preconditions: + 1. The starting guess provided in approx_a_recip must have at least half + the leading mantissa bits in the correct result, such that a single + Newton-Raphson step is sufficient to get within 1-2 ulps of the currect + result. + 2. If a is zero, approx_a_recip must be infinite with the same sign as a. + 3. If a is infinite, approx_a_recip must be zero with the same sign as a. + + If the preconditions are satisfied, which they are for for the _*_rcp_ps + instructions on x86, the result has a maximum relative error of 2 ulps, + and correctly handles reciprocals of zero, infinity, and NaN. +*/ +template +struct generic_reciprocal_newton_step { + static_assert(Steps > 0, "Steps must be at least 1."); + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Packet run(const Packet& a, const Packet& approx_a_recip) { + using Scalar = typename unpacket_traits::type; + const Packet two = pset1(Scalar(2)); + // Refine the approximation using one Newton-Raphson step: + // x_{i} = x_{i-1} * (2 - a * x_{i-1}) + const Packet x = generic_reciprocal_newton_step::run(a, approx_a_recip); + const Packet tmp = pnmadd(a, x, two); + // If tmp is NaN, it means that a is either +/-0 or +/-Inf. + // In this case return the approximation directly. + const Packet is_not_nan = pcmp_eq(tmp, tmp); + return pselect(is_not_nan, pmul(x, tmp), x); + } +}; + +template +struct generic_reciprocal_newton_step { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Packet run(const Packet& /*unused*/, const Packet& approx_rsqrt) { + return approx_rsqrt; + } +}; + +/** \internal Fast reciprocal sqrt using Newton-Raphson's method. + + Preconditions: + 1. The starting guess provided in approx_a_recip must have at least half + the leading mantissa bits in the correct result, such that a single + Newton-Raphson step is sufficient to get within 1-2 ulps of the currect + result. + 2. If a is zero, approx_a_recip must be infinite with the same sign as a. + 3. If a is infinite, approx_a_recip must be zero with the same sign as a. + + If the preconditions are satisfied, which they are for for the _*_rcp_ps + instructions on x86, the result has a maximum relative error of 2 ulps, + and correctly handles zero, infinity, and NaN. Positive denormals are + treated as zero. +*/ +template +struct generic_rsqrt_newton_step { + static_assert(Steps > 0, "Steps must be at least 1."); + using Scalar = typename unpacket_traits::type; + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Packet run(const Packet& a, const Packet& approx_rsqrt) { + constexpr Scalar kMinusHalf = Scalar(-1) / Scalar(2); + const Packet cst_minus_half = pset1(kMinusHalf); + const Packet cst_minus_one = pset1(Scalar(-1)); + + Packet inv_sqrt = approx_rsqrt; + for (int step = 0; step < Steps; ++step) { + // Refine the approximation using one Newton-Raphson step: + // h_n = (x * inv_sqrt) * inv_sqrt - 1 (so that h_n is nearly 0). + // inv_sqrt = inv_sqrt - 0.5 * inv_sqrt * h_n + Packet r2 = pmul(a, inv_sqrt); + Packet half_r = pmul(inv_sqrt, cst_minus_half); + Packet h_n = pmadd(r2, inv_sqrt, cst_minus_one); + inv_sqrt = pmadd(half_r, h_n, inv_sqrt); + } + + // If x is NaN, then either: + // 1) the input is NaN + // 2) zero and infinity were multiplied + // In either of these cases, return approx_rsqrt + return pselect(pisnan(inv_sqrt), approx_rsqrt, inv_sqrt); + } +}; + +template +struct generic_rsqrt_newton_step { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Packet run(const Packet& /*unused*/, const Packet& approx_rsqrt) { + return approx_rsqrt; + } +}; + +/** \internal Fast sqrt using Newton-Raphson's method. + + Preconditions: + 1. The starting guess for the reciprocal sqrt provided in approx_rsqrt must + have at least half the leading mantissa bits in the correct result, such + that a single Newton-Raphson step is sufficient to get within 1-2 ulps of + the currect result. + 2. If a is zero, approx_rsqrt must be infinite. + 3. If a is infinite, approx_rsqrt must be zero. + + If the preconditions are satisfied, which they are for for the _*_rsqrt_ps + instructions on x86, the result has a maximum relative error of 2 ulps, + and correctly handles zero and infinity, and NaN. Positive denormal inputs + are treated as zero. +*/ +template +struct generic_sqrt_newton_step { + static_assert(Steps > 0, "Steps must be at least 1."); + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Packet run(const Packet& a, const Packet& approx_rsqrt) { + using Scalar = typename unpacket_traits::type; + const Packet one_point_five = pset1(Scalar(1.5)); + const Packet minus_half = pset1(Scalar(-0.5)); + // If a is inf or zero, return a directly. + const Packet inf_mask = pcmp_eq(a, pset1(NumTraits::infinity())); + const Packet return_a = por(pcmp_eq(a, pzero(a)), inf_mask); + // Do a single step of Newton's iteration for reciprocal square root: + // x_{n+1} = x_n * (1.5 + (-0.5 * x_n) * (a * x_n))). + // The Newton's step is computed this way to avoid over/under-flows. + Packet rsqrt = pmul(approx_rsqrt, pmadd(pmul(minus_half, approx_rsqrt), pmul(a, approx_rsqrt), one_point_five)); + for (int step = 1; step < Steps; ++step) { + rsqrt = pmul(rsqrt, pmadd(pmul(minus_half, rsqrt), pmul(a, rsqrt), one_point_five)); + } + + // Return sqrt(x) = x * rsqrt(x) for non-zero finite positive arguments. + // Return a itself for 0 or +inf, NaN for negative arguments. + return pselect(return_a, a, pmul(a, rsqrt)); + } +}; + +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RealScalar positive_real_hypot(const RealScalar& x, const RealScalar& y) { + // IEEE IEC 6059 special cases. + if ((numext::isinf)(x) || (numext::isinf)(y)) return NumTraits::infinity(); + if ((numext::isnan)(x) || (numext::isnan)(y)) return NumTraits::quiet_NaN(); + + EIGEN_USING_STD(sqrt); + RealScalar p, qp; + p = numext::maxi(x, y); + if (numext::is_exactly_zero(p)) return RealScalar(0); + qp = numext::mini(y, x) / p; + return p * sqrt(RealScalar(1) + qp * qp); +} + +template +struct hypot_impl { + typedef typename NumTraits::Real RealScalar; + static EIGEN_DEVICE_FUNC inline RealScalar run(const Scalar& x, const Scalar& y) { + EIGEN_USING_STD(abs); + return positive_real_hypot(abs(x), abs(y)); + } +}; + +// Generic complex sqrt implementation that correctly handles corner cases +// according to https://en.cppreference.com/w/cpp/numeric/complex/sqrt +template +EIGEN_DEVICE_FUNC std::complex complex_sqrt(const std::complex& z) { + // Computes the principal sqrt of the input. + // + // For a complex square root of the number x + i*y. We want to find real + // numbers u and v such that + // (u + i*v)^2 = x + i*y <=> + // u^2 - v^2 + i*2*u*v = x + i*v. + // By equating the real and imaginary parts we get: + // u^2 - v^2 = x + // 2*u*v = y. + // + // For x >= 0, this has the numerically stable solution + // u = sqrt(0.5 * (x + sqrt(x^2 + y^2))) + // v = y / (2 * u) + // and for x < 0, + // v = sign(y) * sqrt(0.5 * (-x + sqrt(x^2 + y^2))) + // u = y / (2 * v) + // + // Letting w = sqrt(0.5 * (|x| + |z|)), + // if x == 0: u = w, v = sign(y) * w + // if x > 0: u = w, v = y / (2 * w) + // if x < 0: u = |y| / (2 * w), v = sign(y) * w + + const T x = numext::real(z); + const T y = numext::imag(z); + const T zero = T(0); + const T w = numext::sqrt(T(0.5) * (numext::abs(x) + numext::hypot(x, y))); + + return (numext::isinf)(y) ? std::complex(NumTraits::infinity(), y) + : numext::is_exactly_zero(x) ? std::complex(w, y < zero ? -w : w) + : x > zero ? std::complex(w, y / (2 * w)) + : std::complex(numext::abs(y) / (2 * w), y < zero ? -w : w); +} + +// Generic complex rsqrt implementation. +template +EIGEN_DEVICE_FUNC std::complex complex_rsqrt(const std::complex& z) { + // Computes the principal reciprocal sqrt of the input. + // + // For a complex reciprocal square root of the number z = x + i*y. We want to + // find real numbers u and v such that + // (u + i*v)^2 = 1 / (x + i*y) <=> + // u^2 - v^2 + i*2*u*v = x/|z|^2 - i*v/|z|^2. + // By equating the real and imaginary parts we get: + // u^2 - v^2 = x/|z|^2 + // 2*u*v = y/|z|^2. + // + // For x >= 0, this has the numerically stable solution + // u = sqrt(0.5 * (x + |z|)) / |z| + // v = -y / (2 * u * |z|) + // and for x < 0, + // v = -sign(y) * sqrt(0.5 * (-x + |z|)) / |z| + // u = -y / (2 * v * |z|) + // + // Letting w = sqrt(0.5 * (|x| + |z|)), + // if x == 0: u = w / |z|, v = -sign(y) * w / |z| + // if x > 0: u = w / |z|, v = -y / (2 * w * |z|) + // if x < 0: u = |y| / (2 * w * |z|), v = -sign(y) * w / |z| + + const T x = numext::real(z); + const T y = numext::imag(z); + const T zero = T(0); + + const T abs_z = numext::hypot(x, y); + const T w = numext::sqrt(T(0.5) * (numext::abs(x) + abs_z)); + const T woz = w / abs_z; + // Corner cases consistent with 1/sqrt(z) on gcc/clang. + return numext::is_exactly_zero(abs_z) ? std::complex(NumTraits::infinity(), NumTraits::quiet_NaN()) + : ((numext::isinf)(x) || (numext::isinf)(y)) ? std::complex(zero, zero) + : numext::is_exactly_zero(x) ? std::complex(woz, y < zero ? woz : -woz) + : x > zero ? std::complex(woz, -y / (2 * w * abs_z)) + : std::complex(numext::abs(y) / (2 * w * abs_z), y < zero ? woz : -woz); +} + +template +EIGEN_DEVICE_FUNC std::complex complex_log(const std::complex& z) { + // Computes complex log. + T a = numext::abs(z); + EIGEN_USING_STD(atan2); + T b = atan2(z.imag(), z.real()); + return std::complex(numext::log(a), b); +} + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_MATHFUNCTIONSIMPL_H diff --git a/dae-cpp/Eigen/src/Core/Matrix.h b/dae-cpp/Eigen/src/Core/Matrix.h new file mode 100644 index 0000000..c11a994 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Matrix.h @@ -0,0 +1,527 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2010 Benoit Jacob +// Copyright (C) 2008-2009 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_MATRIX_H +#define EIGEN_MATRIX_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits> { + private: + constexpr static int size = internal::size_at_compile_time(Rows_, Cols_); + typedef typename find_best_packet::type PacketScalar; + enum { + row_major_bit = Options_ & RowMajor ? RowMajorBit : 0, + is_dynamic_size_storage = MaxRows_ == Dynamic || MaxCols_ == Dynamic, + max_size = is_dynamic_size_storage ? Dynamic : MaxRows_ * MaxCols_, + default_alignment = compute_default_alignment::value, + actual_alignment = ((Options_ & DontAlign) == 0) ? default_alignment : 0, + required_alignment = unpacket_traits::alignment, + packet_access_bit = (packet_traits::Vectorizable && + (EIGEN_UNALIGNED_VECTORIZE || (int(actual_alignment) >= int(required_alignment)))) + ? PacketAccessBit + : 0 + }; + + public: + typedef Scalar_ Scalar; + typedef Dense StorageKind; + typedef Eigen::Index StorageIndex; + typedef MatrixXpr XprKind; + enum { + RowsAtCompileTime = Rows_, + ColsAtCompileTime = Cols_, + MaxRowsAtCompileTime = MaxRows_, + MaxColsAtCompileTime = MaxCols_, + Flags = compute_matrix_flags(Options_), + Options = Options_, + InnerStrideAtCompileTime = 1, + OuterStrideAtCompileTime = (int(Options) & int(RowMajor)) ? ColsAtCompileTime : RowsAtCompileTime, + + // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase + EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit, + Alignment = actual_alignment + }; +}; +} // namespace internal + +/** \class Matrix + * \ingroup Core_Module + * + * \brief The matrix class, also used for vectors and row-vectors + * + * The %Matrix class is the work-horse for all \em dense (\ref dense "note") matrices and vectors within Eigen. + * Vectors are matrices with one column, and row-vectors are matrices with one row. + * + * The %Matrix class encompasses \em both fixed-size and dynamic-size objects (\ref fixedsize "note"). + * + * The first three template parameters are required: + * \tparam Scalar_ Numeric type, e.g. float, double, int or std::complex. + * User defined scalar types are supported as well (see \ref user_defined_scalars "here"). + * \tparam Rows_ Number of rows, or \b Dynamic + * \tparam Cols_ Number of columns, or \b Dynamic + * + * The remaining template parameters are optional -- in most cases you don't have to worry about them. + * \tparam Options_ A combination of either \b #RowMajor or \b #ColMajor, and of either + * \b #AutoAlign or \b #DontAlign. + * The former controls \ref TopicStorageOrders "storage order", and defaults to column-major. The latter + * controls alignment, which is required for vectorization. It defaults to aligning matrices except for fixed sizes that + * aren't a multiple of the packet size. \tparam MaxRows_ Maximum number of rows. Defaults to \a Rows_ (\ref maxrows + * "note"). \tparam MaxCols_ Maximum number of columns. Defaults to \a Cols_ (\ref maxrows "note"). + * + * Eigen provides a number of typedefs covering the usual cases. Here are some examples: + * + * \li \c Matrix2d is a 2x2 square matrix of doubles (\c Matrix) + * \li \c Vector4f is a vector of 4 floats (\c Matrix) + * \li \c RowVector3i is a row-vector of 3 ints (\c Matrix) + * + * \li \c MatrixXf is a dynamic-size matrix of floats (\c Matrix) + * \li \c VectorXf is a dynamic-size vector of floats (\c Matrix) + * + * \li \c Matrix2Xf is a partially fixed-size (dynamic-size) matrix of floats (\c Matrix) + * \li \c MatrixX3d is a partially dynamic-size (fixed-size) matrix of double (\c Matrix) + * + * See \link matrixtypedefs this page \endlink for a complete list of predefined \em %Matrix and \em Vector typedefs. + * + * You can access elements of vectors and matrices using normal subscripting: + * + * \code + * Eigen::VectorXd v(10); + * v[0] = 0.1; + * v[1] = 0.2; + * v(0) = 0.3; + * v(1) = 0.4; + * + * Eigen::MatrixXi m(10, 10); + * m(0, 1) = 1; + * m(0, 2) = 2; + * m(0, 3) = 3; + * \endcode + * + * This class can be extended with the help of the plugin mechanism described on the page + * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIX_PLUGIN. + * + * Some notes: + * + *
+ *
\anchor dense Dense versus sparse:
+ *
This %Matrix class handles dense, not sparse matrices and vectors. For sparse matrices and vectors, see the + * Sparse module. + * + * Dense matrices and vectors are plain usual arrays of coefficients. All the coefficients are stored, in an ordinary + * contiguous array. This is unlike Sparse matrices and vectors where the coefficients are stored as a list of nonzero + * coefficients.
+ * + *
\anchor fixedsize Fixed-size versus dynamic-size:
+ *
Fixed-size means that the numbers of rows and columns are known are compile-time. In this case, Eigen allocates + * the array of coefficients as a fixed-size array, as a class member. This makes sense for very small matrices, + * typically up to 4x4, sometimes up to 16x16. Larger matrices should be declared as dynamic-size even if one happens to + * know their size at compile-time. + * + * Dynamic-size means that the numbers of rows or columns are not necessarily known at compile-time. In this case they + * are runtime variables, and the array of coefficients is allocated dynamically on the heap. + * + * Note that \em dense matrices, be they Fixed-size or Dynamic-size, do not expand dynamically in the sense of + * a std::map. If you want this behavior, see the Sparse module.
+ * + *
\anchor maxrows MaxRows_ and MaxCols_:
+ *
In most cases, one just leaves these parameters to the default values. + * These parameters mean the maximum size of rows and columns that the matrix may have. They are useful in cases + * when the exact numbers of rows and columns are not known are compile-time, but it is known at compile-time that they + * cannot exceed a certain value. This happens when taking dynamic-size blocks inside fixed-size matrices: in this case + * MaxRows_ and MaxCols_ are the dimensions of the original matrix, while Rows_ and Cols_ are Dynamic.
+ *
+ * + * ABI and storage layout + * + * The table below summarizes the ABI of some possible Matrix instances which is fixed thorough the lifetime of Eigen 3. + * + * + * + * + * + * + *
Matrix typeEquivalent C structure
\code Matrix \endcode\code + * struct { + * T *data; // with (size_t(data)%EIGEN_MAX_ALIGN_BYTES)==0 + * Eigen::Index rows, cols; + * }; + * \endcode
\code + * Matrix + * Matrix \endcode\code + * struct { + * T *data; // with (size_t(data)%EIGEN_MAX_ALIGN_BYTES)==0 + * Eigen::Index size; + * }; + * \endcode
\code Matrix \endcode\code + * struct { + * T data[Rows*Cols]; // with (size_t(data)%A(Rows*Cols*sizeof(T)))==0 + * }; + * \endcode
\code Matrix \endcode\code + * struct { + * T data[MaxRows*MaxCols]; // with (size_t(data)%A(MaxRows*MaxCols*sizeof(T)))==0 + * Eigen::Index rows, cols; + * }; + * \endcode
+ * Note that in this table Rows, Cols, MaxRows and MaxCols are all positive integers. A(S) is defined to the largest + * possible power-of-two smaller to EIGEN_MAX_STATIC_ALIGN_BYTES. + * + * \see MatrixBase for the majority of the API methods for matrices, \ref TopicClassHierarchy, + * \ref TopicStorageOrders + */ + +template +class Matrix : public PlainObjectBase> { + public: + /** \brief Base class typedef. + * \sa PlainObjectBase + */ + typedef PlainObjectBase Base; + + enum { Options = Options_ }; + + EIGEN_DENSE_PUBLIC_INTERFACE(Matrix) + + typedef typename Base::PlainObject PlainObject; + + using Base::base; + using Base::coeffRef; + + /** + * \brief Assigns matrices to each other. + * + * \note This is a special case of the templated operator=. Its purpose is + * to prevent a default operator= from hiding the templated operator=. + * + * \callgraph + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other) { return Base::_set(other); } + + /** \internal + * \brief Copies the value of the expression \a other into \c *this with automatic resizing. + * + * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized), + * it will be initialized. + * + * Note that copying a row-vector into a vector (and conversely) is allowed. + * The resizing, if any, is then done in the appropriate way so that row-vectors + * remain row-vectors and vectors remain vectors. + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase& other) { + return Base::_set(other); + } + + /* Here, doxygen failed to copy the brief information when using \copydoc */ + + /** + * \brief Copies the generic expression \a other into *this. + * \copydetails DenseBase::operator=(const EigenBase &other) + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase& other) { + return Base::operator=(other); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue& func) { + return Base::operator=(func); + } + + /** \brief Default constructor. + * + * For fixed-size matrices, does nothing. + * + * For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix + * is called a null matrix. This constructor is the unique way to create null matrices: resizing + * a matrix to 0 is not supported. + * + * \sa resize(Index,Index) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix() + : Base(){EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED} + + // FIXME is it still needed + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Matrix(internal::constructor_without_unaligned_array_assert) + : Base(internal::constructor_without_unaligned_array_assert()){EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED} + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(Matrix && other) + EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible::value) + : Base(std::move(other)) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(Matrix&& other) + EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable::value) { + Base::operator=(std::move(other)); + return *this; + } + + /** \copydoc PlainObjectBase(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&... args) + * + * Example: \include Matrix_variadic_ctor_cxx11.cpp + * Output: \verbinclude Matrix_variadic_ctor_cxx11.out + * + * \sa Matrix(const std::initializer_list>&) + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, + const ArgTypes&... args) + : Base(a0, a1, a2, a3, args...) {} + + /** \brief Constructs a Matrix and initializes it from the coefficients given as initializer-lists grouped by row. + * \cpp11 + * + * In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients: + * + * Example: \include Matrix_initializer_list_23_cxx11.cpp + * Output: \verbinclude Matrix_initializer_list_23_cxx11.out + * + * Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is + * triggered. + * + * In the case of a compile-time column vector, implicit transposition from a single row is allowed. + * Therefore VectorXd{{1,2,3,4,5}} is legal and the more verbose syntax + * RowVectorXd{{1},{2},{3},{4},{5}} can be avoided: + * + * Example: \include Matrix_initializer_list_vector_cxx11.cpp + * Output: \verbinclude Matrix_initializer_list_vector_cxx11.out + * + * In the case of fixed-sized matrices, the initializer list sizes must exactly match the matrix sizes, + * and implicit transposition is allowed for compile-time vectors only. + * + * \sa Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) + */ + EIGEN_DEVICE_FUNC explicit constexpr EIGEN_STRONG_INLINE Matrix( + const std::initializer_list>& list) + : Base(list) {} + +#ifndef EIGEN_PARSED_BY_DOXYGEN + + // This constructor is for both 1x1 matrices and dynamic vectors + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Matrix(const T& x) { + Base::template _init1(x); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const T0& x, const T1& y) { + Base::template _init2(x, y); + } + +#else + /** \brief Constructs a fixed-sized matrix initialized with coefficients starting at \a data */ + EIGEN_DEVICE_FUNC explicit Matrix(const Scalar* data); + + /** \brief Constructs a vector or row-vector with given dimension. \only_for_vectors + * + * This is useful for dynamic-size vectors. For fixed-size vectors, + * it is redundant to pass these parameters, so one should use the default constructor + * Matrix() instead. + * + * \warning This constructor is disabled for fixed-size \c 1x1 matrices. For instance, + * calling Matrix(1) will call the initialization constructor: Matrix(const Scalar&). + * For fixed-size \c 1x1 matrices it is therefore recommended to use the default + * constructor Matrix() instead, especially when using one of the non standard + * \c EIGEN_INITIALIZE_MATRICES_BY_{ZERO,\c NAN} macros (see \ref TopicPreprocessorDirectives). + */ + EIGEN_STRONG_INLINE explicit Matrix(Index dim); + /** \brief Constructs an initialized 1x1 matrix with the given coefficient + * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) */ + Matrix(const Scalar& x); + /** \brief Constructs an uninitialized matrix with \a rows rows and \a cols columns. + * + * This is useful for dynamic-size matrices. For fixed-size matrices, + * it is redundant to pass these parameters, so one should use the default constructor + * Matrix() instead. + * + * \warning This constructor is disabled for fixed-size \c 1x2 and \c 2x1 vectors. For instance, + * calling Matrix2f(2,1) will call the initialization constructor: Matrix(const Scalar& x, const Scalar& y). + * For fixed-size \c 1x2 or \c 2x1 vectors it is therefore recommended to use the default + * constructor Matrix() instead, especially when using one of the non standard + * \c EIGEN_INITIALIZE_MATRICES_BY_{ZERO,\c NAN} macros (see \ref TopicPreprocessorDirectives). + */ + EIGEN_DEVICE_FUNC Matrix(Index rows, Index cols); + + /** \brief Constructs an initialized 2D vector with given coefficients + * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) */ + Matrix(const Scalar& x, const Scalar& y); +#endif // end EIGEN_PARSED_BY_DOXYGEN + + /** \brief Constructs an initialized 3D vector with given coefficients + * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z) { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3) + m_storage.data()[0] = x; + m_storage.data()[1] = y; + m_storage.data()[2] = z; + } + /** \brief Constructs an initialized 4D vector with given coefficients + * \sa Matrix(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&...) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w) { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4) + m_storage.data()[0] = x; + m_storage.data()[1] = y; + m_storage.data()[2] = z; + m_storage.data()[3] = w; + } + + /** \brief Copy constructor */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other) {} + + /** \brief Copy constructor for generic expressions. + * \sa MatrixBase::operator=(const EigenBase&) + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const EigenBase& other) : Base(other.derived()) {} + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { return 1; } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); } + + /////////// Geometry module /////////// + + template + EIGEN_DEVICE_FUNC explicit Matrix(const RotationBase& r); + template + EIGEN_DEVICE_FUNC Matrix& operator=(const RotationBase& r); + +// allow to extend Matrix outside Eigen +#ifdef EIGEN_MATRIX_PLUGIN +#include EIGEN_MATRIX_PLUGIN +#endif + + protected: + template + friend struct internal::conservative_resize_like_impl; + + using Base::m_storage; +}; + +/** \defgroup matrixtypedefs Global matrix typedefs + * + * \ingroup Core_Module + * + * %Eigen defines several typedef shortcuts for most common matrix and vector types. + * + * The general patterns are the following: + * + * \c MatrixSizeType where \c Size can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size, + * and where \c Type can be \c i for integer, \c f for float, \c d for double, \c cf for complex float, \c cd + * for complex double. + * + * For example, \c Matrix3d is a fixed-size 3x3 matrix type of doubles, and \c MatrixXf is a dynamic-size matrix of + * floats. + * + * There are also \c VectorSizeType and \c RowVectorSizeType which are self-explanatory. For example, \c Vector4cf is + * a fixed-size vector of 4 complex floats. + * + * With \cpp11, template alias are also defined for common sizes. + * They follow the same pattern as above except that the scalar type suffix is replaced by a + * template parameter, i.e.: + * - `MatrixSize` where `Size` can be \c 2,\c 3,\c 4 for fixed size square matrices or \c X for dynamic size. + * - `MatrixXSize` and `MatrixSizeX` where `Size` can be \c 2,\c 3,\c 4 for hybrid dynamic/fixed matrices. + * - `VectorSize` and `RowVectorSize` for column and row vectors. + * + * With \cpp11, you can also use fully generic column and row vector types: `Vector` and + * `RowVector`. + * + * \sa class Matrix + */ + +#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ + /** \ingroup matrixtypedefs */ \ + /** \brief `Size`×`Size` matrix of type `Type`. */ \ + typedef Matrix Matrix##SizeSuffix##TypeSuffix; \ + /** \ingroup matrixtypedefs */ \ + /** \brief `Size`×`1` vector of type `Type`. */ \ + typedef Matrix Vector##SizeSuffix##TypeSuffix; \ + /** \ingroup matrixtypedefs */ \ + /** \brief `1`×`Size` vector of type `Type`. */ \ + typedef Matrix RowVector##SizeSuffix##TypeSuffix; + +#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \ + /** \ingroup matrixtypedefs */ \ + /** \brief `Size`×`Dynamic` matrix of type `Type`. */ \ + typedef Matrix Matrix##Size##X##TypeSuffix; \ + /** \ingroup matrixtypedefs */ \ + /** \brief `Dynamic`×`Size` matrix of type `Type`. */ \ + typedef Matrix Matrix##X##Size##TypeSuffix; + +#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ + EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \ + EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \ + EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \ + EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \ + EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \ + EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \ + EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4) + +EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i) +EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f) +EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d) +EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cf) +EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex, cd) + +#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES +#undef EIGEN_MAKE_TYPEDEFS +#undef EIGEN_MAKE_FIXED_TYPEDEFS + +#define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \ + /** \ingroup matrixtypedefs */ \ + /** \brief \cpp11 `Size`×`Size` matrix of type `Type`.*/ \ + template \ + using Matrix##SizeSuffix = Matrix; \ + /** \ingroup matrixtypedefs */ \ + /** \brief \cpp11 `Size`×`1` vector of type `Type`.*/ \ + template \ + using Vector##SizeSuffix = Matrix; \ + /** \ingroup matrixtypedefs */ \ + /** \brief \cpp11 `1`×`Size` vector of type `Type`.*/ \ + template \ + using RowVector##SizeSuffix = Matrix; + +#define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \ + /** \ingroup matrixtypedefs */ \ + /** \brief \cpp11 `Size`×`Dynamic` matrix of type `Type` */ \ + template \ + using Matrix##Size##X = Matrix; \ + /** \ingroup matrixtypedefs */ \ + /** \brief \cpp11 `Dynamic`×`Size` matrix of type `Type`. */ \ + template \ + using Matrix##X##Size = Matrix; + +EIGEN_MAKE_TYPEDEFS(2, 2) +EIGEN_MAKE_TYPEDEFS(3, 3) +EIGEN_MAKE_TYPEDEFS(4, 4) +EIGEN_MAKE_TYPEDEFS(Dynamic, X) +EIGEN_MAKE_FIXED_TYPEDEFS(2) +EIGEN_MAKE_FIXED_TYPEDEFS(3) +EIGEN_MAKE_FIXED_TYPEDEFS(4) + +/** \ingroup matrixtypedefs + * \brief \cpp11 `Size`×`1` vector of type `Type`. */ +template +using Vector = Matrix; + +/** \ingroup matrixtypedefs + * \brief \cpp11 `1`×`Size` vector of type `Type`. */ +template +using RowVector = Matrix; + +#undef EIGEN_MAKE_TYPEDEFS +#undef EIGEN_MAKE_FIXED_TYPEDEFS + +} // end namespace Eigen + +#endif // EIGEN_MATRIX_H diff --git a/dae-cpp/Eigen/src/Core/MatrixBase.h b/dae-cpp/Eigen/src/Core/MatrixBase.h new file mode 100644 index 0000000..81d5a97 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/MatrixBase.h @@ -0,0 +1,542 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2009 Benoit Jacob +// Copyright (C) 2008 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_MATRIXBASE_H +#define EIGEN_MATRIXBASE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class MatrixBase + * \ingroup Core_Module + * + * \brief Base class for all dense matrices, vectors, and expressions + * + * This class is the base that is inherited by all matrix, vector, and related expression + * types. Most of the Eigen API is contained in this class, and its base classes. Other important + * classes for the Eigen API are Matrix, and VectorwiseOp. + * + * Note that some methods are defined in other modules such as the \ref LU_Module LU module + * for all functions related to matrix inversions. + * + * \tparam Derived is the derived type, e.g. a matrix type, or an expression, etc. + * + * When writing a function taking Eigen objects as argument, if you want your function + * to take as argument any matrix, vector, or expression, just let it take a + * MatrixBase argument. As an example, here is a function printFirstRow which, given + * a matrix, vector, or expression \a x, prints the first row of \a x. + * + * \code + template + void printFirstRow(const Eigen::MatrixBase& x) + { + cout << x.row(0) << endl; + } + * \endcode + * + * This class can be extended with the help of the plugin mechanism described on the page + * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_MATRIXBASE_PLUGIN. + * + * \sa \blank \ref TopicClassHierarchy + */ +template +class MatrixBase : public DenseBase { + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef MatrixBase StorageBaseType; + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::StorageIndex StorageIndex; + typedef typename internal::traits::Scalar Scalar; + typedef typename internal::packet_traits::type PacketScalar; + typedef typename NumTraits::Real RealScalar; + + typedef DenseBase Base; + using Base::ColsAtCompileTime; + using Base::Flags; + using Base::IsVectorAtCompileTime; + using Base::MaxColsAtCompileTime; + using Base::MaxRowsAtCompileTime; + using Base::MaxSizeAtCompileTime; + using Base::RowsAtCompileTime; + using Base::SizeAtCompileTime; + + using Base::coeff; + using Base::coeffRef; + using Base::cols; + using Base::const_cast_derived; + using Base::derived; + using Base::eval; + using Base::lazyAssign; + using Base::rows; + using Base::size; + using Base::operator-; + using Base::operator+=; + using Base::operator-=; + using Base::operator*=; + using Base::operator/=; + + typedef typename Base::CoeffReturnType CoeffReturnType; + typedef typename Base::ConstTransposeReturnType ConstTransposeReturnType; + typedef typename Base::RowXpr RowXpr; + typedef typename Base::ColXpr ColXpr; +#endif // not EIGEN_PARSED_BY_DOXYGEN + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** type of the equivalent square matrix */ + typedef Matrix + SquareMatrixType; +#endif // not EIGEN_PARSED_BY_DOXYGEN + + /** \returns the size of the main diagonal, which is min(rows(),cols()). + * \sa rows(), cols(), SizeAtCompileTime. */ + EIGEN_DEVICE_FUNC inline Index diagonalSize() const { return (numext::mini)(rows(), cols()); } + + typedef typename Base::PlainObject PlainObject; + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** \internal Represents a matrix with all coefficients equal to one another*/ + typedef CwiseNullaryOp, PlainObject> ConstantReturnType; + /** \internal the return type of MatrixBase::adjoint() */ + typedef std::conditional_t::IsComplex, + CwiseUnaryOp, ConstTransposeReturnType>, + ConstTransposeReturnType> + AdjointReturnType; + /** \internal Return type of eigenvalues() */ + typedef Matrix, internal::traits::ColsAtCompileTime, 1, ColMajor> + EigenvaluesReturnType; + /** \internal the return type of identity */ + typedef CwiseNullaryOp, PlainObject> IdentityReturnType; + /** \internal the return type of unit vectors */ + typedef Block, SquareMatrixType>, + internal::traits::RowsAtCompileTime, internal::traits::ColsAtCompileTime> + BasisReturnType; +#endif // not EIGEN_PARSED_BY_DOXYGEN + +#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::MatrixBase +#define EIGEN_DOC_UNARY_ADDONS(X, Y) +#include "../plugins/CommonCwiseBinaryOps.inc" +#include "../plugins/MatrixCwiseUnaryOps.inc" +#include "../plugins/MatrixCwiseBinaryOps.inc" +#ifdef EIGEN_MATRIXBASE_PLUGIN +#include EIGEN_MATRIXBASE_PLUGIN +#endif +#undef EIGEN_CURRENT_STORAGE_BASE_CLASS +#undef EIGEN_DOC_UNARY_ADDONS + + /** Special case of the template operator=, in order to prevent the compiler + * from generating a default operator= (issue hit with g++ 4.1) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const MatrixBase& other); + + // We cannot inherit here via Base::operator= since it is causing + // trouble with MSVC. + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const DenseBase& other); + + template + EIGEN_DEVICE_FUNC Derived& operator=(const EigenBase& other); + + template + EIGEN_DEVICE_FUNC Derived& operator=(const ReturnByValue& other); + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const MatrixBase& other); + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const MatrixBase& other); + + template + EIGEN_DEVICE_FUNC const Product operator*(const MatrixBase& other) const; + + template + EIGEN_DEVICE_FUNC const Product lazyProduct( + const MatrixBase& other) const; + + template + Derived& operator*=(const EigenBase& other); + + template + void applyOnTheLeft(const EigenBase& other); + + template + void applyOnTheRight(const EigenBase& other); + + template + EIGEN_DEVICE_FUNC const Product operator*( + const DiagonalBase& diagonal) const; + + template + EIGEN_DEVICE_FUNC const Product operator*( + const SkewSymmetricBase& skew) const; + + template + EIGEN_DEVICE_FUNC typename ScalarBinaryOpTraits::Scalar, + typename internal::traits::Scalar>::ReturnType + dot(const MatrixBase& other) const; + + EIGEN_DEVICE_FUNC RealScalar squaredNorm() const; + EIGEN_DEVICE_FUNC RealScalar norm() const; + RealScalar stableNorm() const; + RealScalar blueNorm() const; + RealScalar hypotNorm() const; + EIGEN_DEVICE_FUNC const PlainObject normalized() const; + EIGEN_DEVICE_FUNC const PlainObject stableNormalized() const; + EIGEN_DEVICE_FUNC void normalize(); + EIGEN_DEVICE_FUNC void stableNormalize(); + + EIGEN_DEVICE_FUNC const AdjointReturnType adjoint() const; + EIGEN_DEVICE_FUNC void adjointInPlace(); + + typedef Diagonal DiagonalReturnType; + EIGEN_DEVICE_FUNC DiagonalReturnType diagonal(); + + typedef Diagonal ConstDiagonalReturnType; + EIGEN_DEVICE_FUNC const ConstDiagonalReturnType diagonal() const; + + template + EIGEN_DEVICE_FUNC Diagonal diagonal(); + + template + EIGEN_DEVICE_FUNC const Diagonal diagonal() const; + + EIGEN_DEVICE_FUNC Diagonal diagonal(Index index); + EIGEN_DEVICE_FUNC const Diagonal diagonal(Index index) const; + + template + struct TriangularViewReturnType { + typedef TriangularView Type; + }; + template + struct ConstTriangularViewReturnType { + typedef const TriangularView Type; + }; + + template + EIGEN_DEVICE_FUNC typename TriangularViewReturnType::Type triangularView(); + template + EIGEN_DEVICE_FUNC typename ConstTriangularViewReturnType::Type triangularView() const; + + template + struct SelfAdjointViewReturnType { + typedef SelfAdjointView Type; + }; + template + struct ConstSelfAdjointViewReturnType { + typedef const SelfAdjointView Type; + }; + + template + EIGEN_DEVICE_FUNC typename SelfAdjointViewReturnType::Type selfadjointView(); + template + EIGEN_DEVICE_FUNC typename ConstSelfAdjointViewReturnType::Type selfadjointView() const; + + const SparseView sparseView( + const Scalar& m_reference = Scalar(0), + const typename NumTraits::Real& m_epsilon = NumTraits::dummy_precision()) const; + EIGEN_DEVICE_FUNC static const IdentityReturnType Identity(); + EIGEN_DEVICE_FUNC static const IdentityReturnType Identity(Index rows, Index cols); + EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index size, Index i); + EIGEN_DEVICE_FUNC static const BasisReturnType Unit(Index i); + EIGEN_DEVICE_FUNC static const BasisReturnType UnitX(); + EIGEN_DEVICE_FUNC static const BasisReturnType UnitY(); + EIGEN_DEVICE_FUNC static const BasisReturnType UnitZ(); + EIGEN_DEVICE_FUNC static const BasisReturnType UnitW(); + + EIGEN_DEVICE_FUNC const DiagonalWrapper asDiagonal() const; + const PermutationWrapper asPermutation() const; + EIGEN_DEVICE_FUNC const SkewSymmetricWrapper asSkewSymmetric() const; + + EIGEN_DEVICE_FUNC Derived& setIdentity(); + EIGEN_DEVICE_FUNC Derived& setIdentity(Index rows, Index cols); + EIGEN_DEVICE_FUNC Derived& setUnit(Index i); + EIGEN_DEVICE_FUNC Derived& setUnit(Index newSize, Index i); + + bool isIdentity(const RealScalar& prec = NumTraits::dummy_precision()) const; + bool isDiagonal(const RealScalar& prec = NumTraits::dummy_precision()) const; + + bool isUpperTriangular(const RealScalar& prec = NumTraits::dummy_precision()) const; + bool isLowerTriangular(const RealScalar& prec = NumTraits::dummy_precision()) const; + + bool isSkewSymmetric(const RealScalar& prec = NumTraits::dummy_precision()) const; + + template + bool isOrthogonal(const MatrixBase& other, + const RealScalar& prec = NumTraits::dummy_precision()) const; + bool isUnitary(const RealScalar& prec = NumTraits::dummy_precision()) const; + + /** \returns true if each coefficients of \c *this and \a other are all exactly equal. + * \warning When using floating point scalar values you probably should rather use a + * fuzzy comparison such as isApprox() + * \sa isApprox(), operator!= */ + template + EIGEN_DEVICE_FUNC inline bool operator==(const MatrixBase& other) const { + return cwiseEqual(other).all(); + } + + /** \returns true if at least one pair of coefficients of \c *this and \a other are not exactly equal to each other. + * \warning When using floating point scalar values you probably should rather use a + * fuzzy comparison such as isApprox() + * \sa isApprox(), operator== */ + template + EIGEN_DEVICE_FUNC inline bool operator!=(const MatrixBase& other) const { + return cwiseNotEqual(other).any(); + } + + NoAlias EIGEN_DEVICE_FUNC noalias(); + + // TODO forceAlignedAccess is temporarily disabled + // Need to find a nicer workaround. + inline const Derived& forceAlignedAccess() const { return derived(); } + inline Derived& forceAlignedAccess() { return derived(); } + template + inline const Derived& forceAlignedAccessIf() const { + return derived(); + } + template + inline Derived& forceAlignedAccessIf() { + return derived(); + } + + EIGEN_DEVICE_FUNC Scalar trace() const; + + template + EIGEN_DEVICE_FUNC RealScalar lpNorm() const; + + EIGEN_DEVICE_FUNC MatrixBase& matrix() { return *this; } + EIGEN_DEVICE_FUNC const MatrixBase& matrix() const { return *this; } + + /** \returns an \link Eigen::ArrayBase Array \endlink expression of this matrix + * \sa ArrayBase::matrix() */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ArrayWrapper array() { return ArrayWrapper(derived()); } + /** \returns a const \link Eigen::ArrayBase Array \endlink expression of this matrix + * \sa ArrayBase::matrix() */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArrayWrapper array() const { + return ArrayWrapper(derived()); + } + + /////////// LU module /////////// + + template + inline const FullPivLU fullPivLu() const; + template + inline const PartialPivLU partialPivLu() const; + + template + inline const PartialPivLU lu() const; + + EIGEN_DEVICE_FUNC inline const Inverse inverse() const; + + template + inline void computeInverseAndDetWithCheck( + ResultType& inverse, typename ResultType::Scalar& determinant, bool& invertible, + const RealScalar& absDeterminantThreshold = NumTraits::dummy_precision()) const; + + template + inline void computeInverseWithCheck( + ResultType& inverse, bool& invertible, + const RealScalar& absDeterminantThreshold = NumTraits::dummy_precision()) const; + + EIGEN_DEVICE_FUNC Scalar determinant() const; + + /////////// Cholesky module /////////// + + inline const LLT llt() const; + inline const LDLT ldlt() const; + + /////////// QR module /////////// + + inline const HouseholderQR householderQr() const; + template + inline const ColPivHouseholderQR colPivHouseholderQr() const; + template + inline const FullPivHouseholderQR fullPivHouseholderQr() const; + template + inline const CompleteOrthogonalDecomposition completeOrthogonalDecomposition() const; + + /////////// Eigenvalues module /////////// + + inline EigenvaluesReturnType eigenvalues() const; + inline RealScalar operatorNorm() const; + + /////////// SVD module /////////// + + template + inline JacobiSVD jacobiSvd() const; + template + EIGEN_DEPRECATED inline JacobiSVD jacobiSvd(unsigned int computationOptions) const; + + template + inline BDCSVD bdcSvd() const; + template + EIGEN_DEPRECATED inline BDCSVD bdcSvd(unsigned int computationOptions) const; + + /////////// Geometry module /////////// + + template + EIGEN_DEVICE_FUNC inline typename internal::cross_impl::return_type cross( + const MatrixBase& other) const; + + template + EIGEN_DEVICE_FUNC inline PlainObject cross3(const MatrixBase& other) const; + + EIGEN_DEVICE_FUNC inline PlainObject unitOrthogonal(void) const; + + EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline Matrix eulerAngles(Index a0, Index a1, Index a2) const; + + EIGEN_DEVICE_FUNC inline Matrix canonicalEulerAngles(Index a0, Index a1, Index a2) const; + + // put this as separate enum value to work around possible GCC 4.3 bug (?) + enum { + HomogeneousReturnTypeDirection = + ColsAtCompileTime == 1 && RowsAtCompileTime == 1 + ? ((internal::traits::Flags & RowMajorBit) == RowMajorBit ? Horizontal : Vertical) + : ColsAtCompileTime == 1 ? Vertical + : Horizontal + }; + typedef Homogeneous HomogeneousReturnType; + EIGEN_DEVICE_FUNC inline HomogeneousReturnType homogeneous() const; + + enum { SizeMinusOne = SizeAtCompileTime == Dynamic ? Dynamic : SizeAtCompileTime - 1 }; + typedef Block::ColsAtCompileTime == 1 ? SizeMinusOne : 1, + internal::traits::ColsAtCompileTime == 1 ? 1 : SizeMinusOne> + ConstStartMinusOne; + typedef EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(ConstStartMinusOne, Scalar, quotient) HNormalizedReturnType; + EIGEN_DEVICE_FUNC inline const HNormalizedReturnType hnormalized() const; + + ////////// Householder module /////////// + + EIGEN_DEVICE_FUNC void makeHouseholderInPlace(Scalar& tau, RealScalar& beta); + template + EIGEN_DEVICE_FUNC void makeHouseholder(EssentialPart& essential, Scalar& tau, RealScalar& beta) const; + template + EIGEN_DEVICE_FUNC void applyHouseholderOnTheLeft(const EssentialPart& essential, const Scalar& tau, + Scalar* workspace); + template + EIGEN_DEVICE_FUNC void applyHouseholderOnTheRight(const EssentialPart& essential, const Scalar& tau, + Scalar* workspace); + + ///////// Jacobi module ///////// + + template + EIGEN_DEVICE_FUNC void applyOnTheLeft(Index p, Index q, const JacobiRotation& j); + template + EIGEN_DEVICE_FUNC void applyOnTheRight(Index p, Index q, const JacobiRotation& j); + + ///////// SparseCore module ///////// + + template + EIGEN_STRONG_INLINE const typename SparseMatrixBase::template CwiseProductDenseReturnType::Type + cwiseProduct(const SparseMatrixBase& other) const { + return other.cwiseProduct(derived()); + } + + ///////// MatrixFunctions module ///////// + + typedef typename internal::stem_function::type StemFunction; +#define EIGEN_MATRIX_FUNCTION(ReturnType, Name, Description) \ + /** \returns an expression of the matrix Description of \c *this. \brief This function requires the unsupported MatrixFunctions module. To compute the \ + * coefficient-wise Description use ArrayBase::##Name . */ \ + const ReturnType Name() const; +#define EIGEN_MATRIX_FUNCTION_1(ReturnType, Name, Description, Argument) \ + /** \returns an expression of the matrix Description of \c *this. \brief This function requires the unsupported MatrixFunctions module. To compute the \ + * coefficient-wise Description use ArrayBase::##Name . */ \ + const ReturnType Name(Argument) const; + + EIGEN_MATRIX_FUNCTION(MatrixExponentialReturnValue, exp, exponential) + /** \brief Helper function for the unsupported + * MatrixFunctions module.*/ + const MatrixFunctionReturnValue matrixFunction(StemFunction f) const; + EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cosh, hyperbolic cosine) + EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sinh, hyperbolic sine) + EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, atanh, inverse hyperbolic cosine) + EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, acosh, inverse hyperbolic cosine) + EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, asinh, inverse hyperbolic sine) + EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cos, cosine) + EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sin, sine) + EIGEN_MATRIX_FUNCTION(MatrixSquareRootReturnValue, sqrt, square root) + EIGEN_MATRIX_FUNCTION(MatrixLogarithmReturnValue, log, logarithm) + EIGEN_MATRIX_FUNCTION_1(MatrixPowerReturnValue, pow, power to \c p, const RealScalar& p) + EIGEN_MATRIX_FUNCTION_1(MatrixComplexPowerReturnValue, pow, power to \c p, const std::complex& p) + + protected: + EIGEN_DEFAULT_COPY_CONSTRUCTOR(MatrixBase) + EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MatrixBase) + + private: + EIGEN_DEVICE_FUNC explicit MatrixBase(int); + EIGEN_DEVICE_FUNC MatrixBase(int, int); + template + EIGEN_DEVICE_FUNC explicit MatrixBase(const MatrixBase&); + + protected: + // mixing arrays and matrices is not legal + template + Derived& operator+=(const ArrayBase&) { + EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1, + YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); + return *this; + } + // mixing arrays and matrices is not legal + template + Derived& operator-=(const ArrayBase&) { + EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1, + YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); + return *this; + } +}; + +/*************************************************************************** + * Implementation of matrix base methods + ***************************************************************************/ + +/** replaces \c *this by \c *this * \a other. + * + * \returns a reference to \c *this + * + * Example: \include MatrixBase_applyOnTheRight.cpp + * Output: \verbinclude MatrixBase_applyOnTheRight.out + */ +template +template +inline Derived& MatrixBase::operator*=(const EigenBase& other) { + other.derived().applyThisOnTheRight(derived()); + return derived(); +} + +/** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=(). + * + * Example: \include MatrixBase_applyOnTheRight.cpp + * Output: \verbinclude MatrixBase_applyOnTheRight.out + */ +template +template +inline void MatrixBase::applyOnTheRight(const EigenBase& other) { + other.derived().applyThisOnTheRight(derived()); +} + +/** replaces \c *this by \a other * \c *this. + * + * Example: \include MatrixBase_applyOnTheLeft.cpp + * Output: \verbinclude MatrixBase_applyOnTheLeft.out + */ +template +template +inline void MatrixBase::applyOnTheLeft(const EigenBase& other) { + other.derived().applyThisOnTheLeft(derived()); +} + +} // end namespace Eigen + +#endif // EIGEN_MATRIXBASE_H diff --git a/dae-cpp/Eigen/src/Core/NestByValue.h b/dae-cpp/Eigen/src/Core/NestByValue.h new file mode 100644 index 0000000..ec360eb --- /dev/null +++ b/dae-cpp/Eigen/src/Core/NestByValue.h @@ -0,0 +1,91 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2006-2008 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_NESTBYVALUE_H +#define EIGEN_NESTBYVALUE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits > : public traits { + enum { Flags = traits::Flags & ~NestByRefBit }; +}; +} // namespace internal + +/** \class NestByValue + * \ingroup Core_Module + * + * \brief Expression which must be nested by value + * + * \tparam ExpressionType the type of the object of which we are requiring nesting-by-value + * + * This class is the return type of MatrixBase::nestByValue() + * and most of the time this is the only way it is used. + * + * \sa MatrixBase::nestByValue() + */ +template +class NestByValue : public internal::dense_xpr_base >::type { + public: + typedef typename internal::dense_xpr_base::type Base; + static constexpr bool HasDirectAccess = internal::has_direct_access::ret; + + EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue) + + EIGEN_DEVICE_FUNC explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {} + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_expression.rows(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_expression.cols(); } + + EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; } + + EIGEN_DEVICE_FUNC const ExpressionType& nestedExpression() const { return m_expression; } + + EIGEN_DEVICE_FUNC typename std::enable_if::type data() const { + return m_expression.data(); + } + + EIGEN_DEVICE_FUNC typename std::enable_if::type innerStride() const { + return m_expression.innerStride(); + } + + EIGEN_DEVICE_FUNC typename std::enable_if::type outerStride() const { + return m_expression.outerStride(); + } + + protected: + const ExpressionType m_expression; +}; + +/** \returns an expression of the temporary version of *this. + */ +template +EIGEN_DEVICE_FUNC inline const NestByValue DenseBase::nestByValue() const { + return NestByValue(derived()); +} + +namespace internal { + +// Evaluator of Solve -> eval into a temporary +template +struct evaluator > : public evaluator { + typedef evaluator Base; + + EIGEN_DEVICE_FUNC explicit evaluator(const NestByValue& xpr) : Base(xpr.nestedExpression()) {} +}; +} // namespace internal + +} // end namespace Eigen + +#endif // EIGEN_NESTBYVALUE_H diff --git a/dae-cpp/Eigen/src/Core/NoAlias.h b/dae-cpp/Eigen/src/Core/NoAlias.h new file mode 100644 index 0000000..b6c7209 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/NoAlias.h @@ -0,0 +1,102 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_NOALIAS_H +#define EIGEN_NOALIAS_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class NoAlias + * \ingroup Core_Module + * + * \brief Pseudo expression providing an operator = assuming no aliasing + * + * \tparam ExpressionType the type of the object on which to do the lazy assignment + * + * This class represents an expression with special assignment operators + * assuming no aliasing between the target expression and the source expression. + * More precisely it alloas to bypass the EvalBeforeAssignBit flag of the source expression. + * It is the return type of MatrixBase::noalias() + * and most of the time this is the only way it is used. + * + * \sa MatrixBase::noalias() + */ +template class StorageBase> +class NoAlias { + public: + typedef typename ExpressionType::Scalar Scalar; + + EIGEN_DEVICE_FUNC explicit NoAlias(ExpressionType& expression) : m_expression(expression) {} + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase& other) { + call_assignment_no_alias(m_expression, other.derived(), + internal::assign_op()); + return m_expression; + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase& other) { + call_assignment_no_alias(m_expression, other.derived(), + internal::add_assign_op()); + return m_expression; + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase& other) { + call_assignment_no_alias(m_expression, other.derived(), + internal::sub_assign_op()); + return m_expression; + } + + EIGEN_DEVICE_FUNC ExpressionType& expression() const { return m_expression; } + + protected: + ExpressionType& m_expression; +}; + +/** \returns a pseudo expression of \c *this with an operator= assuming + * no aliasing between \c *this and the source expression. + * + * More precisely, noalias() allows to bypass the EvalBeforeAssignBit flag. + * Currently, even though several expressions may alias, only product + * expressions have this flag. Therefore, noalias() is only useful when + * the source expression contains a matrix product. + * + * Here are some examples where noalias is useful: + * \code + * D.noalias() = A * B; + * D.noalias() += A.transpose() * B; + * D.noalias() -= 2 * A * B.adjoint(); + * \endcode + * + * On the other hand the following example will lead to a \b wrong result: + * \code + * A.noalias() = A * B; + * \endcode + * because the result matrix A is also an operand of the matrix product. Therefore, + * there is no alternative than evaluating A * B in a temporary, that is the default + * behavior when you write: + * \code + * A = A * B; + * \endcode + * + * \sa class NoAlias + */ +template +NoAlias EIGEN_DEVICE_FUNC MatrixBase::noalias() { + return NoAlias(derived()); +} + +} // end namespace Eigen + +#endif // EIGEN_NOALIAS_H diff --git a/dae-cpp/Eigen/src/Core/NumTraits.h b/dae-cpp/Eigen/src/Core/NumTraits.h new file mode 100644 index 0000000..2848b78 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/NumTraits.h @@ -0,0 +1,327 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2010 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_NUMTRAITS_H +#define EIGEN_NUMTRAITS_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +// default implementation of digits(), based on numeric_limits if specialized, +// 0 for integer types, and log2(epsilon()) otherwise. +template ::is_specialized, + bool is_integer = NumTraits::IsInteger> +struct default_digits_impl { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { return std::numeric_limits::digits; } +}; + +template +struct default_digits_impl // Floating point +{ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { + using std::ceil; + using std::log2; + typedef typename NumTraits::Real Real; + return int(ceil(-log2(NumTraits::epsilon()))); + } +}; + +template +struct default_digits_impl // Integer +{ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { return 0; } +}; + +// default implementation of digits10(), based on numeric_limits if specialized, +// 0 for integer types, and floor((digits()-1)*log10(2)) otherwise. +template ::is_specialized, + bool is_integer = NumTraits::IsInteger> +struct default_digits10_impl { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { return std::numeric_limits::digits10; } +}; + +template +struct default_digits10_impl // Floating point +{ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { + using std::floor; + using std::log10; + typedef typename NumTraits::Real Real; + return int(floor((internal::default_digits_impl::run() - 1) * log10(2))); + } +}; + +template +struct default_digits10_impl // Integer +{ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { return 0; } +}; + +// default implementation of max_digits10(), based on numeric_limits if specialized, +// 0 for integer types, and log10(2) * digits() + 1 otherwise. +template ::is_specialized, + bool is_integer = NumTraits::IsInteger> +struct default_max_digits10_impl { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { return std::numeric_limits::max_digits10; } +}; + +template +struct default_max_digits10_impl // Floating point +{ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { + using std::ceil; + using std::log10; + typedef typename NumTraits::Real Real; + return int(ceil(internal::default_digits_impl::run() * log10(2) + 1)); + } +}; + +template +struct default_max_digits10_impl // Integer +{ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static int run() { return 0; } +}; + +} // end namespace internal + +namespace numext { +/** \internal bit-wise cast without changing the underlying bit representation. */ + +// TODO: Replace by std::bit_cast (available in C++20) +template +EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Tgt bit_cast(const Src& src) { + // The behaviour of memcpy is not specified for non-trivially copyable types + EIGEN_STATIC_ASSERT(std::is_trivially_copyable::value, THIS_TYPE_IS_NOT_SUPPORTED); + EIGEN_STATIC_ASSERT(std::is_trivially_copyable::value && std::is_default_constructible::value, + THIS_TYPE_IS_NOT_SUPPORTED); + EIGEN_STATIC_ASSERT(sizeof(Src) == sizeof(Tgt), THIS_TYPE_IS_NOT_SUPPORTED); + + Tgt tgt; + // Load src into registers first. This allows the memcpy to be elided by CUDA. + const Src staged = src; + EIGEN_USING_STD(memcpy) + memcpy(static_cast(&tgt), static_cast(&staged), sizeof(Tgt)); + return tgt; +} +} // namespace numext + +/** \class NumTraits + * \ingroup Core_Module + * + * \brief Holds information about the various numeric (i.e. scalar) types allowed by Eigen. + * + * \tparam T the numeric type at hand + * + * This class stores enums, typedefs and static methods giving information about a numeric type. + * + * The provided data consists of: + * \li A typedef \c Real, giving the "real part" type of \a T. If \a T is already real, + * then \c Real is just a typedef to \a T. If \a T is \c std::complex then \c Real + * is a typedef to \a U. + * \li A typedef \c NonInteger, giving the type that should be used for operations producing non-integral values, + * such as quotients, square roots, etc. If \a T is a floating-point type, then this typedef just gives + * \a T again. Note however that many Eigen functions such as internal::sqrt simply refuse to + * take integers. Outside of a few cases, Eigen doesn't do automatic type promotion. Thus, this typedef is + * only intended as a helper for code that needs to explicitly promote types. + * \li A typedef \c Literal giving the type to use for numeric literals such as "2" or "0.5". For instance, for \c + * std::complex, Literal is defined as \c U. Of course, this type must be fully compatible with \a T. In doubt, just + * use \a T here. \li A typedef \a Nested giving the type to use to nest a value inside of the expression tree. If you + * don't know what this means, just use \a T here. \li An enum value \a IsComplex. It is equal to 1 if \a T is a \c + * std::complex type, and to 0 otherwise. \li An enum value \a IsInteger. It is equal to \c 1 if \a T is an integer type + * such as \c int, and to \c 0 otherwise. \li Enum values ReadCost, AddCost and MulCost representing a rough estimate of + * the number of CPU cycles needed to by move / add / mul instructions respectively, assuming the data is already stored + * in CPU registers. Stay vague here. No need to do architecture-specific stuff. If you don't know what this means, just + * use \c Eigen::HugeCost. \li An enum value \a IsSigned. It is equal to \c 1 if \a T is a signed type and to 0 if \a T + * is unsigned. \li An enum value \a RequireInitialization. It is equal to \c 1 if the constructor of the numeric type + * \a T must be called, and to 0 if it is safe not to call it. Default is 0 if \a T is an arithmetic type, and 1 + * otherwise. \li An epsilon() function which, unlike std::numeric_limits::epsilon(), it returns a + * \a Real instead of a \a T. \li A dummy_precision() function returning a weak epsilon value. It is mainly used as a + * default value by the fuzzy comparison operators. \li highest() and lowest() functions returning the highest and + * lowest possible values respectively. \li digits() function returning the number of radix digits (non-sign digits for + * integers, mantissa for floating-point). This is the analogue of std::numeric_limits::digits which is used + * as the default implementation if specialized. \li digits10() function returning the number of decimal digits that can + * be represented without change. This is the analogue of std::numeric_limits::digits10 which is + * used as the default implementation if specialized. \li max_digits10() function returning the number of decimal digits + * required to uniquely represent all distinct values of the type. This is the analogue of std::numeric_limits::max_digits10 + * which is used as the default implementation if specialized. + * \li min_exponent() and max_exponent() functions returning the highest and lowest possible values, respectively, + * such that the radix raised to the power exponent-1 is a normalized floating-point number. These are equivalent + * to std::numeric_limits::min_exponent/ + * std::numeric_limits::max_exponent. + * \li infinity() function returning a representation of positive infinity, if available. + * \li quiet_NaN function returning a non-signaling "not-a-number", if available. + */ + +template +struct GenericNumTraits { + enum { + IsInteger = std::numeric_limits::is_integer, + IsSigned = std::numeric_limits::is_signed, + IsComplex = 0, + RequireInitialization = internal::is_arithmetic::value ? 0 : 1, + ReadCost = 1, + AddCost = 1, + MulCost = 1 + }; + + typedef T Real; + typedef std::conditional_t, T> NonInteger; + typedef T Nested; + typedef T Literal; + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline Real epsilon() { return numext::numeric_limits::epsilon(); } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline int digits10() { return internal::default_digits10_impl::run(); } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline int max_digits10() { + return internal::default_max_digits10_impl::run(); + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline int digits() { return internal::default_digits_impl::run(); } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline int min_exponent() { return numext::numeric_limits::min_exponent; } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline int max_exponent() { return numext::numeric_limits::max_exponent; } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline Real dummy_precision() { + // make sure to override this for floating-point types + return Real(0); + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline T highest() { return (numext::numeric_limits::max)(); } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline T lowest() { return (numext::numeric_limits::lowest)(); } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline T infinity() { return numext::numeric_limits::infinity(); } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline T quiet_NaN() { return numext::numeric_limits::quiet_NaN(); } +}; + +template +struct NumTraits : GenericNumTraits {}; + +template <> +struct NumTraits : GenericNumTraits { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline float dummy_precision() { return 1e-5f; } +}; + +template <> +struct NumTraits : GenericNumTraits { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline double dummy_precision() { return 1e-12; } +}; + +// GPU devices treat `long double` as `double`. +#ifndef EIGEN_GPU_COMPILE_PHASE +template <> +struct NumTraits : GenericNumTraits { + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline long double dummy_precision() { + return static_cast(1e-15l); + } + +#if defined(EIGEN_ARCH_PPC) && (__LDBL_MANT_DIG__ == 106) + // PowerPC double double causes issues with some values + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline long double epsilon() { + // 2^(-(__LDBL_MANT_DIG__)+1) + return static_cast(2.4651903288156618919116517665087e-32l); + } +#endif +}; +#endif + +template +struct NumTraits > : GenericNumTraits > { + typedef Real_ Real; + typedef typename NumTraits::Literal Literal; + enum { + IsComplex = 1, + RequireInitialization = NumTraits::RequireInitialization, + ReadCost = 2 * NumTraits::ReadCost, + AddCost = 2 * NumTraits::AddCost, + MulCost = 4 * NumTraits::MulCost + 2 * NumTraits::AddCost + }; + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline Real epsilon() { return NumTraits::epsilon(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline Real dummy_precision() { return NumTraits::dummy_precision(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline int digits10() { return NumTraits::digits10(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline int max_digits10() { return NumTraits::max_digits10(); } +}; + +template +struct NumTraits > { + typedef Array ArrayType; + typedef typename NumTraits::Real RealScalar; + typedef Array Real; + typedef typename NumTraits::NonInteger NonIntegerScalar; + typedef Array NonInteger; + typedef ArrayType& Nested; + typedef typename NumTraits::Literal Literal; + + enum { + IsComplex = NumTraits::IsComplex, + IsInteger = NumTraits::IsInteger, + IsSigned = NumTraits::IsSigned, + RequireInitialization = 1, + ReadCost = ArrayType::SizeAtCompileTime == Dynamic + ? HugeCost + : ArrayType::SizeAtCompileTime * int(NumTraits::ReadCost), + AddCost = ArrayType::SizeAtCompileTime == Dynamic ? HugeCost + : ArrayType::SizeAtCompileTime * int(NumTraits::AddCost), + MulCost = ArrayType::SizeAtCompileTime == Dynamic ? HugeCost + : ArrayType::SizeAtCompileTime * int(NumTraits::MulCost) + }; + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline RealScalar epsilon() { return NumTraits::epsilon(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR static inline RealScalar dummy_precision() { + return NumTraits::dummy_precision(); + } + + EIGEN_CONSTEXPR + static inline int digits10() { return NumTraits::digits10(); } + EIGEN_CONSTEXPR + static inline int max_digits10() { return NumTraits::max_digits10(); } +}; + +template <> +struct NumTraits : GenericNumTraits { + enum { RequireInitialization = 1, ReadCost = HugeCost, AddCost = HugeCost, MulCost = HugeCost }; + + EIGEN_CONSTEXPR + static inline int digits10() { return 0; } + EIGEN_CONSTEXPR + static inline int max_digits10() { return 0; } + + private: + static inline std::string epsilon(); + static inline std::string dummy_precision(); + static inline std::string lowest(); + static inline std::string highest(); + static inline std::string infinity(); + static inline std::string quiet_NaN(); +}; + +// Empty specialization for void to allow template specialization based on NumTraits::Real with T==void and SFINAE. +template <> +struct NumTraits {}; + +template <> +struct NumTraits : GenericNumTraits {}; + +} // end namespace Eigen + +#endif // EIGEN_NUMTRAITS_H diff --git a/dae-cpp/Eigen/src/Core/PartialReduxEvaluator.h b/dae-cpp/Eigen/src/Core/PartialReduxEvaluator.h new file mode 100644 index 0000000..7b2c8dc --- /dev/null +++ b/dae-cpp/Eigen/src/Core/PartialReduxEvaluator.h @@ -0,0 +1,209 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2011-2018 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_PARTIALREDUX_H +#define EIGEN_PARTIALREDUX_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +/*************************************************************************** + * + * This file provides evaluators for partial reductions. + * There are two modes: + * + * - scalar path: simply calls the respective function on the column or row. + * -> nothing special here, all the tricky part is handled by the return + * types of VectorwiseOp's members. They embed the functor calling the + * respective DenseBase's member function. + * + * - vectorized path: implements a packet-wise reductions followed by + * some (optional) processing of the outcome, e.g., division by n for mean. + * + * For the vectorized path let's observe that the packet-size and outer-unrolling + * are both decided by the assignment logic. So all we have to do is to decide + * on the inner unrolling. + * + * For the unrolling, we can reuse "internal::redux_vec_unroller" from Redux.h, + * but be need to be careful to specify correct increment. + * + ***************************************************************************/ + +/* logic deciding a strategy for unrolling of vectorized paths */ +template +struct packetwise_redux_traits { + enum { + OuterSize = int(Evaluator::IsRowMajor) ? Evaluator::RowsAtCompileTime : Evaluator::ColsAtCompileTime, + Cost = OuterSize == Dynamic ? HugeCost + : OuterSize * Evaluator::CoeffReadCost + (OuterSize - 1) * functor_traits::Cost, + Unrolling = Cost <= EIGEN_UNROLLING_LIMIT ? CompleteUnrolling : NoUnrolling + }; +}; + +/* Value to be returned when size==0 , by default let's return 0 */ +template +EIGEN_DEVICE_FUNC PacketType packetwise_redux_empty_value(const Func&) { + const typename unpacket_traits::type zero(0); + return pset1(zero); +} + +/* For products the default is 1 */ +template +EIGEN_DEVICE_FUNC PacketType packetwise_redux_empty_value(const scalar_product_op&) { + return pset1(Scalar(1)); +} + +/* Perform the actual reduction */ +template ::Unrolling> +struct packetwise_redux_impl; + +/* Perform the actual reduction with unrolling */ +template +struct packetwise_redux_impl { + typedef redux_novec_unroller Base; + typedef typename Evaluator::Scalar Scalar; + + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE PacketType run(const Evaluator& eval, const Func& func, Index /*size*/) { + return redux_vec_unroller::OuterSize>::template run(eval, + func); + } +}; + +/* Add a specialization of redux_vec_unroller for size==0 at compiletime. + * This specialization is not required for general reductions, which is + * why it is defined here. + */ +template +struct redux_vec_unroller { + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE PacketType run(const Evaluator&, const Func& f) { + return packetwise_redux_empty_value(f); + } +}; + +/* Perform the actual reduction for dynamic sizes */ +template +struct packetwise_redux_impl { + typedef typename Evaluator::Scalar Scalar; + typedef typename redux_traits::PacketType PacketScalar; + + template + EIGEN_DEVICE_FUNC static PacketType run(const Evaluator& eval, const Func& func, Index size) { + if (size == 0) return packetwise_redux_empty_value(func); + + const Index size4 = (size - 1) & (~3); + PacketType p = eval.template packetByOuterInner(0, 0); + Index i = 1; + // This loop is optimized for instruction pipelining: + // - each iteration generates two independent instructions + // - thanks to branch prediction and out-of-order execution we have independent instructions across loops + for (; i < size4; i += 4) + p = func.packetOp( + p, func.packetOp(func.packetOp(eval.template packetByOuterInner(i + 0, 0), + eval.template packetByOuterInner(i + 1, 0)), + func.packetOp(eval.template packetByOuterInner(i + 2, 0), + eval.template packetByOuterInner(i + 3, 0)))); + for (; i < size; ++i) p = func.packetOp(p, eval.template packetByOuterInner(i, 0)); + return p; + } +}; + +template +struct evaluator > + : evaluator_base > { + typedef PartialReduxExpr XprType; + typedef typename internal::nested_eval::type ArgTypeNested; + typedef add_const_on_value_type_t ConstArgTypeNested; + typedef internal::remove_all_t ArgTypeNestedCleaned; + typedef typename ArgType::Scalar InputScalar; + typedef typename XprType::Scalar Scalar; + enum { + TraversalSize = Direction == int(Vertical) ? int(ArgType::RowsAtCompileTime) : int(ArgType::ColsAtCompileTime) + }; + typedef typename MemberOp::template Cost CostOpType; + enum { + CoeffReadCost = TraversalSize == Dynamic ? HugeCost + : TraversalSize == 0 + ? 1 + : int(TraversalSize) * int(evaluator::CoeffReadCost) + int(CostOpType::value), + + ArgFlags_ = evaluator::Flags, + + Vectorizable_ = bool(int(ArgFlags_) & PacketAccessBit) && bool(MemberOp::Vectorizable) && + (Direction == int(Vertical) ? bool(ArgFlags_ & RowMajorBit) : (ArgFlags_ & RowMajorBit) == 0) && + (TraversalSize != 0), + + Flags = (traits::Flags & RowMajorBit) | (evaluator::Flags & (HereditaryBits & (~RowMajorBit))) | + (Vectorizable_ ? PacketAccessBit : 0) | LinearAccessBit, + + Alignment = 0 // FIXME this will need to be improved once PartialReduxExpr is vectorized + }; + + EIGEN_DEVICE_FUNC explicit evaluator(const XprType xpr) : m_arg(xpr.nestedExpression()), m_functor(xpr.functor()) { + EIGEN_INTERNAL_CHECK_COST_VALUE(TraversalSize == Dynamic ? HugeCost + : (TraversalSize == 0 ? 1 : int(CostOpType::value))); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index i, Index j) const { + return coeff(Direction == Vertical ? j : i); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index index) const { + return m_functor(m_arg.template subVector(index)); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packet(Index i, Index j) const { + return packet(Direction == Vertical ? j : i); + } + + template + EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC PacketType packet(Index idx) const { + enum { PacketSize = internal::unpacket_traits::size }; + typedef Block + PanelType; + + PanelType panel(m_arg, Direction == Vertical ? 0 : idx, Direction == Vertical ? idx : 0, + Direction == Vertical ? m_arg.rows() : Index(PacketSize), + Direction == Vertical ? Index(PacketSize) : m_arg.cols()); + + // FIXME + // See bug 1612, currently if PacketSize==1 (i.e. complex with 128bits registers) then the storage-order of + // panel get reversed and methods like packetByOuterInner do not make sense anymore in this context. So let's just + // by pass "vectorization" in this case: + if (PacketSize == 1) return internal::pset1(coeff(idx)); + + typedef typename internal::redux_evaluator PanelEvaluator; + PanelEvaluator panel_eval(panel); + typedef typename MemberOp::BinaryOp BinaryOp; + PacketType p = internal::packetwise_redux_impl::template run( + panel_eval, m_functor.binaryFunc(), m_arg.outerSize()); + return p; + } + + protected: + ConstArgTypeNested m_arg; + const MemberOp m_functor; +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_PARTIALREDUX_H diff --git a/dae-cpp/Eigen/src/Core/PermutationMatrix.h b/dae-cpp/Eigen/src/Core/PermutationMatrix.h new file mode 100644 index 0000000..6945964 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/PermutationMatrix.h @@ -0,0 +1,552 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Benoit Jacob +// Copyright (C) 2009-2015 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_PERMUTATIONMATRIX_H +#define EIGEN_PERMUTATIONMATRIX_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +enum PermPermProduct_t { PermPermProduct }; + +} // end namespace internal + +/** \class PermutationBase + * \ingroup Core_Module + * + * \brief Base class for permutations + * + * \tparam Derived the derived class + * + * This class is the base class for all expressions representing a permutation matrix, + * internally stored as a vector of integers. + * The convention followed here is that if \f$ \sigma \f$ is a permutation, the corresponding permutation matrix + * \f$ P_\sigma \f$ is such that if \f$ (e_1,\ldots,e_p) \f$ is the canonical basis, we have: + * \f[ P_\sigma(e_i) = e_{\sigma(i)}. \f] + * This convention ensures that for any two permutations \f$ \sigma, \tau \f$, we have: + * \f[ P_{\sigma\circ\tau} = P_\sigma P_\tau. \f] + * + * Permutation matrices are square and invertible. + * + * Notice that in addition to the member functions and operators listed here, there also are non-member + * operator* to multiply any kind of permutation object with any kind of matrix expression (MatrixBase) + * on either side. + * + * \sa class PermutationMatrix, class PermutationWrapper + */ +template +class PermutationBase : public EigenBase { + typedef internal::traits Traits; + typedef EigenBase Base; + + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef typename Traits::IndicesType IndicesType; + enum { + Flags = Traits::Flags, + RowsAtCompileTime = Traits::RowsAtCompileTime, + ColsAtCompileTime = Traits::ColsAtCompileTime, + MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = Traits::MaxColsAtCompileTime + }; + typedef typename Traits::StorageIndex StorageIndex; + typedef Matrix + DenseMatrixType; + typedef PermutationMatrix + PlainPermutationType; + typedef PlainPermutationType PlainObject; + using Base::derived; + typedef Inverse InverseReturnType; + typedef void Scalar; +#endif + + /** Copies the other permutation into *this */ + template + Derived& operator=(const PermutationBase& other) { + indices() = other.indices(); + return derived(); + } + + /** Assignment from the Transpositions \a tr */ + template + Derived& operator=(const TranspositionsBase& tr) { + setIdentity(tr.size()); + for (Index k = size() - 1; k >= 0; --k) applyTranspositionOnTheRight(k, tr.coeff(k)); + return derived(); + } + + /** \returns the number of rows */ + inline EIGEN_DEVICE_FUNC Index rows() const { return Index(indices().size()); } + + /** \returns the number of columns */ + inline EIGEN_DEVICE_FUNC Index cols() const { return Index(indices().size()); } + + /** \returns the size of a side of the respective square matrix, i.e., the number of indices */ + inline EIGEN_DEVICE_FUNC Index size() const { return Index(indices().size()); } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + template + void evalTo(MatrixBase& other) const { + other.setZero(); + for (Index i = 0; i < rows(); ++i) other.coeffRef(indices().coeff(i), i) = typename DenseDerived::Scalar(1); + } +#endif + + /** \returns a Matrix object initialized from this permutation matrix. Notice that it + * is inefficient to return this Matrix object by value. For efficiency, favor using + * the Matrix constructor taking EigenBase objects. + */ + DenseMatrixType toDenseMatrix() const { return derived(); } + + /** const version of indices(). */ + const IndicesType& indices() const { return derived().indices(); } + /** \returns a reference to the stored array representing the permutation. */ + IndicesType& indices() { return derived().indices(); } + + /** Resizes to given size. + */ + inline void resize(Index newSize) { indices().resize(newSize); } + + /** Sets *this to be the identity permutation matrix */ + void setIdentity() { + StorageIndex n = StorageIndex(size()); + for (StorageIndex i = 0; i < n; ++i) indices().coeffRef(i) = i; + } + + /** Sets *this to be the identity permutation matrix of given size. + */ + void setIdentity(Index newSize) { + resize(newSize); + setIdentity(); + } + + /** Multiplies *this by the transposition \f$(ij)\f$ on the left. + * + * \returns a reference to *this. + * + * \warning This is much slower than applyTranspositionOnTheRight(Index,Index): + * this has linear complexity and requires a lot of branching. + * + * \sa applyTranspositionOnTheRight(Index,Index) + */ + Derived& applyTranspositionOnTheLeft(Index i, Index j) { + eigen_assert(i >= 0 && j >= 0 && i < size() && j < size()); + for (Index k = 0; k < size(); ++k) { + if (indices().coeff(k) == i) + indices().coeffRef(k) = StorageIndex(j); + else if (indices().coeff(k) == j) + indices().coeffRef(k) = StorageIndex(i); + } + return derived(); + } + + /** Multiplies *this by the transposition \f$(ij)\f$ on the right. + * + * \returns a reference to *this. + * + * This is a fast operation, it only consists in swapping two indices. + * + * \sa applyTranspositionOnTheLeft(Index,Index) + */ + Derived& applyTranspositionOnTheRight(Index i, Index j) { + eigen_assert(i >= 0 && j >= 0 && i < size() && j < size()); + std::swap(indices().coeffRef(i), indices().coeffRef(j)); + return derived(); + } + + /** \returns the inverse permutation matrix. + * + * \note \blank \note_try_to_help_rvo + */ + inline InverseReturnType inverse() const { return InverseReturnType(derived()); } + /** \returns the tranpose permutation matrix. + * + * \note \blank \note_try_to_help_rvo + */ + inline InverseReturnType transpose() const { return InverseReturnType(derived()); } + + /**** multiplication helpers to hopefully get RVO ****/ + +#ifndef EIGEN_PARSED_BY_DOXYGEN + protected: + template + void assignTranspose(const PermutationBase& other) { + for (Index i = 0; i < rows(); ++i) indices().coeffRef(other.indices().coeff(i)) = i; + } + template + void assignProduct(const Lhs& lhs, const Rhs& rhs) { + eigen_assert(lhs.cols() == rhs.rows()); + for (Index i = 0; i < rows(); ++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i)); + } +#endif + + public: + /** \returns the product permutation matrix. + * + * \note \blank \note_try_to_help_rvo + */ + template + inline PlainPermutationType operator*(const PermutationBase& other) const { + return PlainPermutationType(internal::PermPermProduct, derived(), other.derived()); + } + + /** \returns the product of a permutation with another inverse permutation. + * + * \note \blank \note_try_to_help_rvo + */ + template + inline PlainPermutationType operator*(const InverseImpl& other) const { + return PlainPermutationType(internal::PermPermProduct, *this, other.eval()); + } + + /** \returns the product of an inverse permutation with another permutation. + * + * \note \blank \note_try_to_help_rvo + */ + template + friend inline PlainPermutationType operator*(const InverseImpl& other, + const PermutationBase& perm) { + return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); + } + + /** \returns the determinant of the permutation matrix, which is either 1 or -1 depending on the parity of the + * permutation. + * + * This function is O(\c n) procedure allocating a buffer of \c n booleans. + */ + Index determinant() const { + Index res = 1; + Index n = size(); + Matrix mask(n); + mask.fill(false); + Index r = 0; + while (r < n) { + // search for the next seed + while (r < n && mask[r]) r++; + if (r >= n) break; + // we got one, let's follow it until we are back to the seed + Index k0 = r++; + mask.coeffRef(k0) = true; + for (Index k = indices().coeff(k0); k != k0; k = indices().coeff(k)) { + mask.coeffRef(k) = true; + res = -res; + } + } + return res; + } + + protected: +}; + +namespace internal { +template +struct traits > + : traits< + Matrix > { + typedef PermutationStorage StorageKind; + typedef Matrix IndicesType; + typedef StorageIndex_ StorageIndex; + typedef void Scalar; +}; +} // namespace internal + +/** \class PermutationMatrix + * \ingroup Core_Module + * + * \brief Permutation matrix + * + * \tparam SizeAtCompileTime the number of rows/cols, or Dynamic + * \tparam MaxSizeAtCompileTime the maximum number of rows/cols, or Dynamic. This optional parameter defaults to + * SizeAtCompileTime. Most of the time, you should not have to specify it. \tparam StorageIndex_ the integer type of the + * indices + * + * This class represents a permutation matrix, internally stored as a vector of integers. + * + * \sa class PermutationBase, class PermutationWrapper, class DiagonalMatrix + */ +template +class PermutationMatrix + : public PermutationBase > { + typedef PermutationBase Base; + typedef internal::traits Traits; + + public: + typedef const PermutationMatrix& Nested; + +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef typename Traits::IndicesType IndicesType; + typedef typename Traits::StorageIndex StorageIndex; +#endif + + inline PermutationMatrix() {} + + /** Constructs an uninitialized permutation matrix of given size. + */ + explicit inline PermutationMatrix(Index size) : m_indices(size) { + eigen_internal_assert(size <= NumTraits::highest()); + } + + /** Copy constructor. */ + template + inline PermutationMatrix(const PermutationBase& other) : m_indices(other.indices()) {} + + /** Generic constructor from expression of the indices. The indices + * array has the meaning that the permutations sends each integer i to indices[i]. + * + * \warning It is your responsibility to check that the indices array that you passes actually + * describes a permutation, i.e., each value between 0 and n-1 occurs exactly once, where n is the + * array's size. + */ + template + explicit inline PermutationMatrix(const MatrixBase& indices) : m_indices(indices) {} + + /** Convert the Transpositions \a tr to a permutation matrix */ + template + explicit PermutationMatrix(const TranspositionsBase& tr) : m_indices(tr.size()) { + *this = tr; + } + + /** Copies the other permutation into *this */ + template + PermutationMatrix& operator=(const PermutationBase& other) { + m_indices = other.indices(); + return *this; + } + + /** Assignment from the Transpositions \a tr */ + template + PermutationMatrix& operator=(const TranspositionsBase& tr) { + return Base::operator=(tr.derived()); + } + + /** const version of indices(). */ + const IndicesType& indices() const { return m_indices; } + /** \returns a reference to the stored array representing the permutation. */ + IndicesType& indices() { return m_indices; } + + /**** multiplication helpers to hopefully get RVO ****/ + +#ifndef EIGEN_PARSED_BY_DOXYGEN + template + PermutationMatrix(const InverseImpl& other) + : m_indices(other.derived().nestedExpression().size()) { + eigen_internal_assert(m_indices.size() <= NumTraits::highest()); + StorageIndex end = StorageIndex(m_indices.size()); + for (StorageIndex i = 0; i < end; ++i) + m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i; + } + template + PermutationMatrix(internal::PermPermProduct_t, const Lhs& lhs, const Rhs& rhs) : m_indices(lhs.indices().size()) { + Base::assignProduct(lhs, rhs); + } +#endif + + protected: + IndicesType m_indices; +}; + +namespace internal { +template +struct traits, PacketAccess_> > + : traits< + Matrix > { + typedef PermutationStorage StorageKind; + typedef Map, PacketAccess_> IndicesType; + typedef StorageIndex_ StorageIndex; + typedef void Scalar; +}; +} // namespace internal + +template +class Map, PacketAccess_> + : public PermutationBase< + Map, PacketAccess_> > { + typedef PermutationBase Base; + typedef internal::traits Traits; + + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef typename Traits::IndicesType IndicesType; + typedef typename IndicesType::Scalar StorageIndex; +#endif + + inline Map(const StorageIndex* indicesPtr) : m_indices(indicesPtr) {} + + inline Map(const StorageIndex* indicesPtr, Index size) : m_indices(indicesPtr, size) {} + + /** Copies the other permutation into *this */ + template + Map& operator=(const PermutationBase& other) { + return Base::operator=(other.derived()); + } + + /** Assignment from the Transpositions \a tr */ + template + Map& operator=(const TranspositionsBase& tr) { + return Base::operator=(tr.derived()); + } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** This is a special case of the templated operator=. Its purpose is to + * prevent a default operator= from hiding the templated operator=. + */ + Map& operator=(const Map& other) { + m_indices = other.m_indices; + return *this; + } +#endif + + /** const version of indices(). */ + const IndicesType& indices() const { return m_indices; } + /** \returns a reference to the stored array representing the permutation. */ + IndicesType& indices() { return m_indices; } + + protected: + IndicesType m_indices; +}; + +template +class TranspositionsWrapper; +namespace internal { +template +struct traits > { + typedef PermutationStorage StorageKind; + typedef void Scalar; + typedef typename IndicesType_::Scalar StorageIndex; + typedef IndicesType_ IndicesType; + enum { + RowsAtCompileTime = IndicesType_::SizeAtCompileTime, + ColsAtCompileTime = IndicesType_::SizeAtCompileTime, + MaxRowsAtCompileTime = IndicesType::MaxSizeAtCompileTime, + MaxColsAtCompileTime = IndicesType::MaxSizeAtCompileTime, + Flags = 0 + }; +}; +} // namespace internal + +/** \class PermutationWrapper + * \ingroup Core_Module + * + * \brief Class to view a vector of integers as a permutation matrix + * + * \tparam IndicesType_ the type of the vector of integer (can be any compatible expression) + * + * This class allows to view any vector expression of integers as a permutation matrix. + * + * \sa class PermutationBase, class PermutationMatrix + */ +template +class PermutationWrapper : public PermutationBase > { + typedef PermutationBase Base; + typedef internal::traits Traits; + + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef typename Traits::IndicesType IndicesType; +#endif + + inline PermutationWrapper(const IndicesType& indices) : m_indices(indices) {} + + /** const version of indices(). */ + const internal::remove_all_t& indices() const { return m_indices; } + + protected: + typename IndicesType::Nested m_indices; +}; + +/** \returns the matrix with the permutation applied to the columns. + */ +template +EIGEN_DEVICE_FUNC const Product operator*( + const MatrixBase& matrix, const PermutationBase& permutation) { + return Product(matrix.derived(), permutation.derived()); +} + +/** \returns the matrix with the permutation applied to the rows. + */ +template +EIGEN_DEVICE_FUNC const Product operator*( + const PermutationBase& permutation, const MatrixBase& matrix) { + return Product(permutation.derived(), matrix.derived()); +} + +template +class InverseImpl : public EigenBase > { + typedef typename PermutationType::PlainPermutationType PlainPermutationType; + typedef internal::traits PermTraits; + + protected: + InverseImpl() {} + + public: + typedef Inverse InverseType; + using EigenBase >::derived; + +#ifndef EIGEN_PARSED_BY_DOXYGEN + typedef typename PermutationType::DenseMatrixType DenseMatrixType; + enum { + RowsAtCompileTime = PermTraits::RowsAtCompileTime, + ColsAtCompileTime = PermTraits::ColsAtCompileTime, + MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime + }; +#endif + +#ifndef EIGEN_PARSED_BY_DOXYGEN + template + void evalTo(MatrixBase& other) const { + other.setZero(); + for (Index i = 0; i < derived().rows(); ++i) + other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) = typename DenseDerived::Scalar(1); + } +#endif + + /** \return the equivalent permutation matrix */ + PlainPermutationType eval() const { return derived(); } + + DenseMatrixType toDenseMatrix() const { return derived(); } + + /** \returns the matrix with the inverse permutation applied to the columns. + */ + template + friend const Product operator*(const MatrixBase& matrix, + const InverseType& trPerm) { + return Product(matrix.derived(), trPerm.derived()); + } + + /** \returns the matrix with the inverse permutation applied to the rows. + */ + template + const Product operator*(const MatrixBase& matrix) const { + return Product(derived(), matrix.derived()); + } +}; + +template +const PermutationWrapper MatrixBase::asPermutation() const { + return derived(); +} + +namespace internal { + +template <> +struct AssignmentKind { + typedef EigenBase2EigenBase Kind; +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_PERMUTATIONMATRIX_H diff --git a/dae-cpp/Eigen/src/Core/PlainObjectBase.h b/dae-cpp/Eigen/src/Core/PlainObjectBase.h new file mode 100644 index 0000000..5878385 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/PlainObjectBase.h @@ -0,0 +1,1049 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2009 Gael Guennebaud +// Copyright (C) 2006-2008 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_DENSESTORAGEBASE_H +#define EIGEN_DENSESTORAGEBASE_H + +#if defined(EIGEN_INITIALIZE_MATRICES_BY_ZERO) +#define EIGEN_INITIALIZE_COEFFS +#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED \ + for (Index i = 0; i < base().size(); ++i) coeffRef(i) = Scalar(0); +#elif defined(EIGEN_INITIALIZE_MATRICES_BY_NAN) +#define EIGEN_INITIALIZE_COEFFS +#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED \ + for (Index i = 0; i < base().size(); ++i) coeffRef(i) = std::numeric_limits::quiet_NaN(); +#else +#undef EIGEN_INITIALIZE_COEFFS +#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED +#endif + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +#ifndef EIGEN_NO_DEBUG +template +struct check_rows_cols_for_overflow { + EIGEN_STATIC_ASSERT(MaxRowsAtCompileTime* MaxColsAtCompileTime == MaxSizeAtCompileTime, + YOU MADE A PROGRAMMING MISTAKE) + template + EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE constexpr void run(Index, Index) {} +}; + +template +struct check_rows_cols_for_overflow { + template + EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE constexpr void run(Index, Index cols) { + constexpr Index MaxIndex = NumTraits::highest(); + bool error = cols > (MaxIndex / MaxRowsAtCompileTime); + if (error) throw_std_bad_alloc(); + } +}; + +template +struct check_rows_cols_for_overflow { + template + EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE constexpr void run(Index rows, Index) { + constexpr Index MaxIndex = NumTraits::highest(); + bool error = rows > (MaxIndex / MaxColsAtCompileTime); + if (error) throw_std_bad_alloc(); + } +}; + +template <> +struct check_rows_cols_for_overflow { + template + EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE constexpr void run(Index rows, Index cols) { + constexpr Index MaxIndex = NumTraits::highest(); + bool error = cols == 0 ? false : (rows > (MaxIndex / cols)); + if (error) throw_std_bad_alloc(); + } +}; +#endif + +template +struct conservative_resize_like_impl; + +template +struct matrix_swap_impl; + +} // end namespace internal + +#ifdef EIGEN_PARSED_BY_DOXYGEN +namespace doxygen { + +// This is a workaround to doxygen not being able to understand the inheritance logic +// when it is hidden by the dense_xpr_base helper struct. +// Moreover, doxygen fails to include members that are not documented in the declaration body of +// MatrixBase if we inherits MatrixBase >, +// this is why we simply inherits MatrixBase, though this does not make sense. + +/** This class is just a workaround for Doxygen and it does not not actually exist. */ +template +struct dense_xpr_base_dispatcher; +/** This class is just a workaround for Doxygen and it does not not actually exist. */ +template +struct dense_xpr_base_dispatcher> : public MatrixBase {}; +/** This class is just a workaround for Doxygen and it does not not actually exist. */ +template +struct dense_xpr_base_dispatcher> : public ArrayBase {}; + +} // namespace doxygen + +/** \class PlainObjectBase + * \ingroup Core_Module + * \brief %Dense storage base class for matrices and arrays. + * + * This class can be extended with the help of the plugin mechanism described on the page + * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_PLAINOBJECTBASE_PLUGIN. + * + * \tparam Derived is the derived type, e.g., a Matrix or Array + * + * \sa \ref TopicClassHierarchy + */ +template +class PlainObjectBase : public doxygen::dense_xpr_base_dispatcher +#else +template +class PlainObjectBase : public internal::dense_xpr_base::type +#endif +{ + public: + enum { Options = internal::traits::Options }; + typedef typename internal::dense_xpr_base::type Base; + + typedef typename internal::traits::StorageKind StorageKind; + typedef typename internal::traits::Scalar Scalar; + + typedef typename internal::packet_traits::type PacketScalar; + typedef typename NumTraits::Real RealScalar; + typedef Derived DenseType; + + using Base::ColsAtCompileTime; + using Base::Flags; + using Base::IsVectorAtCompileTime; + using Base::MaxColsAtCompileTime; + using Base::MaxRowsAtCompileTime; + using Base::MaxSizeAtCompileTime; + using Base::RowsAtCompileTime; + using Base::SizeAtCompileTime; + + typedef Eigen::Map MapType; + typedef const Eigen::Map ConstMapType; + typedef Eigen::Map AlignedMapType; + typedef const Eigen::Map ConstAlignedMapType; + template + struct StridedMapType { + typedef Eigen::Map type; + }; + template + struct StridedConstMapType { + typedef Eigen::Map type; + }; + template + struct StridedAlignedMapType { + typedef Eigen::Map type; + }; + template + struct StridedConstAlignedMapType { + typedef Eigen::Map type; + }; + + protected: + DenseStorage m_storage; + + public: + enum { NeedsToAlign = (SizeAtCompileTime != Dynamic) && (internal::traits::Alignment > 0) }; + EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) + + EIGEN_STATIC_ASSERT(internal::check_implication(MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1, + (int(Options) & RowMajor) == RowMajor), + INVALID_MATRIX_TEMPLATE_PARAMETERS) + EIGEN_STATIC_ASSERT(internal::check_implication(MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1, + (int(Options) & RowMajor) == 0), + INVALID_MATRIX_TEMPLATE_PARAMETERS) + EIGEN_STATIC_ASSERT((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0), INVALID_MATRIX_TEMPLATE_PARAMETERS) + EIGEN_STATIC_ASSERT((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0), INVALID_MATRIX_TEMPLATE_PARAMETERS) + EIGEN_STATIC_ASSERT((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0), + INVALID_MATRIX_TEMPLATE_PARAMETERS) + EIGEN_STATIC_ASSERT((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0), + INVALID_MATRIX_TEMPLATE_PARAMETERS) + EIGEN_STATIC_ASSERT((MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime == Dynamic), + INVALID_MATRIX_TEMPLATE_PARAMETERS) + EIGEN_STATIC_ASSERT((MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime == Dynamic), + INVALID_MATRIX_TEMPLATE_PARAMETERS) + EIGEN_STATIC_ASSERT(((Options & (DontAlign | RowMajor)) == Options), INVALID_MATRIX_TEMPLATE_PARAMETERS) + + EIGEN_DEVICE_FUNC Base& base() { return *static_cast(this); } + EIGEN_DEVICE_FUNC const Base& base() const { return *static_cast(this); } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_storage.rows(); } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_storage.cols(); } + + /** This is an overloaded version of DenseCoeffsBase::coeff(Index,Index) const + * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts. + * + * See DenseCoeffsBase::coeff(Index) const for details. */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const Scalar& coeff(Index rowId, Index colId) const { + if (Flags & RowMajorBit) + return m_storage.data()[colId + rowId * m_storage.cols()]; + else // column-major + return m_storage.data()[rowId + colId * m_storage.rows()]; + } + + /** This is an overloaded version of DenseCoeffsBase::coeff(Index) const + * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts. + * + * See DenseCoeffsBase::coeff(Index) const for details. */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const Scalar& coeff(Index index) const { + return m_storage.data()[index]; + } + + /** This is an overloaded version of DenseCoeffsBase::coeffRef(Index,Index) const + * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts. + * + * See DenseCoeffsBase::coeffRef(Index,Index) const for details. */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Scalar& coeffRef(Index rowId, Index colId) { + if (Flags & RowMajorBit) + return m_storage.data()[colId + rowId * m_storage.cols()]; + else // column-major + return m_storage.data()[rowId + colId * m_storage.rows()]; + } + + /** This is an overloaded version of DenseCoeffsBase::coeffRef(Index) const + * provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts. + * + * See DenseCoeffsBase::coeffRef(Index) const for details. */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Scalar& coeffRef(Index index) { return m_storage.data()[index]; } + + /** This is the const version of coeffRef(Index,Index) which is thus synonym of coeff(Index,Index). + * It is provided for convenience. */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const Scalar& coeffRef(Index rowId, Index colId) const { + if (Flags & RowMajorBit) + return m_storage.data()[colId + rowId * m_storage.cols()]; + else // column-major + return m_storage.data()[rowId + colId * m_storage.rows()]; + } + + /** This is the const version of coeffRef(Index) which is thus synonym of coeff(Index). + * It is provided for convenience. */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr const Scalar& coeffRef(Index index) const { + return m_storage.data()[index]; + } + + /** \internal */ + template + EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const { + return internal::ploadt( + m_storage.data() + (Flags & RowMajorBit ? colId + rowId * m_storage.cols() : rowId + colId * m_storage.rows())); + } + + /** \internal */ + template + EIGEN_STRONG_INLINE PacketScalar packet(Index index) const { + return internal::ploadt(m_storage.data() + index); + } + + /** \internal */ + template + EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketScalar& val) { + internal::pstoret( + m_storage.data() + (Flags & RowMajorBit ? colId + rowId * m_storage.cols() : rowId + colId * m_storage.rows()), + val); + } + + /** \internal */ + template + EIGEN_STRONG_INLINE void writePacket(Index index, const PacketScalar& val) { + internal::pstoret(m_storage.data() + index, val); + } + + /** \returns a const pointer to the data array of this matrix */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar* data() const { return m_storage.data(); } + + /** \returns a pointer to the data array of this matrix */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar* data() { return m_storage.data(); } + + /** Resizes \c *this to a \a rows x \a cols matrix. + * + * This method is intended for dynamic-size matrices, although it is legal to call it on any + * matrix as long as fixed dimensions are left unchanged. If you only want to change the number + * of rows and/or of columns, you can use resize(NoChange_t, Index), resize(Index, NoChange_t). + * + * If the current number of coefficients of \c *this exactly matches the + * product \a rows * \a cols, then no memory allocation is performed and + * the current values are left unchanged. In all other cases, including + * shrinking, the data is reallocated and all previous values are lost. + * + * Example: \include Matrix_resize_int_int.cpp + * Output: \verbinclude Matrix_resize_int_int.out + * + * \sa resize(Index) for vectors, resize(NoChange_t, Index), resize(Index, NoChange_t) + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void resize(Index rows, Index cols) { + eigen_assert(internal::check_implication(RowsAtCompileTime != Dynamic, rows == RowsAtCompileTime) && + internal::check_implication(ColsAtCompileTime != Dynamic, cols == ColsAtCompileTime) && + internal::check_implication(RowsAtCompileTime == Dynamic && MaxRowsAtCompileTime != Dynamic, + rows <= MaxRowsAtCompileTime) && + internal::check_implication(ColsAtCompileTime == Dynamic && MaxColsAtCompileTime != Dynamic, + cols <= MaxColsAtCompileTime) && + rows >= 0 && cols >= 0 && "Invalid sizes when resizing a matrix or array."); +#ifndef EIGEN_NO_DEBUG + internal::check_rows_cols_for_overflow::run(rows, + cols); +#endif +#ifdef EIGEN_INITIALIZE_COEFFS + Index size = rows * cols; + bool size_changed = size != this->size(); + m_storage.resize(size, rows, cols); + if (size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED +#else + m_storage.resize(rows * cols, rows, cols); +#endif + } + + /** Resizes \c *this to a vector of length \a size + * + * \only_for_vectors. This method does not work for + * partially dynamic matrices when the static dimension is anything other + * than 1. For example it will not work with Matrix. + * + * Example: \include Matrix_resize_int.cpp + * Output: \verbinclude Matrix_resize_int.out + * + * \sa resize(Index,Index), resize(NoChange_t, Index), resize(Index, NoChange_t) + */ + EIGEN_DEVICE_FUNC inline constexpr void resize(Index size) { + EIGEN_STATIC_ASSERT_VECTOR_ONLY(PlainObjectBase) + eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime == Dynamic || size <= MaxSizeAtCompileTime)) || + SizeAtCompileTime == size) && + size >= 0); +#ifdef EIGEN_INITIALIZE_COEFFS + bool size_changed = size != this->size(); +#endif + if (RowsAtCompileTime == 1) + m_storage.resize(size, 1, size); + else + m_storage.resize(size, size, 1); +#ifdef EIGEN_INITIALIZE_COEFFS + if (size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED +#endif + } + + /** Resizes the matrix, changing only the number of columns. For the parameter of type NoChange_t, just pass the + * special value \c NoChange as in the example below. + * + * Example: \include Matrix_resize_NoChange_int.cpp + * Output: \verbinclude Matrix_resize_NoChange_int.out + * + * \sa resize(Index,Index) + */ + EIGEN_DEVICE_FUNC inline constexpr void resize(NoChange_t, Index cols) { resize(rows(), cols); } + + /** Resizes the matrix, changing only the number of rows. For the parameter of type NoChange_t, just pass the special + * value \c NoChange as in the example below. + * + * Example: \include Matrix_resize_int_NoChange.cpp + * Output: \verbinclude Matrix_resize_int_NoChange.out + * + * \sa resize(Index,Index) + */ + EIGEN_DEVICE_FUNC inline constexpr void resize(Index rows, NoChange_t) { resize(rows, cols()); } + + /** Resizes \c *this to have the same dimensions as \a other. + * Takes care of doing all the checking that's needed. + * + * Note that copying a row-vector into a vector (and conversely) is allowed. + * The resizing, if any, is then done in the appropriate way so that row-vectors + * remain row-vectors and vectors remain vectors. + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resizeLike(const EigenBase& _other) { + const OtherDerived& other = _other.derived(); +#ifndef EIGEN_NO_DEBUG + internal::check_rows_cols_for_overflow::run( + other.rows(), other.cols()); +#endif + const Index othersize = other.rows() * other.cols(); + if (RowsAtCompileTime == 1) { + eigen_assert(other.rows() == 1 || other.cols() == 1); + resize(1, othersize); + } else if (ColsAtCompileTime == 1) { + eigen_assert(other.rows() == 1 || other.cols() == 1); + resize(othersize, 1); + } else + resize(other.rows(), other.cols()); + } + + /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. + * + * The method is intended for matrices of dynamic size. If you only want to change the number + * of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or + * conservativeResize(Index, NoChange_t). + * + * Matrices are resized relative to the top-left element. In case values need to be + * appended to the matrix they will be uninitialized. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void conservativeResize(Index rows, Index cols) { + internal::conservative_resize_like_impl::run(*this, rows, cols); + } + + /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. + * + * As opposed to conservativeResize(Index rows, Index cols), this version leaves + * the number of columns unchanged. + * + * In case the matrix is growing, new rows will be uninitialized. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void conservativeResize(Index rows, NoChange_t) { + // Note: see the comment in conservativeResize(Index,Index) + conservativeResize(rows, cols()); + } + + /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. + * + * As opposed to conservativeResize(Index rows, Index cols), this version leaves + * the number of rows unchanged. + * + * In case the matrix is growing, new columns will be uninitialized. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void conservativeResize(NoChange_t, Index cols) { + // Note: see the comment in conservativeResize(Index,Index) + conservativeResize(rows(), cols); + } + + /** Resizes the vector to \a size while retaining old values. + * + * \only_for_vectors. This method does not work for + * partially dynamic matrices when the static dimension is anything other + * than 1. For example it will not work with Matrix. + * + * When values are appended, they will be uninitialized. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void conservativeResize(Index size) { + internal::conservative_resize_like_impl::run(*this, size); + } + + /** Resizes the matrix to \a rows x \a cols of \c other, while leaving old values untouched. + * + * The method is intended for matrices of dynamic size. If you only want to change the number + * of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or + * conservativeResize(Index, NoChange_t). + * + * Matrices are resized relative to the top-left element. In case values need to be + * appended to the matrix they will copied from \c other. + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void conservativeResizeLike(const DenseBase& other) { + internal::conservative_resize_like_impl::run(*this, other); + } + + /** This is a special case of the templated operator=. Its purpose is to + * prevent a default operator= from hiding the templated operator=. + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const PlainObjectBase& other) { return _set(other); } + + /** \sa MatrixBase::lazyAssign() */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& lazyAssign(const DenseBase& other) { + _resize_to_match(other); + return Base::lazyAssign(other.derived()); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const ReturnByValue& func) { + resize(func.rows(), func.cols()); + return Base::operator=(func); + } + + // Prevent user from trying to instantiate PlainObjectBase objects + // by making all its constructor protected. See bug 1074. + protected: + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase() : m_storage() { + // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED + } + +#ifndef EIGEN_PARSED_BY_DOXYGEN + // FIXME is it still needed ? + /** \internal */ + EIGEN_DEVICE_FUNC explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert) + : m_storage(internal::constructor_without_unaligned_array_assert()) { + // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED + } +#endif + + EIGEN_DEVICE_FUNC PlainObjectBase(PlainObjectBase&& other) EIGEN_NOEXCEPT : m_storage(std::move(other.m_storage)) {} + + EIGEN_DEVICE_FUNC PlainObjectBase& operator=(PlainObjectBase&& other) EIGEN_NOEXCEPT { + m_storage = std::move(other.m_storage); + return *this; + } + + /** Copy constructor */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(const PlainObjectBase& other) + : Base(), m_storage(other.m_storage) {} + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(Index size, Index rows, Index cols) + : m_storage(size, rows, cols) { + // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED + } + + /** \brief Construct a row of column vector with fixed size from an arbitrary number of coefficients. + * + * \only_for_vectors + * + * This constructor is for 1D array or vectors with more than 4 coefficients. + * + * \warning To construct a column (resp. row) vector of fixed length, the number of values passed to this + * constructor must match the the fixed number of rows (resp. columns) of \c *this. + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, + const Scalar& a3, const ArgTypes&... args) + : m_storage() { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, sizeof...(args) + 4); + m_storage.data()[0] = a0; + m_storage.data()[1] = a1; + m_storage.data()[2] = a2; + m_storage.data()[3] = a3; + Index i = 4; + auto x = {(m_storage.data()[i++] = args, 0)...}; + static_cast(x); + } + + /** \brief Constructs a Matrix or Array and initializes it by elements given by an initializer list of initializer + * lists + */ + EIGEN_DEVICE_FUNC explicit constexpr EIGEN_STRONG_INLINE PlainObjectBase( + const std::initializer_list>& list) + : m_storage() { + size_t list_size = 0; + if (list.begin() != list.end()) { + list_size = list.begin()->size(); + } + + // This is to allow syntax like VectorXi {{1, 2, 3, 4}} + if (ColsAtCompileTime == 1 && list.size() == 1) { + eigen_assert(list_size == static_cast(RowsAtCompileTime) || RowsAtCompileTime == Dynamic); + resize(list_size, ColsAtCompileTime); + if (list.begin()->begin() != nullptr) { + std::copy(list.begin()->begin(), list.begin()->end(), m_storage.data()); + } + } else { + eigen_assert(list.size() == static_cast(RowsAtCompileTime) || RowsAtCompileTime == Dynamic); + eigen_assert(list_size == static_cast(ColsAtCompileTime) || ColsAtCompileTime == Dynamic); + resize(list.size(), list_size); + + Index row_index = 0; + for (const std::initializer_list& row : list) { + eigen_assert(list_size == row.size()); + Index col_index = 0; + for (const Scalar& e : row) { + coeffRef(row_index, col_index) = e; + ++col_index; + } + ++row_index; + } + } + } + + /** \sa PlainObjectBase::operator=(const EigenBase&) */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(const DenseBase& other) : m_storage() { + resizeLike(other); + _set_noalias(other); + } + + /** \sa PlainObjectBase::operator=(const EigenBase&) */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(const EigenBase& other) : m_storage() { + resizeLike(other); + *this = other.derived(); + } + /** \brief Copy constructor with in-place evaluation */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(const ReturnByValue& other) { + // FIXME this does not automatically transpose vectors if necessary + resize(other.rows(), other.cols()); + other.evalTo(this->derived()); + } + + public: + /** \brief Copies the generic expression \a other into *this. + * \copydetails DenseBase::operator=(const EigenBase &other) + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const EigenBase& other) { + _resize_to_match(other); + Base::operator=(other.derived()); + return this->derived(); + } + + /** \name Map + * These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects, + * while the AlignedMap() functions return aligned Map objects and thus should be called only with 16-byte-aligned + * \a data pointers. + * + * Here is an example using strides: + * \include Matrix_Map_stride.cpp + * Output: \verbinclude Matrix_Map_stride.out + * + * \see class Map + */ + ///@{ + static inline ConstMapType Map(const Scalar* data) { return ConstMapType(data); } + static inline MapType Map(Scalar* data) { return MapType(data); } + static inline ConstMapType Map(const Scalar* data, Index size) { return ConstMapType(data, size); } + static inline MapType Map(Scalar* data, Index size) { return MapType(data, size); } + static inline ConstMapType Map(const Scalar* data, Index rows, Index cols) { return ConstMapType(data, rows, cols); } + static inline MapType Map(Scalar* data, Index rows, Index cols) { return MapType(data, rows, cols); } + + static inline ConstAlignedMapType MapAligned(const Scalar* data) { return ConstAlignedMapType(data); } + static inline AlignedMapType MapAligned(Scalar* data) { return AlignedMapType(data); } + static inline ConstAlignedMapType MapAligned(const Scalar* data, Index size) { + return ConstAlignedMapType(data, size); + } + static inline AlignedMapType MapAligned(Scalar* data, Index size) { return AlignedMapType(data, size); } + static inline ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols) { + return ConstAlignedMapType(data, rows, cols); + } + static inline AlignedMapType MapAligned(Scalar* data, Index rows, Index cols) { + return AlignedMapType(data, rows, cols); + } + + template + static inline typename StridedConstMapType>::type Map(const Scalar* data, + const Stride& stride) { + return typename StridedConstMapType>::type(data, stride); + } + template + static inline typename StridedMapType>::type Map(Scalar* data, + const Stride& stride) { + return typename StridedMapType>::type(data, stride); + } + template + static inline typename StridedConstMapType>::type Map(const Scalar* data, Index size, + const Stride& stride) { + return typename StridedConstMapType>::type(data, size, stride); + } + template + static inline typename StridedMapType>::type Map(Scalar* data, Index size, + const Stride& stride) { + return typename StridedMapType>::type(data, size, stride); + } + template + static inline typename StridedConstMapType>::type Map(const Scalar* data, Index rows, Index cols, + const Stride& stride) { + return typename StridedConstMapType>::type(data, rows, cols, stride); + } + template + static inline typename StridedMapType>::type Map(Scalar* data, Index rows, Index cols, + const Stride& stride) { + return typename StridedMapType>::type(data, rows, cols, stride); + } + + template + static inline typename StridedConstAlignedMapType>::type MapAligned( + const Scalar* data, const Stride& stride) { + return typename StridedConstAlignedMapType>::type(data, stride); + } + template + static inline typename StridedAlignedMapType>::type MapAligned( + Scalar* data, const Stride& stride) { + return typename StridedAlignedMapType>::type(data, stride); + } + template + static inline typename StridedConstAlignedMapType>::type MapAligned( + const Scalar* data, Index size, const Stride& stride) { + return typename StridedConstAlignedMapType>::type(data, size, stride); + } + template + static inline typename StridedAlignedMapType>::type MapAligned( + Scalar* data, Index size, const Stride& stride) { + return typename StridedAlignedMapType>::type(data, size, stride); + } + template + static inline typename StridedConstAlignedMapType>::type MapAligned( + const Scalar* data, Index rows, Index cols, const Stride& stride) { + return typename StridedConstAlignedMapType>::type(data, rows, cols, stride); + } + template + static inline typename StridedAlignedMapType>::type MapAligned( + Scalar* data, Index rows, Index cols, const Stride& stride) { + return typename StridedAlignedMapType>::type(data, rows, cols, stride); + } + ///@} + + using Base::setConstant; + EIGEN_DEVICE_FUNC Derived& setConstant(Index size, const Scalar& val); + EIGEN_DEVICE_FUNC Derived& setConstant(Index rows, Index cols, const Scalar& val); + EIGEN_DEVICE_FUNC Derived& setConstant(NoChange_t, Index cols, const Scalar& val); + EIGEN_DEVICE_FUNC Derived& setConstant(Index rows, NoChange_t, const Scalar& val); + + using Base::setZero; + EIGEN_DEVICE_FUNC Derived& setZero(Index size); + EIGEN_DEVICE_FUNC Derived& setZero(Index rows, Index cols); + EIGEN_DEVICE_FUNC Derived& setZero(NoChange_t, Index cols); + EIGEN_DEVICE_FUNC Derived& setZero(Index rows, NoChange_t); + + using Base::setOnes; + EIGEN_DEVICE_FUNC Derived& setOnes(Index size); + EIGEN_DEVICE_FUNC Derived& setOnes(Index rows, Index cols); + EIGEN_DEVICE_FUNC Derived& setOnes(NoChange_t, Index cols); + EIGEN_DEVICE_FUNC Derived& setOnes(Index rows, NoChange_t); + + using Base::setRandom; + Derived& setRandom(Index size); + Derived& setRandom(Index rows, Index cols); + Derived& setRandom(NoChange_t, Index cols); + Derived& setRandom(Index rows, NoChange_t); + +#ifdef EIGEN_PLAINOBJECTBASE_PLUGIN +#include EIGEN_PLAINOBJECTBASE_PLUGIN +#endif + + protected: + /** \internal Resizes *this in preparation for assigning \a other to it. + * Takes care of doing all the checking that's needed. + * + * Note that copying a row-vector into a vector (and conversely) is allowed. + * The resizing, if any, is then done in the appropriate way so that row-vectors + * remain row-vectors and vectors remain vectors. + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _resize_to_match(const EigenBase& other) { +#ifdef EIGEN_NO_AUTOMATIC_RESIZING + eigen_assert((this->size() == 0 || (IsVectorAtCompileTime ? (this->size() == other.size()) + : (rows() == other.rows() && cols() == other.cols()))) && + "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined"); + EIGEN_ONLY_USED_FOR_DEBUG(other); +#else + resizeLike(other); +#endif + } + + /** + * \brief Copies the value of the expression \a other into \c *this with automatic resizing. + * + * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized), + * it will be initialized. + * + * Note that copying a row-vector into a vector (and conversely) is allowed. + * The resizing, if any, is then done in the appropriate way so that row-vectors + * remain row-vectors and vectors remain vectors. + * + * \sa operator=(const MatrixBase&), _set_noalias() + * + * \internal + */ + // aliasing is dealt once in internal::call_assignment + // so at this stage we have to assume aliasing... and resising has to be done later. + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& _set(const DenseBase& other) { + internal::call_assignment(this->derived(), other.derived()); + return this->derived(); + } + + /** \internal Like _set() but additionally makes the assumption that no aliasing effect can happen (which + * is the case when creating a new matrix) so one can enforce lazy evaluation. + * + * \sa operator=(const MatrixBase&), _set() + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& _set_noalias(const DenseBase& other) { + // I don't think we need this resize call since the lazyAssign will anyways resize + // and lazyAssign will be called by the assign selector. + //_resize_to_match(other); + // the 'false' below means to enforce lazy evaluation. We don't use lazyAssign() because + // it wouldn't allow to copy a row-vector into a column-vector. + internal::call_assignment_no_alias(this->derived(), other.derived(), + internal::assign_op()); + return this->derived(); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init2(Index rows, Index cols, + std::enable_if_t* = 0) { + EIGEN_STATIC_ASSERT(internal::is_valid_index_type::value && internal::is_valid_index_type::value, + T0 AND T1 MUST BE INTEGER TYPES) + resize(rows, cols); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init2(const T0& val0, const T1& val1, + std::enable_if_t* = 0) { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2) + m_storage.data()[0] = Scalar(val0); + m_storage.data()[1] = Scalar(val1); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init2( + const Index& val0, const Index& val1, + std::enable_if_t<(!internal::is_same::value) && (internal::is_same::value) && + (internal::is_same::value) && Base::SizeAtCompileTime == 2, + T1>* = 0) { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2) + m_storage.data()[0] = Scalar(val0); + m_storage.data()[1] = Scalar(val1); + } + + // The argument is convertible to the Index type and we either have a non 1x1 Matrix, or a dynamic-sized Array, + // then the argument is meant to be the size of the object. + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1( + Index size, + std::enable_if_t<(Base::SizeAtCompileTime != 1 || !internal::is_convertible::value) && + ((!internal::is_same::XprKind, ArrayXpr>::value || + Base::SizeAtCompileTime == Dynamic)), + T>* = 0) { + // NOTE MSVC 2008 complains if we directly put bool(NumTraits::IsInteger) as the EIGEN_STATIC_ASSERT argument. + const bool is_integer_alike = internal::is_valid_index_type::value; + EIGEN_UNUSED_VARIABLE(is_integer_alike); + EIGEN_STATIC_ASSERT(is_integer_alike, FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED) + resize(size); + } + + // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar + // type can be implicitly converted) + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1( + const Scalar& val0, + std::enable_if_t::value, T>* = 0) { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1) + m_storage.data()[0] = val0; + } + + // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar + // type match the index type) + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1( + const Index& val0, + std::enable_if_t<(!internal::is_same::value) && (internal::is_same::value) && + Base::SizeAtCompileTime == 1 && internal::is_convertible::value, + T*>* = 0) { + EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1) + m_storage.data()[0] = Scalar(val0); + } + + // Initialize a fixed size matrix from a pointer to raw data + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1(const Scalar* data) { + this->_set_noalias(ConstMapType(data)); + } + + // Initialize an arbitrary matrix from a dense expression + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1(const DenseBase& other) { + this->_set_noalias(other); + } + + // Initialize an arbitrary matrix from an object convertible to the Derived type. + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1(const Derived& other) { + this->_set_noalias(other); + } + + // Initialize an arbitrary matrix from a generic Eigen expression + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1(const EigenBase& other) { + this->derived() = other; + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1(const ReturnByValue& other) { + resize(other.rows(), other.cols()); + other.evalTo(this->derived()); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1(const RotationBase& r) { + this->derived() = r; + } + + // For fixed-size Array + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1( + const Scalar& val0, + std::enable_if_t::value && + internal::is_same::XprKind, ArrayXpr>::value, + T>* = 0) { + Base::setConstant(val0); + } + + // For fixed-size Array + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _init1( + const Index& val0, + std::enable_if_t<(!internal::is_same::value) && (internal::is_same::value) && + Base::SizeAtCompileTime != Dynamic && Base::SizeAtCompileTime != 1 && + internal::is_convertible::value && + internal::is_same::XprKind, ArrayXpr>::value, + T*>* = 0) { + Base::setConstant(val0); + } + + template + friend struct internal::matrix_swap_impl; + + public: +#ifndef EIGEN_PARSED_BY_DOXYGEN + /** \internal + * \brief Override DenseBase::swap() since for dynamic-sized matrices + * of same type it is enough to swap the data pointers. + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseBase& other) { + enum {SwapPointers = internal::is_same::value && Base::SizeAtCompileTime == Dynamic}; + internal::matrix_swap_impl::run(this->derived(), other.derived()); + } + + /** \internal + * \brief const version forwarded to DenseBase::swap + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseBase const& other) { + Base::swap(other.derived()); + } + + enum {IsPlainObjectBase = 1}; +#endif + public: + // These apparently need to be down here for nvcc+icc to prevent duplicate + // Map symbol. + template + friend class Eigen::Map; + friend class Eigen::Map; + friend class Eigen::Map; +#if EIGEN_MAX_ALIGN_BYTES > 0 + // for EIGEN_MAX_ALIGN_BYTES==0, AlignedMax==Unaligned, and many compilers generate warnings for friend-ing a class + // twice. + friend class Eigen::Map; + friend class Eigen::Map; +#endif +}; + +namespace internal { + +template +struct conservative_resize_like_impl { + static constexpr bool IsRelocatable = std::is_trivially_copyable::value; + static void run(DenseBase& _this, Index rows, Index cols) { + if (_this.rows() == rows && _this.cols() == cols) return; + EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived) + + if (IsRelocatable && + ((Derived::IsRowMajor && _this.cols() == cols) || // row-major and we change only the number of rows + (!Derived::IsRowMajor && _this.rows() == rows))) // column-major and we change only the number of columns + { +#ifndef EIGEN_NO_DEBUG + internal::check_rows_cols_for_overflow::run(rows, cols); +#endif + _this.derived().m_storage.conservativeResize(rows * cols, rows, cols); + } else { + // The storage order does not allow us to use reallocation. + Derived tmp(rows, cols); + const Index common_rows = numext::mini(rows, _this.rows()); + const Index common_cols = numext::mini(cols, _this.cols()); + tmp.block(0, 0, common_rows, common_cols) = _this.block(0, 0, common_rows, common_cols); + _this.derived().swap(tmp); + } + } + + static void run(DenseBase& _this, const DenseBase& other) { + if (_this.rows() == other.rows() && _this.cols() == other.cols()) return; + + // Note: Here is space for improvement. Basically, for conservativeResize(Index,Index), + // neither RowsAtCompileTime or ColsAtCompileTime must be Dynamic. If only one of the + // dimensions is dynamic, one could use either conservativeResize(Index rows, NoChange_t) or + // conservativeResize(NoChange_t, Index cols). For these methods new static asserts like + // EIGEN_STATIC_ASSERT_DYNAMIC_ROWS and EIGEN_STATIC_ASSERT_DYNAMIC_COLS would be good. + EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived) + EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived) + + if (IsRelocatable && + ((Derived::IsRowMajor && _this.cols() == other.cols()) || // row-major and we change only the number of rows + (!Derived::IsRowMajor && + _this.rows() == other.rows()))) // column-major and we change only the number of columns + { + const Index new_rows = other.rows() - _this.rows(); + const Index new_cols = other.cols() - _this.cols(); + _this.derived().m_storage.conservativeResize(other.size(), other.rows(), other.cols()); + if (new_rows > 0) + _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows); + else if (new_cols > 0) + _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols); + } else { + // The storage order does not allow us to use reallocation. + Derived tmp(other); + const Index common_rows = numext::mini(tmp.rows(), _this.rows()); + const Index common_cols = numext::mini(tmp.cols(), _this.cols()); + tmp.block(0, 0, common_rows, common_cols) = _this.block(0, 0, common_rows, common_cols); + _this.derived().swap(tmp); + } + } +}; + +// Here, the specialization for vectors inherits from the general matrix case +// to allow calling .conservativeResize(rows,cols) on vectors. +template +struct conservative_resize_like_impl + : conservative_resize_like_impl { + typedef conservative_resize_like_impl Base; + using Base::IsRelocatable; + using Base::run; + + static void run(DenseBase& _this, Index size) { + const Index new_rows = Derived::RowsAtCompileTime == 1 ? 1 : size; + const Index new_cols = Derived::RowsAtCompileTime == 1 ? size : 1; + if (IsRelocatable) + _this.derived().m_storage.conservativeResize(size, new_rows, new_cols); + else + Base::run(_this.derived(), new_rows, new_cols); + } + + static void run(DenseBase& _this, const DenseBase& other) { + if (_this.rows() == other.rows() && _this.cols() == other.cols()) return; + + const Index num_new_elements = other.size() - _this.size(); + + const Index new_rows = Derived::RowsAtCompileTime == 1 ? 1 : other.rows(); + const Index new_cols = Derived::RowsAtCompileTime == 1 ? other.cols() : 1; + if (IsRelocatable) + _this.derived().m_storage.conservativeResize(other.size(), new_rows, new_cols); + else + Base::run(_this.derived(), new_rows, new_cols); + + if (num_new_elements > 0) _this.tail(num_new_elements) = other.tail(num_new_elements); + } +}; + +template +struct matrix_swap_impl { + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(MatrixTypeA& a, MatrixTypeB& b) { a.base().swap(b); } +}; + +template +struct matrix_swap_impl { + EIGEN_DEVICE_FUNC static inline void run(MatrixTypeA& a, MatrixTypeB& b) { + static_cast(a).m_storage.swap(static_cast(b).m_storage); + } +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_DENSESTORAGEBASE_H diff --git a/dae-cpp/Eigen/src/Core/Product.h b/dae-cpp/Eigen/src/Core/Product.h new file mode 100644 index 0000000..6bad832 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Product.h @@ -0,0 +1,174 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2011 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_PRODUCT_H +#define EIGEN_PRODUCT_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +template +class ProductImpl; + +namespace internal { + +template +struct traits > { + typedef remove_all_t LhsCleaned; + typedef remove_all_t RhsCleaned; + typedef traits LhsTraits; + typedef traits RhsTraits; + + typedef MatrixXpr XprKind; + + typedef typename ScalarBinaryOpTraits::Scalar, + typename traits::Scalar>::ReturnType Scalar; + typedef typename product_promote_storage_type::ret>::ret StorageKind; + typedef typename promote_index_type::type + StorageIndex; + + enum { + RowsAtCompileTime = LhsTraits::RowsAtCompileTime, + ColsAtCompileTime = RhsTraits::ColsAtCompileTime, + MaxRowsAtCompileTime = LhsTraits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = RhsTraits::MaxColsAtCompileTime, + + // FIXME: only needed by GeneralMatrixMatrixTriangular + InnerSize = min_size_prefer_fixed(LhsTraits::ColsAtCompileTime, RhsTraits::RowsAtCompileTime), + + // The storage order is somewhat arbitrary here. The correct one will be determined through the evaluator. + Flags = (MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1) ? RowMajorBit + : (MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1) ? 0 + : (((LhsTraits::Flags & NoPreferredStorageOrderBit) && (RhsTraits::Flags & RowMajorBit)) || + ((RhsTraits::Flags & NoPreferredStorageOrderBit) && (LhsTraits::Flags & RowMajorBit))) + ? RowMajorBit + : NoPreferredStorageOrderBit + }; +}; + +} // end namespace internal + +/** \class Product + * \ingroup Core_Module + * + * \brief Expression of the product of two arbitrary matrices or vectors + * + * \tparam Lhs_ the type of the left-hand side expression + * \tparam Rhs_ the type of the right-hand side expression + * + * This class represents an expression of the product of two arbitrary matrices. + * + * The other template parameters are: + * \tparam Option can be DefaultProduct, AliasFreeProduct, or LazyProduct + * + */ +template +class Product + : public ProductImpl::StorageKind, typename internal::traits::StorageKind, + internal::product_type::ret>::ret> { + public: + typedef Lhs_ Lhs; + typedef Rhs_ Rhs; + + typedef + typename ProductImpl::StorageKind, typename internal::traits::StorageKind, + internal::product_type::ret>::ret>::Base Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(Product) + + typedef typename internal::ref_selector::type LhsNested; + typedef typename internal::ref_selector::type RhsNested; + typedef internal::remove_all_t LhsNestedCleaned; + typedef internal::remove_all_t RhsNestedCleaned; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) { + eigen_assert(lhs.cols() == rhs.rows() && "invalid matrix product" && + "if you wanted a coeff-wise or a dot product use the respective explicit functions"); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_lhs.rows(); } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const LhsNestedCleaned& lhs() const { return m_lhs; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const RhsNestedCleaned& rhs() const { return m_rhs; } + + protected: + LhsNested m_lhs; + RhsNested m_rhs; +}; + +namespace internal { + +template ::ret> +class dense_product_base : public internal::dense_xpr_base >::type {}; + +/** Conversion to scalar for inner-products */ +template +class dense_product_base + : public internal::dense_xpr_base >::type { + typedef Product ProductXpr; + typedef typename internal::dense_xpr_base::type Base; + + public: + using Base::derived; + typedef typename Base::Scalar Scalar; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator const Scalar() const { + return internal::evaluator(derived()).coeff(0, 0); + } +}; + +} // namespace internal + +// Generic API dispatcher +template +class ProductImpl : public internal::generic_xpr_base, MatrixXpr, StorageKind>::type { + public: + typedef typename internal::generic_xpr_base, MatrixXpr, StorageKind>::type Base; +}; + +template +class ProductImpl : public internal::dense_product_base { + typedef Product Derived; + + public: + typedef typename internal::dense_product_base Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Derived) + protected: + enum { + IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime == Dynamic) && + (ColsAtCompileTime == 1 || ColsAtCompileTime == Dynamic), + EnableCoeff = IsOneByOne || Option == LazyProduct + }; + + public: + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index row, Index col) const { + EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS); + eigen_assert((Option == LazyProduct) || (this->rows() == 1 && this->cols() == 1)); + + return internal::evaluator(derived()).coeff(row, col); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index i) const { + EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS); + eigen_assert((Option == LazyProduct) || (this->rows() == 1 && this->cols() == 1)); + + return internal::evaluator(derived()).coeff(i); + } +}; + +} // end namespace Eigen + +#endif // EIGEN_PRODUCT_H diff --git a/dae-cpp/Eigen/src/Core/ProductEvaluators.h b/dae-cpp/Eigen/src/Core/ProductEvaluators.h new file mode 100644 index 0000000..19c2560 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/ProductEvaluators.h @@ -0,0 +1,1155 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2008 Benoit Jacob +// Copyright (C) 2008-2010 Gael Guennebaud +// Copyright (C) 2011 Jitse Niesen +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_PRODUCTEVALUATORS_H +#define EIGEN_PRODUCTEVALUATORS_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +/** \internal + * Evaluator of a product expression. + * Since products require special treatments to handle all possible cases, + * we simply defer the evaluation logic to a product_evaluator class + * which offers more partial specialization possibilities. + * + * \sa class product_evaluator + */ +template +struct evaluator> : public product_evaluator> { + typedef Product XprType; + typedef product_evaluator Base; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) : Base(xpr) {} +}; + +// Catch "scalar * ( A * B )" and transform it to "(A*scalar) * B" +// TODO we should apply that rule only if that's really helpful +template +struct evaluator_assume_aliasing, + const CwiseNullaryOp, Plain1>, + const Product>> { + static const bool value = true; +}; +template +struct evaluator, + const CwiseNullaryOp, Plain1>, + const Product>> + : public evaluator> { + typedef CwiseBinaryOp, + const CwiseNullaryOp, Plain1>, + const Product> + XprType; + typedef evaluator> Base; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) + : Base(xpr.lhs().functor().m_other * xpr.rhs().lhs() * xpr.rhs().rhs()) {} +}; + +template +struct evaluator, DiagIndex>> + : public evaluator, DiagIndex>> { + typedef Diagonal, DiagIndex> XprType; + typedef evaluator, DiagIndex>> Base; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& xpr) + : Base(Diagonal, DiagIndex>( + Product(xpr.nestedExpression().lhs(), xpr.nestedExpression().rhs()), xpr.index())) {} +}; + +// Helper class to perform a matrix product with the destination at hand. +// Depending on the sizes of the factors, there are different evaluation strategies +// as controlled by internal::product_type. +template ::Shape, + typename RhsShape = typename evaluator_traits::Shape, + int ProductType = internal::product_type::value> +struct generic_product_impl; + +template +struct evaluator_assume_aliasing> { + static const bool value = true; +}; + +// This is the default evaluator implementation for products: +// It creates a temporary and call generic_product_impl +template +struct product_evaluator, ProductTag, LhsShape, RhsShape> + : public evaluator::PlainObject> { + typedef Product XprType; + typedef typename XprType::PlainObject PlainObject; + typedef evaluator Base; + enum { Flags = Base::Flags | EvalBeforeNestingBit }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit product_evaluator(const XprType& xpr) + : m_result(xpr.rows(), xpr.cols()) { + internal::construct_at(this, m_result); + + // FIXME shall we handle nested_eval here?, + // if so, then we must take care at removing the call to nested_eval in the specializations (e.g., in + // permutation_matrix_product, transposition_matrix_product, etc.) + // typedef typename internal::nested_eval::type LhsNested; + // typedef typename internal::nested_eval::type RhsNested; + // typedef internal::remove_all_t LhsNestedCleaned; + // typedef internal::remove_all_t RhsNestedCleaned; + // + // const LhsNested lhs(xpr.lhs()); + // const RhsNested rhs(xpr.rhs()); + // + // generic_product_impl::evalTo(m_result, lhs, rhs); + + generic_product_impl::evalTo(m_result, xpr.lhs(), xpr.rhs()); + } + + protected: + PlainObject m_result; +}; + +// The following three shortcuts are enabled only if the scalar types match exactly. +// TODO: we could enable them for different scalar types when the product is not vectorized. + +// Dense = Product +template +struct Assignment, internal::assign_op, Dense2Dense, + std::enable_if_t<(Options == DefaultProduct || Options == AliasFreeProduct)>> { + typedef Product SrcXprType; + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src, + const internal::assign_op&) { + Index dstRows = src.rows(); + Index dstCols = src.cols(); + if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols); + // FIXME shall we handle nested_eval here? + generic_product_impl::evalTo(dst, src.lhs(), src.rhs()); + } +}; + +// Dense += Product +template +struct Assignment, internal::add_assign_op, Dense2Dense, + std::enable_if_t<(Options == DefaultProduct || Options == AliasFreeProduct)>> { + typedef Product SrcXprType; + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src, + const internal::add_assign_op&) { + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + // FIXME shall we handle nested_eval here? + generic_product_impl::addTo(dst, src.lhs(), src.rhs()); + } +}; + +// Dense -= Product +template +struct Assignment, internal::sub_assign_op, Dense2Dense, + std::enable_if_t<(Options == DefaultProduct || Options == AliasFreeProduct)>> { + typedef Product SrcXprType; + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src, + const internal::sub_assign_op&) { + eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + // FIXME shall we handle nested_eval here? + generic_product_impl::subTo(dst, src.lhs(), src.rhs()); + } +}; + +// Dense ?= scalar * Product +// TODO we should apply that rule if that's really helpful +// for instance, this is not good for inner products +template +struct Assignment, + const CwiseNullaryOp, Plain>, + const Product>, + AssignFunc, Dense2Dense> { + typedef CwiseBinaryOp, + const CwiseNullaryOp, Plain>, + const Product> + SrcXprType; + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src, + const AssignFunc& func) { + call_assignment_no_alias(dst, (src.lhs().functor().m_other * src.rhs().lhs()) * src.rhs().rhs(), func); + } +}; + +//---------------------------------------- +// Catch "Dense ?= xpr + Product<>" expression to save one temporary +// FIXME we could probably enable these rules for any product, i.e., not only Dense and DefaultProduct + +template +struct evaluator_assume_aliasing< + CwiseBinaryOp< + internal::scalar_sum_op::Scalar>, + const OtherXpr, const Product>, + DenseShape> { + static const bool value = true; +}; + +template +struct evaluator_assume_aliasing< + CwiseBinaryOp< + internal::scalar_difference_op::Scalar>, + const OtherXpr, const Product>, + DenseShape> { + static const bool value = true; +}; + +template +struct assignment_from_xpr_op_product { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src, + const InitialFunc& /*func*/) { + call_assignment_no_alias(dst, src.lhs(), Func1()); + call_assignment_no_alias(dst, src.rhs(), Func2()); + } +}; + +#define EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(ASSIGN_OP, BINOP, ASSIGN_OP2) \ + template \ + struct Assignment, const OtherXpr, \ + const Product>, \ + internal::ASSIGN_OP, Dense2Dense> \ + : assignment_from_xpr_op_product, \ + internal::ASSIGN_OP, \ + internal::ASSIGN_OP2> {} + +EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_sum_op, add_assign_op); +EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op, scalar_sum_op, add_assign_op); +EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op, scalar_sum_op, sub_assign_op); + +EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_difference_op, sub_assign_op); +EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op, scalar_difference_op, sub_assign_op); +EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op, scalar_difference_op, add_assign_op); + +//---------------------------------------- + +template +struct generic_product_impl { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + dst.coeffRef(0, 0) = (lhs.transpose().cwiseProduct(rhs)).sum(); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + dst.coeffRef(0, 0) += (lhs.transpose().cwiseProduct(rhs)).sum(); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + dst.coeffRef(0, 0) -= (lhs.transpose().cwiseProduct(rhs)).sum(); + } +}; + +/*********************************************************************** + * Implementation of outer dense * dense vector product + ***********************************************************************/ + +// Column major result +template +void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Func& func, + const false_type&) { + evaluator rhsEval(rhs); + ei_declare_local_nested_eval(Lhs, lhs, Rhs::SizeAtCompileTime, actual_lhs); + // FIXME if cols is large enough, then it might be useful to make sure that lhs is sequentially stored + // FIXME not very good if rhs is real and lhs complex while alpha is real too + const Index cols = dst.cols(); + for (Index j = 0; j < cols; ++j) func(dst.col(j), rhsEval.coeff(Index(0), j) * actual_lhs); +} + +// Row major result +template +void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst, const Lhs& lhs, const Rhs& rhs, const Func& func, + const true_type&) { + evaluator lhsEval(lhs); + ei_declare_local_nested_eval(Rhs, rhs, Lhs::SizeAtCompileTime, actual_rhs); + // FIXME if rows is large enough, then it might be useful to make sure that rhs is sequentially stored + // FIXME not very good if lhs is real and rhs complex while alpha is real too + const Index rows = dst.rows(); + for (Index i = 0; i < rows; ++i) func(dst.row(i), lhsEval.coeff(i, Index(0)) * actual_rhs); +} + +template +struct generic_product_impl { + template + struct is_row_major : std::conditional_t<(int(T::Flags) & RowMajorBit), internal::true_type, internal::false_type> {}; + typedef typename Product::Scalar Scalar; + + // TODO it would be nice to be able to exploit our *_assign_op functors for that purpose + struct set { + template + EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { + dst.const_cast_derived() = src; + } + }; + struct add { + template + EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { + dst.const_cast_derived() += src; + } + }; + struct sub { + template + EIGEN_DEVICE_FUNC void operator()(const Dst& dst, const Src& src) const { + dst.const_cast_derived() -= src; + } + }; + struct adds { + Scalar m_scale; + explicit adds(const Scalar& s) : m_scale(s) {} + template + void EIGEN_DEVICE_FUNC operator()(const Dst& dst, const Src& src) const { + dst.const_cast_derived() += m_scale * src; + } + }; + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + internal::outer_product_selector_run(dst, lhs, rhs, set(), is_row_major()); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + internal::outer_product_selector_run(dst, lhs, rhs, add(), is_row_major()); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + internal::outer_product_selector_run(dst, lhs, rhs, sub(), is_row_major()); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, + const Scalar& alpha) { + internal::outer_product_selector_run(dst, lhs, rhs, adds(alpha), is_row_major()); + } +}; + +// This base class provides default implementations for evalTo, addTo, subTo, in terms of scaleAndAddTo +template +struct generic_product_impl_base { + typedef typename Product::Scalar Scalar; + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + dst.setZero(); + scaleAndAddTo(dst, lhs, rhs, Scalar(1)); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + scaleAndAddTo(dst, lhs, rhs, Scalar(1)); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + scaleAndAddTo(dst, lhs, rhs, Scalar(-1)); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dst& dst, const Lhs& lhs, const Rhs& rhs, + const Scalar& alpha) { + Derived::scaleAndAddTo(dst, lhs, rhs, alpha); + } +}; + +template +struct generic_product_impl + : generic_product_impl_base> { + typedef typename nested_eval::type LhsNested; + typedef typename nested_eval::type RhsNested; + typedef typename Product::Scalar Scalar; + enum { Side = Lhs::IsVectorAtCompileTime ? OnTheLeft : OnTheRight }; + typedef internal::remove_all_t> MatrixType; + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, + const Scalar& alpha) { + // Fallback to inner product if both the lhs and rhs is a runtime vector. + if (lhs.rows() == 1 && rhs.cols() == 1) { + dst.coeffRef(0, 0) += alpha * lhs.row(0).conjugate().dot(rhs.col(0)); + return; + } + LhsNested actual_lhs(lhs); + RhsNested actual_rhs(rhs); + internal::gemv_dense_selector::HasUsableDirectAccess)>::run(actual_lhs, + actual_rhs, dst, + alpha); + } +}; + +template +struct generic_product_impl { + typedef typename Product::Scalar Scalar; + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + // Same as: dst.noalias() = lhs.lazyProduct(rhs); + // but easier on the compiler side + call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::assign_op()); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void addTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + // dst.noalias() += lhs.lazyProduct(rhs); + call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::add_assign_op()); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void subTo(Dst& dst, const Lhs& lhs, const Rhs& rhs) { + // dst.noalias() -= lhs.lazyProduct(rhs); + call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::sub_assign_op()); + } + + // This is a special evaluation path called from generic_product_impl<...,GemmProduct> in file GeneralMatrixMatrix.h + // This variant tries to extract scalar multiples from both the LHS and RHS and factor them out. For instance: + // dst {,+,-}= (s1*A)*(B*s2) + // will be rewritten as: + // dst {,+,-}= (s1*s2) * (A.lazyProduct(B)) + // There are at least four benefits of doing so: + // 1 - huge performance gain for heap-allocated matrix types as it save costly allocations. + // 2 - it is faster than simply by-passing the heap allocation through stack allocation. + // 3 - it makes this fallback consistent with the heavy GEMM routine. + // 4 - it fully by-passes huge stack allocation attempts when multiplying huge fixed-size matrices. + // (see https://stackoverflow.com/questions/54738495) + // For small fixed sizes matrices, however, the gains are less obvious, it is sometimes x2 faster, but sometimes x3 + // slower, and the behavior depends also a lot on the compiler... This is why this re-writing strategy is currently + // enabled only when falling back from the main GEMM. + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void eval_dynamic(Dst& dst, const Lhs& lhs, const Rhs& rhs, + const Func& func) { + enum { + HasScalarFactor = blas_traits::HasScalarFactor || blas_traits::HasScalarFactor, + ConjLhs = blas_traits::NeedToConjugate, + ConjRhs = blas_traits::NeedToConjugate + }; + // FIXME: in c++11 this should be auto, and extractScalarFactor should also return auto + // this is important for real*complex_mat + Scalar actualAlpha = combine_scalar_factors(lhs, rhs); + + eval_dynamic_impl(dst, blas_traits::extract(lhs).template conjugateIf(), + blas_traits::extract(rhs).template conjugateIf(), func, actualAlpha, + std::conditional_t()); + } + + protected: + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void eval_dynamic_impl(Dst& dst, const LhsT& lhs, const RhsT& rhs, + const Func& func, const Scalar& s /* == 1 */, + false_type) { + EIGEN_UNUSED_VARIABLE(s); + eigen_internal_assert(numext::is_exactly_one(s)); + call_restricted_packet_assignment_no_alias(dst, lhs.lazyProduct(rhs), func); + } + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void eval_dynamic_impl(Dst& dst, const LhsT& lhs, const RhsT& rhs, + const Func& func, const Scalar& s, true_type) { + call_restricted_packet_assignment_no_alias(dst, s * lhs.lazyProduct(rhs), func); + } +}; + +// This specialization enforces the use of a coefficient-based evaluation strategy +template +struct generic_product_impl + : generic_product_impl {}; + +// Case 2: Evaluate coeff by coeff +// +// This is mostly taken from CoeffBasedProduct.h +// The main difference is that we add an extra argument to the etor_product_*_impl::run() function +// for the inner dimension of the product, because evaluator object do not know their size. + +template +struct etor_product_coeff_impl; + +template +struct etor_product_packet_impl; + +template +struct product_evaluator, ProductTag, DenseShape, DenseShape> + : evaluator_base> { + typedef Product XprType; + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit product_evaluator(const XprType& xpr) + : m_lhs(xpr.lhs()), + m_rhs(xpr.rhs()), + m_lhsImpl(m_lhs), // FIXME the creation of the evaluator objects should result in a no-op, but check that! + m_rhsImpl(m_rhs), // Moreover, they are only useful for the packet path, so we could completely disable + // them when not needed, or perhaps declare them on the fly on the packet method... We + // have experiment to check what's best. + m_innerDim(xpr.lhs().cols()) { + EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits::MulCost); + EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits::AddCost); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); +#if 0 + std::cerr << "LhsOuterStrideBytes= " << LhsOuterStrideBytes << "\n"; + std::cerr << "RhsOuterStrideBytes= " << RhsOuterStrideBytes << "\n"; + std::cerr << "LhsAlignment= " << LhsAlignment << "\n"; + std::cerr << "RhsAlignment= " << RhsAlignment << "\n"; + std::cerr << "CanVectorizeLhs= " << CanVectorizeLhs << "\n"; + std::cerr << "CanVectorizeRhs= " << CanVectorizeRhs << "\n"; + std::cerr << "CanVectorizeInner= " << CanVectorizeInner << "\n"; + std::cerr << "EvalToRowMajor= " << EvalToRowMajor << "\n"; + std::cerr << "Alignment= " << Alignment << "\n"; + std::cerr << "Flags= " << Flags << "\n"; +#endif + } + + // Everything below here is taken from CoeffBasedProduct.h + + typedef typename internal::nested_eval::type LhsNested; + typedef typename internal::nested_eval::type RhsNested; + + typedef internal::remove_all_t LhsNestedCleaned; + typedef internal::remove_all_t RhsNestedCleaned; + + typedef evaluator LhsEtorType; + typedef evaluator RhsEtorType; + + enum { + RowsAtCompileTime = LhsNestedCleaned::RowsAtCompileTime, + ColsAtCompileTime = RhsNestedCleaned::ColsAtCompileTime, + InnerSize = min_size_prefer_fixed(LhsNestedCleaned::ColsAtCompileTime, RhsNestedCleaned::RowsAtCompileTime), + MaxRowsAtCompileTime = LhsNestedCleaned::MaxRowsAtCompileTime, + MaxColsAtCompileTime = RhsNestedCleaned::MaxColsAtCompileTime + }; + + typedef typename find_best_packet::type LhsVecPacketType; + typedef typename find_best_packet::type RhsVecPacketType; + + enum { + + LhsCoeffReadCost = LhsEtorType::CoeffReadCost, + RhsCoeffReadCost = RhsEtorType::CoeffReadCost, + CoeffReadCost = InnerSize == 0 ? NumTraits::ReadCost + : InnerSize == Dynamic + ? HugeCost + : InnerSize * (NumTraits::MulCost + int(LhsCoeffReadCost) + int(RhsCoeffReadCost)) + + (InnerSize - 1) * NumTraits::AddCost, + + Unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT, + + LhsFlags = LhsEtorType::Flags, + RhsFlags = RhsEtorType::Flags, + + LhsRowMajor = LhsFlags & RowMajorBit, + RhsRowMajor = RhsFlags & RowMajorBit, + + LhsVecPacketSize = unpacket_traits::size, + RhsVecPacketSize = unpacket_traits::size, + + // Here, we don't care about alignment larger than the usable packet size. + LhsAlignment = + plain_enum_min(LhsEtorType::Alignment, LhsVecPacketSize* int(sizeof(typename LhsNestedCleaned::Scalar))), + RhsAlignment = + plain_enum_min(RhsEtorType::Alignment, RhsVecPacketSize* int(sizeof(typename RhsNestedCleaned::Scalar))), + + SameType = is_same::value, + + CanVectorizeRhs = bool(RhsRowMajor) && (RhsFlags & PacketAccessBit) && (ColsAtCompileTime != 1), + CanVectorizeLhs = (!LhsRowMajor) && (LhsFlags & PacketAccessBit) && (RowsAtCompileTime != 1), + + EvalToRowMajor = (MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1) ? 1 + : (MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1) + ? 0 + : (bool(RhsRowMajor) && !CanVectorizeLhs), + + Flags = ((int(LhsFlags) | int(RhsFlags)) & HereditaryBits & ~RowMajorBit) | + (EvalToRowMajor ? RowMajorBit : 0) + // TODO enable vectorization for mixed types + | (SameType && (CanVectorizeLhs || CanVectorizeRhs) ? PacketAccessBit : 0) | + (XprType::IsVectorAtCompileTime ? LinearAccessBit : 0), + + LhsOuterStrideBytes = + int(LhsNestedCleaned::OuterStrideAtCompileTime) * int(sizeof(typename LhsNestedCleaned::Scalar)), + RhsOuterStrideBytes = + int(RhsNestedCleaned::OuterStrideAtCompileTime) * int(sizeof(typename RhsNestedCleaned::Scalar)), + + Alignment = bool(CanVectorizeLhs) + ? (LhsOuterStrideBytes <= 0 || (int(LhsOuterStrideBytes) % plain_enum_max(1, LhsAlignment)) != 0 + ? 0 + : LhsAlignment) + : bool(CanVectorizeRhs) + ? (RhsOuterStrideBytes <= 0 || (int(RhsOuterStrideBytes) % plain_enum_max(1, RhsAlignment)) != 0 + ? 0 + : RhsAlignment) + : 0, + + /* CanVectorizeInner deserves special explanation. It does not affect the product flags. It is not used outside + * of Product. If the Product itself is not a packet-access expression, there is still a chance that the inner + * loop of the product might be vectorized. This is the meaning of CanVectorizeInner. Since it doesn't affect + * the Flags, it is safe to make this value depend on ActualPacketAccessBit, that doesn't affect the ABI. + */ + CanVectorizeInner = SameType && LhsRowMajor && (!RhsRowMajor) && + (int(LhsFlags) & int(RhsFlags) & ActualPacketAccessBit) && + (int(InnerSize) % packet_traits::size == 0) + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index row, Index col) const { + return (m_lhs.row(row).transpose().cwiseProduct(m_rhs.col(col))).sum(); + } + + /* Allow index-based non-packet access. It is impossible though to allow index-based packed access, + * which is why we don't set the LinearAccessBit. + * TODO: this seems possible when the result is a vector + */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index index) const { + const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime == 1) ? 0 : index; + const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime == 1) ? index : 0; + return (m_lhs.row(row).transpose().cwiseProduct(m_rhs.col(col))).sum(); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const PacketType packet(Index row, Index col) const { + PacketType res; + typedef etor_product_packet_impl + PacketImpl; + PacketImpl::run(row, col, m_lhsImpl, m_rhsImpl, m_innerDim, res); + return res; + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const PacketType packet(Index index) const { + const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime == 1) ? 0 : index; + const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime == 1) ? index : 0; + return packet(row, col); + } + + protected: + add_const_on_value_type_t m_lhs; + add_const_on_value_type_t m_rhs; + + LhsEtorType m_lhsImpl; + RhsEtorType m_rhsImpl; + + // TODO: Get rid of m_innerDim if known at compile time + Index m_innerDim; +}; + +template +struct product_evaluator, LazyCoeffBasedProductMode, DenseShape, DenseShape> + : product_evaluator, CoeffBasedProductMode, DenseShape, DenseShape> { + typedef Product XprType; + typedef Product BaseProduct; + typedef product_evaluator Base; + enum { Flags = Base::Flags | EvalBeforeNestingBit }; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit product_evaluator(const XprType& xpr) + : Base(BaseProduct(xpr.lhs(), xpr.rhs())) {} +}; + +/**************************************** +*** Coeff based product, Packet path *** +****************************************/ + +template +struct etor_product_packet_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, + Index innerDim, Packet& res) { + etor_product_packet_impl::run(row, col, lhs, rhs, + innerDim, res); + res = pmadd(pset1(lhs.coeff(row, Index(UnrollingIndex - 1))), + rhs.template packet(Index(UnrollingIndex - 1), col), res); + } +}; + +template +struct etor_product_packet_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, + Index innerDim, Packet& res) { + etor_product_packet_impl::run(row, col, lhs, rhs, + innerDim, res); + res = pmadd(lhs.template packet(row, Index(UnrollingIndex - 1)), + pset1(rhs.coeff(Index(UnrollingIndex - 1), col)), res); + } +}; + +template +struct etor_product_packet_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, + Index /*innerDim*/, Packet& res) { + res = pmul(pset1(lhs.coeff(row, Index(0))), rhs.template packet(Index(0), col)); + } +}; + +template +struct etor_product_packet_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, + Index /*innerDim*/, Packet& res) { + res = pmul(lhs.template packet(row, Index(0)), pset1(rhs.coeff(Index(0), col))); + } +}; + +template +struct etor_product_packet_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index /*row*/, Index /*col*/, const Lhs& /*lhs*/, + const Rhs& /*rhs*/, Index /*innerDim*/, Packet& res) { + res = pset1(typename unpacket_traits::type(0)); + } +}; + +template +struct etor_product_packet_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index /*row*/, Index /*col*/, const Lhs& /*lhs*/, + const Rhs& /*rhs*/, Index /*innerDim*/, Packet& res) { + res = pset1(typename unpacket_traits::type(0)); + } +}; + +template +struct etor_product_packet_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, + Index innerDim, Packet& res) { + res = pset1(typename unpacket_traits::type(0)); + for (Index i = 0; i < innerDim; ++i) + res = pmadd(pset1(lhs.coeff(row, i)), rhs.template packet(i, col), res); + } +}; + +template +struct etor_product_packet_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Index row, Index col, const Lhs& lhs, const Rhs& rhs, + Index innerDim, Packet& res) { + res = pset1(typename unpacket_traits::type(0)); + for (Index i = 0; i < innerDim; ++i) + res = pmadd(lhs.template packet(row, i), pset1(rhs.coeff(i, col)), res); + } +}; + +/*************************************************************************** + * Triangular products + ***************************************************************************/ +template +struct triangular_product_impl; + +template +struct generic_product_impl + : generic_product_impl_base> { + typedef typename Product::Scalar Scalar; + + template + static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) { + triangular_product_impl::run( + dst, lhs.nestedExpression(), rhs, alpha); + } +}; + +template +struct generic_product_impl + : generic_product_impl_base> { + typedef typename Product::Scalar Scalar; + + template + static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) { + triangular_product_impl::run( + dst, lhs, rhs.nestedExpression(), alpha); + } +}; + +/*************************************************************************** + * SelfAdjoint products + ***************************************************************************/ +template +struct selfadjoint_product_impl; + +template +struct generic_product_impl + : generic_product_impl_base> { + typedef typename Product::Scalar Scalar; + + template + static EIGEN_DEVICE_FUNC void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) { + selfadjoint_product_impl::run( + dst, lhs.nestedExpression(), rhs, alpha); + } +}; + +template +struct generic_product_impl + : generic_product_impl_base> { + typedef typename Product::Scalar Scalar; + + template + static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha) { + selfadjoint_product_impl::run( + dst, lhs, rhs.nestedExpression(), alpha); + } +}; + +/*************************************************************************** + * Diagonal products + ***************************************************************************/ + +template +struct diagonal_product_evaluator_base : evaluator_base { + typedef typename ScalarBinaryOpTraits::ReturnType Scalar; + + public: + enum { + CoeffReadCost = int(NumTraits::MulCost) + int(evaluator::CoeffReadCost) + + int(evaluator::CoeffReadCost), + + MatrixFlags = evaluator::Flags, + DiagFlags = evaluator::Flags, + + StorageOrder_ = (Derived::MaxRowsAtCompileTime == 1 && Derived::MaxColsAtCompileTime != 1) ? RowMajor + : (Derived::MaxColsAtCompileTime == 1 && Derived::MaxRowsAtCompileTime != 1) ? ColMajor + : MatrixFlags & RowMajorBit ? RowMajor + : ColMajor, + SameStorageOrder_ = StorageOrder_ == (MatrixFlags & RowMajorBit ? RowMajor : ColMajor), + + ScalarAccessOnDiag_ = !((int(StorageOrder_) == ColMajor && int(ProductOrder) == OnTheLeft) || + (int(StorageOrder_) == RowMajor && int(ProductOrder) == OnTheRight)), + SameTypes_ = is_same::value, + // FIXME currently we need same types, but in the future the next rule should be the one + // Vectorizable_ = bool(int(MatrixFlags)&PacketAccessBit) && ((!_PacketOnDiag) || (SameTypes_ && + // bool(int(DiagFlags)&PacketAccessBit))), + Vectorizable_ = bool(int(MatrixFlags) & PacketAccessBit) && SameTypes_ && + (SameStorageOrder_ || (MatrixFlags & LinearAccessBit) == LinearAccessBit) && + (ScalarAccessOnDiag_ || (bool(int(DiagFlags) & PacketAccessBit))), + LinearAccessMask_ = + (MatrixType::RowsAtCompileTime == 1 || MatrixType::ColsAtCompileTime == 1) ? LinearAccessBit : 0, + Flags = + ((HereditaryBits | LinearAccessMask_) & (unsigned int)(MatrixFlags)) | (Vectorizable_ ? PacketAccessBit : 0), + Alignment = evaluator::Alignment, + + AsScalarProduct = + (DiagonalType::SizeAtCompileTime == 1) || + (DiagonalType::SizeAtCompileTime == Dynamic && MatrixType::RowsAtCompileTime == 1 && + ProductOrder == OnTheLeft) || + (DiagonalType::SizeAtCompileTime == Dynamic && MatrixType::ColsAtCompileTime == 1 && ProductOrder == OnTheRight) + }; + + EIGEN_DEVICE_FUNC diagonal_product_evaluator_base(const MatrixType& mat, const DiagonalType& diag) + : m_diagImpl(diag), m_matImpl(mat) { + EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits::MulCost); + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index idx) const { + if (AsScalarProduct) + return m_diagImpl.coeff(0) * m_matImpl.coeff(idx); + else + return m_diagImpl.coeff(idx) * m_matImpl.coeff(idx); + } + + protected: + template + EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index id, internal::true_type) const { + return internal::pmul(m_matImpl.template packet(row, col), + internal::pset1(m_diagImpl.coeff(id))); + } + + template + EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index id, internal::false_type) const { + enum { + InnerSize = (MatrixType::Flags & RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime, + DiagonalPacketLoadMode = plain_enum_min( + LoadMode, + ((InnerSize % 16) == 0) ? int(Aligned16) : int(evaluator::Alignment)) // FIXME hardcoded 16!! + }; + return internal::pmul(m_matImpl.template packet(row, col), + m_diagImpl.template packet(id)); + } + + evaluator m_diagImpl; + evaluator m_matImpl; +}; + +// diagonal * dense +template +struct product_evaluator, ProductTag, DiagonalShape, DenseShape> + : diagonal_product_evaluator_base, + OnTheLeft> { + typedef diagonal_product_evaluator_base, + OnTheLeft> + Base; + using Base::coeff; + using Base::m_diagImpl; + using Base::m_matImpl; + typedef typename Base::Scalar Scalar; + + typedef Product XprType; + typedef typename XprType::PlainObject PlainObject; + typedef typename Lhs::DiagonalVectorType DiagonalType; + + enum { StorageOrder = Base::StorageOrder_ }; + + EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) : Base(xpr.rhs(), xpr.lhs().diagonal()) {} + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const { + return m_diagImpl.coeff(row) * m_matImpl.coeff(row, col); + } + +#ifndef EIGEN_GPUCC + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + // FIXME: NVCC used to complain about the template keyword, but we have to check whether this is still the case. + // See also similar calls below. + return this->template packet_impl( + row, col, row, std::conditional_t()); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index idx) const { + return packet(int(StorageOrder) == ColMajor ? idx : 0, + int(StorageOrder) == ColMajor ? 0 : idx); + } +#endif +}; + +// dense * diagonal +template +struct product_evaluator, ProductTag, DenseShape, DiagonalShape> + : diagonal_product_evaluator_base, + OnTheRight> { + typedef diagonal_product_evaluator_base, + OnTheRight> + Base; + using Base::coeff; + using Base::m_diagImpl; + using Base::m_matImpl; + typedef typename Base::Scalar Scalar; + + typedef Product XprType; + typedef typename XprType::PlainObject PlainObject; + + enum { StorageOrder = Base::StorageOrder_ }; + + EIGEN_DEVICE_FUNC explicit product_evaluator(const XprType& xpr) : Base(xpr.lhs(), xpr.rhs().diagonal()) {} + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const { + return m_matImpl.coeff(row, col) * m_diagImpl.coeff(col); + } + +#ifndef EIGEN_GPUCC + template + EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + return this->template packet_impl( + row, col, col, std::conditional_t()); + } + + template + EIGEN_STRONG_INLINE PacketType packet(Index idx) const { + return packet(int(StorageOrder) == ColMajor ? idx : 0, + int(StorageOrder) == ColMajor ? 0 : idx); + } +#endif +}; + +/*************************************************************************** + * Products with permutation matrices + ***************************************************************************/ + +/** \internal + * \class permutation_matrix_product + * Internal helper class implementing the product between a permutation matrix and a matrix. + * This class is specialized for DenseShape below and for SparseShape in SparseCore/SparsePermutation.h + */ +template +struct permutation_matrix_product; + +template +struct permutation_matrix_product { + typedef typename nested_eval::type MatrixType; + typedef remove_all_t MatrixTypeCleaned; + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Dest& dst, const PermutationType& perm, + const ExpressionType& xpr) { + MatrixType mat(xpr); + const Index n = Side == OnTheLeft ? mat.rows() : mat.cols(); + // FIXME we need an is_same for expression that is not sensitive to constness. For instance + // is_same_xpr, Block >::value should be true. + // if(is_same::value && extract_data(dst) == extract_data(mat)) + if (is_same_dense(dst, mat)) { + // apply the permutation inplace + Matrix mask(perm.size()); + mask.fill(false); + Index r = 0; + while (r < perm.size()) { + // search for the next seed + while (r < perm.size() && mask[r]) r++; + if (r >= perm.size()) break; + // we got one, let's follow it until we are back to the seed + Index k0 = r++; + Index kPrev = k0; + mask.coeffRef(k0) = true; + for (Index k = perm.indices().coeff(k0); k != k0; k = perm.indices().coeff(k)) { + Block(dst, k) + .swap(Block < Dest, Side == OnTheLeft ? 1 : Dest::RowsAtCompileTime, + Side == OnTheRight + ? 1 + : Dest::ColsAtCompileTime > (dst, ((Side == OnTheLeft) ^ Transposed) ? k0 : kPrev)); + + mask.coeffRef(k) = true; + kPrev = k; + } + } + } else { + for (Index i = 0; i < n; ++i) { + Block( + dst, ((Side == OnTheLeft) ^ Transposed) ? perm.indices().coeff(i) : i) + + = + + Block < const MatrixTypeCleaned, + Side == OnTheLeft ? 1 : MatrixTypeCleaned::RowsAtCompileTime, + Side == OnTheRight ? 1 + : MatrixTypeCleaned::ColsAtCompileTime > + (mat, ((Side == OnTheRight) ^ Transposed) ? perm.indices().coeff(i) : i); + } + } + } +}; + +template +struct generic_product_impl { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) { + permutation_matrix_product::run(dst, lhs, rhs); + } +}; + +template +struct generic_product_impl { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) { + permutation_matrix_product::run(dst, rhs, lhs); + } +}; + +template +struct generic_product_impl, Rhs, PermutationShape, MatrixShape, ProductTag> { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Inverse& lhs, const Rhs& rhs) { + permutation_matrix_product::run(dst, lhs.nestedExpression(), rhs); + } +}; + +template +struct generic_product_impl, MatrixShape, PermutationShape, ProductTag> { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Inverse& rhs) { + permutation_matrix_product::run(dst, rhs.nestedExpression(), lhs); + } +}; + +/*************************************************************************** + * Products with transpositions matrices + ***************************************************************************/ + +// FIXME could we unify Transpositions and Permutation into a single "shape"?? + +/** \internal + * \class transposition_matrix_product + * Internal helper class implementing the product between a permutation matrix and a matrix. + */ +template +struct transposition_matrix_product { + typedef typename nested_eval::type MatrixType; + typedef remove_all_t MatrixTypeCleaned; + + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Dest& dst, const TranspositionType& tr, + const ExpressionType& xpr) { + MatrixType mat(xpr); + typedef typename TranspositionType::StorageIndex StorageIndex; + const Index size = tr.size(); + StorageIndex j = 0; + + if (!is_same_dense(dst, mat)) dst = mat; + + for (Index k = (Transposed ? size - 1 : 0); Transposed ? k >= 0 : k < size; Transposed ? --k : ++k) + if (Index(j = tr.coeff(k)) != k) { + if (Side == OnTheLeft) + dst.row(k).swap(dst.row(j)); + else if (Side == OnTheRight) + dst.col(k).swap(dst.col(j)); + } + } +}; + +template +struct generic_product_impl { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) { + transposition_matrix_product::run(dst, lhs, rhs); + } +}; + +template +struct generic_product_impl { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) { + transposition_matrix_product::run(dst, rhs, lhs); + } +}; + +template +struct generic_product_impl, Rhs, TranspositionsShape, MatrixShape, ProductTag> { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Transpose& lhs, const Rhs& rhs) { + transposition_matrix_product::run(dst, lhs.nestedExpression(), rhs); + } +}; + +template +struct generic_product_impl, MatrixShape, TranspositionsShape, ProductTag> { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Transpose& rhs) { + transposition_matrix_product::run(dst, rhs.nestedExpression(), lhs); + } +}; + +/*************************************************************************** + * skew symmetric products + * for now we just call the generic implementation + ***************************************************************************/ +template +struct generic_product_impl { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) { + generic_product_impl::evalTo(dst, lhs, + rhs); + } +}; + +template +struct generic_product_impl { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) { + generic_product_impl::evalTo(dst, lhs, + rhs); + } +}; + +template +struct generic_product_impl { + template + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs) { + generic_product_impl::evalTo(dst, lhs, rhs); + } +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_PRODUCT_EVALUATORS_H diff --git a/dae-cpp/Eigen/src/Core/Random.h b/dae-cpp/Eigen/src/Core/Random.h new file mode 100644 index 0000000..f8a5435 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Random.h @@ -0,0 +1,207 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_RANDOM_H +#define EIGEN_RANDOM_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +struct scalar_random_op { + inline const Scalar operator()() const { return random(); } +}; + +template +struct functor_traits > { + enum { Cost = 5 * NumTraits::MulCost, PacketAccess = false, IsRepeatable = false }; +}; + +} // end namespace internal + +/** \returns a random matrix expression + * + * Numbers are uniformly spread through their whole definition range for integer types, + * and in the [-1:1] range for floating point scalar types. + * + * The parameters \a rows and \a cols are the number of rows and of columns of + * the returned matrix. Must be compatible with this MatrixBase type. + * + * \not_reentrant + * + * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, + * it is redundant to pass \a rows and \a cols as arguments, so Random() should be used + * instead. + * + * + * Example: \include MatrixBase_random_int_int.cpp + * Output: \verbinclude MatrixBase_random_int_int.out + * + * This expression has the "evaluate before nesting" flag so that it will be evaluated into + * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected + * behavior with expressions involving random matrices. + * + * See DenseBase::NullaryExpr(Index, const CustomNullaryOp&) for an example using C++11 random generators. + * + * \sa DenseBase::setRandom(), DenseBase::Random(Index), DenseBase::Random() + */ +template +inline const typename DenseBase::RandomReturnType DenseBase::Random(Index rows, Index cols) { + return NullaryExpr(rows, cols, internal::scalar_random_op()); +} + +/** \returns a random vector expression + * + * Numbers are uniformly spread through their whole definition range for integer types, + * and in the [-1:1] range for floating point scalar types. + * + * The parameter \a size is the size of the returned vector. + * Must be compatible with this MatrixBase type. + * + * \only_for_vectors + * \not_reentrant + * + * This variant is meant to be used for dynamic-size vector types. For fixed-size types, + * it is redundant to pass \a size as argument, so Random() should be used + * instead. + * + * Example: \include MatrixBase_random_int.cpp + * Output: \verbinclude MatrixBase_random_int.out + * + * This expression has the "evaluate before nesting" flag so that it will be evaluated into + * a temporary vector whenever it is nested in a larger expression. This prevents unexpected + * behavior with expressions involving random matrices. + * + * \sa DenseBase::setRandom(), DenseBase::Random(Index,Index), DenseBase::Random() + */ +template +inline const typename DenseBase::RandomReturnType DenseBase::Random(Index size) { + return NullaryExpr(size, internal::scalar_random_op()); +} + +/** \returns a fixed-size random matrix or vector expression + * + * Numbers are uniformly spread through their whole definition range for integer types, + * and in the [-1:1] range for floating point scalar types. + * + * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you + * need to use the variants taking size arguments. + * + * Example: \include MatrixBase_random.cpp + * Output: \verbinclude MatrixBase_random.out + * + * This expression has the "evaluate before nesting" flag so that it will be evaluated into + * a temporary matrix whenever it is nested in a larger expression. This prevents unexpected + * behavior with expressions involving random matrices. + * + * \not_reentrant + * + * \sa DenseBase::setRandom(), DenseBase::Random(Index,Index), DenseBase::Random(Index) + */ +template +inline const typename DenseBase::RandomReturnType DenseBase::Random() { + return NullaryExpr(RowsAtCompileTime, ColsAtCompileTime, internal::scalar_random_op()); +} + +/** Sets all coefficients in this expression to random values. + * + * Numbers are uniformly spread through their whole definition range for integer types, + * and in the [-1:1] range for floating point scalar types. + * + * \not_reentrant + * + * Example: \include MatrixBase_setRandom.cpp + * Output: \verbinclude MatrixBase_setRandom.out + * + * \sa class CwiseNullaryOp, setRandom(Index), setRandom(Index,Index) + */ +template +EIGEN_DEVICE_FUNC inline Derived& DenseBase::setRandom() { + return *this = Random(rows(), cols()); +} + +/** Resizes to the given \a newSize, and sets all coefficients in this expression to random values. + * + * Numbers are uniformly spread through their whole definition range for integer types, + * and in the [-1:1] range for floating point scalar types. + * + * \only_for_vectors + * \not_reentrant + * + * Example: \include Matrix_setRandom_int.cpp + * Output: \verbinclude Matrix_setRandom_int.out + * + * \sa DenseBase::setRandom(), setRandom(Index,Index), class CwiseNullaryOp, DenseBase::Random() + */ +template +EIGEN_STRONG_INLINE Derived& PlainObjectBase::setRandom(Index newSize) { + resize(newSize); + return setRandom(); +} + +/** Resizes to the given size, and sets all coefficients in this expression to random values. + * + * Numbers are uniformly spread through their whole definition range for integer types, + * and in the [-1:1] range for floating point scalar types. + * + * \not_reentrant + * + * \param rows the new number of rows + * \param cols the new number of columns + * + * Example: \include Matrix_setRandom_int_int.cpp + * Output: \verbinclude Matrix_setRandom_int_int.out + * + * \sa DenseBase::setRandom(), setRandom(Index), class CwiseNullaryOp, DenseBase::Random() + */ +template +EIGEN_STRONG_INLINE Derived& PlainObjectBase::setRandom(Index rows, Index cols) { + resize(rows, cols); + return setRandom(); +} + +/** Resizes to the given size, changing only the number of columns, and sets all + * coefficients in this expression to random values. For the parameter of type + * NoChange_t, just pass the special value \c NoChange. + * + * Numbers are uniformly spread through their whole definition range for integer types, + * and in the [-1:1] range for floating point scalar types. + * + * \not_reentrant + * + * \sa DenseBase::setRandom(), setRandom(Index), setRandom(Index, NoChange_t), class CwiseNullaryOp, DenseBase::Random() + */ +template +EIGEN_STRONG_INLINE Derived& PlainObjectBase::setRandom(NoChange_t, Index cols) { + return setRandom(rows(), cols); +} + +/** Resizes to the given size, changing only the number of rows, and sets all + * coefficients in this expression to random values. For the parameter of type + * NoChange_t, just pass the special value \c NoChange. + * + * Numbers are uniformly spread through their whole definition range for integer types, + * and in the [-1:1] range for floating point scalar types. + * + * \not_reentrant + * + * \sa DenseBase::setRandom(), setRandom(Index), setRandom(NoChange_t, Index), class CwiseNullaryOp, DenseBase::Random() + */ +template +EIGEN_STRONG_INLINE Derived& PlainObjectBase::setRandom(Index rows, NoChange_t) { + return setRandom(rows, cols()); +} + +} // end namespace Eigen + +#endif // EIGEN_RANDOM_H diff --git a/dae-cpp/Eigen/src/Core/Redux.h b/dae-cpp/Eigen/src/Core/Redux.h new file mode 100644 index 0000000..0c5f2d9 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Redux.h @@ -0,0 +1,528 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// Copyright (C) 2006-2008 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_REDUX_H +#define EIGEN_REDUX_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +// TODO +// * implement other kind of vectorization +// * factorize code + +/*************************************************************************** + * Part 1 : the logic deciding a strategy for vectorization and unrolling + ***************************************************************************/ + +template +struct redux_traits { + public: + typedef typename find_best_packet::type PacketType; + enum { + PacketSize = unpacket_traits::size, + InnerMaxSize = int(Evaluator::IsRowMajor) ? Evaluator::MaxColsAtCompileTime : Evaluator::MaxRowsAtCompileTime, + OuterMaxSize = int(Evaluator::IsRowMajor) ? Evaluator::MaxRowsAtCompileTime : Evaluator::MaxColsAtCompileTime, + SliceVectorizedWork = int(InnerMaxSize) == Dynamic ? Dynamic + : int(OuterMaxSize) == Dynamic ? (int(InnerMaxSize) >= int(PacketSize) ? Dynamic : 0) + : (int(InnerMaxSize) / int(PacketSize)) * int(OuterMaxSize) + }; + + enum { + MayLinearize = (int(Evaluator::Flags) & LinearAccessBit), + MightVectorize = (int(Evaluator::Flags) & ActualPacketAccessBit) && (functor_traits::PacketAccess), + MayLinearVectorize = bool(MightVectorize) && bool(MayLinearize), + MaySliceVectorize = bool(MightVectorize) && (int(SliceVectorizedWork) == Dynamic || int(SliceVectorizedWork) >= 3) + }; + + public: + enum { + Traversal = int(MayLinearVectorize) ? int(LinearVectorizedTraversal) + : int(MaySliceVectorize) ? int(SliceVectorizedTraversal) + : int(MayLinearize) ? int(LinearTraversal) + : int(DefaultTraversal) + }; + + public: + enum { + Cost = Evaluator::SizeAtCompileTime == Dynamic + ? HugeCost + : int(Evaluator::SizeAtCompileTime) * int(Evaluator::CoeffReadCost) + + (Evaluator::SizeAtCompileTime - 1) * functor_traits::Cost, + UnrollingLimit = EIGEN_UNROLLING_LIMIT * (int(Traversal) == int(DefaultTraversal) ? 1 : int(PacketSize)) + }; + + public: + enum { Unrolling = Cost <= UnrollingLimit ? CompleteUnrolling : NoUnrolling }; + +#ifdef EIGEN_DEBUG_ASSIGN + static void debug() { + std::cerr << "Xpr: " << typeid(typename Evaluator::XprType).name() << std::endl; + std::cerr.setf(std::ios::hex, std::ios::basefield); + EIGEN_DEBUG_VAR(Evaluator::Flags) + std::cerr.unsetf(std::ios::hex); + EIGEN_DEBUG_VAR(InnerMaxSize) + EIGEN_DEBUG_VAR(OuterMaxSize) + EIGEN_DEBUG_VAR(SliceVectorizedWork) + EIGEN_DEBUG_VAR(PacketSize) + EIGEN_DEBUG_VAR(MightVectorize) + EIGEN_DEBUG_VAR(MayLinearVectorize) + EIGEN_DEBUG_VAR(MaySliceVectorize) + std::cerr << "Traversal" + << " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl; + EIGEN_DEBUG_VAR(UnrollingLimit) + std::cerr << "Unrolling" + << " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl; + std::cerr << std::endl; + } +#endif +}; + +/*************************************************************************** + * Part 2 : unrollers + ***************************************************************************/ + +/*** no vectorization ***/ + +template +struct redux_novec_unroller { + static constexpr Index HalfLength = Length / 2; + + typedef typename Evaluator::Scalar Scalar; + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func& func) { + return func(redux_novec_unroller::run(eval, func), + redux_novec_unroller::run(eval, func)); + } +}; + +template +struct redux_novec_unroller { + static constexpr Index outer = Start / Evaluator::InnerSizeAtCompileTime; + static constexpr Index inner = Start % Evaluator::InnerSizeAtCompileTime; + + typedef typename Evaluator::Scalar Scalar; + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func&) { + return eval.coeffByOuterInner(outer, inner); + } +}; + +// This is actually dead code and will never be called. It is required +// to prevent false warnings regarding failed inlining though +// for 0 length run() will never be called at all. +template +struct redux_novec_unroller { + typedef typename Evaluator::Scalar Scalar; + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator&, const Func&) { return Scalar(); } +}; + +template +struct redux_novec_linear_unroller { + static constexpr Index HalfLength = Length / 2; + + typedef typename Evaluator::Scalar Scalar; + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func& func) { + return func(redux_novec_linear_unroller::run(eval, func), + redux_novec_linear_unroller::run(eval, func)); + } +}; + +template +struct redux_novec_linear_unroller { + typedef typename Evaluator::Scalar Scalar; + + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func&) { + return eval.coeff(Start); + } +}; + +// This is actually dead code and will never be called. It is required +// to prevent false warnings regarding failed inlining though +// for 0 length run() will never be called at all. +template +struct redux_novec_linear_unroller { + typedef typename Evaluator::Scalar Scalar; + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator&, const Func&) { return Scalar(); } +}; + +/*** vectorization ***/ + +template +struct redux_vec_unroller { + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE PacketType run(const Evaluator& eval, const Func& func) { + constexpr Index HalfLength = Length / 2; + + return func.packetOp( + redux_vec_unroller::template run(eval, func), + redux_vec_unroller::template run(eval, + func)); + } +}; + +template +struct redux_vec_unroller { + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE PacketType run(const Evaluator& eval, const Func&) { + constexpr Index PacketSize = unpacket_traits::size; + constexpr Index index = Start * PacketSize; + constexpr Index outer = index / int(Evaluator::InnerSizeAtCompileTime); + constexpr Index inner = index % int(Evaluator::InnerSizeAtCompileTime); + constexpr int alignment = Evaluator::Alignment; + + return eval.template packetByOuterInner(outer, inner); + } +}; + +template +struct redux_vec_linear_unroller { + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE PacketType run(const Evaluator& eval, const Func& func) { + constexpr Index HalfLength = Length / 2; + + return func.packetOp( + redux_vec_linear_unroller::template run(eval, func), + redux_vec_linear_unroller::template run( + eval, func)); + } +}; + +template +struct redux_vec_linear_unroller { + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE PacketType run(const Evaluator& eval, const Func&) { + constexpr Index PacketSize = unpacket_traits::size; + constexpr Index index = (Start * PacketSize); + constexpr int alignment = Evaluator::Alignment; + return eval.template packet(index); + } +}; + +/*************************************************************************** + * Part 3 : implementation of all cases + ***************************************************************************/ + +template ::Traversal, + int Unrolling = redux_traits::Unrolling> +struct redux_impl; + +template +struct redux_impl { + typedef typename Evaluator::Scalar Scalar; + + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func& func, const XprType& xpr) { + eigen_assert(xpr.rows() > 0 && xpr.cols() > 0 && "you are using an empty matrix"); + Scalar res = eval.coeffByOuterInner(0, 0); + for (Index i = 1; i < xpr.innerSize(); ++i) res = func(res, eval.coeffByOuterInner(0, i)); + for (Index i = 1; i < xpr.outerSize(); ++i) + for (Index j = 0; j < xpr.innerSize(); ++j) res = func(res, eval.coeffByOuterInner(i, j)); + return res; + } +}; + +template +struct redux_impl { + typedef typename Evaluator::Scalar Scalar; + + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func& func, const XprType& xpr) { + eigen_assert(xpr.size() > 0 && "you are using an empty matrix"); + Scalar res = eval.coeff(0); + for (Index k = 1; k < xpr.size(); ++k) res = func(res, eval.coeff(k)); + return res; + } +}; + +template +struct redux_impl + : redux_novec_unroller { + typedef redux_novec_unroller Base; + typedef typename Evaluator::Scalar Scalar; + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func& func, + const XprType& /*xpr*/) { + return Base::run(eval, func); + } +}; + +template +struct redux_impl + : redux_novec_linear_unroller { + typedef redux_novec_linear_unroller Base; + typedef typename Evaluator::Scalar Scalar; + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func& func, + const XprType& /*xpr*/) { + return Base::run(eval, func); + } +}; + +template +struct redux_impl { + typedef typename Evaluator::Scalar Scalar; + typedef typename redux_traits::PacketType PacketScalar; + + template + static Scalar run(const Evaluator& eval, const Func& func, const XprType& xpr) { + const Index size = xpr.size(); + + constexpr Index packetSize = redux_traits::PacketSize; + constexpr int packetAlignment = unpacket_traits::alignment; + constexpr int alignment0 = + (bool(Evaluator::Flags & DirectAccessBit) && bool(packet_traits::AlignedOnScalar)) + ? int(packetAlignment) + : int(Unaligned); + constexpr int alignment = plain_enum_max(alignment0, Evaluator::Alignment); + const Index alignedStart = internal::first_default_aligned(xpr); + const Index alignedSize2 = ((size - alignedStart) / (2 * packetSize)) * (2 * packetSize); + const Index alignedSize = ((size - alignedStart) / (packetSize)) * (packetSize); + const Index alignedEnd2 = alignedStart + alignedSize2; + const Index alignedEnd = alignedStart + alignedSize; + Scalar res; + if (alignedSize) { + PacketScalar packet_res0 = eval.template packet(alignedStart); + if (alignedSize > packetSize) // we have at least two packets to partly unroll the loop + { + PacketScalar packet_res1 = eval.template packet(alignedStart + packetSize); + for (Index index = alignedStart + 2 * packetSize; index < alignedEnd2; index += 2 * packetSize) { + packet_res0 = func.packetOp(packet_res0, eval.template packet(index)); + packet_res1 = func.packetOp(packet_res1, eval.template packet(index + packetSize)); + } + + packet_res0 = func.packetOp(packet_res0, packet_res1); + if (alignedEnd > alignedEnd2) + packet_res0 = func.packetOp(packet_res0, eval.template packet(alignedEnd2)); + } + res = func.predux(packet_res0); + + for (Index index = 0; index < alignedStart; ++index) res = func(res, eval.coeff(index)); + + for (Index index = alignedEnd; index < size; ++index) res = func(res, eval.coeff(index)); + } else // too small to vectorize anything. + // since this is dynamic-size hence inefficient anyway for such small sizes, don't try to optimize. + { + res = eval.coeff(0); + for (Index index = 1; index < size; ++index) res = func(res, eval.coeff(index)); + } + + return res; + } +}; + +// NOTE: for SliceVectorizedTraversal we simply bypass unrolling +template +struct redux_impl { + typedef typename Evaluator::Scalar Scalar; + typedef typename redux_traits::PacketType PacketType; + + template + EIGEN_DEVICE_FUNC static Scalar run(const Evaluator& eval, const Func& func, const XprType& xpr) { + eigen_assert(xpr.rows() > 0 && xpr.cols() > 0 && "you are using an empty matrix"); + constexpr Index packetSize = redux_traits::PacketSize; + const Index innerSize = xpr.innerSize(); + const Index outerSize = xpr.outerSize(); + const Index packetedInnerSize = ((innerSize) / packetSize) * packetSize; + Scalar res; + if (packetedInnerSize) { + PacketType packet_res = eval.template packet(0, 0); + for (Index j = 0; j < outerSize; ++j) + for (Index i = (j == 0 ? packetSize : 0); i < packetedInnerSize; i += Index(packetSize)) + packet_res = func.packetOp(packet_res, eval.template packetByOuterInner(j, i)); + + res = func.predux(packet_res); + for (Index j = 0; j < outerSize; ++j) + for (Index i = packetedInnerSize; i < innerSize; ++i) res = func(res, eval.coeffByOuterInner(j, i)); + } else // too small to vectorize anything. + // since this is dynamic-size hence inefficient anyway for such small sizes, don't try to optimize. + { + res = redux_impl::run(eval, func, xpr); + } + + return res; + } +}; + +template +struct redux_impl { + typedef typename Evaluator::Scalar Scalar; + + typedef typename redux_traits::PacketType PacketType; + static constexpr Index PacketSize = redux_traits::PacketSize; + static constexpr Index Size = Evaluator::SizeAtCompileTime; + static constexpr Index VectorizedSize = (int(Size) / int(PacketSize)) * int(PacketSize); + + template + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Evaluator& eval, const Func& func, const XprType& xpr) { + EIGEN_ONLY_USED_FOR_DEBUG(xpr) + eigen_assert(xpr.rows() > 0 && xpr.cols() > 0 && "you are using an empty matrix"); + if (VectorizedSize > 0) { + Scalar res = func.predux( + redux_vec_linear_unroller::template run(eval, func)); + if (VectorizedSize != Size) + res = func( + res, redux_novec_linear_unroller::run(eval, func)); + return res; + } else { + return redux_novec_linear_unroller::run(eval, func); + } + } +}; + +// evaluator adaptor +template +class redux_evaluator : public internal::evaluator { + typedef internal::evaluator Base; + + public: + typedef XprType_ XprType; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit redux_evaluator(const XprType& xpr) : Base(xpr) {} + + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + typedef typename XprType::PacketScalar PacketScalar; + + enum { + MaxRowsAtCompileTime = XprType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = XprType::MaxColsAtCompileTime, + // TODO we should not remove DirectAccessBit and rather find an elegant way to query the alignment offset at runtime + // from the evaluator + Flags = Base::Flags & ~DirectAccessBit, + IsRowMajor = XprType::IsRowMajor, + SizeAtCompileTime = XprType::SizeAtCompileTime, + InnerSizeAtCompileTime = XprType::InnerSizeAtCompileTime + }; + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner(Index outer, Index inner) const { + return Base::coeff(IsRowMajor ? outer : inner, IsRowMajor ? inner : outer); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packetByOuterInner(Index outer, Index inner) const { + return Base::template packet(IsRowMajor ? outer : inner, IsRowMajor ? inner : outer); + } +}; + +} // end namespace internal + +/*************************************************************************** + * Part 4 : public API + ***************************************************************************/ + +/** \returns the result of a full redux operation on the whole matrix or vector using \a func + * + * The template parameter \a BinaryOp is the type of the functor \a func which must be + * an associative operator. Both current C++98 and C++11 functor styles are handled. + * + * \warning the matrix must be not empty, otherwise an assertion is triggered. + * + * \sa DenseBase::sum(), DenseBase::minCoeff(), DenseBase::maxCoeff(), MatrixBase::colwise(), MatrixBase::rowwise() + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits::Scalar DenseBase::redux( + const Func& func) const { + eigen_assert(this->rows() > 0 && this->cols() > 0 && "you are using an empty matrix"); + + typedef typename internal::redux_evaluator ThisEvaluator; + ThisEvaluator thisEval(derived()); + + // The initial expression is passed to the reducer as an additional argument instead of + // passing it as a member of redux_evaluator to help + return internal::redux_impl::run(thisEval, func, derived()); +} + +/** \returns the minimum of all coefficients of \c *this. + * In case \c *this contains NaN, NaNPropagation determines the behavior: + * NaNPropagation == PropagateFast : undefined + * NaNPropagation == PropagateNaN : result is NaN + * NaNPropagation == PropagateNumbers : result is minimum of elements that are not NaN + * \warning the matrix must be not empty, otherwise an assertion is triggered. + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits::Scalar DenseBase::minCoeff() const { + return derived().redux(Eigen::internal::scalar_min_op()); +} + +/** \returns the maximum of all coefficients of \c *this. + * In case \c *this contains NaN, NaNPropagation determines the behavior: + * NaNPropagation == PropagateFast : undefined + * NaNPropagation == PropagateNaN : result is NaN + * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN + * \warning the matrix must be not empty, otherwise an assertion is triggered. + */ +template +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits::Scalar DenseBase::maxCoeff() const { + return derived().redux(Eigen::internal::scalar_max_op()); +} + +/** \returns the sum of all coefficients of \c *this + * + * If \c *this is empty, then the value 0 is returned. + * + * \sa trace(), prod(), mean() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits::Scalar DenseBase::sum() const { + if (SizeAtCompileTime == 0 || (SizeAtCompileTime == Dynamic && size() == 0)) return Scalar(0); + return derived().redux(Eigen::internal::scalar_sum_op()); +} + +/** \returns the mean of all coefficients of *this + * + * \sa trace(), prod(), sum() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits::Scalar DenseBase::mean() const { +#ifdef __INTEL_COMPILER +#pragma warning push +#pragma warning(disable : 2259) +#endif + return Scalar(derived().redux(Eigen::internal::scalar_sum_op())) / Scalar(this->size()); +#ifdef __INTEL_COMPILER +#pragma warning pop +#endif +} + +/** \returns the product of all coefficients of *this + * + * Example: \include MatrixBase_prod.cpp + * Output: \verbinclude MatrixBase_prod.out + * + * \sa sum(), mean(), trace() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits::Scalar DenseBase::prod() const { + if (SizeAtCompileTime == 0 || (SizeAtCompileTime == Dynamic && size() == 0)) return Scalar(1); + return derived().redux(Eigen::internal::scalar_product_op()); +} + +/** \returns the trace of \c *this, i.e. the sum of the coefficients on the main diagonal. + * + * \c *this can be any matrix, not necessarily square. + * + * \sa diagonal(), sum() + */ +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits::Scalar MatrixBase::trace() const { + return derived().diagonal().sum(); +} + +} // end namespace Eigen + +#endif // EIGEN_REDUX_H diff --git a/dae-cpp/Eigen/src/Core/Ref.h b/dae-cpp/Eigen/src/Core/Ref.h new file mode 100644 index 0000000..129bc85 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Ref.h @@ -0,0 +1,383 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2012 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_REF_H +#define EIGEN_REF_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +struct traits > + : public traits > { + typedef PlainObjectType_ PlainObjectType; + typedef StrideType_ StrideType; + enum { + Options = Options_, + Flags = traits >::Flags | NestByRefBit, + Alignment = traits >::Alignment, + InnerStrideAtCompileTime = traits >::InnerStrideAtCompileTime, + OuterStrideAtCompileTime = traits >::OuterStrideAtCompileTime + }; + + template + struct match { + enum { + IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime || Derived::IsVectorAtCompileTime, + HasDirectAccess = internal::has_direct_access::ret, + StorageOrderMatch = + IsVectorAtCompileTime || ((PlainObjectType::Flags & RowMajorBit) == (Derived::Flags & RowMajorBit)), + InnerStrideMatch = int(InnerStrideAtCompileTime) == int(Dynamic) || + int(InnerStrideAtCompileTime) == int(Derived::InnerStrideAtCompileTime) || + (int(InnerStrideAtCompileTime) == 0 && int(Derived::InnerStrideAtCompileTime) == 1), + OuterStrideMatch = IsVectorAtCompileTime || int(OuterStrideAtCompileTime) == int(Dynamic) || + int(OuterStrideAtCompileTime) == int(Derived::OuterStrideAtCompileTime), + // NOTE, this indirection of evaluator::Alignment is needed + // to workaround a very strange bug in MSVC related to the instantiation + // of has_*ary_operator in evaluator. + // This line is surprisingly very sensitive. For instance, simply adding parenthesis + // as "DerivedAlignment = (int(evaluator::Alignment))," will make MSVC fail... + DerivedAlignment = int(evaluator::Alignment), + AlignmentMatch = (int(traits::Alignment) == int(Unaligned)) || + (DerivedAlignment >= int(Alignment)), // FIXME the first condition is not very clear, it should + // be replaced by the required alignment + ScalarTypeMatch = internal::is_same::value, + MatchAtCompileTime = HasDirectAccess && StorageOrderMatch && InnerStrideMatch && OuterStrideMatch && + AlignmentMatch && ScalarTypeMatch + }; + typedef std::conditional_t type; + }; +}; + +template +struct traits > : public traits {}; + +} // namespace internal + +template +class RefBase : public MapBase { + typedef typename internal::traits::PlainObjectType PlainObjectType; + typedef typename internal::traits::StrideType StrideType; + + public: + typedef MapBase Base; + EIGEN_DENSE_PUBLIC_INTERFACE(RefBase) + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const { + return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1; + } + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const { + return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer() + : IsVectorAtCompileTime ? this->size() + : int(Flags) & RowMajorBit ? this->cols() + : this->rows(); + } + + EIGEN_DEVICE_FUNC RefBase() + : Base(0, RowsAtCompileTime == Dynamic ? 0 : RowsAtCompileTime, + ColsAtCompileTime == Dynamic ? 0 : ColsAtCompileTime), + // Stride<> does not allow default ctor for Dynamic strides, so let' initialize it with dummy values: + m_stride(StrideType::OuterStrideAtCompileTime == Dynamic ? 0 : StrideType::OuterStrideAtCompileTime, + StrideType::InnerStrideAtCompileTime == Dynamic ? 0 : StrideType::InnerStrideAtCompileTime) {} + + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase) + + protected: + typedef Stride StrideBase; + + // Resolves inner stride if default 0. + static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index resolveInnerStride(Index inner) { return inner == 0 ? 1 : inner; } + + // Resolves outer stride if default 0. + static EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index resolveOuterStride(Index inner, Index outer, Index rows, Index cols, + bool isVectorAtCompileTime, bool isRowMajor) { + return outer == 0 ? isVectorAtCompileTime ? inner * rows * cols : isRowMajor ? inner * cols : inner * rows : outer; + } + + // Returns true if construction is valid, false if there is a stride mismatch, + // and fails if there is a size mismatch. + template + EIGEN_DEVICE_FUNC bool construct(Expression& expr) { + // Check matrix sizes. If this is a compile-time vector, we do allow + // implicitly transposing. + EIGEN_STATIC_ASSERT(EIGEN_PREDICATE_SAME_MATRIX_SIZE(PlainObjectType, Expression) + // If it is a vector, the transpose sizes might match. + || (PlainObjectType::IsVectorAtCompileTime && + ((int(PlainObjectType::RowsAtCompileTime) == Eigen::Dynamic || + int(Expression::ColsAtCompileTime) == Eigen::Dynamic || + int(PlainObjectType::RowsAtCompileTime) == int(Expression::ColsAtCompileTime)) && + (int(PlainObjectType::ColsAtCompileTime) == Eigen::Dynamic || + int(Expression::RowsAtCompileTime) == Eigen::Dynamic || + int(PlainObjectType::ColsAtCompileTime) == int(Expression::RowsAtCompileTime)))), + YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES) + + // Determine runtime rows and columns. + Index rows = expr.rows(); + Index cols = expr.cols(); + if (PlainObjectType::RowsAtCompileTime == 1) { + eigen_assert(expr.rows() == 1 || expr.cols() == 1); + rows = 1; + cols = expr.size(); + } else if (PlainObjectType::ColsAtCompileTime == 1) { + eigen_assert(expr.rows() == 1 || expr.cols() == 1); + rows = expr.size(); + cols = 1; + } + // Verify that the sizes are valid. + eigen_assert((PlainObjectType::RowsAtCompileTime == Dynamic) || (PlainObjectType::RowsAtCompileTime == rows)); + eigen_assert((PlainObjectType::ColsAtCompileTime == Dynamic) || (PlainObjectType::ColsAtCompileTime == cols)); + + // If this is a vector, we might be transposing, which means that stride should swap. + const bool transpose = PlainObjectType::IsVectorAtCompileTime && (rows != expr.rows()); + // If the storage format differs, we also need to swap the stride. + const bool row_major = ((PlainObjectType::Flags)&RowMajorBit) != 0; + const bool expr_row_major = (Expression::Flags & RowMajorBit) != 0; + const bool storage_differs = (row_major != expr_row_major); + + const bool swap_stride = (transpose != storage_differs); + + // Determine expr's actual strides, resolving any defaults if zero. + const Index expr_inner_actual = resolveInnerStride(expr.innerStride()); + const Index expr_outer_actual = resolveOuterStride(expr_inner_actual, expr.outerStride(), expr.rows(), expr.cols(), + Expression::IsVectorAtCompileTime != 0, expr_row_major); + + // If this is a column-major row vector or row-major column vector, the inner-stride + // is arbitrary, so set it to either the compile-time inner stride or 1. + const bool row_vector = (rows == 1); + const bool col_vector = (cols == 1); + const Index inner_stride = + ((!row_major && row_vector) || (row_major && col_vector)) + ? (StrideType::InnerStrideAtCompileTime > 0 ? Index(StrideType::InnerStrideAtCompileTime) : 1) + : swap_stride ? expr_outer_actual + : expr_inner_actual; + + // If this is a column-major column vector or row-major row vector, the outer-stride + // is arbitrary, so set it to either the compile-time outer stride or vector size. + const Index outer_stride = + ((!row_major && col_vector) || (row_major && row_vector)) + ? (StrideType::OuterStrideAtCompileTime > 0 ? Index(StrideType::OuterStrideAtCompileTime) + : rows * cols * inner_stride) + : swap_stride ? expr_inner_actual + : expr_outer_actual; + + // Check if given inner/outer strides are compatible with compile-time strides. + const bool inner_valid = (StrideType::InnerStrideAtCompileTime == Dynamic) || + (resolveInnerStride(Index(StrideType::InnerStrideAtCompileTime)) == inner_stride); + if (!inner_valid) { + return false; + } + + const bool outer_valid = + (StrideType::OuterStrideAtCompileTime == Dynamic) || + (resolveOuterStride(inner_stride, Index(StrideType::OuterStrideAtCompileTime), rows, cols, + PlainObjectType::IsVectorAtCompileTime != 0, row_major) == outer_stride); + if (!outer_valid) { + return false; + } + + internal::construct_at(this, expr.data(), rows, cols); + internal::construct_at(&m_stride, (StrideType::OuterStrideAtCompileTime == 0) ? 0 : outer_stride, + (StrideType::InnerStrideAtCompileTime == 0) ? 0 : inner_stride); + return true; + } + + StrideBase m_stride; +}; + +/** \class Ref + * \ingroup Core_Module + * + * \brief A matrix or vector expression mapping an existing expression + * + * \tparam PlainObjectType the equivalent matrix type of the mapped data + * \tparam Options specifies the pointer alignment in bytes. It can be: \c #Aligned128, , \c #Aligned64, \c #Aligned32, + * \c #Aligned16, \c #Aligned8 or \c #Unaligned. The default is \c #Unaligned. \tparam StrideType optionally specifies + * strides. By default, Ref implies a contiguous storage along the inner dimension (inner stride==1), but accepts a + * variable outer stride (leading dimension). This can be overridden by specifying strides. The type passed here must be + * a specialization of the Stride template, see examples below. + * + * This class provides a way to write non-template functions taking Eigen objects as parameters while limiting the + * number of copies. A Ref<> object can represent either a const expression or a l-value: \code + * // in-out argument: + * void foo1(Ref x); + * + * // read-only const argument: + * void foo2(const Ref& x); + * \endcode + * + * In the in-out case, the input argument must satisfy the constraints of the actual Ref<> type, otherwise a compilation + * issue will be triggered. By default, a Ref can reference any dense vector expression of float having a + * contiguous memory layout. Likewise, a Ref can reference any column-major dense matrix expression of float + * whose column's elements are contiguously stored with the possibility to have a constant space in-between each column, + * i.e. the inner stride must be equal to 1, but the outer stride (or leading dimension) can be greater than the number + * of rows. + * + * In the const case, if the input expression does not match the above requirement, then it is evaluated into a + * temporary before being passed to the function. Here are some examples: \code MatrixXf A; VectorXf a; foo1(a.head()); + * // OK foo1(A.col()); // OK foo1(A.row()); // Compilation error because here innerstride!=1 + * foo2(A.row()); // Compilation error because A.row() is a 1xN object while foo2 is expecting a Nx1 object + * foo2(A.row().transpose()); // The row is copied into a contiguous temporary + * foo2(2*a); // The expression is evaluated into a temporary + * foo2(A.col().segment(2,4)); // No temporary + * \endcode + * + * The range of inputs that can be referenced without temporary can be enlarged using the last two template parameters. + * Here is an example accepting an innerstride!=1: + * \code + * // in-out argument: + * void foo3(Ref > x); + * foo3(A.row()); // OK + * \endcode + * The downside here is that the function foo3 might be significantly slower than foo1 because it won't be able to + * exploit vectorization, and will involve more expensive address computations even if the input is contiguously stored + * in memory. To overcome this issue, one might propose to overload internally calling a template function, e.g.: \code + * // in the .h: + * void foo(const Ref& A); + * void foo(const Ref >& A); + * + * // in the .cpp: + * template void foo_impl(const TypeOfA& A) { + * ... // crazy code goes here + * } + * void foo(const Ref& A) { foo_impl(A); } + * void foo(const Ref >& A) { foo_impl(A); } + * \endcode + * + * See also the following stackoverflow questions for further references: + * - Correct usage of the + * Eigen::Ref<> class + * + * \sa PlainObjectBase::Map(), \ref TopicStorageOrders + */ +template +class Ref : public RefBase > { + private: + typedef internal::traits Traits; + template + EIGEN_DEVICE_FUNC inline Ref( + const PlainObjectBase& expr, + std::enable_if_t::MatchAtCompileTime), Derived>* = 0); + + public: + typedef RefBase Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Ref) + +#ifndef EIGEN_PARSED_BY_DOXYGEN + template + EIGEN_DEVICE_FUNC inline Ref( + PlainObjectBase& expr, + std::enable_if_t::MatchAtCompileTime), Derived>* = 0) { + EIGEN_STATIC_ASSERT(bool(Traits::template match::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); + // Construction must pass since we will not create temporary storage in the non-const case. + const bool success = Base::construct(expr.derived()); + EIGEN_UNUSED_VARIABLE(success) + eigen_assert(success); + } + template + EIGEN_DEVICE_FUNC inline Ref( + const DenseBase& expr, + std::enable_if_t::MatchAtCompileTime), Derived>* = 0) +#else + /** Implicit constructor from any dense expression */ + template + inline Ref(DenseBase& expr) +#endif + { + EIGEN_STATIC_ASSERT(bool(internal::is_lvalue::value), THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); + EIGEN_STATIC_ASSERT(bool(Traits::template match::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH); + EIGEN_STATIC_ASSERT(!Derived::IsPlainObjectBase, THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY); + // Construction must pass since we will not create temporary storage in the non-const case. + const bool success = Base::construct(expr.const_cast_derived()); + EIGEN_UNUSED_VARIABLE(success) + eigen_assert(success); + } + + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref) +}; + +// this is the const ref version +template +class Ref + : public RefBase > { + typedef internal::traits Traits; + + static constexpr bool may_map_m_object_successfully = + (static_cast(StrideType::InnerStrideAtCompileTime) == 0 || + static_cast(StrideType::InnerStrideAtCompileTime) == 1 || + static_cast(StrideType::InnerStrideAtCompileTime) == Dynamic) && + (TPlainObjectType::IsVectorAtCompileTime || static_cast(StrideType::OuterStrideAtCompileTime) == 0 || + static_cast(StrideType::OuterStrideAtCompileTime) == Dynamic || + static_cast(StrideType::OuterStrideAtCompileTime) == + static_cast(TPlainObjectType::InnerSizeAtCompileTime) || + static_cast(TPlainObjectType::InnerSizeAtCompileTime) == Dynamic); + + public: + typedef RefBase Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Ref) + + template + EIGEN_DEVICE_FUNC inline Ref(const DenseBase& expr, + std::enable_if_t::ScalarTypeMatch), Derived>* = 0) { + // std::cout << match_helper::HasDirectAccess << "," << match_helper::OuterStrideMatch << "," + // << match_helper::InnerStrideMatch << "\n"; std::cout << int(StrideType::OuterStrideAtCompileTime) + // << " - " << int(Derived::OuterStrideAtCompileTime) << "\n"; std::cout << + // int(StrideType::InnerStrideAtCompileTime) << " - " << int(Derived::InnerStrideAtCompileTime) << "\n"; + EIGEN_STATIC_ASSERT(Traits::template match::type::value || may_map_m_object_successfully, + STORAGE_LAYOUT_DOES_NOT_MATCH); + construct(expr.derived(), typename Traits::template match::type()); + } + + EIGEN_DEVICE_FUNC inline Ref(const Ref& other) : Base(other) { + // copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy + } + + EIGEN_DEVICE_FUNC inline Ref(Ref&& other) { + if (other.data() == other.m_object.data()) { + m_object = std::move(other.m_object); + Base::construct(m_object); + } else + Base::construct(other); + } + + template + EIGEN_DEVICE_FUNC inline Ref(const RefBase& other) { + EIGEN_STATIC_ASSERT(Traits::template match::type::value || may_map_m_object_successfully, + STORAGE_LAYOUT_DOES_NOT_MATCH); + construct(other.derived(), typename Traits::template match::type()); + } + + protected: + template + EIGEN_DEVICE_FUNC void construct(const Expression& expr, internal::true_type) { + // Check if we can use the underlying expr's storage directly, otherwise call the copy version. + if (!Base::construct(expr)) { + construct(expr, internal::false_type()); + } + } + + template + EIGEN_DEVICE_FUNC void construct(const Expression& expr, internal::false_type) { + internal::call_assignment_no_alias(m_object, expr, internal::assign_op()); + const bool success = Base::construct(m_object); + EIGEN_ONLY_USED_FOR_DEBUG(success) + eigen_assert(success); + } + + protected: + TPlainObjectType m_object; +}; + +} // end namespace Eigen + +#endif // EIGEN_REF_H diff --git a/dae-cpp/Eigen/src/Core/Replicate.h b/dae-cpp/Eigen/src/Core/Replicate.h new file mode 100644 index 0000000..c01c627 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Replicate.h @@ -0,0 +1,133 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_REPLICATE_H +#define EIGEN_REPLICATE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { +template +struct traits > : traits { + typedef typename MatrixType::Scalar Scalar; + typedef typename traits::StorageKind StorageKind; + typedef typename traits::XprKind XprKind; + typedef typename ref_selector::type MatrixTypeNested; + typedef std::remove_reference_t MatrixTypeNested_; + enum { + RowsAtCompileTime = RowFactor == Dynamic || int(MatrixType::RowsAtCompileTime) == Dynamic + ? Dynamic + : RowFactor * MatrixType::RowsAtCompileTime, + ColsAtCompileTime = ColFactor == Dynamic || int(MatrixType::ColsAtCompileTime) == Dynamic + ? Dynamic + : ColFactor * MatrixType::ColsAtCompileTime, + // FIXME we don't propagate the max sizes !!! + MaxRowsAtCompileTime = RowsAtCompileTime, + MaxColsAtCompileTime = ColsAtCompileTime, + IsRowMajor = MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1 ? 1 + : MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1 ? 0 + : (MatrixType::Flags & RowMajorBit) ? 1 + : 0, + + // FIXME enable DirectAccess with negative strides? + Flags = IsRowMajor ? RowMajorBit : 0 + }; +}; +} // namespace internal + +/** + * \class Replicate + * \ingroup Core_Module + * + * \brief Expression of the multiple replication of a matrix or vector + * + * \tparam MatrixType the type of the object we are replicating + * \tparam RowFactor number of repetitions at compile time along the vertical direction, can be Dynamic. + * \tparam ColFactor number of repetitions at compile time along the horizontal direction, can be Dynamic. + * + * This class represents an expression of the multiple replication of a matrix or vector. + * It is the return type of DenseBase::replicate() and most of the time + * this is the only way it is used. + * + * \sa DenseBase::replicate() + */ +template +class Replicate : public internal::dense_xpr_base >::type { + typedef typename internal::traits::MatrixTypeNested MatrixTypeNested; + typedef typename internal::traits::MatrixTypeNested_ MatrixTypeNested_; + + public: + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Replicate) + typedef internal::remove_all_t NestedExpression; + + template + EIGEN_DEVICE_FUNC inline explicit Replicate(const OriginalMatrixType& matrix) + : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor) { + EIGEN_STATIC_ASSERT((internal::is_same, OriginalMatrixType>::value), + THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) + eigen_assert(RowFactor != Dynamic && ColFactor != Dynamic); + } + + template + EIGEN_DEVICE_FUNC inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor) + : m_matrix(matrix), + m_rowFactor(rowFactor), + m_colFactor(colFactor){ + EIGEN_STATIC_ASSERT((internal::is_same, OriginalMatrixType>::value), + THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE)} + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const { + return m_matrix.rows() * m_rowFactor.value(); + } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); } + + EIGEN_DEVICE_FUNC const MatrixTypeNested_& nestedExpression() const { return m_matrix; } + + protected: + MatrixTypeNested m_matrix; + const internal::variable_if_dynamic m_rowFactor; + const internal::variable_if_dynamic m_colFactor; +}; + +/** + * \return an expression of the replication of \c *this + * + * Example: \include MatrixBase_replicate.cpp + * Output: \verbinclude MatrixBase_replicate.out + * + * \sa VectorwiseOp::replicate(), DenseBase::replicate(Index,Index), class Replicate + */ +template +template +EIGEN_DEVICE_FUNC const Replicate DenseBase::replicate() const { + return Replicate(derived()); +} + +/** + * \return an expression of the replication of each column (or row) of \c *this + * + * Example: \include DirectionWise_replicate_int.cpp + * Output: \verbinclude DirectionWise_replicate_int.out + * + * \sa VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate + */ +template +EIGEN_DEVICE_FUNC const typename VectorwiseOp::ReplicateReturnType +VectorwiseOp::replicate(Index factor) const { + return typename VectorwiseOp::ReplicateReturnType( + _expression(), Direction == Vertical ? factor : 1, Direction == Horizontal ? factor : 1); +} + +} // end namespace Eigen + +#endif // EIGEN_REPLICATE_H diff --git a/dae-cpp/Eigen/src/Core/Reshaped.h b/dae-cpp/Eigen/src/Core/Reshaped.h new file mode 100644 index 0000000..b881dd6 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Reshaped.h @@ -0,0 +1,398 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2017 Gael Guennebaud +// Copyright (C) 2014 yoco +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_RESHAPED_H +#define EIGEN_RESHAPED_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class Reshaped + * \ingroup Core_Module + * + * \brief Expression of a fixed-size or dynamic-size reshape + * + * \tparam XprType the type of the expression in which we are taking a reshape + * \tparam Rows the number of rows of the reshape we are taking at compile time (optional) + * \tparam Cols the number of columns of the reshape we are taking at compile time (optional) + * \tparam Order can be ColMajor or RowMajor, default is ColMajor. + * + * This class represents an expression of either a fixed-size or dynamic-size reshape. + * It is the return type of DenseBase::reshaped(NRowsType,NColsType) and + * most of the time this is the only way it is used. + * + * If you want to directly manipulate reshaped expressions, + * for instance if you want to write a function returning such an expression, + * it is advised to use the \em auto keyword for such use cases. + * + * Here is an example illustrating the dynamic case: + * \include class_Reshaped.cpp + * Output: \verbinclude class_Reshaped.out + * + * Here is an example illustrating the fixed-size case: + * \include class_FixedReshaped.cpp + * Output: \verbinclude class_FixedReshaped.out + * + * \sa DenseBase::reshaped(NRowsType,NColsType) + */ + +namespace internal { + +template +struct traits > : traits { + typedef typename traits::Scalar Scalar; + typedef typename traits::StorageKind StorageKind; + typedef typename traits::XprKind XprKind; + enum { + MatrixRows = traits::RowsAtCompileTime, + MatrixCols = traits::ColsAtCompileTime, + RowsAtCompileTime = Rows, + ColsAtCompileTime = Cols, + MaxRowsAtCompileTime = Rows, + MaxColsAtCompileTime = Cols, + XpxStorageOrder = ((int(traits::Flags) & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor, + ReshapedStorageOrder = (RowsAtCompileTime == 1 && ColsAtCompileTime != 1) ? RowMajor + : (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ? ColMajor + : XpxStorageOrder, + HasSameStorageOrderAsXprType = (ReshapedStorageOrder == XpxStorageOrder), + InnerSize = (ReshapedStorageOrder == int(RowMajor)) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), + InnerStrideAtCompileTime = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time::ret) : Dynamic, + OuterStrideAtCompileTime = Dynamic, + + HasDirectAccess = internal::has_direct_access::ret && (Order == int(XpxStorageOrder)) && + ((evaluator::Flags & LinearAccessBit) == LinearAccessBit), + + MaskPacketAccessBit = + (InnerSize == Dynamic || (InnerSize % packet_traits::size) == 0) && (InnerStrideAtCompileTime == 1) + ? PacketAccessBit + : 0, + // MaskAlignedBit = ((OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) + // == 0)) ? AlignedBit : 0, + FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0, + FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, + FlagsRowMajorBit = (ReshapedStorageOrder == int(RowMajor)) ? RowMajorBit : 0, + FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0, + Flags0 = traits::Flags & ((HereditaryBits & ~RowMajorBit) | MaskPacketAccessBit), + + Flags = (Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit | FlagsDirectAccessBit) + }; +}; + +template +class ReshapedImpl_dense; + +} // end namespace internal + +template +class ReshapedImpl; + +template +class Reshaped : public ReshapedImpl::StorageKind> { + typedef ReshapedImpl::StorageKind> Impl; + + public: + // typedef typename Impl::Base Base; + typedef Impl Base; + EIGEN_GENERIC_PUBLIC_INTERFACE(Reshaped) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reshaped) + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC inline Reshaped(XprType& xpr) : Impl(xpr) { + EIGEN_STATIC_ASSERT(RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic, + THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE) + eigen_assert(Rows * Cols == xpr.rows() * xpr.cols()); + } + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC inline Reshaped(XprType& xpr, Index reshapeRows, Index reshapeCols) + : Impl(xpr, reshapeRows, reshapeCols) { + eigen_assert((RowsAtCompileTime == Dynamic || RowsAtCompileTime == reshapeRows) && + (ColsAtCompileTime == Dynamic || ColsAtCompileTime == reshapeCols)); + eigen_assert(reshapeRows * reshapeCols == xpr.rows() * xpr.cols()); + } +}; + +// The generic default implementation for dense reshape simply forward to the internal::ReshapedImpl_dense +// that must be specialized for direct and non-direct access... +template +class ReshapedImpl + : public internal::ReshapedImpl_dense >::HasDirectAccess> { + typedef internal::ReshapedImpl_dense >::HasDirectAccess> + Impl; + + public: + typedef Impl Base; + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl) + EIGEN_DEVICE_FUNC inline ReshapedImpl(XprType& xpr) : Impl(xpr) {} + EIGEN_DEVICE_FUNC inline ReshapedImpl(XprType& xpr, Index reshapeRows, Index reshapeCols) + : Impl(xpr, reshapeRows, reshapeCols) {} +}; + +namespace internal { + +/** \internal Internal implementation of dense Reshaped in the general case. */ +template +class ReshapedImpl_dense + : public internal::dense_xpr_base >::type { + typedef Reshaped ReshapedType; + + public: + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense) + + typedef typename internal::ref_selector::non_const_type MatrixTypeNested; + typedef internal::remove_all_t NestedExpression; + + class InnerIterator; + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC inline ReshapedImpl_dense(XprType& xpr) : m_xpr(xpr), m_rows(Rows), m_cols(Cols) {} + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols) + : m_xpr(xpr), m_rows(nRows), m_cols(nCols) {} + + EIGEN_DEVICE_FUNC Index rows() const { return m_rows; } + EIGEN_DEVICE_FUNC Index cols() const { return m_cols; } + +#ifdef EIGEN_PARSED_BY_DOXYGEN + /** \sa MapBase::data() */ + EIGEN_DEVICE_FUNC inline const Scalar* data() const; + EIGEN_DEVICE_FUNC inline Index innerStride() const; + EIGEN_DEVICE_FUNC inline Index outerStride() const; +#endif + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC const internal::remove_all_t& nestedExpression() const { return m_xpr; } + + /** \returns the nested expression */ + EIGEN_DEVICE_FUNC std::remove_reference_t& nestedExpression() { return m_xpr; } + + protected: + MatrixTypeNested m_xpr; + const internal::variable_if_dynamic m_rows; + const internal::variable_if_dynamic m_cols; +}; + +/** \internal Internal implementation of dense Reshaped in the direct access case. */ +template +class ReshapedImpl_dense : public MapBase > { + typedef Reshaped ReshapedType; + typedef typename internal::ref_selector::non_const_type XprTypeNested; + + public: + typedef MapBase Base; + EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense) + + /** Fixed-size constructor + */ + EIGEN_DEVICE_FUNC inline ReshapedImpl_dense(XprType& xpr) : Base(xpr.data()), m_xpr(xpr) {} + + /** Dynamic-size constructor + */ + EIGEN_DEVICE_FUNC inline ReshapedImpl_dense(XprType& xpr, Index nRows, Index nCols) + : Base(xpr.data(), nRows, nCols), m_xpr(xpr) {} + + EIGEN_DEVICE_FUNC const internal::remove_all_t& nestedExpression() const { return m_xpr; } + + EIGEN_DEVICE_FUNC XprType& nestedExpression() { return m_xpr; } + + /** \sa MapBase::innerStride() */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const { return m_xpr.innerStride(); } + + /** \sa MapBase::outerStride() */ + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const { + return (((Flags & RowMajorBit) == RowMajorBit) ? this->cols() : this->rows()) * m_xpr.innerStride(); + } + + protected: + XprTypeNested m_xpr; +}; + +// Evaluators +template +struct reshaped_evaluator; + +template +struct evaluator > + : reshaped_evaluator >::HasDirectAccess> { + typedef Reshaped XprType; + typedef typename XprType::Scalar Scalar; + // TODO: should check for smaller packet types + typedef typename packet_traits::type PacketScalar; + + enum { + CoeffReadCost = evaluator::CoeffReadCost, + HasDirectAccess = traits::HasDirectAccess, + + // RowsAtCompileTime = traits::RowsAtCompileTime, + // ColsAtCompileTime = traits::ColsAtCompileTime, + // MaxRowsAtCompileTime = traits::MaxRowsAtCompileTime, + // MaxColsAtCompileTime = traits::MaxColsAtCompileTime, + // + // InnerStrideAtCompileTime = traits::HasSameStorageOrderAsXprType + // ? int(inner_stride_at_compile_time::ret) + // : Dynamic, + // OuterStrideAtCompileTime = Dynamic, + + FlagsLinearAccessBit = + (traits::RowsAtCompileTime == 1 || traits::ColsAtCompileTime == 1 || HasDirectAccess) + ? LinearAccessBit + : 0, + FlagsRowMajorBit = (traits::ReshapedStorageOrder == int(RowMajor)) ? RowMajorBit : 0, + FlagsDirectAccessBit = HasDirectAccess ? DirectAccessBit : 0, + Flags0 = evaluator::Flags & (HereditaryBits & ~RowMajorBit), + Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit | FlagsDirectAccessBit, + + PacketAlignment = unpacket_traits::alignment, + Alignment = evaluator::Alignment + }; + typedef reshaped_evaluator reshaped_evaluator_type; + EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : reshaped_evaluator_type(xpr) { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } +}; + +template +struct reshaped_evaluator + : evaluator_base > { + typedef Reshaped XprType; + + enum { + CoeffReadCost = evaluator::CoeffReadCost /* TODO + cost of index computations */, + + Flags = (evaluator::Flags & (HereditaryBits /*| LinearAccessBit | DirectAccessBit*/)), + + Alignment = 0 + }; + + EIGEN_DEVICE_FUNC explicit reshaped_evaluator(const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr) { + EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); + } + + typedef typename XprType::Scalar Scalar; + typedef typename XprType::CoeffReturnType CoeffReturnType; + + typedef std::pair RowCol; + + EIGEN_DEVICE_FUNC inline RowCol index_remap(Index rowId, Index colId) const { + if (Order == ColMajor) { + const Index nth_elem_idx = colId * m_xpr.rows() + rowId; + return RowCol(nth_elem_idx % m_xpr.nestedExpression().rows(), nth_elem_idx / m_xpr.nestedExpression().rows()); + } else { + const Index nth_elem_idx = colId + rowId * m_xpr.cols(); + return RowCol(nth_elem_idx / m_xpr.nestedExpression().cols(), nth_elem_idx % m_xpr.nestedExpression().cols()); + } + } + + EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index rowId, Index colId) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.coeffRef(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index rowId, Index colId) const { + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.coeffRef(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CoeffReturnType coeff(Index rowId, Index colId) const { + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.coeff(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index) { + EIGEN_STATIC_ASSERT_LVALUE(XprType) + const RowCol row_col = index_remap(Rows == 1 ? 0 : index, Rows == 1 ? index : 0); + return m_argImpl.coeffRef(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC inline const Scalar& coeffRef(Index index) const { + const RowCol row_col = index_remap(Rows == 1 ? 0 : index, Rows == 1 ? index : 0); + return m_argImpl.coeffRef(row_col.first, row_col.second); + } + + EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const { + const RowCol row_col = index_remap(Rows == 1 ? 0 : index, Rows == 1 ? index : 0); + return m_argImpl.coeff(row_col.first, row_col.second); + } +#if 0 + EIGEN_DEVICE_FUNC + template + inline PacketScalar packet(Index rowId, Index colId) const + { + const RowCol row_col = index_remap(rowId, colId); + return m_argImpl.template packet(row_col.first, row_col.second); + + } + + template + EIGEN_DEVICE_FUNC + inline void writePacket(Index rowId, Index colId, const PacketScalar& val) + { + const RowCol row_col = index_remap(rowId, colId); + m_argImpl.const_cast_derived().template writePacket + (row_col.first, row_col.second, val); + } + + template + EIGEN_DEVICE_FUNC + inline PacketScalar packet(Index index) const + { + const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, + RowsAtCompileTime == 1 ? index : 0); + return m_argImpl.template packet(row_col.first, row_col.second); + } + + template + EIGEN_DEVICE_FUNC + inline void writePacket(Index index, const PacketScalar& val) + { + const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index, + RowsAtCompileTime == 1 ? index : 0); + return m_argImpl.template packet(row_col.first, row_col.second, val); + } +#endif + protected: + evaluator m_argImpl; + const XprType& m_xpr; +}; + +template +struct reshaped_evaluator + : mapbase_evaluator, + typename Reshaped::PlainObject> { + typedef Reshaped XprType; + typedef typename XprType::Scalar Scalar; + + EIGEN_DEVICE_FUNC explicit reshaped_evaluator(const XprType& xpr) + : mapbase_evaluator(xpr) { + // TODO: for the 3.4 release, this should be turned to an internal assertion, but let's keep it as is for the beta + // lifetime + eigen_assert(((std::uintptr_t(xpr.data()) % plain_enum_max(1, evaluator::Alignment)) == 0) && + "data is not aligned"); + } +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_RESHAPED_H diff --git a/dae-cpp/Eigen/src/Core/ReturnByValue.h b/dae-cpp/Eigen/src/Core/ReturnByValue.h new file mode 100644 index 0000000..3b5e470 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/ReturnByValue.h @@ -0,0 +1,115 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009-2010 Gael Guennebaud +// Copyright (C) 2009-2010 Benoit Jacob +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_RETURNBYVALUE_H +#define EIGEN_RETURNBYVALUE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +struct traits > : public traits::ReturnType> { + enum { + // We're disabling the DirectAccess because e.g. the constructor of + // the Block-with-DirectAccess expression requires to have a coeffRef method. + // Also, we don't want to have to implement the stride stuff. + Flags = (traits::ReturnType>::Flags | EvalBeforeNestingBit) & ~DirectAccessBit + }; +}; + +/* The ReturnByValue object doesn't even have a coeff() method. + * So the only way that nesting it in an expression can work, is by evaluating it into a plain matrix. + * So internal::nested always gives the plain return matrix type. + * + * FIXME: I don't understand why we need this specialization: isn't this taken care of by the EvalBeforeNestingBit ?? + * Answer: EvalBeforeNestingBit should be deprecated since we have the evaluators + */ +template +struct nested_eval, n, PlainObject> { + typedef typename traits::ReturnType type; +}; + +} // end namespace internal + +/** \class ReturnByValue + * \ingroup Core_Module + * + */ +template +class ReturnByValue : public internal::dense_xpr_base >::type, internal::no_assignment_operator { + public: + typedef typename internal::traits::ReturnType ReturnType; + + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(ReturnByValue) + + template + EIGEN_DEVICE_FUNC inline void evalTo(Dest& dst) const { + static_cast(this)->evalTo(dst); + } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { + return static_cast(this)->rows(); + } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { + return static_cast(this)->cols(); + } + +#ifndef EIGEN_PARSED_BY_DOXYGEN +#define Unusable \ + YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT + class Unusable { + Unusable(const Unusable&) {} + Unusable& operator=(const Unusable&) { return *this; } + }; + const Unusable& coeff(Index) const { return *reinterpret_cast(this); } + const Unusable& coeff(Index, Index) const { return *reinterpret_cast(this); } + Unusable& coeffRef(Index) { return *reinterpret_cast(this); } + Unusable& coeffRef(Index, Index) { return *reinterpret_cast(this); } +#undef Unusable +#endif +}; + +template +template +EIGEN_DEVICE_FUNC Derived& DenseBase::operator=(const ReturnByValue& other) { + other.evalTo(derived()); + return derived(); +} + +namespace internal { + +// Expression is evaluated in a temporary; default implementation of Assignment is bypassed so that +// when a ReturnByValue expression is assigned, the evaluator is not constructed. +// TODO: Finalize port to new regime; ReturnByValue should not exist in the expression world + +template +struct evaluator > : public evaluator::ReturnType> { + typedef ReturnByValue XprType; + typedef typename internal::traits::ReturnType PlainObject; + typedef evaluator Base; + + EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) { + internal::construct_at(this, m_result); + xpr.evalTo(m_result); + } + + protected: + PlainObject m_result; +}; + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_RETURNBYVALUE_H diff --git a/dae-cpp/Eigen/src/Core/Reverse.h b/dae-cpp/Eigen/src/Core/Reverse.h new file mode 100644 index 0000000..66116aa --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Reverse.h @@ -0,0 +1,196 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2006-2008 Benoit Jacob +// Copyright (C) 2009 Ricard Marxer +// Copyright (C) 2009-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_REVERSE_H +#define EIGEN_REVERSE_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +template +struct traits > : traits { + typedef typename MatrixType::Scalar Scalar; + typedef typename traits::StorageKind StorageKind; + typedef typename traits::XprKind XprKind; + typedef typename ref_selector::type MatrixTypeNested; + typedef std::remove_reference_t MatrixTypeNested_; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + Flags = MatrixTypeNested_::Flags & (RowMajorBit | LvalueBit) + }; +}; + +template +struct reverse_packet_cond { + static inline PacketType run(const PacketType& x) { return preverse(x); } +}; + +template +struct reverse_packet_cond { + static inline PacketType run(const PacketType& x) { return x; } +}; + +} // end namespace internal + +/** \class Reverse + * \ingroup Core_Module + * + * \brief Expression of the reverse of a vector or matrix + * + * \tparam MatrixType the type of the object of which we are taking the reverse + * \tparam Direction defines the direction of the reverse operation, can be Vertical, Horizontal, or BothDirections + * + * This class represents an expression of the reverse of a vector. + * It is the return type of MatrixBase::reverse() and VectorwiseOp::reverse() + * and most of the time this is the only way it is used. + * + * \sa MatrixBase::reverse(), VectorwiseOp::reverse() + */ +template +class Reverse : public internal::dense_xpr_base >::type { + public: + typedef typename internal::dense_xpr_base::type Base; + EIGEN_DENSE_PUBLIC_INTERFACE(Reverse) + typedef internal::remove_all_t NestedExpression; + using Base::IsRowMajor; + + protected: + enum { + PacketSize = internal::packet_traits::size, + IsColMajor = !IsRowMajor, + ReverseRow = (Direction == Vertical) || (Direction == BothDirections), + ReverseCol = (Direction == Horizontal) || (Direction == BothDirections), + OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1, + OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1, + ReversePacket = (Direction == BothDirections) || ((Direction == Vertical) && IsColMajor) || + ((Direction == Horizontal) && IsRowMajor) + }; + typedef internal::reverse_packet_cond reverse_packet; + + public: + EIGEN_DEVICE_FUNC explicit inline Reverse(const MatrixType& matrix) : m_matrix(matrix) {} + + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Reverse) + + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index rows() const EIGEN_NOEXCEPT { return m_matrix.rows(); } + EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index cols() const EIGEN_NOEXCEPT { return m_matrix.cols(); } + + EIGEN_DEVICE_FUNC inline Index innerStride() const { return -m_matrix.innerStride(); } + + EIGEN_DEVICE_FUNC const internal::remove_all_t& nestedExpression() const { + return m_matrix; + } + + protected: + typename MatrixType::Nested m_matrix; +}; + +/** \returns an expression of the reverse of *this. + * + * Example: \include MatrixBase_reverse.cpp + * Output: \verbinclude MatrixBase_reverse.out + * + */ +template +EIGEN_DEVICE_FUNC inline typename DenseBase::ReverseReturnType DenseBase::reverse() { + return ReverseReturnType(derived()); +} + +// reverse const overload moved DenseBase.h due to a CUDA compiler bug + +/** This is the "in place" version of reverse: it reverses \c *this. + * + * In most cases it is probably better to simply use the reversed expression + * of a matrix. However, when reversing the matrix data itself is really needed, + * then this "in-place" version is probably the right choice because it provides + * the following additional benefits: + * - less error prone: doing the same operation with .reverse() requires special care: + * \code m = m.reverse().eval(); \endcode + * - this API enables reverse operations without the need for a temporary + * - it allows future optimizations (cache friendliness, etc.) + * + * \sa VectorwiseOp::reverseInPlace(), reverse() */ +template +EIGEN_DEVICE_FUNC inline void DenseBase::reverseInPlace() { + if (cols() > rows()) { + Index half = cols() / 2; + leftCols(half).swap(rightCols(half).reverse()); + if ((cols() % 2) == 1) { + Index half2 = rows() / 2; + col(half).head(half2).swap(col(half).tail(half2).reverse()); + } + } else { + Index half = rows() / 2; + topRows(half).swap(bottomRows(half).reverse()); + if ((rows() % 2) == 1) { + Index half2 = cols() / 2; + row(half).head(half2).swap(row(half).tail(half2).reverse()); + } + } +} + +namespace internal { + +template +struct vectorwise_reverse_inplace_impl; + +template <> +struct vectorwise_reverse_inplace_impl { + template + static void run(ExpressionType& xpr) { + constexpr Index HalfAtCompileTime = + ExpressionType::RowsAtCompileTime == Dynamic ? Dynamic : ExpressionType::RowsAtCompileTime / 2; + Index half = xpr.rows() / 2; + xpr.template topRows(half).swap( + xpr.template bottomRows(half).colwise().reverse()); + } +}; + +template <> +struct vectorwise_reverse_inplace_impl { + template + static void run(ExpressionType& xpr) { + constexpr Index HalfAtCompileTime = + ExpressionType::ColsAtCompileTime == Dynamic ? Dynamic : ExpressionType::ColsAtCompileTime / 2; + Index half = xpr.cols() / 2; + xpr.template leftCols(half).swap( + xpr.template rightCols(half).rowwise().reverse()); + } +}; + +} // end namespace internal + +/** This is the "in place" version of VectorwiseOp::reverse: it reverses each column or row of \c *this. + * + * In most cases it is probably better to simply use the reversed expression + * of a matrix. However, when reversing the matrix data itself is really needed, + * then this "in-place" version is probably the right choice because it provides + * the following additional benefits: + * - less error prone: doing the same operation with .reverse() requires special care: + * \code m = m.reverse().eval(); \endcode + * - this API enables reverse operations without the need for a temporary + * + * \sa DenseBase::reverseInPlace(), reverse() */ +template +EIGEN_DEVICE_FUNC void VectorwiseOp::reverseInPlace() { + internal::vectorwise_reverse_inplace_impl::run(m_matrix); +} + +} // end namespace Eigen + +#endif // EIGEN_REVERSE_H diff --git a/dae-cpp/Eigen/src/Core/Select.h b/dae-cpp/Eigen/src/Core/Select.h new file mode 100644 index 0000000..9f46120 --- /dev/null +++ b/dae-cpp/Eigen/src/Core/Select.h @@ -0,0 +1,156 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2010 Gael Guennebaud +// +// 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 http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_SELECT_H +#define EIGEN_SELECT_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +/** \class Select + * \ingroup Core_Module + * + * \brief Expression of a coefficient wise version of the C++ ternary operator ?: + * + * \tparam ConditionMatrixType the type of the \em condition expression which must be a boolean matrix + * \tparam ThenMatrixType the type of the \em then expression + * \tparam ElseMatrixType the type of the \em else expression + * + * This class represents an expression of a coefficient wise version of the C++ ternary operator ?:. + * It is the return type of DenseBase::select() and most of the time this is the only way it is used. + * + * \sa DenseBase::select(const DenseBase&, const DenseBase&) const + */ + +namespace internal { +template +struct traits > : traits { + typedef typename traits::Scalar Scalar; + typedef Dense StorageKind; + typedef typename traits::XprKind XprKind; + typedef typename ConditionMatrixType::Nested ConditionMatrixNested; + typedef typename ThenMatrixType::Nested ThenMatrixNested; + typedef typename ElseMatrixType::Nested ElseMatrixNested; + enum { + RowsAtCompileTime = ConditionMatrixType::RowsAtCompileTime, + ColsAtCompileTime = ConditionMatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = ConditionMatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = ConditionMatrixType::MaxColsAtCompileTime, + Flags = (unsigned int)ThenMatrixType::Flags & ElseMatrixType::Flags & RowMajorBit + }; +}; +} // namespace internal + +template +class Select : public internal::dense_xpr_base >::type, + internal::no_assignment_operator { + public: + typedef typename internal::dense_xpr_base