[pytorch] flatten_indices function should use vector::resize instead of reserve (#73831)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73831
stderr:
test_jagged_2d_to_dense_truncation (deeplearning.fbgemm.fbgemm_gpu.test.sparse_ops_test.SparseOpsTest) ... third-party-buck/platform010/build/libgcc/include/c++/trunk/bits/stl_vector.h:1045: std::vector::reference std::vector<long>::operator[](std::vector::size_type) [_Tp = long, _Alloc = std::allocator<long>]: Assertion '__n < this->size()' failed.
After some digging, we found the issue is not caused by fbgemm. It is caused by the underlying coo_sparse_tensor.to_dense() function, which fails for all sparse tensors on platform010, because of the misuse of vector::reserve in flatten_indices function.
Test Plan: buck test mode/dev -c fbcode.platform=platform010 //deeplearning/fbgemm/fbgemm_gpu:sparse_ops_test -- test_jagged_2d_to_dense_truncation
Reviewed By: jspark1105
Differential Revision: D34665804
fbshipit-source-id: 685cfd516fded224cfdb44b5a5f18c2d8e0ec644
(cherry picked from commit 0c33c3a8499d58149afa7b54a333e5b28803210b)