#16627 convert weights using torch.as_tensor to avoid warning (#17067)
authorptrblck <piotr.bialecki@hotmail.de>
Thu, 14 Feb 2019 04:42:45 +0000 (20:42 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 14 Feb 2019 04:54:29 +0000 (20:54 -0800)
Summary:
Minor change which fixes #16627
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17067

Differential Revision: D14078726

Pulled By: soumith

fbshipit-source-id: c04a5f1eff44e4a4b04b981f0ae8de6ff018515b

torch/utils/data/sampler.py

index d0ecdb4..ea0564c 100644 (file)
@@ -116,7 +116,7 @@ class WeightedRandomSampler(Sampler):
         if not isinstance(replacement, bool):
             raise ValueError("replacement should be a boolean value, but got "
                              "replacement={}".format(replacement))
-        self.weights = torch.tensor(weights, dtype=torch.double)
+        self.weights = torch.as_tensor(weights, dtype=torch.double)
         self.num_samples = num_samples
         self.replacement = replacement