本文整理汇总了Java中java.nio.DoubleBuffer类的典型用法代码示例。如果您正苦于以下问题:Java DoubleBuffer类的具体用法?Java DoubleBuffer怎么用?Java DoubleBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DoubleBuffer类属于java.nio包,在下文中一共展示了DoubleBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import java.nio.DoubleBuffer; //导入依赖的package包/类
private void create() throws IOException{
if( isCreate ){
return;
}
ICompressor compressor = FindCompressor.get( columnBinary.compressorClassName );
byte[] binary = compressor.decompress( columnBinary.binary , binaryStart , binaryLength );
ByteBuffer wrapBuffer = ByteBuffer.wrap( binary );
int nullFlagBinaryLength = wrapBuffer.getInt();
int doubleBinaryLength = wrapBuffer.getInt();
int nullFlagBinaryStart = Integer.BYTES * 2;
int doubleBinaryStart = nullFlagBinaryStart + nullFlagBinaryLength;
DoubleBuffer doubleBuffer = ByteBuffer.wrap( binary , doubleBinaryStart , doubleBinaryLength ).asDoubleBuffer();
IDicManager dicManager = new DoubleDicManager( binary , nullFlagBinaryStart , nullFlagBinaryLength , doubleBuffer );
column = new PrimitiveColumn( columnBinary.columnType , columnBinary.columnName );
column.setCellManager( new BufferDirectCellManager( ColumnType.DOUBLE , dicManager , nullFlagBinaryLength ) );
isCreate = true;
}
示例2: clone
import java.nio.DoubleBuffer; //导入依赖的package包/类
/**
* Creates a clone of the given buffer. The clone's capacity is
* equal to the given buffer's limit.
*
* @param buf The buffer to clone
* @return The cloned buffer
*/
public static Buffer clone(Buffer buf) {
if (buf instanceof FloatBuffer) {
return clone((FloatBuffer) buf);
} else if (buf instanceof ShortBuffer) {
return clone((ShortBuffer) buf);
} else if (buf instanceof ByteBuffer) {
return clone((ByteBuffer) buf);
} else if (buf instanceof IntBuffer) {
return clone((IntBuffer) buf);
} else if (buf instanceof DoubleBuffer) {
return clone((DoubleBuffer) buf);
} else {
throw new UnsupportedOperationException();
}
}
示例3: testDoubleGet
import java.nio.DoubleBuffer; //导入依赖的package包/类
@Test(dataProvider = "doubleViewProvider")
public void testDoubleGet(String desc, IntFunction<ByteBuffer> fbb,
Function<ByteBuffer, DoubleBuffer> fbi) {
ByteBuffer bb = allocate(fbb);
DoubleBuffer vb = fbi.apply(bb);
int o = bb.position();
for (int i = 0; i < vb.limit(); i++) {
double fromBytes = getDoubleFromBytes(bb, o + i * 8);
double fromMethodView = bb.getDouble(o + i * 8);
assertValues(i, fromBytes, fromMethodView, bb);
double fromBufferView = vb.get(i);
assertValues(i, fromMethodView, fromBufferView, bb, vb);
}
for (int i = 0; i < vb.limit(); i++) {
double v = getDoubleFromBytes(bb, o + i * 8);
double a = bb.getDouble();
assertValues(i, v, a, bb);
double b = vb.get();
assertValues(i, a, b, bb, vb);
}
}
示例4: doUpdate
import java.nio.DoubleBuffer; //导入依赖的package包/类
@Override
protected void doUpdate(ServerDenseDoubleRow[] rows, double[] scalars) {
Random rand = new Random(System.currentTimeMillis());
try {
rows[0].getLock().writeLock().lock();
double min = scalars[0];
double max = scalars[1];
double factor = max - min;
DoubleBuffer data = rows[0].getData();
int size = rows[0].size();
for (int i = 0; i < size; i++) {
data.put(i, factor * rand.nextDouble() + min);
}
} finally {
rows[0].getLock().writeLock().unlock();
}
}
示例5: initializeCrossline
import java.nio.DoubleBuffer; //导入依赖的package包/类
private void initializeCrossline(DrawContext dc) {
DoubleBuffer verts = crossLine;
if (verts == null)
verts = Buffers.newDirectDoubleBuffer(points.size() * 3);
for (LatLon point : points)
{
double alt =
elevation + baseHeight * exageration * (yMax - yMin) * crossLinePercent;
Vec4 p1 =
dc.getGlobe().computePointFromPosition(point.getLatitude(), point.getLongitude(), alt);
verts.put(p1.x - referenceCenter.x);
verts.put(p1.y - referenceCenter.y);
verts.put(p1.z - referenceCenter.z);
}
this.crossLine = verts;
}
示例6: readPcRasterMapValues
import java.nio.DoubleBuffer; //导入依赖的package包/类
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);
}
示例7: updateDoubleDenseToDoubleDense
import java.nio.DoubleBuffer; //导入依赖的package包/类
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));
}
示例8: byteArray2DoubleArray
import java.nio.DoubleBuffer; //导入依赖的package包/类
@Nullable
private static double[] byteArray2DoubleArray(byte... array) {
if (array == null) {
return null;
}
final int len = array.length;
final double[] res = new double[len >> 3];
try {
final DoubleBuffer buffer = ByteBuffer.wrap(array).asDoubleBuffer();
for (int i = 0, iLen = len >> 3; i < iLen; ++i) {
res[i] = buffer.get();
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
示例9: toBinary
import java.nio.DoubleBuffer; //导入依赖的package包/类
@Override
public ColumnBinary toBinary(final ColumnBinaryMakerConfig commonConfig , final ColumnBinaryMakerCustomConfigNode currentConfigNode , final IColumn column ) throws IOException{
ColumnBinaryMakerConfig currentConfig = commonConfig;
if( currentConfigNode != null ){
currentConfig = currentConfigNode.getCurrentConfig();
}
byte[] binaryRaw = new byte[ getBinaryLength( column.size() ) ];
ByteBuffer lengthBuffer = ByteBuffer.wrap( binaryRaw );
lengthBuffer.putInt( column.size() );
lengthBuffer.putInt( column.size() * Double.BYTES );
ByteBuffer nullFlagBuffer = ByteBuffer.wrap( binaryRaw , Integer.BYTES * 2 , column.size() );
DoubleBuffer doubleBuffer = ByteBuffer.wrap( binaryRaw , ( Integer.BYTES * 2 + column.size() ) , ( column.size() * Double.BYTES ) ).asDoubleBuffer();
int rowCount = 0;
for( int i = 0 ; i < column.size() ; i++ ){
ICell cell = column.get(i);
if( cell.getType() == ColumnType.NULL ){
nullFlagBuffer.put( (byte)1 );
doubleBuffer.put( (double)0 );
}
else{
rowCount++;
PrimitiveCell byteCell = (PrimitiveCell) cell;
nullFlagBuffer.put( (byte)0 );
doubleBuffer.put( byteCell.getRow().getDouble() );
}
}
byte[] binary = currentConfig.compressorClass.compress( binaryRaw , 0 , binaryRaw.length );
return new ColumnBinary( this.getClass().getName() , currentConfig.compressorClass.getClass().getName() , column.getColumnName() , ColumnType.DOUBLE , rowCount , binaryRaw.length , rowCount * Double.BYTES , -1 , binary , 0 , binary.length , null );
}
示例10: asDoubleBuffer
import java.nio.DoubleBuffer; //导入依赖的package包/类
public DoubleBuffer asDoubleBuffer()
{
DoubleBuffer buffer = DoubleBuffer.allocate(4*4);
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
buffer.put(data[i][j]);
buffer.flip();
return buffer;
}
示例11: writeDoubleBuffer
import java.nio.DoubleBuffer; //导入依赖的package包/类
private static void writeDoubleBuffer(DoubleBuffer buf) {
Buffer viewedBuffer = bufferViews.get(buf);
if (viewedBuffer != null) {
bufferEndiannessWritten.put(viewedBuffer, buf.order());
} else {
throw new AssertionError();
}
}
示例12: doProcessRow
import java.nio.DoubleBuffer; //导入依赖的package包/类
@Override
protected double doProcessRow(ServerDenseDoubleRow row) {
double qSum = 0;
DoubleBuffer data = row.getData();
int size = row.size();
for (int i = 0; i < size; i++) {
qSum += Math.pow(data.get(i), 2);
}
return qSum;
}
示例13: doProcessRow
import java.nio.DoubleBuffer; //导入依赖的package包/类
@Override
protected double doProcessRow(ServerDenseDoubleRow row) {
double sum = 0.0;
DoubleBuffer data = row.getData();
int size = row.size();
for (int i = 0; i < size; i++) {
sum += data.get(i);
}
return sum;
}
示例14: doProcessRow
import java.nio.DoubleBuffer; //导入依赖的package包/类
@Override
protected double doProcessRow(ServerDenseDoubleRow row) {
double min = Double.POSITIVE_INFINITY;
DoubleBuffer data = row.getData();
int size = row.size();
for (int i = 0; i < size; i++) {
min = Math.min(min, data.get(i));
}
return min;
}
示例15: doProcessRow
import java.nio.DoubleBuffer; //导入依赖的package包/类
@Override
protected double doProcessRow(ServerDenseDoubleRow row) {
double max = Double.NEGATIVE_INFINITY;
DoubleBuffer data = row.getData();
int size = row.size();
for (int i = 0; i < size; i++) {
max = Math.max(max, data.get(i));
}
return max;
}