some work towards objectifying the UFuncs

This commit is contained in:
Daniel Knüttel 2019-07-12 10:48:49 +02:00
parent 0de1c3e14e
commit aacd1473aa
2 changed files with 54 additions and 28 deletions

View File

@ -30,24 +30,14 @@ interaction_ufunc_force
, void * data) , void * data)
{ {
char * in = args[0] char * in = args[0]
, * raw_coefficients = args[1] , * out = args[1];
, * out = args[2];
npy_intp n = dimensions[0]; npy_intp n = dimensions[0];
npy_intp in_step = steps[0] npy_intp in_step = steps[0]
, raw_coefficients_steps = steps[1] , out_step = steps[1];
, out_step = steps[2];
npy_intp i; npy_intp i;
// Copy the coefficients to a safe array. float * coefficients = (float *) data;
// This is because NumPy arrays are not
// necessarily cast-safe.
float coefficients[19];
for(i = 0; i < 19; i++)
{
coefficients[i] = *(float *)raw_coefficients;
raw_coefficients += raw_coefficients_steps;
}
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
{ {
@ -73,27 +63,17 @@ interaction_ufunc_float2D
, * y_old = args[1] , * y_old = args[1]
, * p_x_old = args[2] , * p_x_old = args[2]
, * p_y_old = args[3] , * p_y_old = args[3]
, * raw_coefficients = args[4] , * p_x_new = args[4]
, * p_x_new = args[5] , * p_y_new = args[5];
, * p_y_new = args[6];
npy_intp x_old_steps = steps[0] npy_intp x_old_steps = steps[0]
, y_old_steps = steps[1] , y_old_steps = steps[1]
, p_x_old_steps = steps[2] , p_x_old_steps = steps[2]
, p_y_old_steps = steps[3] , p_y_old_steps = steps[3]
, raw_coefficients_steps = steps[4] , p_x_new_steps = steps[4]
, p_x_new_steps = steps[5] , p_y_new_steps = steps[5];
, p_y_new_steps = steps[6];
// Copy the coefficients to a safe array. float *coefficients = (float *) data;
// This is because NumPy arrays are not
// necessarily cast-safe.
float coefficients[19];
for(i = 0; i < 19; i++)
{
coefficients[i] = *(float *)raw_coefficients;
raw_coefficients += raw_coefficients_steps;
}
// Compute the new momenta: // Compute the new momenta:
@ -143,6 +123,46 @@ interaction_ufunc_float2D
} }
} }
typedef struct
{
PyObject_HEAD
float coefficients[16];
PyObject * ufunc;
} interaction_UFuncWrapper;
static PyTypeObject interaction_UFuncWrapperType
{
PyTypeObject_HEAD_INIT(NULL, 0)
.tp_name = "brown.interaction.UFuncWrapper",
.tp_doc = "A wrapper that wraps the ufuncs for interaction and force, storing the coeficients",
.tp_basicsize = sizeof(interaction_UFuncWrapper),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
};
static int
interaction_UFuncWrapper_init
( interaction_UFuncWrapper * self
, PyObject * args
, PyObject * kwds)
{
char type;
PyObject * coefficients;
if(!PyArgs_ParseTupleAndKeywords(args, kwds, "" // FIXME
}
static PyObject *
interaction_UFuncWrapper_call
(interaction_UFuncWrapper * self,
PyObject * data)
{
return
}
static PyMethodDef InteractionMethods[] = { static PyMethodDef InteractionMethods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };

View File

@ -28,5 +28,11 @@ interaction_ufunc_float2D
, npy_intp * steps , npy_intp * steps
, void * data); , void * data);
static void
interaction_ufunc_force
( char ** args
, npy_intp * dimensions
, npy_intp * steps
, void * data)
#endif #endif