<commit_before>#include "../core/op_algo.h"
#include "../core/device.h"
#include "../math/basic_functions.h"
#include "../math/blas.h"
#include "../device_context/cpu_context.h"

namespace mlfe{
namespace algorithm_cpu{

template <class Tp>
class ElementwiseAdd : public OpAlgo{
using T = typename Tp::T;
public:
    ElementwiseAdd(OpAlgoContext *oac) : OpAlgo(oac){
        y = oac->get_output(0);
        x1 = y.get_children()[0];
        x2 = y.get_children()[1];
        size = y.Size();
    }

    void Compute() override{
        auto x1_ptr = x1.device_data<T>();
        auto x2_ptr = x2.device_data<T>();
        auto y_ptr = y.mutable_device_data<T>();
        for(int n = 0; n < size; ++n){
            y_ptr[n] = x1_ptr[n] + x2_ptr[n];
        }
    }

private:
    Tensor x1;
    Tensor x2;
    Tensor y;
    int size;
};

REGIST_OP_ALGO(ElementwiseAdd)
    .Input("X1", "float32")
    .Input("X2", "float32")
    .Output("Y", type::float32::string)
    .Device("CPU")
    .CreatorFn([](OpAlgoContext *oac) -> std::shared_ptr<OpAlgo>{
        using T = ElementwiseAdd<type::float32>;
        return std::make_shared<T>(oac);
    })
    .Finish();

template <class Tp>
class ElementwiseMul : public OpAlgo{
using T = typename Tp::T;
public:
    ElementwiseMul(OpAlgoContext *oac) : OpAlgo(oac){
        y = oac->get_output(0);
        x1 = y.get_children()[0];
        x2 = y.get_children()[1];
        size = y.Size();
    }

    void Compute() override{
        auto x1_ptr = x1.device_data<T>();
        auto x2_ptr = x2.device_data<T>();
        auto y_ptr = y.mutable_device_data<T>();
        for(int n = 0; n < size; ++n){
            y_ptr[n] = x1_ptr[n] * x2_ptr[n];
        }
    }
private:
    Tensor x1;
    Tensor x2;
    Tensor y;
    int size;
};

REGIST_OP_ALGO(ElementwiseMul)
    .Input("Xs", "float32s")
    .Output("Y", type::float32::string)
    .Device("CPU")
    .CreatorFn([](OpAlgoContext *oac) -> std::shared_ptr<OpAlgo>{
        using T = ElementwiseMul<type::float32>;
        return std::make_shared<T>(oac);
    })
    .Finish();

template <class Tp>
class AddN : public OpAlgo{
using T = typename Tp::T;
public:
    AddN(OpAlgoContext *oac) : OpAlgo(oac){
        _num_inputs = oac->num_inputs();
        for(int n = 0; n < _num_inputs; ++n){
            xs.push_back(oac->get_input(n));
        }
        y = oac->get_output(0);
        size = xs[0].Size();
    }

    void Compute() override{
        auto y_ptr = y.mutable_device_data<T>();
        math::set<T, CPUContext>(size, 0, y_ptr);
        for(int n = 0; n < _num_inputs; ++n){
            auto x_ptr = xs[n].device_data<T>();
            math::axpy<T, CPUContext>(size, 1.f, x_ptr, y_ptr);
        }
    }
private:
    std::vector<Tensor> xs;
    Tensor y;
    int size;
    int _num_inputs;
};

REGIST_OP_ALGO(AddN)
    .Input("Xs", "float32s")
    .Input("dy", "float32")
    .Output("Y", type::float32::string)
    .Device("CPU")
    .CreatorFn([](OpAlgoContext *oac) -> std::shared_ptr<OpAlgo>{
        using T = AddN<type::float32>;
        return std::make_shared<T>(oac);
    })
    .Finish();<commit_msg>fix remained legacy style code.<commit_after>#include "../core/op_algo.h"
#include "../core/device.h"
#include "../math/basic_functions.h"
#include "../math/blas.h"
#include "../device_context/cpu_context.h"

namespace mlfe{
namespace algorithm_cpu{

template <class Tp>
class ElementwiseAdd : public OpAlgo{
using T = typename Tp::T;
public:
    ElementwiseAdd(OpAlgoContext *oac) 
        : OpAlgo(oac, "ElementwiseAdd"){
        y = oac->get_output(0);
        x1 = y.get_children()[0];
        x2 = y.get_children()[1];
        size = y.Size();
    }

    void Compute() override{
        auto x1_ptr = x1.device_data<T>();
        auto x2_ptr = x2.device_data<T>();
        auto y_ptr = y.mutable_device_data<T>();
        for(int n = 0; n < size; ++n){
            y_ptr[n] = x1_ptr[n] + x2_ptr[n];
        }
    }

private:
    Tensor x1;
    Tensor x2;
    Tensor y;
    int size;
};

REGIST_OP_ALGO(ElementwiseAdd)
    .Input("X1", "float32")
    .Input("X2", "float32")
    .Output("Y", type::float32::string)
    .Device("CPU")
    .CreatorFn([](OpAlgoContext *oac) -> std::shared_ptr<OpAlgo>{
        using T = ElementwiseAdd<type::float32>;
        return std::make_shared<T>(oac);
    })
    .Finish();

template <class Tp>
class ElementwiseMul : public OpAlgo{
using T = typename Tp::T;
public:
    ElementwiseMul(OpAlgoContext *oac) 
        : OpAlgo(oac, "ElementwiseMul"){
        y = oac->get_output(0);
        x1 = y.get_children()[0];
        x2 = y.get_children()[1];
        size = y.Size();
    }

    void Compute() override{
        auto x1_ptr = x1.device_data<T>();
        auto x2_ptr = x2.device_data<T>();
        auto y_ptr = y.mutable_device_data<T>();
        for(int n = 0; n < size; ++n){
            y_ptr[n] = x1_ptr[n] * x2_ptr[n];
        }
    }
private:
    Tensor x1;
    Tensor x2;
    Tensor y;
    int size;
};

REGIST_OP_ALGO(ElementwiseMul)
    .Input("Xs", "float32s")
    .Output("Y", type::float32::string)
    .Device("CPU")
    .CreatorFn([](OpAlgoContext *oac) -> std::shared_ptr<OpAlgo>{
        using T = ElementwiseMul<type::float32>;
        return std::make_shared<T>(oac);
    })
    .Finish();

template <class Tp>
class AddN : public OpAlgo{
using T = typename Tp::T;
public:
    AddN(OpAlgoContext *oac) : OpAlgo(oac, "AddN"){
        y = oac->get_output(0);
        size = y.Size();
        _num_inputs = y.get_children().size();
        for(int n = 0; n < _num_inputs; ++n){
            xs.push_back(y.get_children()[n]);
        }
    }

    void Compute() override{
        auto y_ptr = y.mutable_device_data<T>();
        math::set<T, CPUContext>(size, 0, y_ptr);
        for(int n = 0; n < _num_inputs; ++n){
            auto x_ptr = xs[n].device_data<T>();
            math::axpy<T, CPUContext>(size, 1.f, x_ptr, y_ptr);
        }
    }
private:
    std::vector<Tensor> xs;
    Tensor y;
    int size;
    int _num_inputs;
};

REGIST_OP_ALGO(AddN)
    .Input("Xs", "float32s")
    .Input("dy", "float32")
    .Output("Y", type::float32::string)
    .Device("CPU")
    .CreatorFn([](OpAlgoContext *oac) -> std::shared_ptr<OpAlgo>{
        using T = AddN<type::float32>;
        return std::make_shared<T>(oac);
    })
    .Finish();
{'fraction_non_alphanumeric': 0.17199367088607595, 'fraction_numerical': 0.01819620253164557, 'mean_word_length': 2.5792751981879953, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2354254', 'n_tokens_mistral': 2456, 'n_tokens_neox': 2391, 'n_words': 466}