Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions python/paddle/nn/functional/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import annotations

import math
from typing import TYPE_CHECKING, Literal

import numpy
Expand Down Expand Up @@ -2753,6 +2754,9 @@ def fold(
)

assert len(x.shape) == 3, "input should be the format of [N, C, L]"
assert (
math.prod(x.shape) > 0
), "The number of elements must greater than zero."

def _is_list_or_tuple_(data):
return isinstance(data, (list, tuple))
Expand Down
12 changes: 12 additions & 0 deletions test/legacy_test/test_fold_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ def test_GT_0():
strides=0,
)

def test_zero_size():
x = paddle.randn(shape=[0, 1, 1], dtype="float32")
out = fold(
x,
output_sizes=[0, 0],
kernel_sizes=[0, 0],
dilations=0,
paddings=[0, 0],
strides=0,
)

self.assertRaises(AssertionError, test_input_shape)
self.assertRaises(AssertionError, test_kernel_shape)
self.assertRaises(ValueError, test_padding_shape)
Expand All @@ -292,6 +303,7 @@ def test_GT_0():
self.assertRaises(TypeError, test_output_size_2)
self.assertRaises(ValueError, test_block_h_w)
self.assertRaises(ValueError, test_GT_0)
self.assertRaises(AssertionError, test_zero_size)


if __name__ == '__main__':
Expand Down