Skip to content

Latest commit

 

History

History

gsl

JavaCPP Presets for GSL

GitterMaven CentralSonatype Nexus (Snapshots)
Build status for all platforms:gslCommercial support:xscode

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.11</version> <properties> <exec.mainClass>Demo</exec.mainClass> </properties> <dependencies> <dependency> <groupId>org.bytedeco</groupId> <artifactId>gsl-platform</artifactId> <version>2.8-1.5.11</version> </dependency> <!-- Additional dependencies to use bundled full version of MKL --> <dependency> <groupId>org.bytedeco</groupId> <artifactId>mkl-platform-redist</artifactId> <version>2025.0-1.5.11</version> </dependency> </dependencies> <build> <sourceDirectory>.</sourceDirectory> </build> </project>

The Demo.java source file

importorg.bytedeco.javacpp.*; importorg.bytedeco.gsl.*; importstaticorg.bytedeco.gsl.global.gsl.*; publicclassDemo { publicstaticvoidmain(String[] args) { /* try to use MKL when available */System.setProperty("org.bytedeco.openblas.load", "mkl"); gsl_rng_typeT; gsl_rngr; intn = 10; doublemu = 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 (inti = 0; i < n; i++) { intk = gsl_ran_poisson(r, mu); System.out.printf(" %d", k); } System.out.println(); gsl_rng_free(r); System.exit(0); } }
close