igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Igraph with JNI


From: Tamas Nepusz
Subject: Re: [igraph] Igraph with JNI
Date: Sat, 1 Aug 2009 14:32:30 +0200

The following data structure can't be mapped directly:
igragh_vector_t
I guess these should be mapped to a Java double[], but since I have no experience with JNA, I don't know how to do that. If I'd have to do the same in JNI, I would possibly write a converter function in both directions. A more Java-ish way would possibly be to allow any Java Collection of doubles (i.e., ArrayLists, Vectors and so on) to be converted to igraph_vector_t. Note that you don't have to map the _internal_ elements of igraph_vector_t to Java types, I'd simply create an igraph_vector_t on the fly from an incoming double[] when needed and convert outgoing igraph_vector_t objects back to double[]. The same for igraph_vector_bool_t and igraph_matrix_t (bool[] and double[][]).

By the way, when trying to map igraph_t to a Java object, I would simply create a proxy Graph class that holds the _memory address_ of the underlying igraph_t object (cast to a Java long), so I would't try mapping each member of the igraph_t struct to Java types. But that's just a matter of taste, the Python interface uses this approach, while the R interface doesn't (as far as I know).

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.
I think that's the most reasonable approach for vector types. (Or, if there's a faster way to copy large chunks of data directly without using a for loop, like memcpy() in C).

3. Re-implement the data types in java. This also require me to know the structure of these datatypes
I wouldn't do that as the internal structure of igraph types may change without further notice between releases, and then you would have to adapt your interface as well.

--
Tamas





reply via email to

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