下面列出了java.nio.Buffer#remaining ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** {@inheritDoc} */
@Override
public void set(Buffer data) {
int size = data.remaining();
// int8, uint8, boolean use ByteBuffer, so need to explicitly input DataType
DataType inputType = DataType.fromBuffer(data);
int numOfBytes = inputType.getNumOfBytes();
this.data = ByteBuffer.allocate(size * numOfBytes);
switch (inputType) {
case FLOAT32:
this.data.asFloatBuffer().put((FloatBuffer) data);
break;
case FLOAT64:
this.data.asDoubleBuffer().put((DoubleBuffer) data);
break;
case INT8:
this.data.put((ByteBuffer) data);
break;
case INT32:
this.data.asIntBuffer().put((IntBuffer) data);
break;
case INT64:
this.data.asLongBuffer().put((LongBuffer) data);
break;
case UINT8:
case FLOAT16:
default:
throw new AssertionError("Show never happen");
}
}
/** {@inheritDoc} */
@Override
public TfNDArray create(Buffer data, Shape shape, DataType dataType) {
int size = data.remaining();
// int8, uint8, boolean use ByteBuffer, so need to explicitly input DataType
DataType inputType = DataType.fromBuffer(data);
int numOfBytes = inputType.getNumOfBytes();
ByteBuffer buf = allocateDirect(size * numOfBytes);
switch (inputType) {
case FLOAT32:
buf.asFloatBuffer().put((FloatBuffer) data);
break;
case FLOAT64:
buf.asDoubleBuffer().put((DoubleBuffer) data);
break;
case UINT8:
case INT8:
case BOOLEAN:
buf.put((ByteBuffer) data);
break;
case INT32:
buf.asIntBuffer().put((IntBuffer) data);
break;
case INT64:
buf.asLongBuffer().put((LongBuffer) data);
break;
case FLOAT16:
default:
throw new AssertionError("Show never happen");
}
buf.rewind();
ByteDataBuffer db = DataBuffers.of(buf);
Tensor<?> tensor = Tensor.of(TfDataType.toTf(dataType), TfNDArray.toTfShape(shape), db);
return new TfNDArray(this, tensor);
}
private static void checkLimit(Buffer buffer) {
if (buffer == null) {
return;
}
if (buffer.limit() == 0) {
throw new RendererException("Attempting to upload empty buffer (limit = 0), that's an error");
}
if (buffer.remaining() == 0) {
throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error");
}
}
public void getData_GL2GL3(Buffer buffer){
int data_len = w * h * num_channel;
if(buffer.remaining() < data_len){
System.out.println("ERROR DwGLTexture.getData_GL2GL3: buffer to small: "+buffer.capacity() +" < "+data_len);
return;
}
GL2GL3 gl23 = gl.getGL2GL3();
gl23.glBindTexture(target, HANDLE[0]);
gl23.glGetTexImage(target, 0, format, type, buffer);
gl23.glBindTexture(target, 0);
DwGLError.debug(gl, "DwGLTexture.getData_GL2GL3");
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
private static CoderResult xflow(Buffer src, int mark, int nb) {
src.position(mark);
return (nb == 0 || src.remaining() < nb)
? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}