| 98 | return outs + (self.index[slc], mask, ) |
| 99 | |
| 100 | def padding_mask(self, features, max_len=None): |
| 101 | # Stack and pad features and masks (convert 2D to 3D tensors, i.e. add batch dimension) |
| 102 | lengths = [X.shape[0] for X in features] # original sequence length for each time series |
| 103 | if max_len is None: |
| 104 | max_len = max(lengths) |
| 105 | |
| 106 | padding_masks = self._padding_mask(torch.tensor(lengths, dtype=torch.int16, device=self.device), max_len=max_len) |
| 107 | # (batch_size, padded_length) boolean tensor, "1" means keep |
| 108 | return padding_masks |
| 109 | |
| 110 | @staticmethod |
| 111 | def _padding_mask(lengths, max_len=None): |