Java Code Examples for java.nio.DoubleBuffer#rewind()
The following examples show how to use
java.nio.DoubleBuffer#rewind() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WflowPythonToJavaAdapter.java From OpenDA with GNU Lesser General Public License v3.0 | 6 votes |
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); }
Example 2
Source File: BufferUtils.java From aion-germany with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example 3
Source File: BufferUtils.java From Ultraino with MIT License | 6 votes |
/** * 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; }
Example 4
Source File: CCDKernelCuda.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
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; }
Example 5
Source File: ForcefieldKernelCuda.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
@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; }
Example 6
Source File: ForcefieldKernelOpenCL.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
@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; }
Example 7
Source File: BufferUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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; }
Example 8
Source File: BufferUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * 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; }
Example 9
Source File: NDManager.java From djl with Apache License 2.0 | 5 votes |
/** * 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)); }
Example 10
Source File: BufferUtils.java From aion-germany with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 11
Source File: ResidueForcefieldEnergyCuda.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 12
Source File: BufferUtils.java From Ultraino with MIT License | 3 votes |
/** * 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; }
Example 13
Source File: BufferUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * 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; }
Example 14
Source File: BufferUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 3 votes |
/** * 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; }