use of it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry in project gridss by PapenfussLab.
the class IntervalCoverageAccumulator method writeToBed.
public void writeToBed(File bed) throws IOException {
try (BedWriter writer = new BedWriter(dictionary, bed)) {
for (int i = 0; i < coverage.length; i++) {
ObjectBidirectionalIterator<Entry> it = coverage[i].iterator();
while (it.hasNext()) {
Entry e = it.next();
int start = e.getIntKey();
int binWidth = coverage[i].getBinSize(start);
int end = start + binWidth - 1;
writer.write(i, start, end, coverage[i].getMeanValue(start));
}
}
}
}
use of it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry in project angel by Tencent.
the class ByteBufSerdeUtils method serializeIntDoubleVector.
// IntDoubleVector
private static void serializeIntDoubleVector(ByteBuf out, IntDoubleVector vector) {
IntDoubleVectorStorage storage = vector.getStorage();
if (storage.isDense()) {
serializeInt(out, DENSE_STORAGE_TYPE);
serializeDoubles(out, storage.getValues());
} else if (storage.isSparse()) {
serializeInt(out, SPARSE_STORAGE_TYPE);
serializeInt(out, storage.size());
ObjectIterator<Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
Entry e = iter.next();
serializeInt(out, e.getIntKey());
serializeDouble(out, e.getDoubleValue());
}
} else if (storage.isSorted()) {
serializeInt(out, SORTED_STORAGE_TYPE);
int[] indices = vector.getStorage().getIndices();
double[] values = vector.getStorage().getValues();
serializeInts(out, indices);
serializeDoubles(out, values);
} else {
throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
}
}
use of it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry in project angel by Tencent.
the class StreamSerdeUtils method serializeIntDoubleVector.
// IntDoubleVector
private static void serializeIntDoubleVector(DataOutputStream out, IntDoubleVector vector) throws IOException {
IntDoubleVectorStorage storage = vector.getStorage();
if (storage.isDense()) {
serializeInt(out, DENSE_STORAGE_TYPE);
serializeDoubles(out, storage.getValues());
} else if (storage.isSparse()) {
serializeInt(out, SPARSE_STORAGE_TYPE);
serializeInt(out, storage.size());
ObjectIterator<Entry> iter = storage.entryIterator();
while (iter.hasNext()) {
Entry e = iter.next();
serializeInt(out, e.getIntKey());
serializeDouble(out, e.getDoubleValue());
}
} else if (storage.isSorted()) {
serializeInt(out, SORTED_STORAGE_TYPE);
int[] indices = vector.getStorage().getIndices();
double[] values = vector.getStorage().getValues();
serializeInts(out, indices);
serializeDoubles(out, values);
} else {
throw new UnsupportedOperationException("Unsupport storage type " + vector.getStorage().getClass());
}
}
use of it.unimi.dsi.fastutil.ints.Int2DoubleMap.Entry in project gridss by PapenfussLab.
the class IntervalAccumulator method add.
/**
* Add the given value at all positions in the given interval
* @param start start position (inclusive)
* @param end end position (inclusive)
* @param value value to add
*/
public void add(int start, int end, double value) {
if (binWidth == null) {
throw new IllegalStateException("Must be called after finaliseBins()");
}
if (end < start) {
throw new IllegalArgumentException("end cannot be before start");
}
// double perBaseValue = value / (end - start + 1);
start = Math.max(start, firstBinStart);
end = Math.min(end, lastBinEnd);
int startBinStartKey = bins.headMap(start + 1).lastIntKey();
int endBinStartKey = bins.headMap(end + 1).lastIntKey();
Int2DoubleSortedMap toUpdate = bins.subMap(startBinStartKey, endBinStartKey + 1);
ObjectBidirectionalIterator<Int2DoubleMap.Entry> it = toUpdate.int2DoubleEntrySet().iterator();
int widthLeft = end - start + 1;
while (widthLeft > 0) {
assert (it.hasNext());
Int2DoubleMap.Entry entry = it.next();
int entryStartPosition = entry.getIntKey();
int overlap = IntervalUtil.overlapsWidthClosed(start, end, entryStartPosition, entryStartPosition + getBinSize(entryStartPosition) - 1);
entry.setValue(entry.getDoubleValue() + overlap * value);
widthLeft -= overlap;
}
}
Aggregations