Ejemplo n.º 1
0
  @Override
  public void put(long i, int element) {
    if (dataType() == Type.DOUBLE) {
      if (indexer instanceof DoubleIndexer) {
        ((DoubleIndexer) indexer).put(offset() + i, element);

      } else {
        UByteRawIndexer other = (UByteRawIndexer) indexer;
        other.put(offset() + i, element);
      }
    } else if (dataType() == Type.INT) {
      if (indexer instanceof IntIndexer) {
        ((IntIndexer) indexer).put(offset() + i, element);

      } else {
        UByteRawIndexer other = (UByteRawIndexer) indexer;
        other.put(offset() + i, element);
      }
    } else {
      if (indexer instanceof FloatIndexer) {
        ((FloatIndexer) indexer).put(offset() + i, element);

      } else {
        UByteRawIndexer other = (UByteRawIndexer) indexer;
        other.put(offset() + i, element);
      }
    }

    dirty.set(true);
  }
Ejemplo n.º 2
0
  /**
   * @param data
   * @param copy
   */
  public BaseDataBuffer(float[] data, boolean copy) {
    allocationMode = AllocUtil.getAllocationModeFromContext();
    initTypeAndSize();

    pointer = new FloatPointer(data);
    indexer = FloatIndexer.create((FloatPointer) pointer);
    wrappedBuffer = pointer.asByteBuffer();

    length = data.length;
    underlyingLength = data.length;
  }
Ejemplo n.º 3
0
 public void pointerIndexerByGlobalType(Type currentType) {
   if (currentType == Type.INT) {
     pointer = new IntPointer(length());
     indexer = IntIndexer.create((IntPointer) pointer);
     type = Type.INT;
   } else {
     if (globalType == Type.DOUBLE) {
       pointer = new DoublePointer(length());
       indexer = DoubleIndexer.create((DoublePointer) pointer);
     } else if (globalType == Type.FLOAT) {
       pointer = new FloatPointer(length());
       indexer = FloatIndexer.create((FloatPointer) pointer);
     }
   }
 }
Ejemplo n.º 4
0
  /**
   * Create a data buffer from the given length
   *
   * @param buffer
   * @param length
   */
  public BaseDataBuffer(ByteBuffer buffer, long length) {
    if (length < 1) throw new IllegalArgumentException("Length must be >= 1");
    initTypeAndSize();

    this.length = length;
    allocationMode = AllocUtil.getAllocationModeFromContext();

    if (dataType() == Type.DOUBLE) {
      pointer = new DoublePointer(buffer.asDoubleBuffer());
      indexer = DoubleIndexer.create((DoublePointer) pointer);
    } else if (dataType() == Type.FLOAT) {
      pointer = new FloatPointer(buffer.asFloatBuffer());
      indexer = FloatIndexer.create((FloatPointer) pointer);
    } else if (dataType() == Type.INT) {
      pointer = new IntPointer(buffer.asIntBuffer());
      indexer = IntIndexer.create((IntPointer) pointer);
    }
  }
Ejemplo n.º 5
0
  /**
   * @param length
   * @param elementSize
   */
  public BaseDataBuffer(long length, int elementSize) {
    if (length < 1) throw new IllegalArgumentException("Length must be >= 1");
    initTypeAndSize();
    allocationMode = AllocUtil.getAllocationModeFromContext();
    this.length = length;
    this.underlyingLength = length;
    this.elementSize = elementSize;

    if (dataType() == Type.DOUBLE) {
      pointer = new DoublePointer(length);
      indexer = DoubleIndexer.create((DoublePointer) pointer);
    } else if (dataType() == Type.FLOAT) {
      pointer = new FloatPointer(length);
      indexer = FloatIndexer.create((FloatPointer) pointer);
    } else if (dataType() == Type.INT) {
      pointer = new IntPointer(length);
      indexer = IntIndexer.create((IntPointer) pointer);
    }
  }
Ejemplo n.º 6
0
  protected BaseDataBuffer(long length, boolean initialize) {
    if (length < 1) throw new IllegalArgumentException("Length must be >= 1");
    initTypeAndSize();
    this.length = length;
    this.underlyingLength = length;
    allocationMode = AllocUtil.getAllocationModeFromContext();
    if (length < 0) throw new IllegalArgumentException("Unable to create a buffer of length <= 0");

    if (dataType() == Type.DOUBLE) {
      pointer = new DoublePointer(length());
      indexer = DoubleIndexer.create((DoublePointer) pointer);
      if (initialize) fillPointerWithZero();
    } else if (dataType() == Type.FLOAT) {
      pointer = new FloatPointer(length());
      indexer = FloatIndexer.create((FloatPointer) pointer);
      if (initialize) fillPointerWithZero();

    } else if (dataType() == Type.INT) {
      pointer = new IntPointer(length());
      indexer = IntIndexer.create((IntPointer) pointer);
      if (initialize) fillPointerWithZero();
    }
  }