Пример #1
0
 @Override
 public ByteBuffer asNio() {
   if (wrappedBuffer == null) {
     return pointer.asByteBuffer();
   } else {
     return wrappedBuffer;
   }
 }
Пример #2
0
  @Override
  public IntBuffer asNioInt() {
    if (offset() >= Integer.MAX_VALUE)
      throw new IllegalStateException("Index out of bounds " + offset());

    if (wrappedBuffer == null) {
      return pointer.asByteBuffer().asIntBuffer();
    } else if (offset() == 0) {
      return wrappedBuffer.asIntBuffer();
    } else return (IntBuffer) wrappedBuffer.asIntBuffer().position((int) offset());
  }
Пример #3
0
  /**
   * @param data
   * @param copy
   */
  public BaseDataBuffer(int[] data, boolean copy) {
    allocationMode = AllocUtil.getAllocationModeFromContext();
    initTypeAndSize();

    pointer = new IntPointer(data);
    indexer = IntIndexer.create((IntPointer) pointer);
    wrappedBuffer = pointer.asByteBuffer();

    length = data.length;
    underlyingLength = data.length;
  }
Пример #4
0
  @Override
  public void read(DataInputStream s) {
    try {
      referencing = Collections.synchronizedSet(new HashSet<String>());
      dirty = new AtomicBoolean(false);
      allocationMode = AllocationMode.valueOf(s.readUTF());
      length = s.readInt();
      Type currentType = Type.valueOf(s.readUTF());
      type = globalType;
      if (currentType == Type.DOUBLE) elementSize = 8;
      else if (currentType == Type.FLOAT || currentType == Type.INT) elementSize = 4;
      if (currentType != globalType && currentType != Type.INT) {
        log.warn(
            "Loading a data stream with type different from what is set globally. Expect precision loss");
        if (globalType == Type.INT) log.warn("Int to float/double widening UNSUPPORTED!!!");
      }
      pointerIndexerByGlobalType(currentType);
      if (currentType == Type.DOUBLE) {
        for (int i = 0; i < length(); i++) {
          putByGlobalType(i, s.readDouble());
        }
      } else if (currentType == Type.FLOAT) {
        for (int i = 0; i < length(); i++) {
          putByGlobalType(i, s.readFloat());
        }
      } else {
        for (int i = 0; i < length(); i++) {
          putByGlobalType(i, s.readInt());
        }
      }
      wrappedBuffer = pointer.asByteBuffer();

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Пример #5
0
 @Override
 public long address() {
   return pointer.address() + getElementSize() * offset();
 }
Пример #6
0
 private void fillPointerWithZero() {
   Pointer.memset(this.pointer(), 0, getElementSize() * length());
 }
Пример #7
0
 // sets the nio wrapped buffer (allows to be overridden for other use cases like cuda)
 protected void setNioBuffer() {
   if (elementSize * length >= Integer.MAX_VALUE)
     throw new IllegalArgumentException("Unable to create buffer of length " + length);
   wrappedBuffer = pointer.asByteBuffer();
 }