<commit_before>#ifndef LAYER_HPP
#define LAYER_HPP

#include <string>
#include <vector>
#include <memory>
#include <random>

#ifdef USE_MPI
#include <mpi.h>
#endif

#include "matrix.hpp"
#include "Function.hpp"

class Layer
{
protected:
	typedef Matrix<double> Mat;
	typedef std::vector<double> Vec;

	int prev_num_map, num_map;
	int prev_num_unit, num_unit;
	
	std::vector<std::vector<Mat>> W;
	std::shared_ptr<Function> func, prev_func;
public:
	Layer(){}

	virtual void init ( std::mt19937& m, MPI_Comm inner_world ) = 0;
	virtual void finalize () = 0;
	virtual std::vector<Mat> calc_delta ( const std::vector<Mat>& U, const std::vector<Mat>& delta ) = 0;
	virtual std::vector<std::vector<Mat>> calc_gradient ( const std::vector<Mat>& U, const std::vector<Mat>& delta ) = 0;
	virtual void update_W ( const std::vector<std::vector<Mat>>& dW ) = 0;

	virtual std::vector<Mat> apply ( const std::vector<Mat>& U, bool use_func = true ) = 0;
	virtual std::vector<std::vector<Vec>> apply ( const std::vector<std::vector<Vec>>& u, bool use_func = true ) = 0;

	// virtual std::map<std::string, double> get_error () = 0;
	
	virtual std::vector<std::vector<Mat>> get_W ();
	virtual std::shared_ptr<Function> get_function ();

	virtual int get_num_map();
	virtual int get_num_unit();
	virtual int get_prev_num_map();
	virtual int get_prev_num_unit();
	
	virtual void set_W ( const std::vector<std::vector<Mat>>& W );
	virtual void set_function ( const std::shared_ptr<Function>& f );
	virtual void set_prev_function ( const std::shared_ptr<Function>& f );
	
	virtual void set_W ( const std::string& filename ) = 0;
	virtual void output_W ( const std::string& filename ) = 0;

	virtual void param_mix () = 0;
};

std::vector<std::vector<Layer::Mat>> Layer::get_W ()
{
	return this->W;
}

std::shared_ptr<Function> Layer::get_function ()
{
	return func;
}

int Layer::get_num_map()
{
	return this->num_map;
}<commit_msg>Added some variables and functions under defined USE_MPI.<commit_after>#ifndef LAYER_HPP
#define LAYER_HPP

#include <string>
#include <vector>
#include <memory>
#include <random>

#ifdef USE_MPI
#include <mpi.h>
#endif

#include "matrix.hpp"
#include "Function.hpp"

class Layer
{
protected:
	typedef Matrix<double> Mat;
	typedef std::vector<double> Vec;

	int prev_num_map, num_map;
	int prev_num_unit, num_unit;
	
#ifdef USE_MPI
	MPI_Comm inner_world, outer_world;
	int rank, nprocs;
#endif

	std::vector<std::vector<Mat>> W;
	std::shared_ptr<Function> func, prev_func;
public:
	Layer(){}

#ifdef USE_MPI
	virtual void init ( std::mt19937& m, MPI_Comm inner_world, MPI_Comm outer_world ) = 0;
#else
	virtual void init ( std::mt19937& m ) = 0;
#endif
	virtual void finalize () = 0;
	virtual std::vector<Mat> calc_delta ( const std::vector<Mat>& U, const std::vector<Mat>& delta ) = 0;
	virtual std::vector<std::vector<Mat>> calc_gradient ( const std::vector<Mat>& U, const std::vector<Mat>& delta ) = 0;
	virtual void update_W ( const std::vector<std::vector<Mat>>& dW ) = 0;

	virtual std::vector<Mat> apply ( const std::vector<Mat>& U, bool use_func = true ) = 0;
	virtual std::vector<std::vector<Vec>> apply ( const std::vector<std::vector<Vec>>& u, bool use_func = true ) = 0;

	// virtual std::map<std::string, double> get_error () = 0;
	
	virtual std::vector<std::vector<Mat>> get_W ();
	virtual std::shared_ptr<Function> get_function ();

	virtual int get_num_map();
	virtual int get_num_unit();
	virtual int get_prev_num_map();
	virtual int get_prev_num_unit();
	
	virtual void set_W ( const std::vector<std::vector<Mat>>& W );
	virtual void set_function ( const std::shared_ptr<Function>& f );
	virtual void set_prev_function ( const std::shared_ptr<Function>& f );
	
	virtual void set_W ( const std::string& filename ) = 0;
	virtual void output_W ( const std::string& filename ) = 0;
	
#ifdef USE_MPI
	virtual void param_mix () = 0;
#endif
};

std::vector<std::vector<Layer::Mat>> Layer::get_W ()
{
	return this->W;
}

std::shared_ptr<Function> Layer::get_function ()
{
	return func;
}

int Layer::get_num_map()
{
	return this->num_map;
}
{'fraction_non_alphanumeric': 0.15267175572519084, 'fraction_numerical': 0.009357301157350407, 'mean_word_length': 5.736318407960199, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 79, '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': '4355890', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1424, 'n_words': 377}