Refine search
protected MappeableContainer ilazyor(MappeableBitmapContainer x) { if (BufferUtil.isBackedBySimpleArray(x.bitmap)) { long[] b = this.bitmap.array(); long[] b2 = x.bitmap.array(); for (int k = 0; k < b.length; k++) { b[k] |= b2[k]; } } else { final int m = this.bitmap.limit(); for (int k = 0; k < m; k++) { this.bitmap.put(k, this.bitmap.get(k) | x.bitmap.get(k)); } } this.cardinality = -1;// invalid return this; }
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of longs to fill * @return the buffer instance */ public static LongBuffer fill(LongBuffer buffer, long value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put(value); } } return buffer; }
/** Creates a new long buffer by wrapping the given long array. * <p> * Calling this method has the same effect as {@code wrap(array, 0, array.length)}. * </p> * * @param array the long array which the new buffer will be based on. * @return the created long buffer. * @since Android 1.0 */ public static LongBuffer wrap (long[] array) { return wrap(array, 0, array.length); }
/** Checks whether this long buffer is equal to another object. * <p> * If {@code other} is not a long buffer then {@code false} is returned. Two long buffers are equal if and only if their * remaining longs are exactly the same. Position, limit, capacity and mark are not considered. * </p> * * @param other the object to compare with this long buffer. * @return {@code true} if this long buffer is equal to {@code other}, {@code false} otherwise. * @since Android 1.0 */ public boolean equals (Object other) { if (!(other instanceof LongBuffer)) { return false; } LongBuffer otherBuffer = (LongBuffer)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; }
} else if (buffer instanceof ShortBuffer) { array = new short[d1]; ((ShortBuffer) buffer).get((short[]) array); } else if (buffer instanceof CharBuffer) { array = new char[d1]; } 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);
@SuppressWarnings("unchecked") public static <B extends Buffer> B puti(final B dest, final int v) { if (dest instanceof IntBuffer) { return (B) ((IntBuffer) dest).put(v); } else if (dest instanceof FloatBuffer) { return (B) ((FloatBuffer) dest).put(v); } else if (dest instanceof LongBuffer) { return (B) ((LongBuffer) dest).put(v); } else if (dest instanceof DoubleBuffer) { return (B) ((DoubleBuffer) dest).put(v); } else { throw new IllegalArgumentException("Integer doesn't match Buffer Class: " + dest); } }
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); checkInt(lb.get(), 3); checkInt(lb.get(), 4); lb.position(0); BufferUtils.copy(new long[] {5, 6, 7, 8}, 1, lb, 3); checkInt(lb.get(), 6); checkInt(lb.get(), 7); checkInt(lb.get(), 8); fb.position(4); BufferUtils.copy(new float[] {1, 2, 3, 4}, 0, fb, 4); checkFloat(fb.get(), 1); checkFloat(fb.get(), 2);
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);
/** * Copies {@code count} longs from the memory pointed to by this * {@link MachineSizedUIntPtr} to {@code dst} starting at offset {@code offset}. * Does unsigned {@code int} to {@code long} conversion if running on * a 32-bit platform. * * @param dst the destination. * @param offset the offset within the destination array to start copying to. * @param count the number of elements to copy. */ public void get(long[] dst, int offset, int count) { if (_sizeOf() == 8) { asLongBuffer(count).get(dst, offset, count); } else { Arrays.checkOffsetAndCount(dst.length, offset, count); IntBuffer buf = asIntBuffer(count); for (int i = 0; i < count; i++) { dst[i + offset] = ((long) buf.get()) & 0xffffffffL; } } }
/** * Copies {@code count} ints from {@code src} starting at offset {@code offset} * to the memory pointed to by this {@link MachineSizedUIntPtr}. Does * unsigned {@code int} to {@code long} 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(int[] src, int offset, int count) { if (_sizeOf() == 4) { asIntBuffer(count).put(src, offset, count); } else { Arrays.checkOffsetAndCount(src.length, offset, count); LongBuffer buf = asLongBuffer(count); for (int i = 0; i < count; i++) { buf.put(((long) src[i + offset]) & 0xffffffffL); } } }
/** * 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; }
@Override public Image createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr) { long memFlags = Utils.getMemoryAccessFlags(access); Utils.errorBuffer.rewind(); //fill image format Utils.tempBuffers[0].b16i.rewind(); Utils.tempBuffers[0].b16i.put(LwjglImage.decodeImageChannelOrder(format.channelOrder)) .put(LwjglImage.decodeImageChannelType(format.channelType)); Utils.tempBuffers[0].b16.rewind(); //fill image desc Utils.b80l.rewind(); Utils.b80l.put(LwjglImage.decodeImageType(descr.type)) .put(descr.width).put(descr.height).put(descr.depth) .put(descr.arraySize).put(descr.rowPitch).put(descr.slicePitch) .put(0).put(0).put(0); Utils.b80.rewind(); //create image CLMem mem = CL12.clCreateImage(context, memFlags, Utils.tempBuffers[0].b16, Utils.b80, descr.hostPtr, Utils.errorBuffer); Utils.checkError(Utils.errorBuffer, "clCreateImage"); return new LwjglImage(mem); }
protected void loadData(final MappeableArrayContainer arrayContainer) { this.cardinality = arrayContainer.cardinality; if (!BufferUtil.isBackedBySimpleArray(bitmap)) { throw new RuntimeException("Should not happen. Internal bug."); } long[] bitArray = bitmap.array(); if (BufferUtil.isBackedBySimpleArray(bitmap) && BufferUtil.isBackedBySimpleArray(arrayContainer.content)) { long[] b = bitmap.array(); short[] ac = arrayContainer.content.array(); for (int k = 0; k < arrayContainer.cardinality; ++k) { final short x = ac[k]; bitArray[toIntUnsigned(x) / 64] = b[toIntUnsigned(x) / 64] | (1L << x); } } else { for (int k = 0; k < arrayContainer.cardinality; ++k) { final short x = arrayContainer.content.get(k); bitArray[toIntUnsigned(x) / 64] = bitmap.get(toIntUnsigned(x) / 64) | (1L << x); } } }
/** Writes all the remaining longs of the {@code src} long buffer to this buffer's current position, and increases both buffers' * position by the number of longs copied. * * @param src the source long 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 LongBuffer put (LongBuffer src) { if (src == this) { throw new IllegalArgumentException(); } if (src.remaining() > remaining()) { throw new BufferOverflowException(); } long[] contents = new long[src.remaining()]; src.get(contents); put(contents); return this; }
public static <B extends Buffer> B wrapArray(Object a) { if (a instanceof int[]) return (B)IntBuffer.wrap((int[])a); if (a instanceof long[]) return (B)LongBuffer.wrap((long[])a); if (a instanceof short[]) return (B)ShortBuffer.wrap((short[])a); if (a instanceof byte[]) return (B)ByteBuffer.wrap((byte[])a); if (a instanceof float[]) return (B)FloatBuffer.wrap((float[])a); if (a instanceof double[]) return (B)DoubleBuffer.wrap((double[])a); throw new UnsupportedOperationException("Cannot wrap primitive arrays of type " + a.getClass().getName()); } @SuppressWarnings("unchecked")
/** Writes longs from the given long array to the current position and increases the position by the number of longs written. * <p> * Calling this method has the same effect as {@code put(src, 0, src.length)}. * </p> * * @param src the source long array. * @return this buffer. * @exception BufferOverflowException if {@code remaining()} is less than {@code src.length}. * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer. * @since Android 1.0 */ public final LongBuffer put (long[] src) { return put(src, 0, src.length); }
/** Reads longs from the current position into the specified long array and increases the position by the number of longs read. * <p> * Calling this method has the same effect as {@code get(dest, 0, dest.length)}. * </p> * * @param dest the destination long array. * @return this buffer. * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}. * @since Android 1.0 */ public LongBuffer get (long[] dest) { return get(dest, 0, dest.length); }