Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

1.3 KB
Raw Blame
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import pytest
import numpy as np
import torch

from pytorch_layer_test_class import PytorchLayerTest


@pytest.mark.parametrize("dtype", [pytest.param(np.int32, marks=pytest.mark.xfail(reason="item returns scalar and for i32 it returns i64")),
                                   np.int64,
                                   np.float32,
                                   pytest.param(np.float64, marks=pytest.mark.xfail(reason="item returns scalar and for f64 it returns f32"))])
@pytest.mark.parametrize("shape", [[], [1], [1, 1, 1]])
class TestItem(PytorchLayerTest):
    def _prepare_input(self):
        return [self.random.randn(1, dtype=self.dtype).reshape(self.shape)]

    def create_model(self):
        class aten_item(torch.nn.Module):
            def forward(self, x: torch.Tensor):
                return x.item()


        return aten_item(), "aten::item"

    @pytest.mark.nightly
    @pytest.mark.precommit
    def test_item(self, ie_device, precision, ir_version, dtype, shape):
        self.dtype = dtype
        self.shape = shape
        # Dynamic shapes are not supported by Squeeze implementation
        self._test(*self.create_model(), ie_device, precision,
                   ir_version, dynamic_shapes=False)