java.nio.DoubleBuffer#rewind ( )源码实例Demo

下面列出了java.nio.DoubleBuffer#rewind ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: OpenDA   文件: WflowPythonToJavaAdapter.java
public static synchronized void readPcRasterMapValues(Jep jep, String variableName, double[] dest) throws JepException {
    String bufferName = "readPcRasterMapValues" + dest.length;
    Map<Integer, DoubleBuffer> map = readPcRasterMapValuesBuffers.get(jep);
    if (map == null) {
        map = new HashMap<Integer, DoubleBuffer>();
        readPcRasterMapValuesBuffers.put(jep, map);
    }
    DoubleBuffer buffer = map.get(dest.length);
    if (buffer == null) {
        buffer = buffers.get(dest.length);
        if (buffer == null) {
            buffer = createNativeDoubleBuffer(dest.length);
            buffers.put(dest.length, buffer);
        }
        declareDoubleArray(jep, bufferName, buffer);
        map.put(dest.length, buffer);
    }
    jep.eval(bufferName + "[:]=reshape(pcr2numpy(" + variableName + ", 1E31), " + dest.length + ')');
    buffer.rewind();
    buffer.get(dest);
}
 
源代码2 项目: aion-germany   文件: BufferUtils.java
/**
 * Creates a new DoubleBuffer with the same contents as the given DoubleBuffer. The new DoubleBuffer is seperate from the old one and changes are not reflected across. If you want to reflect
 * changes, consider using Buffer.duplicate().
 *
 * @param buf
 *            the DoubleBuffer to copy
 * @return the copy
 */
public static DoubleBuffer clone(DoubleBuffer buf) {
	if (buf == null) {
		return null;
	}
	buf.rewind();

	DoubleBuffer copy;
	if (buf.isDirect()) {
		copy = createDoubleBuffer(buf.limit());
	}
	else {
		copy = DoubleBuffer.allocate(buf.limit());
	}
	copy.put(buf);

	return copy;
}
 
源代码3 项目: Ultraino   文件: BufferUtils.java
/**
 * Creates a new DoubleBuffer with the same contents as the given
 * DoubleBuffer. The new DoubleBuffer is separate from the old one and
 * changes are not reflected across. If you want to reflect changes,
 * consider using Buffer.duplicate().
 *
 * @param buf
 *            the DoubleBuffer to copy
 * @return the copy
 */
public static DoubleBuffer clone(DoubleBuffer buf) {
    if (buf == null) {
        return null;
    }
    buf.rewind();

    DoubleBuffer copy;
    if (isDirect(buf)) {
        copy = createDoubleBuffer(buf.limit());
    } else {
        copy = DoubleBuffer.allocate(buf.limit());
    }
    copy.put(buf);

    return copy;
}
 
源代码4 项目: OSPREY3   文件: CCDKernelCuda.java
public Minimizer.Result downloadResultSync() {
	
	// allocate space for the result
	int numDofs = dofInfos.size();
	Minimizer.Result result = new Minimizer.Result(DoubleFactory1D.dense.make(numDofs), 0);
	
	// wait for the kernel to finish and download the out buffer
	DoubleBuffer buf = ccdOut.downloadSync();
	
	// copy to the result
	buf.rewind();
	result.energy = buf.get();
	for (int d=0; d<numDofs; d++) {
		result.dofValues.set(d, Math.toDegrees(buf.get()));
	}
	
	return result;
}
 
源代码5 项目: OSPREY3   文件: ForcefieldKernelCuda.java
@Override
public double downloadEnergySync() {
	
	// make sure this thread can use the cuda context
	getStream().getContext().attachCurrentThread();
	
	energies.downloadSync();
	DoubleBuffer buf = energies.getHostBuffer();
	
	// do the last bit of the energy sum on the cpu
	// add one element per work group on the gpu
	// typically, it's a factor of groupSize less than the number of atom pairs
	double energy = subset.getInternalSolvationEnergy();
	buf.rewind();
	int n = getEnergySize(subset, func.blockThreads);
	for (int i=0; i<n; i++) {
		energy += buf.get();
	}
	return energy;
}
 
源代码6 项目: OSPREY3   文件: ForcefieldKernelOpenCL.java
@Override
public double downloadEnergySync() {
	
	// IMPORTANT!! rewind the output buffer before downloading energies
	// otherwise we get weird segfaults in nvidia's opencl driver that are next to impossible to diagnose!
	energies.getBuffer().rewind();
	downloadBufferSync(energies);
	
	DoubleBuffer buf = energies.getBuffer();
	
	// do the last bit of the energy sum on the cpu
	// add one element per work group on the gpu
	// typically, it's a factor of groupSize less than the number of atom pairs
	double energy = subset.getInternalSolvationEnergy();
	buf.rewind();
	int n = getEnergySize();
	for (int i=0; i<n; i++) {
		energy += buf.get();
	}
	return energy;
}
 
源代码7 项目: jmonkeyengine   文件: BufferUtils.java
/**
 * Creates a new DoubleBuffer with the same contents as the given
 * DoubleBuffer. The new DoubleBuffer is separate from the old one and
 * changes are not reflected across. If you want to reflect changes,
 * consider using Buffer.duplicate().
 *
 * @param buf
 *            the DoubleBuffer to copy
 * @return the copy
 */
public static DoubleBuffer clone(DoubleBuffer buf) {
    if (buf == null) {
        return null;
    }
    buf.rewind();

    DoubleBuffer copy;
    if (isDirect(buf)) {
        copy = createDoubleBuffer(buf.limit());
    } else {
        copy = DoubleBuffer.allocate(buf.limit());
    }
    copy.put(buf);

    return copy;
}
 
源代码8 项目: MikuMikuStudio   文件: BufferUtils.java
/**
 * Creates a new DoubleBuffer with the same contents as the given
 * DoubleBuffer. The new DoubleBuffer is seperate from the old one and
 * changes are not reflected across. If you want to reflect changes,
 * consider using Buffer.duplicate().
 *
 * @param buf
 *            the DoubleBuffer to copy
 * @return the copy
 */
public static DoubleBuffer clone(DoubleBuffer buf) {
    if (buf == null) {
        return null;
    }
    buf.rewind();

    DoubleBuffer copy;
    if (buf.isDirect()) {
        copy = createDoubleBuffer(buf.limit());
    } else {
        copy = DoubleBuffer.allocate(buf.limit());
    }
    copy.put(buf);

    return copy;
}
 
源代码9 项目: djl   文件: NDManager.java
/**
 * Creates and initializes a 2D {@link NDArray}.
 *
 * @param data the float array that needs to be set
 * @return a new instance of {@link NDArray}
 */
default NDArray create(double[][] data) {
    DoubleBuffer buffer = DoubleBuffer.allocate(data.length * data[0].length);
    for (double[] d : data) {
        buffer.put(d);
    }
    buffer.rewind();
    return create(buffer, new Shape(data.length, data[0].length));
}
 
源代码10 项目: aion-germany   文件: BufferUtils.java
/**
 * Create a new DoubleBuffer of an appropriate size to hold the specified number of doubles only if the given buffer if not already the right size.
 *
 * @param buf
 *            the buffer to first check and rewind
 * @param size
 *            number of doubles that need to be held by the newly created buffer
 * @return the requested new DoubleBuffer
 */
public static DoubleBuffer createDoubleBuffer(DoubleBuffer buf, int size) {
	if (buf != null && buf.limit() == size) {
		buf.rewind();
		return buf;
	}

	buf = createDoubleBuffer(size);
	return buf;
}
 
源代码11 项目: OSPREY3   文件: ResidueForcefieldEnergyCuda.java
private double getEnergy(CUBuffer<IntBuffer> indices) {
	
	// check broken-ness first. easy peasy
	if (isBroken) {
		return Double.POSITIVE_INFINITY;
	}
	
	// make sure this thread can use the cuda context
	getStream().getContext().attachCurrentThread();
	
	// capture the current molecule state
	DoubleBuffer coordsbuf = coords.getHostBuffer();
	coordsbuf.clear();
	for (Residue res : residues) {
		coordsbuf.put(res.coords);
	}
	coordsbuf.clear();
	coords.uploadAsync();
	
	// launch kernel
	func.setArgs(Pointer.to(
		coords.getDevicePointer(),
		data.getDevicePointer(),
		Pointer.to(new int[] { indices.getHostBuffer().limit() }),
		indices.getDevicePointer(),
		energy.getDevicePointer()
	));
	func.runAsync();
	
	// download the energy
	DoubleBuffer buf = energy.downloadSync();
	buf.rewind();
	return buf.get();
}
 
源代码12 项目: Ultraino   文件: BufferUtils.java
/**
 * Create a new DoubleBuffer of an appropriate size to hold the specified
 * number of doubles only if the given buffer if not already the right size.
 *
 * @param buf
 *            the buffer to first check and rewind
 * @param size
 *            number of doubles that need to be held by the newly created
 *            buffer
 * @return the requested new DoubleBuffer
 */
public static DoubleBuffer createDoubleBuffer(DoubleBuffer buf, int size) {
    if (buf != null && buf.limit() == size) {
        buf.rewind();
        return buf;
    }

    buf = createDoubleBuffer(size);
    return buf;
}
 
源代码13 项目: jmonkeyengine   文件: BufferUtils.java
/**
 * Create a new DoubleBuffer of an appropriate size to hold the specified
 * number of doubles only if the given buffer if not already the right size.
 *
 * @param buf
 *            the buffer to first check and rewind
 * @param size
 *            number of doubles that need to be held by the newly created
 *            buffer
 * @return the requested new DoubleBuffer
 */
public static DoubleBuffer createDoubleBuffer(DoubleBuffer buf, int size) {
    if (buf != null && buf.limit() == size) {
        buf.rewind();
        return buf;
    }

    buf = createDoubleBuffer(size);
    return buf;
}
 
源代码14 项目: MikuMikuStudio   文件: BufferUtils.java
/**
 * Create a new DoubleBuffer of an appropriate size to hold the specified
 * number of doubles only if the given buffer if not already the right size.
 *
 * @param buf
 *            the buffer to first check and rewind
 * @param size
 *            number of doubles that need to be held by the newly created
 *            buffer
 * @return the requested new DoubleBuffer
 */
public static DoubleBuffer createDoubleBuffer(DoubleBuffer buf, int size) {
    if (buf != null && buf.limit() == size) {
        buf.rewind();
        return buf;
    }

    buf = createDoubleBuffer(size);
    return buf;
}