#include #include"fast_matrix.hpp" template void print_matrix(T* matrix, int n, int m) { for (int i=0; i A(input_a), B(input_b), C; matrix_add(A, B, C); float* output = C.dump_array(); std::cout << "Testing: Matrix Add" << std::endl; std::cout << "\tOutput: " << std::endl; print_matrix(output, 3, 3); std::cout << std::endl; std::cout << "\tTruth: " << std::endl; print_matrix(truth, 3, 3); std::cout << std::endl; } void test_matrix_sub() { alignas(32) float input_a[3*3] = { 1, 2, 0, 2, 5, 1, 1, 1, 0.1, }; alignas(32) float input_b[3*3] = { 2, 2, 4, 1, 0, 0.5, 1, 1, 2, }; alignas(32) float truth[3*3] = { -1, 0, -4, 1, 5, 0.5, 0, 0, -1.9, }; BaseMatrix A(input_a), B(input_b), C; matrix_sub(A, B, C); float* output = C.dump_array(); std::cout << "Testing: Matrix sub" << std::endl; std::cout << "\tOutput: " << std::endl; print_matrix(output, 3, 3); std::cout << std::endl; std::cout << "\tTruth: " << std::endl; print_matrix(truth, 3, 3); std::cout << std::endl; } void test_matrix_mul_m_m() { alignas(32) float input_a[3*3] = { 1, 2, 0, 2, 5, 1, 1, 1, 0.1, }; alignas(32) float input_b[3*3] = { 2, 2, 4, 1, 0, 0.5, 1, 1, 2, }; alignas(32) float truth[3*3] = { 4, 2, 5, 10, 5, 12.5, 3.1, 2.1, 4.7, }; BaseMatrix A(input_a), B(input_b), C; matrix_mul_m_m(A, B, C); float* output = C.dump_array(); std::cout << "Testing: Matrix Mul M M" << std::endl; std::cout << "\tOutput: " << std::endl; print_matrix(output, 3, 3); std::cout << std::endl; std::cout << "\tTruth: " << std::endl; print_matrix(truth, 3, 3); std::cout << std::endl; } void test_identity() { //IdentityMatrix A; BaseMatrix A(1); std::cout << "Testing identity matrix" << std::endl; std::cout << A; } void test_matrix_inv() { alignas(32) float input[3*3] = { 1, 0, 0, 0, 2, 0, 0, 0, 4, }; alignas(32) float truth[3*3] = { 1, 0, 0, 0, 0.5, 0, 0, 0, 0.25, }; BaseMatrix A(input), I; Inverse::inverse(A, I); std::cout << "Testing Matrix inversion" << std::endl; std::cout << "\tOutput: " << std::endl; print_matrix(I.dump_array(), 3, 3); std::cout << "\tTruth: " << std::endl; print_matrix(truth, 3, 3); std::cout << std::endl; } int main(int argc, char **argv) { test_matrix_add(); test_matrix_sub(); test_matrix_mul_m_m(); test_identity(); test_matrix_inv(); return 0; }