Jun-22-2020, 10:20 AM
Hello.
I'm trying to solve this problem but still in pycharm, when i'm looking at my function argument
name i see only "*args" and "**kwargs" despite "labels_list" which i set while defining my function in
C++.
I can pass argument with keyword "labels_list" or without it, but i can't see this argument name
in function arguments list in PyCharm.
Here is my code:
I'm trying to solve this problem but still in pycharm, when i'm looking at my function argument
name i see only "*args" and "**kwargs" despite "labels_list" which i set while defining my function in
C++.
I can pass argument with keyword "labels_list" or without it, but i can't see this argument name
in function arguments list in PyCharm.
Here is my code:
static PyObject* encode_one_hot(PyObject* self, PyObject* args, PyObject* kwargs) { PyArrayObject* labels = NULL; PyArrayObject* one_hot; npy_intp dims[2]; map<int, int> classes_map; int current_label; int labels_size; int new_numeration = 0; void* ptr; static char* kwlist[] = { (char*)"labels_list", NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &labels)) return NULL; PyArray_Sort(labels, 0, NPY_QUICKSORT); labels_size = PyArray_SIZE(labels); for (int i = 0; i < labels_size; i++) { ptr = PyArray_GETPTR1(labels, i); current_label = PyLong_AsLong(PyArray_GETITEM(labels, ptr)); if (classes_map.find(current_label) == classes_map.end()) { classes_map[current_label] = new_numeration; new_numeration++; } } dims[0] = labels_size; dims[1] = (int)classes_map.size(); one_hot = (PyArrayObject*)PyArray_ZEROS(2, dims, NPY_INT, 0); for (int i = 0; i < labels_size; i++) { current_label = classes_map[PyLong_AsLong(PyArray_GETITEM(labels, PyArray_GETPTR1(labels, i)))]; ptr = PyArray_GETPTR2(one_hot, i, current_label); PyArray_SETITEM(one_hot, ptr, PyLong_FromLong(1)); } return PyArray_Return(one_hot); }I'll be very gratefull for help :)