Remove tensorFromBlob() from Type (#18779)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18779
ghimport-source-id: e7453b74fcce0e4f4a9cbce0324992a85272a426

Stack from [ghstack](https://github.com/ezyang/ghstack):
* #18780 Remove tensorWithAllocator() from Type
* **#18779 Remove tensorFromBlob() from Type**

Differential Revision: D14739335

fbshipit-source-id: 8a0619a5b412332efa3b2d60c1edebd53d089d50
This commit is contained in:
Roy Li
2019-04-07 01:35:11 -07:00
committed by Facebook Github Bot
parent 9b69f21a95
commit f6af76ead7
19 changed files with 116 additions and 117 deletions

View File

@ -133,17 +133,22 @@ at::Tensor tensor_from_numpy(PyObject* obj) {
}
void* data_ptr = PyArray_DATA(array);
auto& type = CPU(numpy_dtype_to_aten(PyArray_TYPE(array)));
if (!PyArray_EquivByteorders(PyArray_DESCR(array)->byteorder, NPY_NATIVE)) {
throw ValueError(
"given numpy array has byte order different from the native byte order. "
"Conversion between byte orders is currently not supported.");
}
Py_INCREF(obj);
return type.tensorFromBlob(data_ptr, sizes, strides, [obj](void* data) {
AutoGIL gil;
Py_DECREF(obj);
});
return at::from_blob(
data_ptr,
sizes,
strides,
[obj](void* data) {
AutoGIL gil;
Py_DECREF(obj);
},
at::device(kCPU).dtype(numpy_dtype_to_aten(PyArray_TYPE(array)))
);
}
static int aten_to_dtype(const ScalarType scalar_type) {