Skip to content

Latest commit

 

History

History
 
 

gsl

JavaCPP Presets for GSL

Introduction

This directory contains the JavaCPP Presets module for:

Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.

Documentation

Java API documentation is available here:

Sample Usage

Here is a simple example of GSL ported to Java from this demo.c source file:

We can use Maven 3 to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the pom.xml and Demo.java source files below, simply execute on the command line:

 $ mvn compile exec:java

The pom.xml build file

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.bytedeco.gsl</groupId>
    <artifactId>demo</artifactId>
    <version>1.5-SNAPSHOT</version>
    <properties>
        <exec.mainClass>Demo</exec.mainClass>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>gsl-platform</artifactId>
            <version>2.5-1.5-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>.</sourceDirectory>
    </build>
</project>

The Demo.java source file

import org.bytedeco.javacpp.*;
import org.bytedeco.gsl.*;
import static org.bytedeco.gsl.global.gsl.*;

public class Demo {
    public static void main(String[] args) {
        gsl_rng_type T;
        gsl_rng r;

        int n = 10;
        double mu = 3.0;

        /* create a generator chosen by the 
           environment variable GSL_RNG_TYPE */

        gsl_rng_env_setup();

        T = gsl_rng_default();
        r = gsl_rng_alloc(T);

        /* print n random variates chosen from 
           the poisson distribution with mean 
           parameter mu */

        for (int i = 0; i < n; i++) {
            int k = gsl_ran_poisson(r, mu);
            System.out.printf(" %d", k);
        }

        System.out.println();
        gsl_rng_free(r);
        System.exit(0);
    }
}