From: Kraus P. <phi...@fl...> - 2012-03-25 01:15:25
|
Hello, I'm using this typemap: %typemap(out) ublas::matrix<double> { $result = swig::convert::getArrayFromMatrix(jenv, $1); } Swig creates this code: SWIGEXPORT jlong JNICALL Java_moduleJNI_returndata(JNIEnv *jenv, jclass jcls) { jlong jresult = 0 ; ublas::matrix<double > result; (void)jenv; (void)jcls; result = returndata(); { jresult = swig::convert::getArrayFromMatrix(jenv, result); } return jresult; } and this Java class: class moduleJNI { public final static native long returndata(); } My function call swig::convert::getArrayFromMatrix returns a jobjectArray. How can I tell in the interface file, that Swig should use a jobjectArray in the JNICALL function instead of the jlong and in the Java class a Double[][] instead of the long type? I have tried %apply but no errors are shown and no code changes are created. |
From: William S F. <ws...@fu...> - 2012-03-27 20:41:43
|
On 25/03/12 02:15, Kraus Philipp wrote: > Hello, > > I'm using this typemap: > > %typemap(out) ublas::matrix<double> { > $result = swig::convert::getArrayFromMatrix(jenv, $1); > } > > Swig creates this code: > > SWIGEXPORT jlong JNICALL Java_moduleJNI_returndata(JNIEnv *jenv, jclass > jcls) { > jlong jresult = 0 ; > ublas::matrix<double > result; > > > (void)jenv; > (void)jcls; > result = returndata(); > { > jresult = swig::convert::getArrayFromMatrix(jenv, result); > } > return jresult; > } > > and this Java class: > > class moduleJNI { > publicfinalstaticnativelongreturndata(); > } > > My function call swig::convert::getArrayFromMatrix returns a > jobjectArray. How can I tell in the interface file, that Swig should use > a jobjectArray in the JNICALL function instead of the jlong and in the > Java class a Double[][] instead of the long type? > > I have tried %apply but no errors are shown and no code changes are created. There is a set of typemaps you can define (usually you also need 'jni', 'jtype' and 'jstype' typemaps). Check out any examples or look in the java.swg file. William |
From: Philipp K. <phi...@fl...> - 2012-03-28 09:10:26
|
On 2012-03-27 22:41:06 +0200, William S Fulton said: > On 25/03/12 02:15, Kraus Philipp wrote: >> Hello, >> >> I'm using this typemap: >> >> %typemap(out) ublas::matrix<double> { >> $result = swig::convert::getArrayFromMatrix(jenv, $1); >> } >> >> Swig creates this code: >> >> SWIGEXPORT jlong JNICALL Java_moduleJNI_returndata(JNIEnv *jenv, jclass >> jcls) { >> jlong jresult = 0 ; >> ublas::matrix<double > result; >> >> >> (void)jenv; >> (void)jcls; >> result = returndata(); >> { >> jresult = swig::convert::getArrayFromMatrix(jenv, result); >> } >> return jresult; >> } >> >> and this Java class: >> >> class moduleJNI { >> publicfinalstaticnativelongreturndata(); >> } >> >> My function call swig::convert::getArrayFromMatrix returns a >> jobjectArray. How can I tell in the interface file, that Swig should use >> a jobjectArray in the JNICALL function instead of the jlong and in the >> Java class a Double[][] instead of the long type? >> >> I have tried %apply but no errors are shown and no code changes are created. > > There is a set of typemaps you can define (usually you also need 'jni', > 'jtype' and 'jstype' typemaps). Check out any examples or look in the > java.swg file. Thanks, I have found it yesterday and set it to: %typemap(jni) ublas::matrix<double>, ublas::matrix<double>& "jobjectArray" %typemap(jtype) ublas::matrix<double>, ublas::matrix<double>& "Double[][]" %typemap(jstype) ublas::matrix<double>, ublas::matrix<double>& "Double[][]" |