Files
pytorch/torch/csrc/utils.cpp
Soumith Chintala 5ee3358a92 python 2 support
2016-06-08 19:14:57 -04:00

22 lines
540 B
C++

#include <Python.h>
#include "THP.h"
#include "generic/utils.cpp"
#include <TH/THGenerateAllTypes.h>
int THPUtils_getLong(PyObject *index, long *result) {
if (PyLong_Check(index)) {
*result = PyLong_AsLong(index);
} else if (PyInt_Check(index)) {
*result = PyInt_AsLong(index);
} else {
char err_string[512];
snprintf (err_string, 512, "%s %s",
"getLong expected int or long, but got type: ",
index->ob_type->tp_name);
PyErr_SetString(PyExc_RuntimeError, err_string);
return 0;
}
return 1;
}