| 101 | // ============= Scalar Operations ============= |
| 102 | |
| 103 | TEST_F(TensorOpsTest, ScalarAdd) { |
| 104 | std::vector<float> data(12); |
| 105 | for (auto& val : data) |
| 106 | val = dist(gen); |
| 107 | |
| 108 | auto custom_tensor = Tensor::from_vector(data, {3, 4}, Device::CUDA); |
| 109 | auto torch_tensor = torch::tensor(data, torch::TensorOptions().device(torch::kCUDA)) |
| 110 | .reshape({3, 4}); |
| 111 | |
| 112 | float scalar = 2.5f; |
| 113 | |
| 114 | auto custom_result = custom_tensor.add(scalar); |
| 115 | auto torch_result = torch_tensor + scalar; |
| 116 | |
| 117 | compare_tensors(custom_result, torch_result, 1e-5f, 1e-6f, "ScalarAdd"); |
| 118 | |
| 119 | // Test operator overload |
| 120 | auto custom_result2 = custom_tensor + scalar; |
| 121 | compare_tensors(custom_result2, torch_result, 1e-5f, 1e-6f, "ScalarAdd_Operator"); |
| 122 | } |
| 123 | |
| 124 | TEST_F(TensorOpsTest, ScalarSubtract) { |
| 125 | std::vector<float> data(10); |
nothing calls this directly
no test coverage detected