/* Copyright 2002 by Jeffrey Chang. All rights reserved. * This code is part of the Biopython distribution and governed by its * license. Please see the LICENSE file that should have been included * as part of this package. * * cdistancemodule.c * Created 12 Jan 2002 * * Optimized C routines that complement distance.py. */ #include "Python.h" #include #include "csupport.h" /* Functions in this module. */ static char cdistance_euclidean__doc__[] = "euclidean(x, y) -> euclidean distance between x and y"; static PyObject * cdistance_euclidean(PyObject *self, PyObject *args) { int i; int length; PyObject *py_x, *py_y; PyObject *py_fastx, *py_fasty; PyObject *py_xi, *py_yi; double xi, yi; double sum; /* This could be optimized a lot more if I operated on the Numeric * Array directly. However, that would seriously compromise the * module's portability... */ if(!PyArg_ParseTuple(args, "OO", &py_x, &py_y)) return NULL; length = PySequence_Size(py_x); if(length < 0) return NULL; if(length != PySequence_Size(py_y)) { PyErr_SetString(PyExc_ValueError, "vectors must be same length"); return NULL; } if(!(py_fastx = PySequence_Fast(py_x, "could not get fast sequence"))) return NULL; if(!(py_fasty = PySequence_Fast(py_y, "could not get fast sequence"))) { Py_DECREF(py_fastx); return NULL; } sum = 0.0; for(i=0; i