So in Network.java I added
Code: Select all
public native void setSoftEvidence(String nodeId, double[] evidence);
Code: Select all
JNIEXPORT void JNICALL Java_smile_Network_setSoftEvidence__Ljava_lang_String_2_3D(JNIEnv *env, jobject obj, jstring nodeId, jdoubleArray evidence)
{
JSMILE_ENTER;
int nodeHandle = ValidateNodeId(env, obj, nodeId);
DSL_node *node = ValidateNodeHandle(env, obj, nodeHandle);
std::vector<double> vEvidence;
int length = env->GetArrayLength(evidence);
for (int i = 0; i < length; i ++)
{
double d;
env->GetDoubleArrayRegion(evidence, i, 1, &d);
vEvidence.push_back(d);
}
int res = node->Value()->SetSoftEvidence(vEvidence);
if (DSL_OKAY != res)
{
ThrowSmileException(env, "SetSoftEvidence", res);
}
JSMILE_LEAVE;
}
The problem now is, that when I'm calling the new method from my Java programm, "res" is -2, which corresponds to DSL_OUT_OF_RANGE.
I don't think there's a problem with the call from Java itself, the double array should have the right length.
I tried to open the same xdsl with SMILE and add the soft evidence to the same node and that worked, so I think the problem also isn't in the file.
My best bet would be that the code I posted above is wrong or I missed something, which wouldn't be a very big surprise, given I have almost no experience with wrappers or JNI.
So, any help is appreciated.