/** * Allocates enough memory for the array and copies it. * * @param array the array to copy * @see #put(float[]) */ public FloatPointer(float ... array) { this(array.length); put(array); } /**
/** @return {@code put(array, 0, array.length)} */ public FloatPointer put(float ... array) { return put(array, 0, array.length); } /**
/** @return {@code put(0, f)} */ public FloatPointer put(float f) { return put(0, f); } /**
@Override public void release() { pointer.position(position).put(array); super.release(); } };
/** * For direct buffers, calls {@link Pointer#Pointer(Buffer)}, while for buffers * backed with an array, allocates enough memory for the array and copies it. * * @param buffer the Buffer to reference or copy * @see #put(float[]) */ public FloatPointer(FloatBuffer buffer) { super(buffer); if (buffer != null && !buffer.isDirect() && buffer.hasArray()) { float[] array = buffer.array(); allocateArray(array.length - buffer.arrayOffset()); put(array, buffer.arrayOffset(), array.length - buffer.arrayOffset()); position(buffer.position()); limit(buffer.limit()); } } /**
public BaseDataBuffer(float[] data, boolean copy, MemoryWorkspace workspace) { allocationMode = AllocUtil.getAllocationModeFromContext(); length = data.length; underlyingLength = data.length; attached = true; parentWorkspace = workspace; initTypeAndSize(); //log.info("Allocating FloatPointer from array of {} elements", data.length); pointer = workspace.alloc(data.length * getElementSize(), dataType(), false).asFloatPointer().put(data); workspaceGenerationId = workspace.getGenerationId(); setIndexer(FloatIndexer.create((FloatPointer) pointer)); //wrappedBuffer = pointer.asByteBuffer(); }
/** * Sets specified value at specified index. * <pre> * {@code nativeArray[i] = v; } * </pre> * @param i index * @param v value * @return this for chaining */ @FloatPrecisionVersion public NativeRealArray set(long i, float v){ if(i >= this.length){ throw new ArrayIndexOutOfBoundsException( String.format("Cannot set value at %d, array is of length %d", i, this.length)); } pointer.position(0).put(i, v); return this; }
/** * Reads <i>length</i> number of elements from the specified * array starting at <i>offset</i> and puts them into this * native array starting at <i>i</i>. * <pre> * {@code for(j=0;j<length;j++) nativeArray[i+j]=values[offset+j]; } * </pre> * @param i offset into this native array * @param length number of values to be copied * @param offset into the specified array * @param values the array from which values will be copied * @return this for chaining * * @throws IllegalArgumentException when specified offset plus length exceeds the specified values array's length */ @FloatPrecisionVersion public NativeRealArray set(long i, int length, int offset, float[] values){ if(offset+length > values.length){ throw new IllegalArgumentException( String.format("Cannot read %d values starting from %d, argument array is only of length %d", length, offset, values.length)); } if(i+length > this.length){ throw new ArrayIndexOutOfBoundsException( String.format("Number of values to be set (%d) to insert at index %d exceed length of this array (%d)", length, i, this.length)); } pointer.position(i).put(values, offset, length); return this; }
public Pair<List<Rectangle>, HeatMap> detect(BufferedImage image) { Timer timer = new Timer(); timer.start(); setCaffeMode(caffe_gpu); PreprocessedImage processedImage = processImage(image, NETWORK_INPUT_WIDTH, NETWORK_INPUT_HEIGHT); FloatPointer pointer = new FloatPointer(processedImage.data.length); pointer.put(processedImage.data); float[] output; synchronized (caffeNetLock) { caffe_net.input_blobs().get(0).set_cpu_data(pointer); output = transferNetworkOutputToJava(caffe_net.Forward()); } HeatMap outputMap = new HeatMap(0, 0, NETWORK_OUTPUT_WIDTH, NETWORK_OUTPUT_HEIGHT); System.arraycopy(output, 0, outputMap.data, 0, output.length); final float outputScaleX = outputMap.w / (float)NETWORK_INPUT_WIDTH; final float outputScaleY = outputMap.h / (float)NETWORK_INPUT_HEIGHT; List<Component> components = findComponents(binarize(outputMap)); List<Rectangle> result = new ArrayList<>(); for (Component component : components) { float inputScaleX = NETWORK_INPUT_WIDTH / (float) image.getWidth(); float inputScaleY = NETWORK_INPUT_HEIGHT / (float) image.getHeight(); result.add(componentBound(component, inputScaleX, inputScaleY, outputScaleX, outputScaleY)); } System.out.println("Total detection time: " + timer.lap()); return Pair.of(result, outputMap); }
tArgs.put(cnt++, (float) t);
FloatBuffer b = (FloatBuffer)samples[i]; if (samples_in[i] instanceof FloatPointer && samples_in[i].capacity() >= inputSize && b.hasArray()) { ((FloatPointer)samples_in[i]).position(0).put(b.array(), b.position(), inputSize); } else { samples_in[i] = new FloatPointer(b);
FloatBuffer b = (FloatBuffer)samples[i]; if (samples_in[i] instanceof FloatPointer && samples_in[i].capacity() >= inputSize && b.hasArray()) { ((FloatPointer)samples_in[i]).position(0).put(b.array(), b.position(), inputSize); } else { samples_in[i] = new FloatPointer(b);
for (int e = 0; e < op.getRealArguments().size(); e++) { idx = realPos + i * op.maxRealArguments(); realPtr.put(idx + e, op.getRealArguments().get(e).floatValue());
for (int e = 0; e < op.getRealArguments().size(); e++) { idx = realPos + i * op.maxRealArguments(); realPtr.put(idx + e, op.getRealArguments().get(e).floatValue());
tArgs.put(cnt++, (float) t);