Permalink
Browse files

Replace PyNumber_AsDouble by PyFloat_AsDouble, which does the same thing

  • Loading branch information...
Michiel de Hoon Michiel de Hoon
Michiel de Hoon authored and Michiel de Hoon committed Jun 30, 2013
1 parent 35c5e96 commit 0705af84bf376cdaa3a584ae01b3300842dfd327
Showing with 16 additions and 30 deletions.
  1. +16 −30 Bio/cpairwise2module.c
View
@@ -15,21 +15,6 @@
#define _PRECISION 1000
#define rint(x) (int)((x)*_PRECISION+0.5)
-/* Return a PyNumber as a double.
- * Raises a TypeError if I can't do it.
- */
-static double PyNumber_AsDouble(PyObject *py_num)
-{
- double val;
- PyObject *floatobj;
-
- if((floatobj = PyNumber_Float(py_num)) == NULL)
- return(0.0);
- val = PyFloat_AsDouble(floatobj);
- Py_DECREF(floatobj);
- return val;
-}
-
/* Functions in this module. */
double calc_affine_penalty(int length, double open, double extend,
@@ -180,7 +165,7 @@ double _get_match_score(PyObject *py_sequenceA, PyObject *py_sequenceB,
if(!(py_result = PyEval_CallObject(py_match_fn, py_arglist)))
goto _get_match_score_cleanup;
- score = PyNumber_AsDouble(py_result);
+ score = PyFloat_AsDouble(py_result);
_get_match_score_cleanup:
if(py_A) {
Py_DECREF(py_A);
@@ -299,13 +284,13 @@ static PyObject *cpairwise2__make_score_matrix_fast(
use_match_mismatch_scores = 0;
if(!(py_match = PyObject_GetAttrString(py_match_fn, "match")))
goto cleanup_after_py_match_fn;
- match = PyNumber_AsDouble(py_match);
- if(PyErr_Occurred())
+ match = PyFloat_AsDouble(py_match);
+ if(match==-1.0 && PyErr_Occurred())
goto cleanup_after_py_match_fn;
if(!(py_mismatch = PyObject_GetAttrString(py_match_fn, "mismatch")))
goto cleanup_after_py_match_fn;
- mismatch = PyNumber_AsDouble(py_mismatch);
- if(PyErr_Occurred())
+ mismatch = PyFloat_AsDouble(py_mismatch);
+ if(mismtach==-1.0 && PyErr_Occurred())
goto cleanup_after_py_match_fn;
use_match_mismatch_scores = 1;
cleanup_after_py_match_fn:
@@ -346,7 +331,7 @@ static PyObject *cpairwise2__make_score_matrix_fast(
use_sequence_cstring,
match, mismatch,
use_match_mismatch_scores);
- if(PyErr_Occurred())
+ if(score==-1.0 && PyErr_Occurred())
goto _cleanup_make_score_matrix_fast;
if(penalize_end_gaps_B)
score += calc_affine_penalty(i, open_B, extend_B,
@@ -360,7 +345,7 @@ static PyObject *cpairwise2__make_score_matrix_fast(
use_sequence_cstring,
match, mismatch,
use_match_mismatch_scores);
- if(PyErr_Occurred())
+ if(score==-1.0 && PyErr_Occurred())
goto _cleanup_make_score_matrix_fast;
if(penalize_end_gaps_A)
score += calc_affine_penalty(i, open_A, extend_A,
@@ -398,7 +383,7 @@ static PyObject *cpairwise2__make_score_matrix_fast(
int best_score_rint;
struct IndexList *il;
- double score, open_score, extend_score;
+ double score, open_score, extend_score, delta_score;
int open_score_rint, extend_score_rint;
/* Calculate the best score. */
@@ -420,14 +405,15 @@ static PyObject *cpairwise2__make_score_matrix_fast(
best_score_rint = rint(best_score);
/* Set the score and traceback matrices. */
- score = best_score + _get_match_score(py_sequenceA, py_sequenceB,
- py_match_fn, row, col,
- sequenceA, sequenceB,
- use_sequence_cstring,
- match, mismatch,
- use_match_mismatch_scores);
- if(PyErr_Occurred())
+ delta_score = _get_match_score(py_sequenceA, py_sequenceB,
+ py_match_fn, row, col,
+ sequenceA, sequenceB,
+ use_sequence_cstring,
+ match, mismatch,
+ use_match_mismatch_scores);
+ if(delta_score==-1.0 && PyErr_Occurred())
goto _cleanup_make_score_matrix_fast;
+ score = best_score + delta_score;
if(!align_globally && score < 0)
score_matrix[row*lenB+col] = 0;
else

0 comments on commit 0705af8

Please sign in to comment.