<commit_before>/**
 * @file partial_reduce.h
 *
 * Partial reduction expression and evaluation
 *
 * @author <NAME>
 */

#ifdef _MSC_VER
#pragma once
#endif

#ifndef LIGHTMAT_PARTIAL_REDUCE_H_
#define LIGHTMAT_PARTIAL_REDUCE_H_

#include <light_mat/math/reduction_functors.h>
#include <light_mat/matrix/matrix_arith.h>
#include <light_mat/matrix/matrix_ewise_eval.h>

#include "bits/partial_reduce_internal.h"

namespace lmat
{
	/********************************************
	 *
	 *  Expression classes
	 *
	 ********************************************/

	template<class Fun, typename Arg_HP, class Arg>
	struct matrix_traits<colwise_reduce_expr<Fun, Arg_HP, Arg> >
	{
		static const int num_dimensions = 2;
		static const int compile_time_num_rows = 1;
		static const int compile_time_num_cols = ct_cols<Arg>::value;

		static const bool is_readonly = true;

		typedef typename Fun::result_type value_type;
		typedef typename matrix_traits<Arg>::domain domain;
	};

	template<class Fun, typename Arg_HP, class Arg>
	struct matrix_traits<rowwise_reduce_expr<Fun, Arg_HP, Arg> >
	{
		static const int num_dimensions = 2;
		static const int compile_time_num_rows = ct_rows<Arg>::value;
		static const int compile_time_num_cols = 1;

		static const bool is_readonly = true;

		typedef typename Fun::result_type value_type;
		typedef typename matrix_traits<Arg>::domain domain;
	};


	template<class Fun, typename Arg_HP, class Arg>
	class colwise_reduce_expr
	: public unary_expr_base<Arg_HP, Arg>
	, public IMatrixXpr<
	  	  colwise_reduce_expr<Fun, Arg_HP, Arg>,
	  	  typename Fun::result_type>
	{
#ifdef LMAT_USE_STATIC_ASSERT
		static_assert(is_reduction_functor<Fun>::value, "Fun must be a reduction_functor");
		static_assert(is_mat_xpr<Arg>::value, "Arg must be a matrix expression class.");
#endif

	public:
		typedef unary_expr_base<Arg_HP, Arg> base_t;
		typedef typename Fun::result_type value_type;

		LMAT_ENSURE_INLINE
		colwise_reduce_expr(const Fun& fun, const arg_forwarder<Arg_HP, Arg>& arg_fwd)
		: base_t(arg_fwd), m_fun(fun) { }

		LMAT_ENSURE_INLINE const Fun& fun() const
		{
			return m_fun;
		}

		LMAT_ENSURE_INLINE index_t nelems() const
		{
			return this->arg().ncolumns();
		}

		LMAT_ENSURE_INLINE size_t size() const
		{
			return static_cast<size_t>(nelems());
		}

		LMAT_ENSURE_INLINE index_t nrows() const
		{
			return 1;
		}

		LMAT_ENSURE_INLINE index_t ncolumns() const
		{
			return this->arg().ncolumns();
		}

	private:
		Fun m_fun;
	};


	template<class Fun, typename Arg_HP, class Arg>
	class rowwise_reduce_expr
	: public unary_expr_base<Arg_HP, Arg>
	, public IMatrixXpr<rowwise_reduce_expr<Fun, Arg_HP, Arg>, typename Fun::result_type>
	{
#ifdef LMAT_USE_STATIC_ASSERT
		static_assert(is_reduction_functor<Fun>::value, "Fun must be a reduction_functor");
		static_assert(is_mat_xpr<Arg>::value, "Arg must be a matrix expression class.");
#endif

	public:
		typedef unary_expr_base<Arg_HP, Arg> base_t;
		typedef typename Fun::result_type value_type;

		LMAT_ENSURE_INLINE
		rowwise_reduce_expr(const Fun& fun, const arg_forwarder<Arg_HP, Arg>& arg_fwd)
		: base_t(arg_fwd), m_fun(fun) { }

		LMAT_ENSURE_INLINE const Fun& fun() const
		{
			return m_fun;
		}

		LMAT_ENSURE_INLINE index_t nelems() const
		{
			return this->arg().nrows();
		}

		LMAT_ENSURE_INLINE size_t size() const
		{
			return static_cast<size_t>(nelems());
		}

		LMAT_ENSURE_INLINE index_t nrows() const
		{
			return this->arg().nrows();
		}

		LMAT_ENSURE_INLINE index_t ncolumns() const
		{
			return 1;
		}

	private:
		Fun m_fun;
	};


	/********************************************
	 *
	 *  Expression Maps
	 *
	 ********************************************/

	template<class Fun>
	struct colwise_reduce_t
	{
		const Fun& fun;

		LMAT_ENSURE_INLINE
		explicit colwise_reduce_t(const Fun& f)
		: fun(f) { }
	};

	template<class Fun>
	struct rowwise_reduce_t
	{
		const Fun& fun;

		LMAT_ENSURE_INLINE
		explicit rowwise_reduce_t(const Fun& f)
		: fun(f) { }
	};

	template<class Fun>
	inline colwise_reduce_t<Fun> colwise_reduce(const Fun& f)
	{
		return colwise_reduce_t<Fun>(f);
	};

	template<class Fun>
	inline rowwise_reduce_t<Fun> rowwise_reduce(const Fun& f)
	{
		return rowwise_reduce_t<Fun>(f);
	};


	template<class Fun, class Arg>
	struct unary_expr_verifier<colwise_reduce_t<Fun>, Arg>
	{
		static const bool value = is_mat_xpr<Arg>::value;
	};

	template<class Fun, class Arg>
	struct unary_expr_verifier<rowwise_reduce_t<Fun>, Arg>
	{
		static const bool value = is_mat_xpr<Arg>::value;
	};

	template<class Fun, typename Arg_HP, class Arg>
	struct unary_expr_map<colwise_reduce_t<Fun>, Arg_HP, Arg>
	{
		typedef colwise_reduce_expr<Fun, Arg_HP, Arg> type;

		LMAT_ENSURE_INLINE
		static type get(const colwise_reduce_t<Fun>& spec,<commit_msg>minor fixes<commit_after>/**
 * @file partial_reduce.h
 *
 * Partial reduction expression and evaluation
 *
 * @author <NAME>
 */

#ifdef _MSC_VER
#pragma once
#endif

#ifndef LIGHTMAT_PARTIAL_REDUCE_H_
#define LIGHTMAT_PARTIAL_REDUCE_H_

#include <light_mat/math/reduction_functors.h>
#include <light_mat/matrix/matrix_arith.h>
#include <light_mat/matrix/matrix_ewise_eval.h>

#include "bits/partial_reduce_internal.h"

namespace lmat
{
	/********************************************
	 *
	 *  Expression classes
	 *
	 ********************************************/

	template<class Fun, typename Arg_HP, class Arg>
	struct matrix_traits<colwise_reduce_expr<Fun, Arg_HP, Arg> >
	{
		static const int num_dimensions = 2;
		static const int compile_time_num_rows = 1;
		static const int compile_time_num_cols = ct_cols<Arg>::value;

		static const bool is_readonly = true;

		typedef typename Fun::result_type value_type;
		typedef typename matrix_traits<Arg>::domain domain;
	};

	template<class Fun, typename Arg_HP, class Arg>
	struct matrix_traits<rowwise_reduce_expr<Fun, Arg_HP, Arg> >
	{
		static const int num_dimensions = 2;
		static const int compile_time_num_rows = ct_rows<Arg>::value;
		static const int compile_time_num_cols = 1;

		static const bool is_readonly = true;

		typedef typename Fun::result_type value_type;
		typedef typename matrix_traits<Arg>::domain domain;
	};


	template<class Fun, typename Arg_HP, class Arg>
	class colwise_reduce_expr
	: public unary_expr_base<Arg_HP, Arg>
	, public IMatrixXpr<
	  	  colwise_reduce_expr<Fun, Arg_HP, Arg>,
	  	  typename Fun::result_type>
	{
#ifdef LMAT_USE_STATIC_ASSERT
		static_assert(is_reduction_functor<Fun>::value, "Fun must be a reduction_functor");
		static_assert(is_mat_xpr<Arg>::value, "Arg must be a matrix expression class.");
#endif

	public:
		typedef unary_expr_base<Arg_HP, Arg> base_t;
		typedef typename Fun::result_type value_type;

		LMAT_ENSURE_INLINE
		colwise_reduce_expr(const Fun& fun, const arg_forwarder<Arg_HP, Arg>& arg_fwd)
		: base_t(arg_fwd), m_fun(fun) { }

		LMAT_ENSURE_INLINE const Fun& fun() const
		{
			return m_fun;
		}

		LMAT_ENSURE_INLINE index_t nelems() const
		{
			return this->arg().ncolumns();
		}

		LMAT_ENSURE_INLINE size_t size() const
		{
			return static_cast<size_t>(nelems());
		}

		LMAT_ENSURE_INLINE index_t nrows() const
		{
			return 1;
		}

		LMAT_ENSURE_INLINE index_t ncolumns() const
		{
			return this->arg().ncolumns();
		}

	private:
		Fun m_fun;
	};


	template<class Fun, typename Arg_HP, class Arg>
	class rowwise_reduce_expr
	: public unary_expr_base<Arg_HP, Arg>
	, public IMatrixXpr<rowwise_reduce_expr<Fun, Arg_HP, Arg>, typename Fun::result_type>
	{
#ifdef LMAT_USE_STATIC_ASSERT
		static_assert(is_reduction_functor<Fun>::value, "Fun must be a reduction_functor");
		static_assert(is_mat_xpr<Arg>::value, "Arg must be a matrix expression class.");
#endif

	public:
		typedef unary_expr_base<Arg_HP, Arg> base_t;
		typedef typename Fun::result_type value_type;

		LMAT_ENSURE_INLINE
		rowwise_reduce_expr(const Fun& fun, const arg_forwarder<Arg_HP, Arg>& arg_fwd)
		: base_t(arg_fwd), m_fun(fun) { }

		LMAT_ENSURE_INLINE const Fun& fun() const
		{
			return m_fun;
		}

		LMAT_ENSURE_INLINE index_t nelems() const
		{
			return this->arg().nrows();
		}

		LMAT_ENSURE_INLINE size_t size() const
		{
			return static_cast<size_t>(nelems());
		}

		LMAT_ENSURE_INLINE index_t nrows() const
		{
			return this->arg().nrows();
		}

		LMAT_ENSURE_INLINE index_t ncolumns() const
		{
			return 1;
		}

	private:
		Fun m_fun;
	};


	/********************************************
	 *
	 *  Expression Maps
	 *
	 ********************************************/

	template<class Fun>
	struct colwise_reduce_t
	{
		const Fun& fun;

		LMAT_ENSURE_INLINE
		explicit colwise_reduce_t(const Fun& f)
		: fun(f) { }
	};

	template<class Fun>
	struct rowwise_reduce_t
	{
		const Fun& fun;

		LMAT_ENSURE_INLINE
		explicit rowwise_reduce_t(const Fun& f)
		: fun(f) { }
	};

	template<class Fun>
	inline colwise_reduce_t<Fun> colwise_reduce(const Fun& f)
	{
		return colwise_reduce_t<Fun>(f);
	}

	template<class Fun>
	inline rowwise_reduce_t<Fun> rowwise_reduce(const Fun& f)
	{
		return rowwise_reduce_t<Fun>(f);
	}


	template<class Fun, class Arg>
	struct unary_expr_verifier<colwise_reduce_t<Fun>, Arg>
	{
		static const bool value = is_mat_xpr<Arg>::value;
	};

	template<class Fun, class Arg>
	struct unary_expr_verifier<rowwise_reduce_t<Fun>, Arg>
	{
		static const bool value = is_mat_xpr<Arg>::value;
	};

	template<class Fun, typename Arg_HP, class Arg>
	struct unary_expr_map<colwise_reduce_t<Fun>, Arg_HP, Arg>
	{
		typedef colwise_reduce_expr<Fun, Arg_HP, Arg> type;

		LMAT_ENSURE_INLINE
		static type get(const colwise_reduce_t<Fun>& spec,
{'fraction_non_alphanumeric': 0.1349090148504497, 'fraction_numerical': 0.0012549675800041832, 'mean_word_length': 5.006909547738694, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 117, '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': '7037989', 'n_tokens_mistral': 3882, 'n_tokens_neox': 3463, 'n_words': 746}