| 38 | } // namespace |
| 39 | |
| 40 | void TestRelu() { |
| 41 | const auto shape = RandomShape(); |
| 42 | const auto data = RandomData<float>(shape.Count(0)); |
| 43 | const auto target_data = Relu(data); |
| 44 | std::vector<float> result(shape.Count(0)); |
| 45 | |
| 46 | auto tensor = Tensor::from_buffer(data.data(), shape, Device("cpu"), DType::kFloat); |
| 47 | auto result_tensor = nn::relu(tensor); |
| 48 | |
| 49 | result_tensor.copy_to(result.data()); |
| 50 | |
| 51 | ASSERT_EQ(result, target_data); |
| 52 | } |
| 53 | |
| 54 | TEST(Api, nn_relu) { |
| 55 | EnvScope scope; |