Welcome to the Java GNU Scientific Library project

The JGSL is a collection of Java classes that wrap around the GNU Scientific Library . I started this project while I was working on different building automation projects written in Java. I am no longer very active on these projects but still maintain a blog on this topic, Computing and Smart Buildings .

Download

JGSL can be downloaded directly from Sourceforge .

Example Usage

All programs that use the JGSL must call the following initialization command at least once :

ch.visnet.jgsl.Jgsl.init();

This command loads the part of GSL's native library that comes with JGSL and makes its functions available to the JGSL classes. Calling this command more than once is harmless. It is, however, not thread-safe.

The following demonstrates the use of the natural logarithm function.

import ch.visnet.jgsl.Jgsl;
import ch.visnet.jgsl.sf.Log;

public class LogDemo {
  public static void main(String[] args) {
    Jgsl.init();
    System.out.println("Log 42 = " + Log.log(42));
  }
}

Compile this program and run it with the JGSL jarfile on your classpath:

> java -cp .:jgsl.jar LogDemo
Log 42 = 3.7376696182833684
>

Features

This version (0.2) includes only GSL's special functions and the statistics module. The GSL's special functions have been are accessible from the ch.visnet.jgsl.sf package. Each family of special functions (log, exp, airy, bessel, etc) is mapped to a class whose static functions are wrappers around the functions in that family:

double Log.log(double x);            // log(x)
double Log.logAbs(double x);         // log(1 + x)
...

double Exp.exp(double x);            // exp(x)
double Exp.mult(double x, double y); // y * exp(x)
...

The statistics functions are accessible from the ch.visnet.jgsl.stats package. The wrapper classes will not work directly with Java arrays and you must wrap double arrays to JGSL's DoubleArray class, as is done in ch.visnet.jgsl.Util.java in the test folder:

static public DoubleArray toDoubleArray(double[] array) {
       DoubleArray result = new DoubleArray(array.length);
       for (int i = 0; i < array.length; i++) {
       	   result.setitem(i, array[i]);
       }
       return result;
}

The statistics functions can then be called with this DoubleArray as argument, e.g.

double variance = Stats.variance(doubleArray, /*stride*/ 1, array.length);

See the README file for more information.

Note

Starting this project has been a pleasure but I have no more time to maintain it on my own, unless there's a very specific feature from GSL you need included in JGSL (and are willing to help me with). Don't hesitate to get in touch with me through this project's SourceForge homepage .