Search in sources :

Example 6 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.

the class KmerPathNode method prepend.

/**
 * Adds the given node to the front of this one
 * @param node
 */
public void prepend(KmerPathNode node) {
    assert (firstStart() == node.lastStart() + 1);
    assert (firstEnd() == node.lastEnd() + 1);
    assert (isReference() == node.isReference());
    assert (node.nextList != null);
    assert (node.nextList.size() == 1);
    assert (node.nextList.get(0) == this);
    assert (prevList != null);
    assert (prevList.size() == 1);
    assert (prevList.get(0) == node);
    int nodeLength = node.length();
    node.kmers.addAll(kmers);
    kmers = node.kmers;
    node.weight.addAll(weight);
    weight = node.weight;
    totalWeight += node.totalWeight;
    reference |= node.reference;
    if (additionalKmerOffsets != null) {
        // shift over the additional kmers offsets to their new values
        for (int i = 0; i < additionalKmerOffsets.size(); i++) {
            additionalKmerOffsets.set(i, additionalKmerOffsets.getInt(i) + nodeLength);
        }
    }
    if (node.additionalKmers != null) {
        if (additionalKmers == null) {
            additionalKmers = new LongArrayList(node.additionalKmers.size());
            additionalKmerOffsets = new IntArrayList(node.additionalKmers.size());
        }
        additionalKmers.addAll(node.additionalKmers);
        additionalKmerOffsets.addAll(node.additionalKmerOffsets);
    }
    prevList = node.prevList;
    edgesSorted &= node.edgesSorted;
    if (prevList != null) {
        for (KmerPathNode n : prevList) {
            replaceFirst(n.nextList, node, this);
            n.edgesSorted = false;
        }
    }
    start = node.start;
    end = node.end;
    node.prevList = null;
    node.nextList = null;
    node.invalidate();
    if (Defaults.SANITY_CHECK_DE_BRUIJN) {
        sanityCheck();
    }
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Example 7 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.

the class LeafBubbleCollapseIterator method partialSequenceBasesDifferent.

private int partialSequenceBasesDifferent(LongArrayList toCollapsePathKmers, TraversalNode tn, boolean traversalForward) {
    LongArrayList nodeKmers = tn.node.node().pathKmers();
    int basesDifference;
    if (traversalForward) {
        basesDifference = KmerEncodingHelper.partialSequenceBasesDifferent(k, toCollapsePathKmers, nodeKmers, tn.pathLength - tn.node.length(), true);
    } else {
        basesDifference = KmerEncodingHelper.partialSequenceBasesDifferent(k, toCollapsePathKmers, nodeKmers, toCollapsePathKmers.size() - tn.pathLength, false);
    }
    return basesDifference;
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList)

Example 8 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project gridss by PapenfussLab.

the class LeafBubbleCollapseIterator method memoizedCollapse.

/**
 * Use a memoized breadth first search to find a similar path
 * @param collapseNodes lookup of collapse path
 * @param toCollapse path to attempt to collapse
 * @param traversalForward traversal direction
 * @param terminalNode node our path must finish on, null if collapsing leaf
 * @return true if the path was collapsed, false otherwise
 */
private boolean memoizedCollapse(Set<KmerPathNode> collapseNodes, TraversalNode toCollapse, boolean traversalForward, KmerPathNode terminalNode) {
    LongArrayList toCollapsePathKmers = new LongArrayList(toCollapse.pathLength);
    for (KmerPathSubnode sn : traversalForward ? toCollapse.toSubnodeNextPath() : toCollapse.toSubnodePrevPath()) {
        toCollapsePathKmers.addAll(sn.node().pathKmers());
    }
    assert (toCollapsePathKmers.size() == toCollapse.pathLength);
    if (terminalNode != null) {
        collapseNodes.remove(terminalNode);
    }
    SortedMap<KmerPathSubnode, List<MemoizedPath>> frontier = new TreeMap<KmerPathSubnode, List<MemoizedPath>>(KmerNodeUtil.ByFirstStartKmer);
    KmerPathSubnode root = traversalForward ? toCollapse.toSubnodeNextPath().getFirst() : toCollapse.toSubnodePrevPath().getLast();
    // set up frontier
    for (TraversalNode tn : successors(collapseNodes, new TraversalNode(root, 0), traversalForward)) {
        MemoizedPath mp = new MemoizedPath(tn, partialSequenceBasesDifferent(toCollapsePathKmers, tn, traversalForward));
        if (frontierProcess(frontier, mp, toCollapse, traversalForward, terminalNode))
            return true;
    }
    while (!frontier.isEmpty()) {
        for (MemoizedPath mp : frontierPop(frontier)) {
            for (TraversalNode tn : successors(collapseNodes, mp.path, traversalForward)) {
                int basesDifferent = mp.basesDifferent + partialSequenceBasesDifferent(toCollapsePathKmers, tn, traversalForward);
                MemoizedPath mpnext = new MemoizedPath(tn, basesDifferent);
                if (frontierProcess(frontier, mpnext, toCollapse, traversalForward, terminalNode))
                    return true;
            }
        }
    }
    if (terminalNode != null) {
        collapseNodes.add(terminalNode);
    }
    return false;
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) List(java.util.List) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 9 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project presto by prestodb.

the class TestColumnIndexFilter method assertAllRows.

private static void assertAllRows(RowRanges ranges, long rowCount) {
    LongList actualList = new LongArrayList();
    ranges.iterator().forEachRemaining((long value) -> actualList.add(value));
    LongList expectedList = new LongArrayList();
    LongStream.range(0, rowCount).forEach(expectedList::add);
    assertArrayEquals(expectedList + " != " + actualList, expectedList.toLongArray(), actualList.toLongArray());
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) LongList(it.unimi.dsi.fastutil.longs.LongList)

Example 10 with LongArrayList

use of it.unimi.dsi.fastutil.longs.LongArrayList in project symja_android_library by axkr.

the class InstantColumn method lag.

@Override
public InstantColumn lag(int n) {
    int srcPos = n >= 0 ? 0 : 0 - n;
    long[] dest = new long[size()];
    int destPos = n <= 0 ? 0 : n;
    int length = n >= 0 ? size() - n : size() + n;
    for (int i = 0; i < size(); i++) {
        dest[i] = InstantColumnType.missingValueIndicator();
    }
    System.arraycopy(data.toLongArray(), srcPos, dest, destPos, length);
    InstantColumn copy = emptyCopy(size());
    copy.data = new LongArrayList(dest);
    copy.setName(name() + " lag(" + n + ")");
    return copy;
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList)

Aggregations

LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)37 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)3 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)3 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)3 LongList (it.unimi.dsi.fastutil.longs.LongList)3 LongOpenHashSet (it.unimi.dsi.fastutil.longs.LongOpenHashSet)3 IOException (java.io.IOException)3 List (java.util.List)3 Block (com.facebook.presto.spi.block.Block)2 Type (com.facebook.presto.spi.type.Type)2 Supplier (com.google.common.base.Supplier)2 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)2 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)2 FloatArrayList (it.unimi.dsi.fastutil.floats.FloatArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)1