Skip to content

Commit

Permalink
Fix buffer rewind compilation error compat with jdk 9+
Browse files Browse the repository at this point in the history
See similar issue: apache/felix#114
  • Loading branch information
agibsonccc committed Apr 1, 2021
1 parent 652b854 commit 137af78
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.datavec.api.writable;

import org.datavec.api.writable.batch.NDArrayRecordBatch;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.nd4j.common.tests.BaseND4JTest;
Expand All @@ -28,13 +29,13 @@
import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.junit.jupiter.api.DisplayName;

import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@
import org.datavec.api.writable.*;
import org.datavec.arrow.recordreader.ArrowWritableRecordBatch;
import org.datavec.arrow.recordreader.ArrowWritableRecordTimeSeriesBatch;
import org.nd4j.common.primitives.Pair;
import org.nd4j.linalg.api.buffer.DataBuffer;
import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.exception.ND4JIllegalArgumentException;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.common.primitives.Pair;
import org.nd4j.serde.binary.BinarySerde;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.*;
Expand Down Expand Up @@ -171,7 +172,8 @@ public static INDArray convertArrowVector(FieldVector fieldVector,ColumnType typ
ByteBuffer direct = ByteBuffer.allocateDirect(fieldVector.getDataBuffer().capacity());
direct.order(ByteOrder.nativeOrder());
fieldVector.getDataBuffer().getBytes(0,direct);
direct.rewind();
Buffer buffer1 = (Buffer) direct;
buffer1.rewind();
switch(type) {
case Integer:
buffer = Nd4j.createBuffer(direct, DataType.INT,cols,0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static ByteBuffer concat(ByteBuffer[] buffers, int overAllCapacity) {
ByteBuffer curr = buffers[i].slice();
all.put(curr);
}

all.rewind();
Buffer buffer = (Buffer) all;
buffer.rewind();
return all;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.nd4j.linalg.factory.Nd4j;

import javax.annotation.concurrent.NotThreadSafe;
import java.nio.Buffer;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -45,7 +46,8 @@ public class NDArrayMessageTest extends BaseND4JTest {
public void testNDArrayMessageToAndFrom() {
NDArrayMessage message = NDArrayMessage.wholeArrayUpdate(Nd4j.scalar(1.0));
DirectBuffer bufferConvert = NDArrayMessage.toBuffer(message);
bufferConvert.byteBuffer().rewind();
Buffer buffer = (Buffer) bufferConvert.byteBuffer();
buffer.rewind();
NDArrayMessage newMessage = NDArrayMessage.fromBuffer(bufferConvert, 0);
assertEquals(message, newMessage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.nd4j.common.tests.BaseND4JTest;
import org.nd4j.aeron.ipc.NDArrayMessage;
import org.nd4j.aeron.util.BufferUtil;
import org.nd4j.common.tests.BaseND4JTest;
import org.nd4j.common.tests.tags.NativeTag;
import org.nd4j.common.tests.tags.TagNames;
import org.nd4j.linalg.factory.Nd4j;

import javax.annotation.concurrent.NotThreadSafe;
import java.nio.Buffer;
import java.nio.ByteBuffer;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
Expand Down Expand Up @@ -67,11 +68,13 @@ public void testChunkSerialization() {
//test equality of direct byte buffer contents vs chunked
ByteBuffer byteBuffer = buffer.byteBuffer();
ByteBuffer concatAll = BufferUtil.concat(concat, buffer.capacity());
Buffer concatAllBuffer = (Buffer) concatAll;
Buffer byteBuffer1 = (Buffer) byteBuffer;
byte[] arrays = new byte[byteBuffer.capacity()];
byteBuffer.rewind();
byteBuffer1.rewind();
byteBuffer.get(arrays);
byte[] arrays2 = new byte[concatAll.capacity()];
concatAll.rewind();
concatAllBuffer.rewind();
concatAll.get(arrays2);
assertArrayEquals(arrays, arrays2);
NDArrayMessage message1 = NDArrayMessage.fromChunks(chunks);
Expand Down

0 comments on commit 137af78

Please sign in to comment.