Line data Source code
1 : #include "t_matrix.hpp" 2 : #include <chrono> 3 : #include <cmath> 4 : #include <cstdint> 5 : #include <gtest/gtest.h> 6 : #include <iostream> 7 : #include <limits.h> 8 : #include <openGPMP/linalg/mtx.hpp> 9 : #include <openGPMP/linalg/mtx_tmpl.hpp> 10 : #include <string> 11 : #include <vector> 12 : 13 : using namespace gpmp; 14 : #define TEST_COUT std::cerr << "\033[32m[ ] [ INFO ] \033[0m" 15 : #define INFO_COUT \ 16 : std::cerr << "\033[32m[ ] [ INFO ] \033[0m\033[1;34m\033[1m" 17 : namespace { 18 4 : TEST(MatrixArrayTest, BasicTest) { 19 1 : INFO_COUT << "MATRIX (as Arrays) NAIVE" << std::endl; 20 : 21 : gpmp::linalg::Mtx mtx; 22 1 : const int rowsA = 2; 23 1 : const int colsA = 3; 24 1 : const int colsB = 2; 25 : 26 : // Define matrices A, B, and expected result C 27 1 : int A[rowsA * colsA] = {1, 2, 3, 4, 5, 6}; 28 1 : int B[colsA * colsB] = {7, 8, 9, 10, 11, 12}; 29 : 30 1 : int expectedC[rowsA * colsB] = {58, 64, 139, 154}; 31 : 32 : // Initialize result matrix C 33 : int C[rowsA * colsB]; 34 : 35 : // Perform matrix multiplication 36 1 : mtx.std_mtx_mult(A, B, C, rowsA, colsA, colsB); 37 : 38 : // Check if result matrix C matches expectedC 39 3 : for (int i = 0; i < rowsA; ++i) { 40 6 : for (int j = 0; j < colsB; ++j) { 41 4 : EXPECT_EQ(C[i * colsB + j], expectedC[i * colsB + j]); 42 : } 43 : } 44 1 : } 45 : 46 : } // namespace