Refine search
case Short: case UnsignedShort: short s = ((ShortBuffer) buf2).get(index); ((ShortBuffer) buf1).put(s); break; int i = ((IntBuffer) buf2).get(index); ((IntBuffer) buf1).put(i); break; case Float: float f = ((FloatBuffer) buf2).get(index); ((FloatBuffer) buf1).put(f); break; case Double: double d = ((DoubleBuffer) buf2).get(index); ((DoubleBuffer) buf1).put(d); break; default:
/** Checks whether this double buffer is equal to another object. * <p> * If {@code other} is not a double buffer then {@code false} is returned. Two double buffers are equal if and only if their * remaining doubles are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this double buffer. * @return {@code true} if this double buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof DoubleBuffer)) { return false; } DoubleBuffer otherBuffer = (DoubleBuffer)other; if (remaining() != otherBuffer.remaining()) { return false; } int myPosition = position; int otherPosition = otherBuffer.position; boolean equalSoFar = true; while (equalSoFar && (myPosition < limit)) { equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++); } return equalSoFar; }
/** Writes all the remaining doubles of the {@code src} double buffer to this buffer's current position, and increases both * buffers' position by the number of doubles copied. * * @param src the source double buffer. * @return this buffer. * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}. * @exception IllegalArgumentException if {@code src} is this buffer. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public DoubleBuffer put (DoubleBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } double[] doubles = new double[src.remaining()]; src.get(doubles); put(doubles); return this; }
private static void bulkPut(VertexBuffer.Format format, Buffer buf1, Buffer buf2) { switch (format) { case Byte: case Half: case UnsignedByte: ((ByteBuffer) buf1).put((ByteBuffer) buf2); break; case Short: case UnsignedShort: ((ShortBuffer) buf1).put((ShortBuffer) buf2); break; case Int: case UnsignedInt: ((IntBuffer) buf1).put((IntBuffer) buf2); break; case Float: ((FloatBuffer) buf1).put((FloatBuffer) buf2); break; case Double: ((DoubleBuffer) buf1).put((DoubleBuffer) buf2); break; default: throw new UnsupportedOperationException("Unrecoginized buffer format: " + format); } }
Number get(DataType dataType, int index) { if (dataType == DataType.BYTE) return bb.get(index); if (dataType == DataType.SHORT) return bb.asShortBuffer().get(index); if (dataType == DataType.INT) return bb.asIntBuffer().get(index); if (dataType == DataType.LONG) return bb.asLongBuffer().get(index); if (dataType == DataType.FLOAT) return bb.asFloatBuffer().get(index); if (dataType == DataType.DOUBLE) return bb.asDoubleBuffer().get(index); return Double.NaN; }
@Override public void glBufferSubData(int target, int offset, int size, Buffer data) { // Limit the buffer to the given size, restoring it afterwards int oldLimit = data.limit(); if (data instanceof ByteBuffer) { ByteBuffer subData = (ByteBuffer)data; subData.limit(subData.position() + size); GL15.glBufferSubData(target, offset, subData); } else if (data instanceof IntBuffer) { IntBuffer subData = (IntBuffer)data; subData.limit(subData.position() + size/4); GL15.glBufferSubData(target, offset, subData); } else if (data instanceof FloatBuffer) { FloatBuffer subData = (FloatBuffer)data; subData.limit(subData.position() + size/4); GL15.glBufferSubData(target, offset, subData); } else if (data instanceof DoubleBuffer) { DoubleBuffer subData = (DoubleBuffer)data; subData.limit(subData.position() + size/8); GL15.glBufferSubData(target, offset, subData); } else if (data instanceof ShortBuffer) { ShortBuffer subData = (ShortBuffer)data; subData.limit(subData.position() + size/2); GL15.glBufferSubData(target, offset, subData); } data.limit(oldLimit); }
private static void copyBuffer(Buffer buffer, long handle, long flags, int d1) { if (d1 != buffer.capacity()) { Class<?> cls = null; if (buffer instanceof ByteBuffer) { cls.getName() + " of capacity " + d1 + ". Got " + cls.getName() + " of capacity " + buffer.capacity()); int offset = 0; int shift = VM.getInt(VM.getObjectAddress(buffer) + _ELEMENT_SIZE_SHIFT_OFFSET); if (buffer.isDirect()) { src = VM.getLong(VM.getObjectAddress(buffer) + EFFECTIVE_DIRECT_ADDRESS_OFFSET); } else { } else if (buffer instanceof IntBuffer) { array = new int[d1]; ((IntBuffer) buffer).get((int[]) array); } else if (buffer instanceof LongBuffer) { array = new long[d1]; ((LongBuffer) buffer).get((long[]) array); } else if (buffer instanceof FloatBuffer) { array = new float[d1]; ((FloatBuffer) buffer).get((float[]) array); } else if (buffer instanceof DoubleBuffer) { array = new double[d1]; ((DoubleBuffer) buffer).get((double[]) array); buffer.position(pos);
IntBuffer toInt = toView.asIntBuffer(); for (int i = 0; i < n; i++) { int put = fromInt.get(fromOffset + i * fromStride); toInt.put(toOffset + i * toStride, put); FloatBuffer toFloat = toView.asFloatBuffer(); for (int i = 0; i < n; i++) { float put = fromFloat.get(fromOffset + i * fromStride); toFloat.put(toOffset + i * toStride, put); DoubleBuffer toDouble = toView.asDoubleBuffer(); for (int i = 0; i < n; i++) { toDouble.put(toOffset + i * toStride, fromDouble.get(fromOffset + i * fromStride));
checkInt(cb.get(), 8); sb.position(4); BufferUtils.copy(new short[] {1, 2, 3, 4}, 0, sb, 4); checkInt(sb.get(), 1); checkInt(sb.get(), 2); ib.position(4); BufferUtils.copy(new int[] {1, 2, 3, 4}, 0, ib, 4); checkInt(ib.get(), 1); checkInt(ib.get(), 2); lb.position(4); BufferUtils.copy(new long[] {1, 2, 3, 4}, 0, lb, 4); checkInt(lb.get(), 1); checkInt(lb.get(), 2); db.position(4); BufferUtils.copy(new double[] {1, 2, 3, 4}, 0, db, 4); checkFloat(db.get(), 1); checkFloat(db.get(), 2); checkFloat(db.get(), 3); checkFloat(db.get(), 4); db.position(0); BufferUtils.copy(new double[] {5, 6, 7, 8}, 1, db, 3); checkFloat(db.get(), 6); checkFloat(db.get(), 7); checkFloat(db.get(), 8);
@SuppressWarnings("unchecked") public static <B extends Buffer> Object getArray(B buffer) { int length = buffer.capacity(); if (buffer instanceof IntBuffer) { int[] a = new int[length]; ((IntBuffer)buffer).duplicate().get(a); return a; } else if (buffer instanceof LongBuffer) { long[] a = new long[length]; ((LongBuffer)buffer).duplicate().get(a); return a; } else if (buffer instanceof ShortBuffer) { short[] a = new short[length]; ((ShortBuffer)buffer).duplicate().get(a); return a; } else if (buffer instanceof ByteBuffer) { } else if (buffer instanceof DoubleBuffer) { double[] a = new double[length]; ((DoubleBuffer)buffer).duplicate().get(a); return a; } else if (buffer instanceof FloatBuffer) { float[] a = new float[length]; ((FloatBuffer)buffer).duplicate().get(a); return a; } else
val fa = new float[fb.capacity()]; for (int e = 0; e < fb.capacity(); e++) fa[e] = (float) fb.get(e); val fa = new float[fb.capacity()]; for (int e = 0; e < fb.capacity(); e++) fa[e] = fb.get(e); val da = new double[fb.capacity()]; for (int e = 0; e < fb.capacity(); e++) da[e] = fb.get(e); val fa = new float[lb.capacity()]; for (int e = 0; e < lb.capacity(); e++) fa[e] = (float) lb.get(e); if (fa.length == 0) throw new ND4JIllegalStateException("Can't find Tensor values! Probably you've forgot to freeze graph before saving?");
tmpByteBuffer.asLongBuffer().put(seeds); seedsBuffer.write(clQueue, tmpByteBuffer); resultBuffer.read(clQueue, resultByteBuffer); for (int i=0; i<count; ++i) { assertEquals(randoms[i].nextInt(), resultIntBuffer.get(i), "randInt at i="+i); resultBuffer.read(clQueue, resultByteBuffer); for (int i=0; i<count; ++i) { assertEquals(randoms[i].nextInt(186), resultIntBuffer.get(i), "randInt at i="+i+" with n="+186); resultBuffer.read(clQueue, resultByteBuffer); for (int i=0; i<count; ++i) { assertEquals(randoms[i].nextInt(97357), resultIntBuffer.get(i), "randInt at i="+i+" with n="+97357); resultBuffer.read(clQueue, resultByteBuffer); for (int i=0; i<count; ++i) { assertEquals(randoms[i].nextLong(), resultLongBuffer.get(i), "randLong at i="+i); resultBuffer.read(clQueue, resultByteBuffer); for (int i=0; i<count; ++i) { assertEquals(randoms[i].nextFloat(), resultFloatBuffer.get(i), "randFloat at i="+i); resultBuffer.read(clQueue, resultByteBuffer); for (int i=0; i<count; ++i) { assertEquals(randoms[i].nextDouble(), resultDoubleBuffer.get(i), "randLong at i="+i);
vb.getData().clear(); // reset position & limit (used later) FloatBuffer fb = (FloatBuffer) vb.getData(); for (int comp = 0; comp < vb.components; comp++){ dataBuf.putFloat(fb.get()); ShortBuffer sb = (ShortBuffer) vb.getData(); for (int comp = 0; comp < vb.components; comp++){ dataBuf.putShort(sb.get()); IntBuffer ib = (IntBuffer) vb.getData(); for (int comp = 0; comp < vb.components; comp++){ dataBuf.putInt(ib.get()); DoubleBuffer db = (DoubleBuffer) vb.getData(); for (int comp = 0; comp < vb.components; comp++){ dataBuf.putDouble(db.get());
geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Reused(), 1); geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Indices(), createBuffer(queryContext, indices)); geometryData.set("nrIndices", indicesAsInt.capacity()); ByteBuffer vertices = geometry.getVertices(); DoubleBuffer verticesAsDouble = vertices.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer(); geometryData.set("nrVertices", verticesAsDouble.capacity()); geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Vertices(), createBuffer(queryContext, vertices)); ByteBuffer normals = geometry.getNormals(); FloatBuffer normalsAsFloat = normals.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer(); geometryData.set("nrNormals", normalsAsFloat.capacity()); geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Normals(), createBuffer(queryContext, normals)); FloatBuffer materialsAsFloat = geometry.getMaterials().order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer(); boolean hasMaterial = false; colors = ByteBuffer.allocate((verticesAsDouble.capacity() / 3) * 4); triangle[j * 3 + 0] = verticesAsDouble.get(3 * k); triangle[j * 3 + 1] = verticesAsDouble.get(3 * k + 1); triangle[j * 3 + 2] = verticesAsDouble.get(3 * k + 2); hasMaterial = true; for (int l = 0; l < 4; ++l) { float val = fixColor(materialsAsFloat.get(4 * c + l)); colors.put(4 * k + l, UnsignedBytes.checkedCast((int)(val * 255))); geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_NrVertices(), verticesAsDouble.capacity()); geometryInfo.setReference(GeometryPackage.eINSTANCE.getGeometryInfo_Data(), geometryData.getOid(), 0); geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_HasTransparency(), hasTransparency); double[] firstVertex = new double[] { verticesAsDouble.get(firstIndex), verticesAsDouble.get(firstIndex + 1), verticesAsDouble.get(firstIndex + 2) };
array.getDataAsByteBuffer().asDoubleBuffer(); double[] samples = new double[destRegion.width * destRegion.height]; doubleBuffer.get(samples); raster.setSamples( xmin, float[] samples = new float[destRegion.width * destRegion.height]; FloatBuffer floatBuffer = array.getDataAsByteBuffer().asFloatBuffer(); floatBuffer.get(samples); raster.setSamples( xmin, ymin, destRegion.width, destRegion.height, dstBand, samples); IntBuffer intBuffer = array.getDataAsByteBuffer().asIntBuffer(); int[] intSamples = new int[destRegion.width * destRegion.height]; intBuffer.get(intSamples); raster.setSamples( xmin,
/** * Creates the actual Buffer objects. */ public void createBuffers() { for (BufferInfo info : mBuffers) { if (info.buffer != null) { if (info.buffer instanceof FloatBuffer) { ((FloatBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof IntBuffer) { ((IntBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof ShortBuffer) { ((ShortBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof ByteBuffer) { ((ByteBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof DoubleBuffer) { ((DoubleBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof LongBuffer) { ((LongBuffer) info.buffer).compact().position(0); } else if (info.buffer instanceof CharBuffer) { ((CharBuffer) info.buffer).compact().position(0); } } createBuffer(info); } GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); mHaveCreatedBuffers = true; }
/** * Copies {@code count} floats from {@code src} starting at offset {@code offset} * to the memory pointed to by this {@link MachineSizedFloatPtr}. Does * {@code float} to {@code double} conversion if running on a 64-bit * platform. * * @param src the source. * @param offset the offset within the source array to start copying from. * @param count the number of elements to copy. */ public void set(float[] src, int offset, int count) { if (_sizeOf() == 4) { asFloatBuffer(count).put(src, offset, count); } else { Arrays.checkOffsetAndCount(src.length, offset, count); DoubleBuffer buf = asDoubleBuffer(count); for (int i = 0; i < count; i++) { buf.put(src[i + offset]); } } }
val db = bb.order(_order).asDoubleBuffer(); for (int e = 0; e < prod; e++) doubles[e] = db.get(e); val fb = bb.order(_order).asFloatBuffer(); for (int e = 0; e < prod; e++) doubles[e] = (double) fb.get(e); val sb = bb.order(_order).asShortBuffer(); for (int e = 0; e < prod; e++) doubles[e] = (double) HalfIndexer.toFloat((int) sb.get(e));
@Override public void copy(@Nonnull double[] from, @Nonnull byte[] to) { @Nonnull DoubleBuffer inBuffer = DoubleBuffer.wrap(from); @Nonnull FloatBuffer outBuffer = ByteBuffer.wrap(to).asFloatBuffer(); while (inBuffer.hasRemaining()) { outBuffer.put((float) inBuffer.get()); } }