mirror of https://github.com/Jittor/Jittor
fix: support reshape empty var with uncertain dimension
This commit is contained in:
parent
e661f19e20
commit
05ed6c7e34
|
@ -44,8 +44,12 @@ void ReshapeOp::infer_shape() {
|
|||
if (uncertain_dim == 0) {
|
||||
CHECKop(x_items,==,y_items) << "reshape shape is invalid for input of size";
|
||||
} else {
|
||||
CHECK(y_items != 0 && x_items % y_items == 0) << "reshape shape is invalid for input of size " << x_items;
|
||||
uncertain_dim = x_items / y_items;
|
||||
if (x_items == 0) {
|
||||
uncertain_dim = 0;
|
||||
} else {
|
||||
CHECK(y_items != 0 && x_items % y_items == 0) << "reshape shape is invalid for input of size " << x_items;
|
||||
uncertain_dim = x_items / y_items;
|
||||
}
|
||||
yshape.clear();
|
||||
for (auto a : shape)
|
||||
yshape.push_back(a<0 ? uncertain_dim : a);
|
||||
|
|
|
@ -75,6 +75,13 @@ class TestReshapeOp(unittest.TestCase):
|
|||
a = jt.zeros(10)
|
||||
b = a.reshape(a.shape)
|
||||
|
||||
def test_reshape_empty(self):
|
||||
a = jt.array([])
|
||||
b = a.reshape(0, 1, 2)
|
||||
assert b.shape == [0, 1, 2]
|
||||
b = a.reshape(0, -1)
|
||||
assert b.shape == [0, 0]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in New Issue