Java Code Examples for java.nio.DoubleBuffer#remaining()
The following examples show how to use
java.nio.DoubleBuffer#remaining() .
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: ArrayUtils.java From pixymeta-android with Eclipse Public License 1.0 | 6 votes |
public static double[] toDoubleArray(byte[] data, int offset, int len, boolean bigEndian) { ByteBuffer byteBuffer = ByteBuffer.wrap(data, offset, len); if (bigEndian) { byteBuffer.order(ByteOrder.BIG_ENDIAN); } else { byteBuffer.order(ByteOrder.LITTLE_ENDIAN); } DoubleBuffer doubleBuf = byteBuffer.asDoubleBuffer(); double[] array = new double[doubleBuf.remaining()]; doubleBuf.get(array); return array; }
Example 2
Source File: ArrayUtils.java From icafe with Eclipse Public License 1.0 | 6 votes |
public static double[] toDoubleArray(byte[] data, int offset, int len, boolean bigEndian) { ByteBuffer byteBuffer = ByteBuffer.wrap(data, offset, len); if (bigEndian) { byteBuffer.order(ByteOrder.BIG_ENDIAN); } else { byteBuffer.order(ByteOrder.LITTLE_ENDIAN); } DoubleBuffer doubleBuf = byteBuffer.asDoubleBuffer(); double[] array = new double[doubleBuf.remaining()]; doubleBuf.get(array); return array; }
Example 3
Source File: NDArray.java From djl with Apache License 2.0 | 5 votes |
/** * Converts this {@code NDArray} to a double array. * * @return a double array * @throws IllegalStateException when {@link DataType} of this {@code NDArray} mismatches */ default double[] toDoubleArray() { if (getDataType() != DataType.FLOAT64) { throw new IllegalStateException( "DataType mismatch, Required double" + " Actual " + getDataType()); } DoubleBuffer db = toByteBuffer().asDoubleBuffer(); double[] ret = new double[db.remaining()]; db.get(ret); return ret; }
Example 4
Source File: PrimitiveDoubleArraySerializationProvider.java From geowave with Apache License 2.0 | 5 votes |
@Override public double[] readField(final byte[] fieldData) { if ((fieldData == null) || (fieldData.length < 8)) { return null; } final DoubleBuffer buff = ByteBuffer.wrap(fieldData).asDoubleBuffer(); final double[] result = new double[buff.remaining()]; buff.get(result); return result; }
Example 5
Source File: CdmrfReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
CoverageCoordAxis decodeCoordAxis(CdmrFeatureProto.CoordAxis proto, CoordAxisReader reader) { AxisType axisType = convertAxisType(proto.getAxisType()); String name = proto.getName(); DataType dataType = NcStream.convertDataType(proto.getDataType()); CoverageCoordAxis.DependenceType dependenceType = convertDependenceType(proto.getDepend()); CoverageCoordAxis.Spacing spacing = convertSpacing(proto.getSpacing()); Formatter result = new Formatter(); for (String s : proto.getDependsOnList()) result.format("%s ", s); String dependsOn = result.toString().trim(); AttributeContainerMutable atts = new AttributeContainerMutable("axis atts"); for (ucar.nc2.stream.NcStreamProto.Attribute patt : proto.getAttsList()) atts.addAttribute(NcStream.decodeAtt(patt)); int ncoords = (int) proto.getNvalues(); double[] values = null; if (!proto.getValues().isEmpty()) { // LOOK may mess with ability to change var size later. ByteBuffer bb = ByteBuffer.wrap(proto.getValues().toByteArray()); DoubleBuffer db = bb.asDoubleBuffer(); int n = db.remaining(); values = new double[n]; for (int i = 0; i < n; i++) values[i] = db.get(i); } int[] shape = new int[proto.getShapeCount()]; // LOOK not used ?? for (int i = 0; i < proto.getShapeCount(); i++) shape[i] = proto.getShape(i); CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(); builder.name = name; builder.units = proto.getUnits(); builder.description = proto.getDescription(); builder.dataType = dataType; builder.axisType = axisType; builder.attributes = atts; builder.dependenceType = dependenceType; builder.setDependsOn(dependsOn); builder.spacing = spacing; builder.ncoords = ncoords; builder.startValue = proto.getStartValue(); builder.endValue = proto.getEndValue(); builder.resolution = proto.getResolution(); builder.values = values; builder.reader = reader; builder.isSubset = false; builder.shape = shape.length > 0 ? shape : null; if (dependenceType == CoverageCoordAxis.DependenceType.fmrcReg) { return new TimeAxis2DFmrcReg(builder); } else if (dependenceType == CoverageCoordAxis.DependenceType.twoD && (axisType == AxisType.Lat || axisType == AxisType.Lon)) { return new LatLonAxis2D(builder); } else if (axisType == AxisType.TimeOffset) { return new TimeOffsetAxis(builder); } else { return new CoverageCoordAxis1D(builder); } }