pytorch
450221c5 - Sparse CSR: Add tensor.resize_ and tensor.copy_ (#63510)

Commit
3 years ago
Sparse CSR: Add tensor.resize_ and tensor.copy_ (#63510) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/63510 Sparse CSR matrix resizing behavior: If we _increase the number of rows_ the number of specified elements in the matrix remains the same -> the size of col_indices, values doesn't change, the size of crow_indices becomes `rows+1`. If we _decrease the number of rows_ the number of specified elements will be `min(nnz, rows*cols)` -> need to resize `crow_indices` to `rows+1` and set the last element to `min(nnz, rows*cols)`; decrease the size of col_indices and values to `min(nnz, rows*cols)`. If we _increase the number of columns_ the number of specified elements in the matrix remains the same, the number of rows remains the same -> no need to resize anything, just set new sizes. We _cannot decrease the number of columns_ because it would require recomputing `crow_indices`. cc nikitaved pearu cpuhrsch IvanYashchuk Test Plan: Imported from OSS Reviewed By: anjali411 Differential Revision: D31796680 Pulled By: cpuhrsch fbshipit-source-id: 7d8a9701ce06d30a1841f94bba0a057cacea9401
Author
Parents
Loading