MTensor supports shared pass, where the argument can be modified in the library function and that modification can be seen in Mathematica side. Is it possible to do the same thing to a integer or double type?
For example, in the following code, the library function takes an integer and set it to 2.
MMASrc = "#include
#include
DLLEXPORT mint WolframLibrary_getVersion(){
return WolframLibraryVersion;
}
DLLEXPORT int WolframLibrary_initialize(WolframLibraryData libData){
return 0;
}
EXTERN_C DLLEXPORT int test(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){
int a = MArgument_getInteger(Args[0]);
a=2; //library function set a to 2
return LIBRARY_NO_ERROR;
}";
Needs["CCompilerDriver`"];
lib = CreateLibrary[MMASrc, "test", "Debug" -> True,
"TargetDirectory" -> "/tmp"];
testFunc = LibraryFunctionLoad[lib, "test", {Integer}, "Void"];
a = 3;
testFunc[a];
a
(*3*)
However, I get 3 as output. So it is possible to have shared pass so that I Mathematica can reflect the modify of a by the library function, except making it into a MTensor with one element?
Comments
Post a Comment