Return the feature data. Perform index selecting if needed.
(self)
| 225 | |
| 226 | @property |
| 227 | def data(self): |
| 228 | """Return the feature data. Perform index selecting if needed.""" |
| 229 | if self.index is not None: |
| 230 | if isinstance(self.index, _LazyIndex): |
| 231 | self.index = self.index.flatten() |
| 232 | |
| 233 | storage_ctx = F.context(self.storage) |
| 234 | index_ctx = F.context(self.index) |
| 235 | # If under the special case where the storage is pinned and the index is on |
| 236 | # CUDA, directly call UVA slicing (even if they aree not in the same context). |
| 237 | if ( |
| 238 | storage_ctx != index_ctx |
| 239 | and storage_ctx == F.cpu() |
| 240 | and F.is_pinned(self.storage) |
| 241 | ): |
| 242 | self.storage = gather_pinned_tensor_rows( |
| 243 | self.storage, self.index |
| 244 | ) |
| 245 | else: |
| 246 | # If index and storage is not in the same context, |
| 247 | # copy index to the same context of storage. |
| 248 | # Copy index is usually cheaper than copy data |
| 249 | if storage_ctx != index_ctx: |
| 250 | kwargs = {} |
| 251 | if self.device is not None: |
| 252 | kwargs = self.device[1] |
| 253 | self.index = F.copy_to(self.index, storage_ctx, **kwargs) |
| 254 | self.storage = F.gather_row(self.storage, self.index) |
| 255 | self.index = None |
| 256 | |
| 257 | # move data to the right device |
| 258 | if self.device is not None: |
| 259 | self.storage = F.copy_to( |
| 260 | self.storage, self.device[0], **self.device[1] |
| 261 | ) |
| 262 | self.device = None |
| 263 | |
| 264 | # convert data to the right type |
| 265 | if self.deferred_dtype is not None: |
| 266 | self.storage = F.astype(self.storage, self.deferred_dtype) |
| 267 | self.deferred_dtype = None |
| 268 | return self.storage |
| 269 | |
| 270 | @data.setter |
| 271 | def data(self, val): |