| 69 | // ============= Matrix Multiplication Tests ============= |
| 70 | |
| 71 | TEST_F(TensorMatrixTest, MatMul2D) { |
| 72 | // Test basic 2D matrix multiplication: (2x3) @ (3x2) = (2x2) |
| 73 | std::vector<float> data_a = {1, 2, 3, |
| 74 | 4, 5, 6}; // 2x3 |
| 75 | std::vector<float> data_b = {7, 8, |
| 76 | 9, 10, |
| 77 | 11, 12}; // 3x2 |
| 78 | |
| 79 | auto custom_a = Tensor::from_vector(data_a, {2, 3}, Device::CUDA); |
| 80 | auto custom_b = Tensor::from_vector(data_b, {3, 2}, Device::CUDA); |
| 81 | |
| 82 | auto torch_a = torch::tensor(data_a, torch::TensorOptions().device(torch::kCUDA)) |
| 83 | .reshape({2, 3}); |
| 84 | auto torch_b = torch::tensor(data_b, torch::TensorOptions().device(torch::kCUDA)) |
| 85 | .reshape({3, 2}); |
| 86 | |
| 87 | auto custom_result = custom_a.matmul(custom_b); |
| 88 | auto torch_result = torch::matmul(torch_a, torch_b); |
| 89 | |
| 90 | compare_tensors(custom_result, torch_result, 1e-4f, 1e-5f, "MatMul2D"); |
| 91 | |
| 92 | // Test mm() alias - should give same result |
| 93 | auto custom_mm = custom_a.mm(custom_b); |
| 94 | compare_tensors(custom_mm, torch_result, 1e-4f, 1e-5f, "MM_Alias"); |
| 95 | } |
| 96 | |
| 97 | TEST_F(TensorMatrixTest, MatMulVectorMatrix) { |
| 98 | // Test vector-matrix multiplication: (3,) @ (3x2) = (2,) |
nothing calls this directly
no test coverage detected