Mercurial > hg > libxtract
view swig/java/jxtract.i @ 214:f28f66faa016
Add "stateful" feature type with initial feature "last n"
Stateful feature extraction functions are functions that require state to be maintained between successive calls. This is necessary, for example when an accumulation of values is required, or changes need to be measured over time.
The initial xtract_last_n() function accumulates the last N (single) values from *data and writes them to *result
author | Jamie Bullock <jamie@jamiebullock.com> |
---|---|
date | Tue, 03 Jun 2014 21:17:07 +0100 |
parents | 826eb46b2f91 |
children |
line wrap: on
line source
%include "../xtract.i" %include "arrays_java.i" %apply double[] {const double *data}; %apply double *OUTPUT { double *result }; %typemap(in,numinputs=0) JNIEnv *env "$1 = jenv;" %javamethodmodifiers arr2voidd "private"; %javamethodmodifiers arr2voidi "private"; %javamethodmodifiers freearrd "private"; %javamethodmodifiers freearri "private"; %inline %{ jlong arr2voidd(JNIEnv *env, jdoubleArray arr) { void *ptr = (*env)->GetFloatArrayElements(env, arr, NULL); return (intptr_t)ptr; } void freearrd(JNIEnv *env, jdoubleArray arr, jlong map) { void *ptr = 0; ptr = *(void **)↦ (*env)->ReleaseFloatArrayElements(env, arr, ptr, JNI_ABORT); } jlong arr2voidi(JNIEnv *env, jintArray arr) { void *ptr = (*env)->GetIntArrayElements(env, arr, NULL); return (intptr_t)ptr; } void freearri(JNIEnv *env, jintArray arr, jlong map) { void *ptr = 0; ptr = *(void **)↦ (*env)->ReleaseIntArrayElements(env, arr, ptr, JNI_ABORT); } %} %pragma(java) modulecode=%{ private static long arrPtr(Object o) { if (o instanceof double[]) { return arr2voidd((double[])o); } else if (o instanceof int[]) { return arr2voidi((int[])o); } else if (o == null) { return 0L; } throw new IllegalArgumentException(); } private static void freeArrPtr(Object o, long addr) { if (o instanceof double[]) { freearrd((double[])o, addr); return; } else if (o instanceof int[]) { freearri((int[])o, addr); return; } else if (o == null) { return; } throw new IllegalArgumentException(); } %} %typemap(jstype) void *argv "Object" %typemap(javain,pre=" long tmp$javainput = arrPtr($javainput);",post=" freeArrPtr($javainput, tmp$javainput);") void *argv "tmp$javainput" %include xtract_redeclare.i