Skip to content

Commit d2d2979

Browse files
committed
torch: remove unused sparse_row function
1 parent 510511e commit d2d2979

1 file changed

Lines changed: 0 additions & 19 deletions

File tree

src/lenskit/torch.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,6 @@ def wrapper(*args, **kwargs):
2727
return wrapper
2828

2929

30-
def sparse_row(mat: torch.Tensor, row: int) -> torch.Tensor:
31-
"""
32-
Get a row of a sparse (CSR) tensor. This is needed because indexing a
33-
tensor does not work in inference mode.
34-
"""
35-
36-
assert mat.is_sparse_csr
37-
38-
cri = mat.crow_indices()
39-
sp = cri[row]
40-
ep = cri[row + 1]
41-
42-
cs = mat.col_indices()
43-
vs = mat.values()
44-
return torch.sparse_coo_tensor(
45-
indices=cs[sp:ep].reshape(1, -1), values=vs[sp:ep], size=mat.shape[1:]
46-
)
47-
48-
4930
def safe_tensor(array) -> torch.Tensor:
5031
"""
5132
Safely convert an array into a NumPy tensor. This includes copying it to

0 commit comments

Comments
 (0)