Skip to content

Commit

Permalink
Merge pull request scipy#43 from GaelVaroquaux/master
Browse files Browse the repository at this point in the history
Minor clean up.  Tests pass for me now.
  • Loading branch information
scopatz committed Jul 22, 2011
2 parents c7503ea + aa80ab6 commit f5eac13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 129 deletions.
72 changes: 0 additions & 72 deletions scipy/sparse/sparsetools/csgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,75 +74,3 @@ I cs_graph_components(const I n_nod,
}

#endif
#ifndef __CSGRAPH_H__
#define __CSGRAPH_H__

#include <vector>

/*
* Determine connected compoments of a compressed sparse graph.
* Note:
* Output array flag must be preallocated
*/
template <class I>
I cs_graph_components(const I n_nod,
const I Ap[],
const I Aj[],
I flag[])
{
// pos is a work array: list of nodes (rows) to process.
std::vector<I> pos(n_nod,01);
I n_comp;
I n_tot, n_pos, n_pos_new, n_pos0, n_new, n_stop;
I icomp, ii, ir, ic;

n_stop = n_nod;
for (ir = 0; ir < n_nod; ir++) {
flag[ir] = -1;
if ((Ap[ir+1] - Ap[ir]) == 0) n_stop--;
}

n_tot = 0;
for (icomp = 0; icomp < n_nod; icomp++) {
// Find seed.
ii = 0;
while (flag[ii] >= 0) {
ii++;
if (ii >= n_nod) {
/* Sanity check, if this happens, the graph is corrupted. */
return -1;
}
}
flag[ii] = icomp;
pos[0] = ii;
n_pos0 = 0;
n_pos_new = n_pos = 1;

for (ii = 0; ii < n_nod; ii++) {
n_new = 0;
for (ir = n_pos0; ir < n_pos; ir++) {
for (ic = Ap[pos[ir]]; ic < Ap[pos[ir]+1]; ic++) {
if (flag[Aj[ic]] == -1) {
flag[Aj[ic]] = icomp;
pos[n_pos_new] = Aj[ic];
n_pos_new++;
n_new++;
}
}
}
n_pos0 = n_pos;
n_pos = n_pos_new;
if (n_new == 0) break;
}
n_tot += n_pos;

if (n_tot == n_stop) {
n_comp = icomp + 1;
break;
}
}

return n_comp;
}

#endif
2 changes: 1 addition & 1 deletion scipy/sparse/sparsetools/csgraph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 2.0.1+capsulehack
# Version 1.3.40
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
Expand Down
75 changes: 19 additions & 56 deletions scipy/sparse/sparsetools/csgraph_wrap.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 2.0.1+capsulehack
* Version 1.3.40
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
Expand Down Expand Up @@ -201,7 +201,7 @@ template <typename T> T SwigValueInit() {
/*
Flags/methods for returning states.
The SWIG conversion methods, as ConvertPtr, return an integer
The SWIG conversion methods, as ConvertPtr, return and integer
that tells if the conversion was successful or not. And if not,
an error code can be returned (see swigerrors.swg for the codes).
Expand Down Expand Up @@ -1088,6 +1088,9 @@ SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func)


/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* pyrun.swg
*
* This file contains the runtime support for Python modules
Expand Down Expand Up @@ -1134,18 +1137,8 @@ SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func)
#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg
#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code)
#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg)
#define SWIG_fail goto fail
#define SWIG_fail goto fail

/*
* Python 2.7 and newer and Python 3.1 and newer should use Capsules API instead of
* CObjects API.
*/
#if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION > 6) || \
(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 0))
#define USE_CAPSULES
#define TYPE_POINTER_NAME \
((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
#endif

/* Runtime API implementation */

Expand Down Expand Up @@ -2078,13 +2071,10 @@ _SWIG_This(void)
return SWIG_Python_str_FromChar("this");
}

static PyObject *swig_this = NULL;

SWIGRUNTIME PyObject *
SWIG_This(void)
{
if (swig_this == NULL)
swig_this = _SWIG_This();
static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This();
return swig_this;
}

Expand Down Expand Up @@ -2188,7 +2178,7 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
int newmemory = 0;
*ptr = SWIG_TypeCast(tc,vptr,&newmemory);
if (newmemory == SWIG_CAST_NEW_MEMORY) {
assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
assert(own);
if (own)
*own = *own | SWIG_CAST_NEW_MEMORY;
}
Expand Down Expand Up @@ -2457,13 +2447,9 @@ SWIG_Python_GetModule(void) {
if (!type_pointer) {
#ifdef SWIG_LINK_RUNTIME
type_pointer = SWIG_ReturnGlobalTypeList((void *)0);
#else
#ifdef USE_CAPSULES
type_pointer = PyCapsule_Import(TYPE_POINTER_NAME, 0);
#else
type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
(char*)"type_pointer" SWIG_TYPE_TABLE_NAME);
#endif
if (PyErr_Occurred()) {
PyErr_Clear();
type_pointer = (void *)0;
Expand Down Expand Up @@ -2508,14 +2494,9 @@ PyModule_AddObject(PyObject *m, char *name, PyObject *o)
SWIGRUNTIME void
SWIG_Python_DestroyModule(void *vptr)
{
size_t i;
#ifdef USE_CAPSULES
swig_module_info *swig_module =
(swig_module_info *) PyCapsule_GetPointer((PyObject *)vptr, TYPE_POINTER_NAME);
#else
swig_module_info *swig_module = (swig_module_info *) vptr;
#endif
swig_type_info **types = swig_module->types;
size_t i;
for (i =0; i < swig_module->size; ++i) {
swig_type_info *ty = types[i];
if (ty->owndata) {
Expand All @@ -2524,7 +2505,6 @@ SWIG_Python_DestroyModule(void *vptr)
}
}
Py_DECREF(SWIG_This());
swig_this = NULL;
}

SWIGRUNTIME void
Expand All @@ -2538,18 +2518,9 @@ SWIG_Python_SetModule(swig_module_info *swig_module) {
PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
swig_empty_runtime_method_table);
#endif
#ifdef USE_CAPSULES
PyObject *pointer = PyCapsule_New((void *)swig_module, TYPE_POINTER_NAME,
(PyCapsule_Destructor)SWIG_Python_DestroyModule);
#else
PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule);
#endif
if (pointer && module) {
#ifdef USE_CAPSULES
PyModule_AddObject(module, (char*)"type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer);
#else
PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer);
#endif
} else {
Py_XDECREF(pointer);
}
Expand All @@ -2570,20 +2541,12 @@ SWIG_Python_TypeQuery(const char *type)
PyObject *obj = PyDict_GetItem(cache, key);
swig_type_info *descriptor;
if (obj) {
#ifdef USE_CAPSULES
descriptor = (swig_type_info *) PyCapsule_GetPointer(obj, type);
#else
descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj);
#endif
} else {
swig_module_info *swig_module = SWIG_Python_GetModule();
descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type);
if (descriptor) {
#ifdef USE_CAPSULES
obj = PyCapsule_New(descriptor, type, NULL);
#else
obj = PyCObject_FromVoidPtr(descriptor, NULL);
#endif
PyDict_SetItem(cache, key, obj);
Py_DECREF(obj);
}
Expand Down Expand Up @@ -2745,7 +2708,7 @@ static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0};
#endif
#define SWIG_name "_csgraph"

#define SWIGVERSION 0x020001
#define SWIGVERSION 0x010340
#define SWIG_VERSION SWIGVERSION


Expand Down Expand Up @@ -3957,15 +3920,15 @@ extern "C" {
}
}
if (ci) {
void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
if (ptr) {
size_t shift = (ci->ptype) - types;
swig_type_info *ty = types_initial[shift];
size_t ldoc = (c - methods[i].ml_doc);
size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
char *ndoc = (char*)malloc(ldoc + lptr + 10);
if (ndoc) {
char *buff = ndoc;
size_t shift = (ci->ptype) - types;
swig_type_info *ty = types_initial[shift];
size_t ldoc = (c - methods[i].ml_doc);
size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
char *ndoc = (char*)malloc(ldoc + lptr + 10);
if (ndoc) {
char *buff = ndoc;
void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
if (ptr) {
strncpy(buff, methods[i].ml_doc, ldoc);
buff += ldoc;
strncpy(buff, "swig_ptr: ", 10);
Expand Down

0 comments on commit f5eac13

Please sign in to comment.