Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Micro optimizations determined while talking with Tim.
Browse files Browse the repository at this point in the history
  • Loading branch information
freddrake committed May 29, 2002
1 parent 0b14b83 commit d6a3352
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions okascore.c
Expand Up @@ -38,6 +38,10 @@
#define K1 1.2
#define B 0.75

#ifndef PyTuple_CheckExact
#define PyTuple_CheckExact PyTuple_Check
#endif

static PyObject *
score(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -74,8 +78,8 @@ score(PyObject *self, PyObject *args)
d_and_f = PySequence_GetItem(d2fitems, i);
if (d_and_f == NULL)
return NULL;
if (!(PyTuple_Check(d_and_f) &&
PyTuple_Size(d_and_f) == 2)) {
if (!(PyTuple_CheckExact(d_and_f) &&
PyTuple_GET_SIZE(d_and_f) == 2)) {
PyErr_SetString(PyExc_TypeError,
"d2fitems must produce 2-item tuples");
Py_DECREF(d_and_f);
Expand All @@ -89,7 +93,7 @@ score(PyObject *self, PyObject *args)
Py_DECREF(d_and_f);
return NULL;
}
lenweight = B_FROM1 + B * PyInt_AsLong(doclen) / meandoclen;
lenweight = B_FROM1 + B * PyInt_AS_LONG(doclen) / meandoclen;

tf = f * K1_PLUS1 / (f + K1 * lenweight);
scaled_int = PyInt_FromLong((long)(tf * idf + 0.5));
Expand Down

0 comments on commit d6a3352

Please sign in to comment.