<commit_before>#include <cstdlib>
#include <iostream>
using std::cout;
using std::endl;

#include <eeros/core/Matrix.hpp>
using namespace eeros::math;

template < int N, int M, typename T >
void print(Matrix<N,M,T> A, int indent = 1)
{
	for (int n = 1; n <= N; n++)
	{
		for (int i = 0; i < indent; i++) cout << '\t';
		for (int m = 1; m <= M; m++)
		{
			if (m > 1) cout << '\t';
			cout << A(n,m);
		}
		cout << endl;
	}
}

template < int N, int M, typename T >
void rot(int axis, Matrix<N,M,T> &A, T angle)
{
	if (axis == 0)
		A.rotx(angle);
	else if (axis == 1)
		A.roty(angle);
	else
		A.rotz(angle);
}

int main(int argc, char *argv[])
{
	int error = 0;
	int stage = 0;

	stage = 1;
	Matrix<3,3> m1;
	m1.zero();
	for (int n = 1; n <= 3; n++)
	{
		for (int m = 1; m <= 3; m++)
		{
			if (m1(n,m) != 0)
			{
				cout << stage << ": 0 expected, n = " << n << ", m = " << m << endl;
				error++;
			}
		}
	}

	stage = 2;
	Matrix<3,3> m2;
	m2.eye();
	double m2trace = m2.trace();
	if (m2trace != 3)
	{
		cout << stage << ": trace expected to be 3, m2.trace() = " << m2trace << endl;
		error++;
	}
	for (int n = 1; n <= 3; n++)
	{
		for (int m = 1; m <= 3; m++)
		{
			if (n == m)
			{
				if (m2(n,m) != 1)
				{
					cout << stage << ": 1 expected, n = " << n << ", m = " << m << endl;
					error++;
				}
			}
			else
			{
				if (m2(n,m) != 0)
				{
					cout << stage << ": 0 expected, n = " << n << ", m = " << m << endl;
					error++;
				}
			}
		}
	}
	if (m1 == m2)
	{
		cout << stage << ": == fails" << endl;
		error++;
	}
	if (!(m1 != m2))
	{
		cout << stage << ": != fails" << endl;
		error++;
	}

	stage = 3;
	Matrix<3,3> m3 = m1 + m2;
	if (m3 != m2)
	{
		cout << stage << ": eye expected" << endl;
		error++;
	}

	stage = 4;
	Matrix<3,3> m4;
	for (int j = 0; j < 3; j++)
	{
		for (int i = 0; i < 360; i++)
		{
			rot<3,3,double>(j, m4, i*3.14/180);
			Matrix<3,3> m4inv = !m4;
			Matrix<3,3> m4result = (m4 * m4inv);

			double sum = 0;
			for (int n = 1; n <= 3; n++)
			{
				for (int m = 1; m <= 3; m++)
				{
					double res = m4result(n,m);
					sum += (res > 0 ) ? res : -res;
				}
			}

//			if (sum != 3 || m4result != m2)
			if (sum != 3)
			{
				cout << stage << ": inverse fails, j = " << j << ", i = " << i << ", sum = " << sum << endl;
				error++;

//				cout << "  m4 " << endl;
//				print(m4);
//
//				cout << "  m4inv =" << endl;
//				print(m4inv);
//
//				cout << "  m4result =" << endl;
//				print(m4result);
//				break;
			}
		}
	}

	Matrix<2,4> m;
	std::cout << sizeof(m) << std::endl;
	
	if (error == 0)
		cout << "matrix test succeeded" << endl;
	else
		cout << "matrix test failed: " << error << " errors" << endl;

	return error;
}<commit_msg>[Framework] Matrix test class modified<commit_after>#include <cstdlib>
#include <iostream>

#include <eeros/core/Matrix.hpp>
using namespace eeros::math;

template < uint8_t N, uint8_t M, typename T >
void print(Matrix<N,M,T> &A, int indent = 1) {
	for (int n = 1; n <= N; n++) {
		for (int i = 0; i < indent; i++) std::cout << '\t';
		for (int m = 1; m <= M; m++) {
			if (m > 1) std::cout << '\t';
			std::cout << A(n,m);
		}
		std::cout << std::endl;
	}
}

template < uint8_t N, uint8_t M, typename T >
void rot(int axis, Matrix<N,M,T> &A, T angle) {
	if (axis == 0)
		A.rotx(angle);
	else if (axis == 1)
		A.roty(angle);
	else
		A.rotz(angle);
}

int main(int argc, char *argv[]) {
	int error = 0;
	int stage = 0;

	// Stage 1: zero()
	stage = 1;
	Matrix<3,3> m1;
	m1.zero();
	for(int n = 1; n <= 3; n++) {
		for(int m = 1; m <= 3; m++) {
			if(m1(n,m) != 0) {
				std::cout << stage << ": 0 expected, n = " << n << ", m = " << m << std::endl;
				error++;
			}
		}
	}
	std::cout << "Stage " << stage << ":" << " m1 = " << std::endl;
	print(m1);

	// Stage 2: eye()
	stage = 2;
	Matrix<3,3> m2;
	m2.eye();
	double m2trace = m2.trace();
	if (m2trace != 3) {
		std::cout << stage << ": trace expected to be 3, m2.trace() = " << m2trace << std::endl;
		error++;
	}
	for (int n = 1; n <= 3; n++) {
		for (int m = 1; m <= 3; m++) {
			if (n == m) {
				if (m2(n,m) != 1) {
					std::cout << stage << ": 1 expected, n = " << n << ", m = " << m << std::endl;
					error++;
				}
			}
			else {
				if (m2(n,m) != 0) {
					std::cout << stage << ": 0 expected, n = " << n << ", m = " << m << std::endl;
					error++;
				}
			}
		}
	}
	if (m1 == m2) {
		std::cout << stage << ": == fails" << std::endl;
		error++;
	}
	if (!(m1 != m2)) {
		std::cout << stage << ": != fails" << std::endl;
		error++;
	}
	std::cout << "Stage " << stage << ":" << " m2 = " << std::endl;
	print(m2);

	// Stage 3: +
	stage = 3;
	Matrix<3,3> m3 = m1 + m2;
	if (m3 != m2) {
		std::cout << stage << ": eye expected" << std::endl;
		error++;
	}
	std::cout << "Stage " << stage << ":" << " m3 = m1 + m2 = " << std::endl;
	print(m3);

	// Stage 4: rot()
	stage = 4;
	Matrix<3,3> m4;
	for (int j = 0; j < 3; j++) {
		for (int i = 0; i < 360; i++) {
			rot<3,3,double>(j, m4, i*3.14/180);
			Matrix<3,3> m4inv = !m4;
			Matrix<3,3> m4result = (m4 * m4inv);

			double sum = 0;
			for (int n = 1; n <= 3; n++) {
				for (int m = 1; m <= 3; m++) {
					double res = m4result(n,m);
					sum += (res > 0 ) ? res : -res;
				}
			}

			if (sum != 3) {
				std::cout << stage << ": inverse fails, j = " << j << ", i = " << i << ", sum = " << sum << std::endl;
				error++;

				std::cout << "  m4 " << std::endl;
				print(m4);

				std::cout << "  m4inv =" << std::endl;
				print(m4inv);

				std::cout << "  m4result =" << std::endl;
				print(m4result);
				break;
			}
		}
	}
	std::cout << "Stage " << stage << ":" << " m4 = " << std::endl;
	print(m4);

	// Stage 4: sizeof()
	stage = 5;
	Matrix<2,4> m5;
	std::cout << "Stage " << stage << ":" << " Size of m5 (Matrix<2,4,double>) = " << sizeof(m5) << std::endl;
	
	if (error == 0)
		std::cout << "matrix test succeeded" << std::endl;
	else
		std::cout << "matrix test failed: " << error << " errors" << std::endl;

	return error;
}
{'fraction_non_alphanumeric': 0.24907376220949815, 'fraction_numerical': 0.038396766588076794, 'mean_word_length': 2.314174107142857, 'pattern_counts': {'":': 21, '<': 332, '<?xml version=': 0, '>': 38, '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': '71364', 'n_tokens_mistral': 3005, 'n_tokens_neox': 2596, 'n_words': 704}