Skip to content

Commit

Permalink
Implement #1077 update with docstring and type hinting.
Browse files Browse the repository at this point in the history
Implement #1077 update with docstring and type hinting. Note that black adds
spaces in the method signature type hinting for the `padding` argument. We add
a docstring for _build_spare_tensor(), as this is being modified in this
issue's implementation. The motivation for this is improved codebase
readability.
  • Loading branch information
Adam Lesnikowski committed Sep 16, 2021
1 parent d9e457d commit e25c6e8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion nvtabular/loader/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,32 @@ def _get_sparse_tensor(self, values, indices, num_rows, seq_limit):
return sparse_tensor

def _build_sparse_tensor(
self, values, offsets, diff_offsets, num_rows, seq_limit, padding=None
self, values, offsets, diff_offsets, num_rows, seq_limit, padding: str = ""
):
"""Builds sparse tensors in our torch dataloader.
Parameters
----------
values :
offsets :
diff_offsets :
num_rows :
seq_limit :
padding : str, optional
Padding mode, choose among 'left' for left padding, 'right' for right padding,
or '' for no padding, by default ''
Returns
-------
torch.sparse
Our built torch sparse tensor.
Raises
------
NotImplementedError
Raises this error when this method is called with a not implemented
padding mode string.
"""
indices = self._get_indices(offsets, diff_offsets)
if padding == "left":
indices[:, 1] = seq_limit - 1 - indices[:, 1]
Expand Down

0 comments on commit e25c6e8

Please sign in to comment.