From e1b5dbf699a0c1e948c692767288a34482c37f8a Mon Sep 17 00:00:00 2001 From: SsnL Date: Mon, 10 Dec 2018 07:33:26 -0800 Subject: [PATCH] Allow converting CharTensor to np arrays (#14710) Summary: The other direction of #14700 cc soumith Pull Request resolved: https://github.com/pytorch/pytorch/pull/14710 Reviewed By: weiyangfb Differential Revision: D13306052 Pulled By: soumith fbshipit-source-id: 202d038f139cf05e01069ff8d05268c66354c983 --- test/test_torch.py | 2 ++ torch/csrc/utils/tensor_numpy.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/test/test_torch.py b/test/test_torch.py index b3acca5..fb4b676 100644 --- a/test/test_torch.py +++ b/test/test_torch.py @@ -8643,6 +8643,8 @@ tensor([[[1., 1., 1., ..., 1., 1., 1.], def test_toNumpy(self): types = [ 'torch.ByteTensor', + 'torch.CharTensor', + 'torch.ShortTensor', 'torch.IntTensor', 'torch.HalfTensor', 'torch.FloatTensor', diff --git a/torch/csrc/utils/tensor_numpy.cpp b/torch/csrc/utils/tensor_numpy.cpp index bc9791c..ed91cd6 100644 --- a/torch/csrc/utils/tensor_numpy.cpp +++ b/torch/csrc/utils/tensor_numpy.cpp @@ -152,6 +152,7 @@ static int aten_to_dtype(const at::Type& type) { case kLong: return NPY_INT64; case kInt: return NPY_INT32; case kShort: return NPY_INT16; + case kChar: return NPY_INT8; case kByte: return NPY_UINT8; default: break; } -- 2.7.4