[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Igraph with JNI

From: Gang Su
Subject: Re: [igraph] Igraph with JNI
Date: Thu, 30 Jul 2009 13:38:42 -0400
User-agent: Internet Messaging Program (IMP) H3 (4.2)


I took a look at some of the c source code and understand what you meant. Actually I have been playing around jna: Java Native Access:


It provides a much nicer way to connect C and Java. There's a tool called


That can help auto generating interfaces to map c functions.
I just began to look at these things yesterday, but I have already successfully connecting c and java over my experiments. I tried a little bit on igraph, the major problem is custom data structrue mapping.

The following data structure can't be mapped directly:

The jna can only define java jna "pointer" association to these data structures. Then the java programmer need to know exactly how these data structures are formed, and extend the pointer class to add functions to find, add, set, retrive data. It can be a little bit complicated.

There are several work arounds:
1. To write a wrapper function to convert primitive java types into igraph types. For example, when a java int[] array is passed, convert to igraph_vector_t first, after computation, assign the values back into int[] array, this will automatically pass the values back to java as the java int[] array were passed into c by reference.

2. Need to know exactly how those data types are defined. Need header files for those data types. If I know how those data types are defined then it's possible to write java interfaces. I couldn't find the definition of these data types header in the include folder... could you tell me where they are?

3. Re-implement the data types in java. This also require me to know the structure of these datatypes and how pointers work on these data types. Take a look at jna pointer api:

This is what i have got so far. I am going to try some small programs to connect java to igraph. I will keep you updated.


Quoting Tamas Nepusz <address@hidden>:

Hi Gang,

Also if you could provide me with some of your proof-of-concept code that will be great.
I will clean up my code soon and commit it to the igraph Launchpad repository so you can take a look at it. The conversion between C and Java is not completely trivial as we have some C functions that are able to return multiple values via input pointers, and this cannot be reproduced easily in Java (e.g., if a community detection routine uses a pointer to a C double to return the modularity of the obtained partition if the pointer is not null, this cannot be translated directly to Java as there's no such thing as a pointer in Java). Anyway, if you take a look at the igraph source tree, we have an interface generator written in Python that is responsible for producing a large amount of glue code between R and C. I started adapting the interface generator to be able to do the same for Java and C, and this is already used in my experiments with a Java interface for igraph. This means that you will need a working Python interpreter to use my code.


Gang Su

PhD student
Bioinformatics training track
Program in Biomedical Sciences
University of Michigan, Ann Arbor
MI, 48105, U.S.A.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]