use of org.ojalgo.scalar.Scalar in project ojAlgo by optimatika.
the class BufferArray method create.
private static BasicArray<Double> create(final File file, final long... structure) {
final long tmpCount = StructureAnyD.count(structure);
DoubleBuffer tmpDoubleBuffer = null;
try {
final RandomAccessFile tmpRandomAccessFile = new RandomAccessFile(file, "rw");
final FileChannel tmpFileChannel = tmpRandomAccessFile.getChannel();
final long tmpSize = DOUBLE_ELEMENT_SIZE * tmpCount;
if (tmpCount > (1L << 8)) {
final DenseArray.Factory<Double> tmpFactory = new DenseArray.Factory<Double>() {
long offset = 0L;
@Override
public AggregatorSet<Double> aggregator() {
return PrimitiveAggregator.getSet();
}
@Override
public FunctionSet<Double> function() {
return PrimitiveFunction.getSet();
}
@Override
public Scalar.Factory<Double> scalar() {
return PrimitiveScalar.FACTORY;
}
@Override
long getElementSize() {
return DOUBLE_ELEMENT_SIZE;
}
@Override
PlainArray<Double> make(final long size) {
final long tmpSize2 = size * DOUBLE_ELEMENT_SIZE;
try {
final MappedByteBuffer tmpMap = tmpFileChannel.map(MapMode.READ_WRITE, offset, tmpSize2);
tmpMap.order(ByteOrder.nativeOrder());
return new DoubleBufferArray(tmpMap.asDoubleBuffer(), tmpRandomAccessFile);
} catch (final IOException exception) {
throw new RuntimeException(exception);
} finally {
offset += tmpSize2;
}
}
};
return tmpFactory.makeSegmented(structure);
} else {
final MappedByteBuffer tmpMappedByteBuffer = tmpFileChannel.map(FileChannel.MapMode.READ_WRITE, 0L, tmpSize);
tmpMappedByteBuffer.order(ByteOrder.nativeOrder());
tmpDoubleBuffer = tmpMappedByteBuffer.asDoubleBuffer();
return new DoubleBufferArray(tmpDoubleBuffer, tmpRandomAccessFile);
}
} catch (final FileNotFoundException exception) {
throw new RuntimeException(exception);
} catch (final IOException exception) {
throw new RuntimeException(exception);
}
}
Aggregations