Python Forum
How to give a name to function arguments in C-API?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to give a name to function arguments in C-API?
#1
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:

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 :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  calling external function with arguments Wimpy_Wellington 7 1,438 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  'namespace' shorthand for function arguments? shadowphile 5 2,600 Aug-11-2021, 09:02 PM
Last Post: shadowphile
  Checking the number of arguments a function takes Chirumer 3 2,162 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  Possible to dynamically pass arguments to a function? grimm1111 2 2,197 Feb-21-2021, 05:57 AM
Last Post: deanhystad
  How to pass multiple arguments into function Mekala 4 2,455 Jul-11-2020, 07:03 AM
Last Post: Mekala
  Function Recognises Variable Without Arguments Or Global Variable Calling. OJGeorge4 1 2,250 Apr-06-2020, 09:14 AM
Last Post: bowlofred
  Pass Arguments to Function phillyfa 2 2,027 Mar-27-2020, 12:05 PM
Last Post: phillyfa
  Function with many arguments, with some default values medatib531 3 2,600 Mar-14-2020, 02:39 AM
Last Post: medatib531
  Using function *args to multiply multiple arguments allusernametaken 8 6,087 Nov-20-2019, 12:01 AM
Last Post: allusernametaken
  How to access arguments by name from function SriRajesh 7 2,832 Sep-19-2019, 07:14 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020