<commit_before>#pragma once

#include <memory>

#include <anyode/anyode.hpp>
#include <anyode/anyode_blas_lapack.hpp>  // dgemv, dgesvd
#include <anyode/anyode_matrix.hpp> // DenseMatrix
#include <anyode/anyode_decomposition.hpp>  // SVD

namespace AnyODE {

    template <typename Real_t=double, typename JacMat_t=DenseMatrix<Real_t>, typename Decomp_t=SVD<Real_t>>
    struct OdeSysIterativeBase : public OdeSysBase<Real_t> {
        int m_njacvec_dot=0, m_nprec_setup=0, m_nprec_solve=0;
        std::unique_ptr<JacMat_t> m_jac_cache {nullptr};
        std::unique_ptr<JacMat_t> m_M_cache {nullptr};
        std::unique_ptr<Decomp_t> m_decomp_cache {nullptr};

        virtual Status jac_times_vec(const Real_t * const __restrict__ vec,
                                     Real_t * const __restrict__ out,
                                     Real_t t,
                                     const Real_t * const __restrict__ y,
                                     const Real_t * const __restrict__ fy
                                     ) override
        {
            // See "Jacobian information (matrix-vector product)"
            //     (4.6.8 in cvs_guide.pdf for sundials 2.7.0)
            auto status = AnyODE::Status::success;
            const int ny = this->get_ny();
            auto jac = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
            status = this->dense_jac_cmaj(t, y, fy, jac->m_data, jac->m_ld);
            jac->dot_vec(vec, out);
            m_njacvec_dot++;
            return status;
        }

        virtual Status prec_setup(Real_t t,
                                  const Real_t * const __restrict__ y,
                                  const Real_t * const __restrict__ fy,
                                  bool jac_ok,
                                  bool& jac_recomputed,
                                  Real_t gamma) override
        {
            const int ny = this->get_ny();
            auto status = AnyODE::Status::success;
            ignore(gamma);
            // See "Preconditioning (Jacobian data)" in cvs_guide.pdf (4.6.10 for 2.7.0)
            if (m_jac_cache == nullptr)
                m_jac_cache = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);

            if (jac_ok){
                jac_recomputed = false;
            } else {
                status = this->dense_jac_cmaj(t, y, fy, m_jac_cache->m_data, m_jac_cache->m_ld);
                jac_recomputed = true;
            }
            if (m_M_cache == nullptr)
                m_M_cache = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
            m_M_cache->set_to_eye_plus_scaled_mtx(-gamma, *m_jac_cache);
            m_decomp_cache = std::make_unique<Decomp_t>(m_M_cache.get());
            m_decomp_cache->factorize();
            m_nprec_setup++;
            return status;
        }

        virtual Status prec_solve_left(const Real_t t,
                                       const Real_t * const __restrict__ y,
                                       const Real_t * const __restrict__ fy,
                                       const Real_t * const __restrict__ r,
                                       Real_t * const __restrict__ z,
                                       Real_t /* gamma */,
                                       Real_t /* delta */,
                                       const Real_t * const __restrict__ ewt
                                       ) override
        {
            // See 4.6.9 on page 75 in cvs_guide.pdf (Sundials 2.6.2)
            // Solves P*z = r, where P ~= I - gamma*J
            const int ny = this->get_ny();
            if (ewt)
                throw std::runtime_error("Not implemented.");
            m_nprec_solve++;

            ignore(t); ignore(fy); ignore(y);
            int info = m_decomp_cache->solve(r, z);
            if (info == 0)
                return AnyODE::Status::success;
            return AnyODE::Status::recoverable_error;
        }


    };
}
<commit_msg>Avoid warning about unused variable<commit_after>#pragma once

#include <memory>

#include <anyode/anyode.hpp>
#include <anyode/anyode_blas_lapack.hpp>  // dgemv, dgesvd
#include <anyode/anyode_matrix.hpp> // DenseMatrix
#include <anyode/anyode_decomposition.hpp>  // SVD

namespace AnyODE {

    template <typename Real_t=double, typename JacMat_t=DenseMatrix<Real_t>, typename Decomp_t=SVD<Real_t>>
    struct OdeSysIterativeBase : public OdeSysBase<Real_t> {
        int m_njacvec_dot=0, m_nprec_setup=0, m_nprec_solve=0;
        std::unique_ptr<JacMat_t> m_jac_cache {nullptr};
        std::unique_ptr<JacMat_t> m_M_cache {nullptr};
        std::unique_ptr<Decomp_t> m_decomp_cache {nullptr};

        virtual Status jac_times_vec(const Real_t * const __restrict__ vec,
                                     Real_t * const __restrict__ out,
                                     Real_t t,
                                     const Real_t * const __restrict__ y,
                                     const Real_t * const __restrict__ fy
                                     ) override
        {
            // See "Jacobian information (matrix-vector product)"
            //     (4.6.8 in cvs_guide.pdf for sundials 2.7.0)
            auto status = AnyODE::Status::success;
            const int ny = this->get_ny();
            auto jac = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
            status = this->dense_jac_cmaj(t, y, fy, jac->m_data, jac->m_ld);
            jac->dot_vec(vec, out);
            m_njacvec_dot++;
            return status;
        }

        virtual Status prec_setup(Real_t t,
                                  const Real_t * const __restrict__ y,
                                  const Real_t * const __restrict__ fy,
                                  bool jac_ok,
                                  bool& jac_recomputed,
                                  Real_t gamma) override
        {
            const int ny = this->get_ny();
            auto status = AnyODE::Status::success;
            ignore(gamma);
            // See "Preconditioning (Jacobian data)" in cvs_guide.pdf (4.6.10 for 2.7.0)
            if (m_jac_cache == nullptr)
                m_jac_cache = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);

            if (jac_ok){
                jac_recomputed = false;
            } else {
                status = this->dense_jac_cmaj(t, y, fy, m_jac_cache->m_data, m_jac_cache->m_ld);
                jac_recomputed = true;
            }
            if (m_M_cache == nullptr)
                m_M_cache = std::make_unique<JacMat_t>(nullptr, ny, ny, ny, true);
            m_M_cache->set_to_eye_plus_scaled_mtx(-gamma, *m_jac_cache);
            m_decomp_cache = std::make_unique<Decomp_t>(m_M_cache.get());
            m_decomp_cache->factorize();
            m_nprec_setup++;
            return status;
        }

        virtual Status prec_solve_left(const Real_t t,
                                       const Real_t * const __restrict__ y,
                                       const Real_t * const __restrict__ fy,
                                       const Real_t * const __restrict__ r,
                                       Real_t * const __restrict__ z,
                                       Real_t /* gamma */,
                                       Real_t /* delta */,
                                       const Real_t * const __restrict__ ewt
                                       ) override
        {
            // See 4.6.9 on page 75 in cvs_guide.pdf (Sundials 2.6.2)
            // Solves P*z = r, where P ~= I - gamma*J
            if (ewt)
                throw std::runtime_error("Not implemented.");
            m_nprec_solve++;

            ignore(t); ignore(fy); ignore(y);
            int info = m_decomp_cache->solve(r, z);
            if (info == 0)
                return AnyODE::Status::success;
            return AnyODE::Status::recoverable_error;
        }


    };
}

{'fraction_non_alphanumeric': 0.09228840125391849, 'fraction_numerical': 0.006269592476489028, 'mean_word_length': 1.398796992481203, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1686569', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2347, 'n_words': 506}