pmneila / PyMaxflow

Python library for creating flow networks and computing the maxflow/mincut (aka graph-cuts for Python)
http://pmneila.github.io/PyMaxflow/
242 stars 59 forks source link

Fixes #22 added Graph[int].add_edges and Graph[float].add_edges #23

Closed LeeKamentsky closed 8 years ago

LeeKamentsky commented 8 years ago

Graph.add_edges takes any type and shape of Numpy array and casts each to what's called for in Graph._add_edges. If someone wants to be memory-efficient, they would make sure to use arrays of the correct type, but IMHO, most people will be more casual users and not care.

If you're wondering about the inner loop, Cython boils it down to this:

for (__pyx_v_idx = 0; __pyx_v_idx < __pyx_t_6; __pyx_v_idx++) {
     __pyx_t_7 = __pyx_v_idx;
     __pyx_t_8 = __pyx_v_idx;
    __pyx_t_9 = __pyx_v_idx;
    __pyx_t_10 = __pyx_v_idx;
    try {
      __pyx_v_self->thisptr->add_edge((*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_i.rcbuffer->pybuffer.buf, __pyx_t_7, __pyx_pybuffernd_i.diminfo[0].strides)), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint32_t *, __pyx_pybuffernd_j.rcbuffer->pybuffer.buf, __pyx_t_8, __pyx_pybuffernd_j.diminfo[0].strides)), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_capacity.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_capacity.diminfo[0].strides)), (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_rcapacity.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_rcapacity.diminfo[0].strides)));
    } catch(...) {
      __Pyx_CppExn2PyErr();
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
pmneila commented 8 years ago

Thank you!