xref: /aosp_15_r20/external/executorch/backends/xnnpack/test/ops/ceil.py (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the BSD-style license found in the
5# LICENSE file in the root directory of this source tree.
6
7import unittest
8
9import torch
10from executorch.backends.xnnpack.test.tester import Tester
11
12
13class TestCeil(unittest.TestCase):
14    class Ceil(torch.nn.Module):
15        def __init__(self):
16            super().__init__()
17
18        def forward(self, x):
19            z = torch.ceil(x)
20            return z
21
22    def _test_ceil(self, inputs):
23        (
24            Tester(self.Ceil(), inputs)
25            .export()
26            .check_count({"torch.ops.aten.ceil.default": 1})
27            .to_edge_transform_and_lower()
28            .check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
29            .check_not(["executorch_exir_dialects_edge__ops_aten_ceil_default"])
30            .to_executorch()
31            .serialize()
32            .run_method_and_compare_outputs()
33        )
34
35    def test_fp16_ceil(self):
36        inputs = (
37            torch.Tensor(
38                [
39                    [0.0, 0.1, 0.5, 0.499],
40                    [-0.6, -0.4, 100.1, -1000.1],
41                ]
42            ).to(torch.float16),
43        )
44        self._test_ceil(inputs)
45
46    def test_fp32_ceil(self):
47        inputs = (
48            torch.Tensor(
49                [
50                    [0.0, 0.1, 0.5, 0.499],
51                    [-0.6, -0.4, 100.1, -1000.1],
52                ]
53            ),
54        )
55        self._test_ceil(inputs)
56