mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Remove TH/THC Storage functions for unused dtypes (#67480)
Summary: Fixes https://github.com/pytorch/pytorch/issues/67466 Pull Request resolved: https://github.com/pytorch/pytorch/pull/67480 Reviewed By: mruberry Differential Revision: D32023494 Pulled By: ngimel fbshipit-source-id: 8827e1d6e765fee7219b5ee9888a1a3e3c5fbe89
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a122ba776a
commit
4d99bc839b
@ -22,37 +22,6 @@ int THPUtils_getCallable(PyObject *arg, PyObject **result) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
THLongStoragePtr THPUtils_unpackSize(PyObject *arg) {
|
||||
THLongStoragePtr result;
|
||||
if (!THPUtils_tryUnpackLongs(arg, result)) {
|
||||
std::string msg = "THPUtils_unpackSize() expects a torch.Size (got '";
|
||||
msg += Py_TYPE(arg)->tp_name;
|
||||
msg += "')";
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool THPUtils_tryUnpackLongs(PyObject *arg, THLongStoragePtr& result) {
|
||||
bool tuple = PyTuple_Check(arg);
|
||||
bool list = PyList_Check(arg);
|
||||
if (tuple || list) {
|
||||
// NOLINTNEXTLINE(bugprone-branch-clone)
|
||||
const auto nDim = tuple ? PyTuple_GET_SIZE(arg) : PyList_GET_SIZE(arg);
|
||||
THLongStoragePtr storage(THLongStorage_newWithSize(nDim));
|
||||
for (int i = 0; i != nDim; ++i) {
|
||||
PyObject* item = tuple ? PyTuple_GET_ITEM(arg, i) : PyList_GET_ITEM(arg, i);
|
||||
if (!THPUtils_checkLong(item)) {
|
||||
return false;
|
||||
}
|
||||
THLongStorage_set(storage, i, THPUtils_unpackLong(item));
|
||||
}
|
||||
result = std::move(storage);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<int64_t> THPUtils_unpackLongs(PyObject *arg) {
|
||||
bool tuple = PyTuple_Check(arg);
|
||||
bool list = PyList_Check(arg);
|
||||
@ -74,29 +43,6 @@ std::vector<int64_t> THPUtils_unpackLongs(PyObject *arg) {
|
||||
throw std::runtime_error("Expected tuple or list");
|
||||
}
|
||||
|
||||
bool THPUtils_tryUnpackLongVarArgs(PyObject *args, int ignore_first, THLongStoragePtr& result) {
|
||||
Py_ssize_t length = PyTuple_Size(args) - ignore_first;
|
||||
if (length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PyObject *first_arg = PyTuple_GET_ITEM(args, ignore_first);
|
||||
if (length == 1 && THPUtils_tryUnpackLongs(first_arg, result)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Try to parse the numbers
|
||||
result = THLongStorage_newWithSize(length);
|
||||
for (Py_ssize_t i = 0; i < length; ++i) {
|
||||
PyObject *arg = PyTuple_GET_ITEM(args, i + ignore_first);
|
||||
if (!THPUtils_checkLong(arg)) {
|
||||
return false;
|
||||
}
|
||||
THLongStorage_set(result, i, THPUtils_unpackLong(arg));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool THPUtils_checkIntTuple(PyObject *arg)
|
||||
{
|
||||
if (!PyTuple_Check(arg)) {
|
||||
|
Reference in New Issue
Block a user