use of java.nio.DoubleBuffer in project robovm by robovm.
the class Main method storeValues.
static void storeValues(ByteBuffer directBuf) {
directBuf.position(0);
ShortBuffer shortBuf = directBuf.asShortBuffer();
CharBuffer charBuf = directBuf.asCharBuffer();
IntBuffer intBuf = directBuf.asIntBuffer();
FloatBuffer floatBuf = directBuf.asFloatBuffer();
LongBuffer longBuf = directBuf.asLongBuffer();
DoubleBuffer doubleBuf = directBuf.asDoubleBuffer();
final byte byteValue = -5;
final short shortValue = -1234;
final char charValue = 49200;
final int intValue = 0x12345678;
final float floatValue = 3.14159f;
final long longValue = 0x1122334455667788L;
final double doubleValue = Double.MIN_VALUE;
if (directBuf.put(1, byteValue).get(1) != byteValue) {
throw new RuntimeException("byte get/store failed");
}
if (shortBuf.put(1, shortValue).get(1) != shortValue) {
throw new RuntimeException("short get/store failed");
}
if (charBuf.put(2, charValue).get(2) != charValue) {
throw new RuntimeException("char get/store failed");
}
if (intBuf.put(2, intValue).get(2) != intValue) {
throw new RuntimeException("int get/store failed");
}
if (floatBuf.put(3, floatValue).get(3) != floatValue) {
throw new RuntimeException("float get/store failed");
}
if (longBuf.put(2, longValue).get(2) != longValue) {
throw new RuntimeException("long get/store failed");
}
if (doubleBuf.put(3, doubleValue).get(3) != doubleValue) {
throw new RuntimeException("double get/store failed");
}
directBuf.position(0);
char[] outBuf = new char[directBuf.limit() * 2];
for (int i = 0; i < directBuf.limit(); i++) {
byte b = directBuf.get();
outBuf[i * 2] = hexChar((byte) ((b >> 4) & 0x0f));
outBuf[i * 2 + 1] = hexChar((byte) (b & 0x0f));
}
System.out.println(new String(outBuf));
}
use of java.nio.DoubleBuffer in project angel by Tencent.
the class DefaultRowUpdater method updateDoubleDenseToDoubleDense.
public void updateDoubleDenseToDoubleDense(int size, ByteBuf buf, ServerDenseDoubleRow row, int compressRatio) {
int bitPerItem = 8 * 8 / compressRatio;
DoubleBuffer data = row.getData();
LOG.debug("update double to double, size: " + size);
if (size <= 0)
return;
double maxAbs = buf.readDouble();
int maxPoint = (int) Math.pow(2, bitPerItem - 1) - 1;
for (int i = 0; i < size - 1; i++) {
byte[] itemBytes = new byte[bitPerItem / 8];
buf.readBytes(itemBytes);
int point = byteArray2int(itemBytes);
double parsedValue = (double) point / (double) maxPoint * maxAbs;
data.put(i, data.get(i) + parsedValue);
}
LOG.info(String.format("parse compressed %d double data, max abs: %f, max point: %d", size - 1, maxAbs, maxPoint));
}
use of java.nio.DoubleBuffer in project angel by Tencent.
the class Amax method doProcessRow.
@Override
protected double doProcessRow(ServerDenseDoubleRow row) {
double amax = Double.MIN_VALUE;
DoubleBuffer data = row.getData();
int size = row.size();
for (int i = 0; i < size; i++) {
amax = Math.max(amax, Math.abs(data.get(i)));
}
return amax;
}
use of java.nio.DoubleBuffer in project angel by Tencent.
the class Asum method doProcessRow.
@Override
protected double doProcessRow(ServerDenseDoubleRow row) {
double asum = 0.0;
DoubleBuffer data = row.getData();
int size = row.size();
for (int i = 0; i < size; i++) {
asum += Math.abs(data.get(i));
}
return asum;
}
use of java.nio.DoubleBuffer in project angel by Tencent.
the class Equal method doProcessRow.
@Override
protected double doProcessRow(ServerDenseDoubleRow row1, ServerDenseDoubleRow row2) {
double isEqual = 1.0;
DoubleBuffer data1 = row1.getData();
DoubleBuffer data2 = row2.getData();
int size = row1.size();
for (int i = 0; i < size; i++) {
if (Math.abs(data1.get(i) - data2.get(i)) > 1e-10) {
isEqual = 0.0;
break;
}
}
return isEqual;
}
Aggregations