[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] perl bindings
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] perl bindings |
Date: |
Sun, 7 Mar 2010 11:29:39 +0000 |
Hi John,
> 1) Make a simple binding of igraph data types to perl
> objects (and maybe add named arguments etc, which is fairly
> easy, but would require more hand coding). But perl has no
> native C-,Fortran- like array type, so flexible IO, etc. would
> be problematic. Did someone say python does have such a native
> data type ?
Well, Python does have an array-like data type in the NumPy (Numeric Python)
module, but this is not part of Python's standard library and igraph does not
use it. igraph simply uses standard Python lists in place of igraph_vector_t
objects and they are converted on-the-fly to igraph_vector_t before calling an
internal igraph function. Lists of lists are converted to igraph_matrix_t.
Basically, for most of igraph's internal data types, the source code of the
Python interface contains a conversion function that takes an arbitrary Python
object and decides whether it can be converted to the target igraph data type.
If so, it also does the conversion, if not, it raises the appropriate Python
exception which is then propagated back to the Python interpreter. The actual
methods of the Graph class in Python then simply call the conversion functions
for each input argument, call the appropriate igraph function with the
converted arguments, then take the result and convert them back to Python. It
is so straightforward that it could even have been generated by a script; in
fact, the vast majority of the code for the R interface is generated by
tools/stimulus.py in the source tree, which takes the interface definitions
from interfaces/functions.def and some code snippets from
interfaces/R/types-C.def and interfaces/R/types-R.def. If you decide to build a
Perl interface for igraph, consider hacking tools/stimulus.py (by extending it
with a Perl code generator based on the already existing R and Java code
generators) and using that instead of coding your interface manually.
--
Tamas