<commit_before>/**
    @file
    @author  <NAME>

    @copyright 2017 <NAME>. Licensed under the Apache License,
    Version 2.0. (see LICENSE or http://www.apache.org/licenses/LICENSE-2.0)

    @brief
*/

#pragma once


namespace qpmad
{
    class FactorizationData
    {
        public:
            QPMatrix    QLi_aka_J;
            QPMatrix    R;
            MatrixIndex primal_size_;


        public:
            template <class t_MatrixType>
                void initialize(const t_MatrixType &H,
                                const MatrixIndex primal_size)
            {
                primal_size_ = primal_size;

                QLi_aka_J.resize(primal_size_, primal_size_);
                QLi_aka_J.triangularView<Eigen::Lower>().setZero();
                TriangularInversion::compute(QLi_aka_J, H);

                R.resize(primal_size_, primal_size_);
            }


            bool update(const MatrixIndex R_col,
                        const double tolerance)
            {
                GivensReflection    givens;
                for (MatrixIndex i = primal_size_-1; i > R_col; --i)
                {
                    givens.computeAndApply(R(i-1, R_col), R(i, R_col), 0.0);
                    givens.applyColumnWise(QLi_aka_J, 0, primal_size_, i-1, i);
                }

                if (std::abs(R(R_col, R_col)) < tolerance)
                {
                    return (false);
                }
                else
                {
                    return (true);
                }
            }


            void downdate(  const MatrixIndex R_col_index,
                            const MatrixIndex R_cols,
                            const double tolerance)
            {
                GivensReflection    givens;
                for (MatrixIndex i = R_col_index + 1; i < R_cols; ++i)
                {
                    Eigen::MatrixXd tmp = R.block(0,
                                0,
                                R_cols,
                                R_cols).triangularView<Eigen::Upper>();

                    givens.computeAndApply(R(i-1, i), R(i, i), 0.0);
                    givens.applyColumnWise(QLi_aka_J, 0, primal_size_, i-1, i);
                    givens.applyRowWise(R, i+1, R_cols, i-1, i);

                    /// @todo no need to copy the part corresponding to equalities
                    /// @todo block copy?
                    R.col(i-1).segment(0, i) = R.col(i).segment(0, i);
                }
            }
<commit_msg>FactorizationData: delete old debug code in downdate().<commit_after>/**
    @file
    @author  <NAME>

    @copyright 2017 <NAME>. Licensed under the Apache License,
    Version 2.0. (see LICENSE or http://www.apache.org/licenses/LICENSE-2.0)

    @brief
*/

#pragma once


namespace qpmad
{
    class FactorizationData
    {
        public:
            QPMatrix    QLi_aka_J;
            QPMatrix    R;
            MatrixIndex primal_size_;


        public:
            template <class t_MatrixType>
                void initialize(const t_MatrixType &H,
                                const MatrixIndex primal_size)
            {
                primal_size_ = primal_size;

                QLi_aka_J.resize(primal_size_, primal_size_);
                QLi_aka_J.triangularView<Eigen::Lower>().setZero();
                TriangularInversion::compute(QLi_aka_J, H);

                R.resize(primal_size_, primal_size_);
            }


            bool update(const MatrixIndex R_col,
                        const double tolerance)
            {
                GivensReflection    givens;
                for (MatrixIndex i = primal_size_-1; i > R_col; --i)
                {
                    givens.computeAndApply(R(i-1, R_col), R(i, R_col), 0.0);
                    givens.applyColumnWise(QLi_aka_J, 0, primal_size_, i-1, i);
                }

                if (std::abs(R(R_col, R_col)) < tolerance)
                {
                    return (false);
                }
                else
                {
                    return (true);
                }
            }


            void downdate(  const MatrixIndex R_col_index,
                            const MatrixIndex R_cols,
                            const double tolerance)
            {
                GivensReflection    givens;
                for (MatrixIndex i = R_col_index + 1; i < R_cols; ++i)
                {
                    givens.computeAndApply(R(i-1, i), R(i, i), 0.0);
                    givens.applyColumnWise(QLi_aka_J, 0, primal_size_, i-1, i);
                    givens.applyRowWise(R, i+1, R_cols, i-1, i);

                    /// @todo no need to copy the part corresponding to equalities
                    /// @todo block copy?
                    R.col(i-1).segment(0, i) = R.col(i).segment(0, i);
                }
            }

{'fraction_non_alphanumeric': 0.09188078108941418, 'fraction_numerical': 0.010688591983556012, 'mean_word_length': 1.1607460035523978, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1970361', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1367, 'n_words': 292}