You should totally check the Python documentation on this issue:
https://docs.python.org/2/extending/
Having the doc in mind you can define a new Type; assuming that stars would be a double precision array:
typedef struct {
PyObject_HEAD
double * Stars;
} Galaxy;
Then define the Math operations method ... (python doc)
static PyObject* Galaxy_calc(Galaxy *self, PyObject *args)
{
double * Star_temp;
/* Your Array is referenced by self->Stars*/
Star_temp = self->Stars;
/* Do the math in C++ */
// All necessary calculations go here.
};
It is fairly easy to include these methods in the new type defined (Galaxy), you just have to set the variables:
static PyMethodDef Galaxy_methods[] =
{
{"calc", (PyCFunction)Galaxy_calc, METH_VARARGS,"Performs stelar calculations."},
{NULL} /* Sentinel */
};
static PyMemberDef Galaxy_members[] =
{ {"Stars", T_OBJECT_EX, offsetof(Galaxy, Galaxy), 0, "Galaxy Stars"},
{NULL} /* Sentinel */
};
Now just include the Galaxy_methods var on the adequate position under
static PyTypeObject Galaxy_GalaxyType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"Galaxy.Galaxy ", /*tp_name*/
sizeof(Galaxy), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)Galaxy_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Galaxy objects", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
Galaxy_methods, /* tp_methods */
Galaxy_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)Galaxy_init, /* tp_init */
0, /* tp_alloc */
Galaxy_new, /* tp_new */
};
Use python documentation refered above to implement new, alloc, dealloc and init methods (these are quite simple) and it is done!