コード例 #1
0
ファイル: BaseDataBuffer.java プロジェクト: Raveesh/nd4j
  /**
   * @param data
   * @param copy
   */
  public BaseDataBuffer(double[] data, boolean copy) {
    allocationMode = AllocUtil.getAllocationModeFromContext();
    initTypeAndSize();

    pointer = new DoublePointer(data);
    indexer = DoubleIndexer.create((DoublePointer) pointer);
    wrappedBuffer = pointer.asByteBuffer();

    length = data.length;
    underlyingLength = data.length;
  }
コード例 #2
0
ファイル: BaseDataBuffer.java プロジェクト: Raveesh/nd4j
 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);
     }
   }
 }
コード例 #3
0
ファイル: BaseDataBuffer.java プロジェクト: Raveesh/nd4j
  /**
   * 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);
    }
  }
コード例 #4
0
ファイル: BaseDataBuffer.java プロジェクト: Raveesh/nd4j
  /**
   * @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);
    }
  }
コード例 #5
0
ファイル: BaseDataBuffer.java プロジェクト: Raveesh/nd4j
  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();
    }
  }
コード例 #6
0
ファイル: Frame.java プロジェクト: lizhecome/javacv
 /** Returns an {@link Indexer} for the <i>i</i>th image plane. */
 public <I extends Indexer> I createIndexer(boolean direct, int i) {
   int[] sizes = {imageHeight, imageWidth, imageChannels};
   int[] strides = {imageStride, imageChannels, 1};
   Buffer buffer = image[i];
   Object array = buffer.hasArray() ? buffer.array() : null;
   switch (imageDepth) {
     case DEPTH_UBYTE:
       return array != null
           ? (I) UByteIndexer.create((byte[]) array, sizes, strides)
           : direct
               ? (I) UByteIndexer.create((ByteBuffer) buffer, sizes, strides)
               : (I)
                   UByteIndexer.create(
                       new BytePointer((ByteBuffer) buffer), sizes, strides, false);
     case DEPTH_BYTE:
       return array != null
           ? (I) ByteIndexer.create((byte[]) array, sizes, strides)
           : direct
               ? (I) ByteIndexer.create((ByteBuffer) buffer, sizes, strides)
               : (I)
                   ByteIndexer.create(new BytePointer((ByteBuffer) buffer), sizes, strides, false);
     case DEPTH_USHORT:
       return array != null
           ? (I) UShortIndexer.create((short[]) array, sizes, strides)
           : direct
               ? (I) UShortIndexer.create((ShortBuffer) buffer, sizes, strides)
               : (I)
                   UShortIndexer.create(
                       new ShortPointer((ShortBuffer) buffer), sizes, strides, false);
     case DEPTH_SHORT:
       return array != null
           ? (I) ShortIndexer.create((short[]) array, sizes, strides)
           : direct
               ? (I) ShortIndexer.create((ShortBuffer) buffer, sizes, strides)
               : (I)
                   ShortIndexer.create(
                       new ShortPointer((ShortBuffer) buffer), sizes, strides, false);
     case DEPTH_INT:
       return array != null
           ? (I) IntIndexer.create((int[]) array, sizes, strides)
           : direct
               ? (I) IntIndexer.create((IntBuffer) buffer, sizes, strides)
               : (I) IntIndexer.create(new IntPointer((IntBuffer) buffer), sizes, strides, false);
     case DEPTH_LONG:
       return array != null
           ? (I) LongIndexer.create((long[]) array, sizes, strides)
           : direct
               ? (I) LongIndexer.create((LongBuffer) buffer, sizes, strides)
               : (I)
                   LongIndexer.create(new LongPointer((LongBuffer) buffer), sizes, strides, false);
     case DEPTH_FLOAT:
       return array != null
           ? (I) FloatIndexer.create((float[]) array, sizes, strides)
           : direct
               ? (I) FloatIndexer.create((FloatBuffer) buffer, sizes, strides)
               : (I)
                   FloatIndexer.create(
                       new FloatPointer((FloatBuffer) buffer), sizes, strides, false);
     case DEPTH_DOUBLE:
       return array != null
           ? (I) DoubleIndexer.create((double[]) array, sizes, strides)
           : direct
               ? (I) DoubleIndexer.create((DoubleBuffer) buffer, sizes, strides)
               : (I)
                   DoubleIndexer.create(
                       new DoublePointer((DoubleBuffer) buffer), sizes, strides, false);
     default:
       assert false;
   }
   return null;
 }