@ Override public INDArray createFromNpyPointer ( Pointer pointer ) { Pointer dataPointer = nativeOps . dataPointForNumpy ( pointer ) ; int dataBufferElementSize = nativeOps . elementSizeForNpyArray ( pointer ) ; DataBuffer data = null ; Pointer shapeBufferPointer = nativeOps . shapeBufferForNumpy ( pointer ) ; int length = nativeOps . lengthForShapeBufferPointer ( shapeBufferPointer ) ; shapeBufferPointer . capacity ( 4 * length ) ; shapeBufferPointer . limit ( 4 * length ) ; shapeBufferPointer . position ( 0 ) ; val intPointer = new LongPointer ( shapeBufferPointer ) ; DataBuffer shapeBuffer = Nd4j . createBuffer ( shapeBufferPointer , DataBuffer . Type . LONG , length , LongRawIndexer . create ( intPointer ) ) ; dataPointer . position ( 0 ) ; dataPointer . limit ( dataBufferElementSize * Shape . length ( shapeBuffer ) ) ; dataPointer . capacity ( dataBufferElementSize * Shape . length ( shapeBuffer ) ) ; // we don't care about pointers here, they will be copied in BaseCudaDataBuffer method, and indexer will be recreated if ( dataBufferElementSize == ( Float . SIZE / 8 ) ) { data = Nd4j . createBuffer ( dataPointer , DataBuffer . Type . FLOAT , Shape . length ( shapeBuffer ) , FloatIndexer . create ( new FloatPointer ( dataPointer ) ) ) ; } else if ( dataBufferElementSize == ( Double . SIZE / 8 ) ) { data = Nd4j . createBuffer ( dataPointer , DataBuffer . Type . DOUBLE , Shape . length ( shapeBuffer ) , DoubleIndexer . create ( new DoublePointer ( dataPointer ) ) ) ; } INDArray ret = Nd4j . create ( data , Shape . shape ( shapeBuffer ) , Shape . strideArr ( shapeBuffer ) , Shape . offset ( shapeBuffer ) , Shape . order ( shapeBuffer ) ) ; return ret ; }
Create from an in memory numpy pointer