Add NativeProblem that loads libeva2problem.jnilib
if present.
closes #47
This commit is contained in:
parent
8eba939655
commit
77b0750c74
31
resources/NativeInterface/eva2_problems_NativeProblem.h
Executable file
31
resources/NativeInterface/eva2_problems_NativeProblem.h
Executable file
@ -0,0 +1,31 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class eva2_problems_NativeProblem */
|
||||
|
||||
#ifndef _Included_eva2_problems_NativeProblem
|
||||
#define _Included_eva2_problems_NativeProblem
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#undef eva2_problems_NativeProblem_serialVersionUID
|
||||
#define eva2_problems_NativeProblem_serialVersionUID -3904130243174390134LL
|
||||
/*
|
||||
* Class: eva2_problems_NativeProblem
|
||||
* Method: evaluate
|
||||
* Signature: ([D)[D
|
||||
*/
|
||||
JNIEXPORT jdoubleArray JNICALL Java_eva2_problems_NativeProblem_evaluate
|
||||
(JNIEnv *, jobject, jdoubleArray);
|
||||
|
||||
/*
|
||||
* Class: eva2_problems_NativeProblem
|
||||
* Method: getName
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_eva2_problems_NativeProblem_getName
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
29
resources/NativeInterface/eva2problem.c
Executable file
29
resources/NativeInterface/eva2problem.c
Executable file
@ -0,0 +1,29 @@
|
||||
#include "eva2_problems_NativeProblem.h"
|
||||
|
||||
JNIEXPORT jdoubleArray JNICALL Java_eva2_problems_NativeProblem_evaluate
|
||||
(JNIEnv *env, jobject obj, jdoubleArray array) {
|
||||
int i;
|
||||
double result[1] = {0.0};
|
||||
jdoubleArray resultArray = (*env)->NewDoubleArray(env, 1);
|
||||
if (resultArray == NULL) {
|
||||
return NULL; /* out of memory :( */
|
||||
}
|
||||
jsize len = (*env)->GetArrayLength(env, array);
|
||||
jdouble *body = (*env)->GetDoubleArrayElements(env, array, 0);
|
||||
|
||||
// Calculate sum(x_i^2)
|
||||
for(i=0; i<len; i++) {
|
||||
result[0] += body[i] * body[i];
|
||||
}
|
||||
|
||||
// Release input array
|
||||
(*env)->ReleaseDoubleArrayElements(env, array, body, 0);
|
||||
// Set result
|
||||
(*env)->SetDoubleArrayRegion(env, resultArray, 0, 1, result);
|
||||
return resultArray;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_eva2_problems_NativeProblem_getName
|
||||
(JNIEnv *env, jobject obj) {
|
||||
return (*env)->NewStringUTF(env, "Native Sphere");
|
||||
}
|
27
src/eva2/problems/NativeProblem.java
Normal file
27
src/eva2/problems/NativeProblem.java
Normal file
@ -0,0 +1,27 @@
|
||||
package eva2.problems;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class NativeProblem extends AbstractProblemDouble {
|
||||
|
||||
private static boolean isLibraryLoaded = false;
|
||||
|
||||
public NativeProblem() {
|
||||
if (!isLibraryLoaded) {
|
||||
System.loadLibrary("eva2problem");
|
||||
}
|
||||
isLibraryLoaded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public native double[] evaluate(double[] x);
|
||||
|
||||
@Override
|
||||
public native String getName();
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
return this.clone();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user