Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions test/legacy_test/test_split_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import paddle
from paddle import base
from paddle.base import Program, core, program_guard
from paddle.base import core
from paddle.pir_utils import test_with_pir_api


Expand Down Expand Up @@ -361,57 +361,51 @@ def test_api(self):
np.testing.assert_array_equal(res_5, out[2])


class TestSplitOpError(unittest.TestCase):
def test_errors(self):
class TestSplitOpErrorStatic(unittest.TestCase):
@test_with_pir_api
def test_errors_with_static(self):
paddle.enable_static()
with program_guard(Program(), Program()):
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
# The type of axis in split_op should be int or Variable.
def test_axis_type():
x6 = paddle.static.data(
shape=[-1, 4], dtype='float16', name='x3'
x5 = paddle.static.data(
shape=[-1, 4], dtype='float16', name='x5'
)
paddle.split(x=x6, num_or_sections=2, axis=3.2)
paddle.split(x=x5, num_or_sections=2, axis=3.2)

self.assertRaises(TypeError, test_axis_type)

# The type of axis in split_op should be int or Variable.
def test_axis_variable_type():
x9 = paddle.static.data(
shape=[-1, 4], dtype='float16', name='x9'
)
x10 = paddle.static.data(
shape=[-1, 1], dtype='float16', name='x10'
)
paddle.split(x=x9, num_or_sections=2, axis=x10)

self.assertRaises(TypeError, test_axis_variable_type)

# The type of num_or_sections in split_op should be int, tuple or list.
def test_num_or_sections_type():
x6 = paddle.static.data(
shape=[-1, 4], dtype='float16', name='x4'
shape=[-1, 4], dtype='float16', name='x6'
)
paddle.split(x=x6, num_or_sections=2.1, axis=3)

self.assertRaises(TypeError, test_num_or_sections_type)

def test_num_or_sections_type_tensor():
x7 = paddle.static.data(
shape=[-1, 4], dtype='float16', name='x5'
shape=[-1, 4], dtype='float16', name='x7'
)
paddle.split(input=x7, num_or_sections=2.1, dim=3)

self.assertRaises(TypeError, test_num_or_sections_type_tensor)

def test_axis_type_tensor():
x8 = paddle.static.data(
shape=[-1, 4], dtype='float16', name='x6'
shape=[-1, 4], dtype='float16', name='x8'
)
paddle.split(input=x8, num_or_sections=2, dim=3.2)

self.assertRaises(TypeError, test_axis_type_tensor)
paddle.disable_static()


class TestSplitOpErrorDynamic(unittest.TestCase):
def test_errors_with_dynamic(self):
with paddle.base.dygraph.guard():

def test_0_num_tensor():
Expand Down