|
|
@ -271,6 +271,14 @@ class TestSplitOpError(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, test_axis_type)
|
|
|
|
self.assertRaises(TypeError, test_axis_type)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# The type of axis in split_op should be int or Variable.
|
|
|
|
|
|
|
|
def test_axis_variable_type():
|
|
|
|
|
|
|
|
x9 = fluid.layers.data(shape=[4], dtype='float16', name='x9')
|
|
|
|
|
|
|
|
x10 = fluid.layers.data(shape=[1], dtype='float16', name='x10')
|
|
|
|
|
|
|
|
fluid.layers.split(input=x9, num_or_sections=2, dim=x10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertRaises(TypeError, test_axis_variable_type)
|
|
|
|
|
|
|
|
|
|
|
|
# The type of num_or_sections in split_op should be int, tuple or list.
|
|
|
|
# The type of num_or_sections in split_op should be int, tuple or list.
|
|
|
|
def test_num_or_sections_type():
|
|
|
|
def test_num_or_sections_type():
|
|
|
|
x6 = fluid.layers.data(shape=[4], dtype='float16', name='x4')
|
|
|
|
x6 = fluid.layers.data(shape=[4], dtype='float16', name='x4')
|
|
|
@ -296,7 +304,7 @@ class API_TestSplit(unittest.TestCase):
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
data1 = fluid.layers.data('data1', shape=[4, 6, 6], dtype='float64')
|
|
|
|
data1 = fluid.layers.data('data1', shape=[4, 6, 6], dtype='float64')
|
|
|
|
data2 = fluid.layers.data('data2', shape=[1], dtype='int32')
|
|
|
|
data2 = fluid.layers.data('data2', shape=[1], dtype='int32')
|
|
|
|
x0, x1, x2 = paddle.split(data1, num_or_sections=3, dim=data2)
|
|
|
|
x0, x1, x2 = paddle.split(data1, num_or_sections=3, axis=data2)
|
|
|
|
place = fluid.CPUPlace()
|
|
|
|
place = fluid.CPUPlace()
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
input1 = np.random.random([4, 6, 6]).astype('float64')
|
|
|
|
input1 = np.random.random([4, 6, 6]).astype('float64')
|
|
|
@ -314,7 +322,7 @@ class API_TestSplit2(unittest.TestCase):
|
|
|
|
def test_out(self):
|
|
|
|
def test_out(self):
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
data1 = fluid.layers.data('data1', shape=[4, 6, 6], dtype='float64')
|
|
|
|
data1 = fluid.layers.data('data1', shape=[4, 6, 6], dtype='float64')
|
|
|
|
x0, x1, x2 = paddle.split(data1, num_or_sections=3, dim=2)
|
|
|
|
x0, x1, x2 = paddle.split(data1, num_or_sections=3, axis=2)
|
|
|
|
place = fluid.CPUPlace()
|
|
|
|
place = fluid.CPUPlace()
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
input1 = np.random.random([4, 6, 6]).astype('float64')
|
|
|
|
input1 = np.random.random([4, 6, 6]).astype('float64')
|
|
|
@ -330,7 +338,7 @@ class API_TestSplit3(unittest.TestCase):
|
|
|
|
def test_out(self):
|
|
|
|
def test_out(self):
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
data = fluid.layers.data('data', shape=[-1, 10], dtype='float64')
|
|
|
|
data = fluid.layers.data('data', shape=[-1, 10], dtype='float64')
|
|
|
|
x0, x1 = paddle.split(data, num_or_sections=(3, 7), dim=1)
|
|
|
|
x0, x1 = paddle.split(data, num_or_sections=(3, 7), axis=1)
|
|
|
|
place = fluid.CPUPlace()
|
|
|
|
place = fluid.CPUPlace()
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
input1 = np.random.random([1, 10]).astype('float64')
|
|
|
|
input1 = np.random.random([1, 10]).astype('float64')
|
|
|
@ -345,7 +353,7 @@ class API_TestSplit4(unittest.TestCase):
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
with fluid.program_guard(fluid.Program(), fluid.Program()):
|
|
|
|
data = fluid.layers.data('data', shape=[-1, 10], dtype='float64')
|
|
|
|
data = fluid.layers.data('data', shape=[-1, 10], dtype='float64')
|
|
|
|
index = fluid.layers.data('index', shape=[1], dtype='int32')
|
|
|
|
index = fluid.layers.data('index', shape=[1], dtype='int32')
|
|
|
|
x0, x1 = paddle.split(data, num_or_sections=(3, index), dim=1)
|
|
|
|
x0, x1 = paddle.split(data, num_or_sections=(3, index), axis=1)
|
|
|
|
place = fluid.CPUPlace()
|
|
|
|
place = fluid.CPUPlace()
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
input1 = np.random.random([1, 10]).astype('float64')
|
|
|
|
input1 = np.random.random([1, 10]).astype('float64')
|
|
|
@ -359,12 +367,58 @@ class API_TestSplit4(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class API_TestDygraphSplit(unittest.TestCase):
|
|
|
|
class API_TestDygraphSplit(unittest.TestCase):
|
|
|
|
def test_out(self):
|
|
|
|
def test_out1(self):
|
|
|
|
|
|
|
|
with fluid.dygraph.guard():
|
|
|
|
|
|
|
|
input_1 = np.random.random([4, 6, 6]).astype("int32")
|
|
|
|
|
|
|
|
# input is a variable which shape is [4, 6, 6]
|
|
|
|
|
|
|
|
input = fluid.dygraph.to_variable(input_1)
|
|
|
|
|
|
|
|
x0, x1, x2 = paddle.split(input, num_or_sections=3, axis=1)
|
|
|
|
|
|
|
|
x0_out = x0.numpy()
|
|
|
|
|
|
|
|
x1_out = x1.numpy()
|
|
|
|
|
|
|
|
x2_out = x2.numpy()
|
|
|
|
|
|
|
|
ex_x0, ex_x1, ex_x2 = np.split(input_1, 3, axis=1)
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x0, x0_out))
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x1, x1_out))
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x2, x2_out))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_out2(self):
|
|
|
|
|
|
|
|
with fluid.dygraph.guard():
|
|
|
|
|
|
|
|
input_1 = np.random.random([4, 6, 6]).astype("bool")
|
|
|
|
|
|
|
|
# input is a variable which shape is [4, 6, 6]
|
|
|
|
|
|
|
|
input = fluid.dygraph.to_variable(input_1)
|
|
|
|
|
|
|
|
x0, x1, x2 = paddle.split(input, num_or_sections=3, axis=1)
|
|
|
|
|
|
|
|
x0_out = x0.numpy()
|
|
|
|
|
|
|
|
x1_out = x1.numpy()
|
|
|
|
|
|
|
|
x2_out = x2.numpy()
|
|
|
|
|
|
|
|
ex_x0, ex_x1, ex_x2 = np.split(input_1, 3, axis=1)
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x0, x0_out))
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x1, x1_out))
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x2, x2_out))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_out_tensor_input(self):
|
|
|
|
|
|
|
|
with fluid.dygraph.guard():
|
|
|
|
|
|
|
|
input_1 = np.random.random([4, 6, 6]).astype("int32")
|
|
|
|
|
|
|
|
# input is a variable which shape is [4, 6, 6]
|
|
|
|
|
|
|
|
input = fluid.dygraph.to_variable(input_1)
|
|
|
|
|
|
|
|
num1 = paddle.full(shape=[1], fill_value=2, dtype='int32')
|
|
|
|
|
|
|
|
x0, x1, x2 = paddle.split(
|
|
|
|
|
|
|
|
input, num_or_sections=[num1, 2, 2], axis=1)
|
|
|
|
|
|
|
|
x0_out = x0.numpy()
|
|
|
|
|
|
|
|
x1_out = x1.numpy()
|
|
|
|
|
|
|
|
x2_out = x2.numpy()
|
|
|
|
|
|
|
|
ex_x0, ex_x1, ex_x2 = np.split(input_1, 3, axis=1)
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x0, x0_out))
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x1, x1_out))
|
|
|
|
|
|
|
|
self.assertTrue(np.allclose(ex_x2, x2_out))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_axis_tensor_input(self):
|
|
|
|
with fluid.dygraph.guard():
|
|
|
|
with fluid.dygraph.guard():
|
|
|
|
input_1 = np.random.random([4, 6, 6]).astype("int32")
|
|
|
|
input_1 = np.random.random([4, 6, 6]).astype("int32")
|
|
|
|
# input is a variable which shape is [4, 6, 6]
|
|
|
|
# input is a variable which shape is [4, 6, 6]
|
|
|
|
input = fluid.dygraph.to_variable(input_1)
|
|
|
|
input = fluid.dygraph.to_variable(input_1)
|
|
|
|
x0, x1, x2 = paddle.split(input, num_or_sections=3, dim=1)
|
|
|
|
num1 = paddle.full(shape=[1], fill_value=1, dtype='int32')
|
|
|
|
|
|
|
|
x0, x1, x2 = paddle.split(
|
|
|
|
|
|
|
|
input, num_or_sections=[2, 2, 2], axis=num1)
|
|
|
|
x0_out = x0.numpy()
|
|
|
|
x0_out = x0.numpy()
|
|
|
|
x1_out = x1.numpy()
|
|
|
|
x1_out = x1.numpy()
|
|
|
|
x2_out = x2.numpy()
|
|
|
|
x2_out = x2.numpy()
|
|
|
|