Skip to content

Conversation

@zasdfgbnm
Copy link
Collaborator

This PR propose the following changes:

  1. Move torch.utils.data.dataset.random_split to torch.utils.data.random_split.
  2. Move torch.utils.data.dataset.Subset to torch.utils.data.Subset.
  3. Add docstring for Subset and expose it.
  4. Change some wording from 'iterable' and 'list' to 'sequence'.

Note:
The relationship between iterable and sequence is stated at python#term-sequence:

(A sequence is) an iterable which supports efficient element access using integer indices via the __getitem__() special method and defines a __len__() method that returns the length of the sequence.

@zasdfgbnm
Copy link
Collaborator Author

Some quick experiments:

import collections
f = open('examples.desktop')
print(isinstance(f, collections.Iterable))
print(isinstance(f, collections.Sequence))
f[0]

gives

True
False
Traceback (most recent call last):
  File "iterable-vs-sequence.py", line 5, in <module>
    f[0]
TypeError: '_io.TextIOWrapper' object is not subscriptable

And

import torch
class A:
	def __getitem__(self,idx):
		if idx == 0:
			return 0
		elif idx == 1:
			return 1
		else:
			raise IndexError('index out of range')
	def __len__(self):
		return 2

print(torch.tensor(A()))

gives

tensor([ 0,  1])

@apaszke
Copy link
Contributor

apaszke commented May 25, 2018

@pytorchbot retest this please

@apaszke apaszke merged commit d7c32df into pytorch:master May 25, 2018
@apaszke
Copy link
Contributor

apaszke commented May 25, 2018

Thanks @zasdfgbnm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants