Skip to content
Snippets Groups Projects
Commit a6a253d1 authored by Kipp Cannon's avatar Kipp Cannon
Browse files

snglinspiraltable: more performance work

- move more performance-critical methods into the C layer, this time the
  rich comparison methods
parent 206d2e52
No related branches found
No related tags found
No related merge requests found
......@@ -410,6 +410,77 @@ static struct PyMethodDef methods[] = {
};
/*
* comparison is defined specifically for the coincidence code, allowing a
* bisection search of a sorted trigger list to be used to identify the
* subset of triggers that fall within a time interval
*/
static PyObject *richcompare(PyObject *self, PyObject *other, int op_id)
{
PyObject *converted = PyObject_CallFunctionObjArgs(LIGOTimeGPSType, other, NULL);
PyObject *attr;
PyObject *result;
LIGOTimeGPS t_other;
int cmp;
if(!converted)
return NULL;
attr = PyObject_GetAttrString(converted, "gpsSeconds");
if(!attr) {
Py_DECREF(converted);
return NULL;
}
t_other.gpsSeconds = PyInt_AsLong(attr);
Py_DECREF(attr);
attr = PyObject_GetAttrString(converted, "gpsNanoSeconds");
if(!attr) {
Py_DECREF(converted);
return NULL;
}
t_other.gpsNanoSeconds = PyInt_AsLong(attr);
Py_DECREF(attr);
Py_DECREF(converted);
cmp = XLALGPSCmp(&((gstlal_GSTLALSnglInspiral *) self)->row.end, &t_other);
switch(op_id) {
case Py_LT:
result = (cmp < 0) ? Py_True : Py_False;
break;
case Py_LE:
result = (cmp <= 0) ? Py_True : Py_False;
break;
case Py_EQ:
result = (cmp == 0) ? Py_True : Py_False;
break;
case Py_NE:
result = (cmp != 0) ? Py_True : Py_False;
break;
case Py_GE:
result = (cmp >= 0) ? Py_True : Py_False;
break;
case Py_GT:
result = (cmp > 0) ? Py_True : Py_False;
break;
default:
PyErr_BadInternalCall();
return NULL;
}
Py_INCREF(result);
return result;
}
/*
* Type
*/
......@@ -426,6 +497,7 @@ static PyTypeObject gstlal_GSTLALSnglInspiral_Type = {
.tp_name = MODULE_NAME ".GSTLALSnglInspiral",
.tp_new = __new__,
.tp_dealloc = __del__,
.tp_richcompare = richcompare,
};
......
......@@ -33,31 +33,6 @@ class GSTLALSnglInspiral(_snglinspiraltable.GSTLALSnglInspiral):
spin1 = lsctables.SnglInspiral.spin1
spin2 = lsctables.SnglInspiral.spin2
#
# comparison is defined specifically for the coincidence code,
# allowing a bisection search of a sorted trigger list to be used
# to identify the subset of triggers that fall within a time
# interval
#
def __eq__(self, other):
return self.end == other
def __ne__(self, other):
return self.end != other
def __lt__(self, other):
return self.end < other
def __le__(self, other):
return self.end <= other
def __gt__(self, other):
return self.end > other
def __ge__(self, other):
return self.end >= other
@property
def process_id(self):
return self.process_id_type(self._process_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment