Skip to content

Commit

Permalink
[fix] fix lgbm bytebuffer native order (#3258)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewan0x79 authored Jun 17, 2024
1 parent 0b026dc commit 0b768e3
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.microsoft.ml.lightgbm.lightgbmlibConstants;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;

Expand Down Expand Up @@ -104,15 +105,17 @@ public static Pair<Integer, ByteBuffer> inferenceMat(
checkCall(result);
int length = Math.toIntExact(lightgbmlib.int64_tp_value(outLength));
if (a.getDataType() == DataType.FLOAT32) {
ByteBuffer bb = ByteBuffer.allocateDirect(length * 4);
ByteBuffer bb =
ByteBuffer.allocateDirect(length * 4).order(ByteOrder.nativeOrder());
FloatBuffer wrapped = bb.asFloatBuffer();
for (int i = 0; i < length; i++) {
wrapped.put((float) lightgbmlib.doubleArray_getitem(outBuffer, i));
}
bb.rewind();
return new Pair<>(length, bb);
} else if (a.getDataType() == DataType.FLOAT64) {
ByteBuffer bb = ByteBuffer.allocateDirect(length * 8);
ByteBuffer bb =
ByteBuffer.allocateDirect(length * 8).order(ByteOrder.nativeOrder());
DoubleBuffer wrapped = bb.asDoubleBuffer();
for (int i = 0; i < length; i++) {
wrapped.put(lightgbmlib.doubleArray_getitem(outBuffer, i));
Expand Down

0 comments on commit 0b768e3

Please sign in to comment.