Generalize `sum_intlist` and `prod_intlist`, clean up dimensionality functions (#50495)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/50495
Test Plan:
```
buck test mode/opt //caffe2/c10:c10_test_0
```
Reviewed By: ngimel
Differential Revision: D25902853
fbshipit-source-id: a7d30251ca443df57dd8005ed77dba7b2f1002d4