OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import pytest
import numpy as np
from pytorch_layer_test_class import PytorchLayerTest
class TestRavel(PytorchLayerTest):
def _prepare_input(self, shape, dtype="float32"):
if dtype.startswith("int"):
return (self.random.randint(-100, 100, size=shape).astype(dtype),)
return (self.random.randn(*shape).astype(dtype),)
def create_model(self):
import torch
class aten_ravel(torch.nn.Module):
def forward(self, x):
return torch.ravel(x)
return aten_ravel(), "aten::ravel"
@pytest.mark.parametrize("shape", [
[2, 3],
[2, 3, 4],
[2, 3, 4, 5],
[1],
[5],
[1, 1, 1],
[],
])
@pytest.mark.parametrize("dtype", ["float32", "float64", "int32", "int64", "int8"])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_ravel(self, shape, dtype, ie_device, precision, ir_version):
self._test(
*self.create_model(),
ie_device,
precision,
ir_version,
kwargs_to_prepare_input={"shape": shape, "dtype": dtype},
)
class TestRavelComplex(PytorchLayerTest):
def _prepare_input(self, shape):
return (self.random.randn(*shape, 2).astype(np.float32),)
def create_model(self):
import torch
class aten_ravel(torch.nn.Module):
def forward(self, x):
x = torch.view_as_complex(x)
return torch.view_as_real(torch.ravel(x))
return aten_ravel(), "aten::ravel"
@pytest.mark.parametrize("shape", [
[2, 3],
[2, 3, 4],
[],
])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_ravel_complex(self, shape, ie_device, precision, ir_version):
self._test(
*self.create_model(),
ie_device,
precision,
ir_version,
kwargs_to_prepare_input={"shape": shape},
)