Skip to content

Java API DataBuffers.of uses buffer incorrectly #9

Open
@fyang996

Description

@fyang996

Hi,

I am seeing this behavior when creating a Tensor using a buffer that is created by wrapping an array.
The example below can reproduce the issue:

// create an buffer by wrapping an array but buffer start from position 3 and length is 4
final IntBuffer src = IntBuffer.wrap(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8}, 3, 4).asReadOnlyBuffer();
final org.tensorflow.Tensor tensor = TInt32.tensorOf(Shape.of(4), DataBuffers.of(src));

final int[] value = new int[4];
tensor.asRawTensor().data().asInts().read(value);
assertArrayEquals(new int[]{0, 1, 2, 3}, value); // This is not really a correct behavior, it is not honoring the buffer offset when wrapping the array, it just takes the first 4 elements
//assertArrayEquals(new int[]{3, 4, 5, 6}, value); // This should be the desired result

System info:
Java 8
tensorflow-java (tensorflow-core-api) 0.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions