Update start_index and end_index for adaptive pooling (#84010)
### Description
The PR fixes the issue #81409. To fix the issue the procedure of determining start and end indices for adaptive max pooling and average pooling is modified towards integer-only arithmetic.
### Testing
The testing of the new functions is straightforward:
```
#include <iostream>
#include <cassert>
#include <cmath>
int64_t start_index(int64_t a, int64_t b, int64_t c) {
return (int64_t)std::floor((float)(a * c) / b);
}
int64_t end_index(int64_t a, int64_t b, int64_t c) {
return (int64_t)std::ceil((float)((a + 1) * c) / b);
}
int64_t start_index_new(int64_t a, int64_t b, int64_t c) {
return (a / b) * c + ((a % b) * c) / b;
}
int64_t end_index_new(int64_t a, int64_t b, int64_t c) {
return 1 + ((a + 1) * c - 1) / b;
}
int main() {
size_t N = 2<<24;
std::cout<<N<<'\n';
int64_t c = 1;
for(int64_t i=1; i<N; i++) {
for(int64_t j=1; j<N; j++) {
int64_t s_id0 = start_index(i, j, c);
int64_t s_id1 = start_index_new(i, j, c);
assert(s_id0 == s_id1);
}
}
for(int64_t i=1; i<N; i++) {
for(int64_t j=1; j<N; j++) {
int64_t e_id0 = end_index(i, j, c);
int64_t e_id1 = end_index_new(i, j, c);
assert(e_id0 == e_id1);
}
}
}
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/84010
Approved by: https://github.com/ezyang