<commit_before>#pragma once

#include <cassert>

namespace ncv
{
        namespace math
        {
                ///
                /// \brief 2D convolution: odata += idata @ kdata (for 5x5 kernels)
                ///
                struct conv2d_5x5_t
                {
                        template
                        <
                                typename tmatrixi,
                                typename tmatrixk = tmatrixi,
                                typename tmatrixo = tmatrixi,
                                typename tscalar = typename tmatrixo::Scalar
                        >
                        void operator()(const tmatrixi& idata, const tmatrixk& kdata, tmatrixo& odata) const
                        {
                                assert(idata.rows() + 1 == kdata.rows() + odata.rows());
                                assert(idata.cols() + 1 == kdata.cols() + odata.cols());
                                assert(kdata.rows() == 5);
                                assert(kdata.cols() == 5);

                                const auto orows = odata.rows();
                                const auto ocols = odata.cols();

                                for (auto r = 0; r < orows; r ++)
                                {
                                        odata.row(r) +=

                                        idata.row(r + 0).segment(0, ocols) * kdata(0, 0) +
                                        idata.row(r + 0).segment(1, ocols) * kdata(0, 1) +
                                        idata.row(r + 0).segment(2, ocols) * kdata(0, 2) +
                                        idata.row(r + 0).segment(3, ocols) * kdata(0, 3) +
                                        idata.row(r + 0).segment(4, ocols) * kdata(0, 4) +

                                        idata.row(r + 1).segment(0, ocols) * kdata(1, 0) +
                                        idata.row(r + 1).segment(1, ocols) * kdata(1, 1) +
                                        idata.row(r + 1).segment(2, ocols) * kdata(1, 2) +
                                        idata.row(r + 1).segment(3, ocols) * kdata(1, 3) +
                                        idata.row(r + 1).segment(4, ocols) * kdata(1, 4) +

                                        idata.row(r + 2).segment(0, ocols) * kdata(2, 0) +
                                        idata.row(r + 2).segment(1, ocols) * kdata(2, 1) +
                                        idata.row(r + 2).segment(2, ocols) * kdata(2, 2) +
                                        idata.row(r + 2).segment(3, ocols) * kdata(2, 3) +
                                        idata.row(r + 2).segment(4, ocols) * kdata(2, 4) +

                                        idata.row(r + 3).segment(0, ocols) * kdata(3, 0) +
                                        idata.row(r + 3).segment(1, ocols) * kdata(3, 1) +
                                        idata.row(r + 3).segment(2, ocols) * kdata(3, 2) +
                                        idata.row(r + 3).segment(3, ocols) * kdata(3, 3) +
                                        idata.row(r + 3).segment(4, ocols) * kdata(3, 4) +

                                        idata.row(r + 4).segment(0, ocols) * kdata(4, 0) +
                                        idata.row(r + 4).segment(1, ocols) * kdata(4, 1) +
                                        idata.row(r + 4).segment(2, ocols) * kdata(4, 2) +
                                        idata.row(r + 4).segment(3, ocols) * kdata(4, 3) +
                                        idata.row(r + 4).segment(4, ocols) * kdata(4, 4);
                                }
                        }
                };
        }
}
<commit_msg>faster 5x5 convolution<commit_after>#pragma once

#include <cassert>

namespace ncv
{
        namespace math
        {
                ///
                /// \brief 2D convolution: odata += idata @ kdata (for 5x5 kernels)
                ///
                struct conv2d_5x5_t
                {
                        template
                        <
                                typename tmatrixi,
                                typename tmatrixk = tmatrixi,
                                typename tmatrixo = tmatrixi,
                                typename tscalar = typename tmatrixo::Scalar
                        >
                        void operator()(const tmatrixi& idata, const tmatrixk& kdata, tmatrixo& odata) const
                        {
                                assert(idata.rows() + 1 == kdata.rows() + odata.rows());
                                assert(idata.cols() + 1 == kdata.cols() + odata.cols());
                                assert(kdata.rows() == 5);
                                assert(kdata.cols() == 5);

                                const auto orows = odata.rows();
                                const auto ocols = odata.cols();

                                for (auto r = 0; r < orows; r ++)
                                {
                                        for (int kr = 0; kr < 5; kr ++)
                                        {
                                                odata.row(r) +=
                                                idata.row(r + kr).segment(0, ocols) * kdata(kr, 0) +
                                                idata.row(r + kr).segment(1, ocols) * kdata(kr, 1) +
                                                idata.row(r + kr).segment(2, ocols) * kdata(kr, 2) +
                                                idata.row(r + kr).segment(3, ocols) * kdata(kr, 3) +
                                                idata.row(r + kr).segment(4, ocols) * kdata(kr, 4);
                                        }
                                }
                        }
                };
        }
}

{'fraction_non_alphanumeric': 0.11122554067971163, 'fraction_numerical': 0.02334363199450738, 'mean_word_length': 0.7219267139479906, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '743385', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1425, 'n_words': 299}