Skip to content

Commit

Permalink
refactored java wrapper, no change in behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilaye Alemu committed Jun 16, 2017
1 parent 50746ef commit b209176
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
4 changes: 2 additions & 2 deletions java/src/main/c++/vowpalWabbit_learner_VWMulticlassLearner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ JNIEXPORT jint JNICALL Java_vowpalWabbit_learner_VWMulticlassLearner_predictMult
jfloatArray multiclass_raw_predictor(example* vec, JNIEnv *env){
size_t num_values = vec->l.cs.costs.size();
jfloatArray j_labels = env->NewFloatArray(num_values);
for(int i=0;i<num_values;i++) {
jfloat f[] = {vec->l.cs.costs[i].partial_prediction};
for (int i=0 ; i<num_values; i++) {
jfloat f[] = { vec->l.cs.costs[i].partial_prediction };
env->SetFloatArrayRegion(j_labels, i, 1, (float*)f);
}
return j_labels;
Expand Down
20 changes: 4 additions & 16 deletions java/src/main/java/vowpalWabbit/learner/VWMulticlassLearner.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,19 @@ final public class VWMulticlassLearner extends VWIntLearner {
protected native float[] rawPredict(String example, boolean learn, long nativePointer);

/**
* Runs prediction on <code>example</code> and returns the prediction output.
* Get raw prediction output.
*
* @param example a single vw example string
* @return A prediction
* @return Raw prediction
*/
public float[] rawPredict(final String example) {
return rawLearnOrPredict(example, false);
}

/**
* <code>learnOrPredict</code> allows the ability to return an unboxed prediction. This will reduce the overhead
* of this function call.
* @param example an example
* @param learn whether to call the learn or predict VW functions.
* @return an <em>UNBOXED</em> prediction.
*/
private float[] rawLearnOrPredict(final String example, final boolean learn) {
lock.lock();
try {
if (isOpen()) {
return rawPredict(example, learn, nativePointer);
return rawPredict(example, false, nativePointer);
}
throw new IllegalStateException("Already closed.");
}
finally {
} finally {
lock.unlock();
}
}
Expand Down

0 comments on commit b209176

Please sign in to comment.