Package gnu.trove.set.hash

Examples of gnu.trove.set.hash.TIntHashSet


        if (forbiddenNames.length == 0)
            return tensor;
        if (tensor instanceof Complex || tensor instanceof ScalarFunction)
            return tensor;

        TIntHashSet allIndicesNames = TensorUtils.getAllDummyIndicesT(tensor);
        //no indices in tensor
        if (allIndicesNames.isEmpty())
            return tensor;

        allIndicesNames.ensureCapacity(forbiddenNames.length);

        IntArrayList fromL = null;
        for (int forbidden : forbiddenNames) {
            if (!allIndicesNames.add(forbidden)) {
                if (fromL == null)
                    fromL = new IntArrayList();
                fromL.add(forbidden);
            }
        }

        if (fromL == null)
            return tensor;

        allIndicesNames.addAll(getIndicesNames(tensor.getIndices().getFree()));
        IndexGeneratorImpl generator = new IndexGeneratorImpl(allIndicesNames.toArray());
        int[] from = fromL.toArray(), to = new int[fromL.size()];
        Arrays.sort(from);
        int i;
        for (i = from.length - 1; i >= 0; --i)
            to[i] = generator.generate(IndicesUtils.getType(from[i]));
View Full Code Here


        if (t instanceof Sum || t instanceof Expression) {
            Tensor[] oldData = t instanceof Sum ? ((Sum) t).data : t.toArray(),
                    newData = null;
            Tensor c;
            TIntHashSet dummies[] = new TIntHashSet[t.size()];
            int maxDummiesPosition = -1;
            for (int i = oldData.length - 1; i >= 0; --i) {
                c = optimizeDummies(oldData[i]);
                if (c != oldData[i]) {
                    if (newData == null)
                        newData = oldData.clone();
                    newData[i] = c;
                }
                dummies[i] = TensorUtils.getAllDummyIndicesT(c);
                if (maxDummiesPosition == -1 || dummies[maxDummiesPosition].size() < dummies[i].size())
                    maxDummiesPosition = i;
            }

            TIntHashSet temp;
            TIntIterator iterator;
            int count, index;
            for (int i = oldData.length - 1; i >= 0; --i) {
                if (i == maxDummiesPosition)
                    continue;

                iterator = dummies[i].iterator();
                count = 0;
                while (iterator.hasNext())
                    if (!dummies[maxDummiesPosition].contains(iterator.next()))
                        ++count;

                if (count == 0)
                    continue;

                int[] from = new int[count], to = new int[count];

                temp = new TIntHashSet(dummies[maxDummiesPosition]);
                iterator = dummies[i].iterator();
                while (iterator.hasNext())
                    if (!temp.remove(index = iterator.next()))
                        from[--count] = index;

                assert count == 0;
                iterator = temp.iterator();
                count = to.length;
                while (iterator.hasNext() && count > 0)
                    to[--count] = iterator.next();

                if (newData == null)
View Full Code Here

     * @param patterns        specified simple tensors or tensor fields
     * @param transformations transformations to be applied to the expression that forms the coefficient
     *                        of each term obtained
     */
    public CollectTransformation(SimpleTensor[] patterns, Transformation[] transformations) {
        patternsNames = new TIntHashSet();
        powerExpand = new PowerExpandUnwrapTransformation(patterns);
        for (SimpleTensor t : patterns)
            patternsNames.add(t.getName());
        this.transformations = transformations;
    }
View Full Code Here

            factors = factorsList.toArray(new Tensor[factorsList.size()]);
        } else
            return new Split(new Tensor[0], tensor);


        TIntHashSet freeIndices = new TIntHashSet(IndicesUtils.getIndicesNames(tensor.getIndices().getFree()));

        //now we need to uncontract dummies and free

        Indices factorIndices = new IndicesBuilder().append(factors).getIndices();
        TIntHashSet dummies = new TIntHashSet(IndicesUtils.getIntersections(
                factorIndices.getUpper().copy(), factorIndices.getLower().copy()));
        SimpleIndices currentFactorIndices;
        IntArrayList from = new IntArrayList(), to = new IntArrayList();
        ArrayList<Tensor> kroneckers = new ArrayList<>();
        int j, index, newIndex;
        IndexGeneratorImpl generator = new IndexGeneratorImpl(TensorUtils.getAllIndicesNamesT(tensor).toArray());
        for (int i = 0; i < factors.length; ++i) {
            from.clear();
            to.clear();
            currentFactorIndices = IndicesFactory.createSimple(null, factors[i].getIndices());

            for (j = currentFactorIndices.size() - 1; j >= 0; --j) {
                index = currentFactorIndices.get(j);
                if (freeIndices.contains(getNameWithType(index))) {
                    newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index)));
                    from.add(index);
                    to.add(newIndex);
                    kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex)));
                } else if (IndicesUtils.getState(index) && dummies.contains(getNameWithType(index))) {
                    newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index)));
                    from.add(index);
                    to.add(newIndex);
                    kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex)));
                }
View Full Code Here

  }

  @Override
  @SuppressWarnings("unchecked")
  public TIntSet getRXNORMCuis() {
    TIntSet cuis = new TIntHashSet();
    for (String cui : (List<String>) sessionFactory.getCurrentSession()
        .getNamedQuery("getRXNORMCuis").list()) {
      Matcher m = UMLSDao.cuiPattern.matcher(cui);
      if (m.find()) {
        cuis.add(Integer.parseInt(m.group(1)));
      }
    }
    return cuis;
  }
View Full Code Here

    SoftReference<TIntSet> refLeaves = leafCache[concept.getNodeIndex()];
    if (refLeaves != null && refLeaves.get() != null) {
      return refLeaves.get();
    }
    // not in cache - compute recursively
    TIntSet leaves = new TIntHashSet();
    leafCache[concept.getNodeIndex()] = new SoftReference<TIntSet>(leaves);
    if (concept.isLeaf()) {
      // for leaves, just add the concept id
      leaves.add(concept.getNodeIndex());
    } else {
      IntrinsicICInfo icInfo = icInfoMap.get(concept.getConceptID());
      // have we already computed the leaf count for this node?
      // if yes, then we can ignore previously visited nodes
      // if no, then compute it now and revisit previously visited nodes
      // if we have to
      boolean needLeaves = (icInfo != null && icInfo.getLeafCount() == 0);
      TIntSet visitedNodesLocal = visitedNodes;
      if (needLeaves || visitedNodesLocal == null) {
        // allocate a set to keep track of nodes we've already visited
        // so that we don't revisit them. if we have already computed
        // this node's leaf count then we reuse whatever the caller gave
        // us if non null, else allocate a new one.
        // if we haven't already computed this node's leaf count,
        // allocate a new set to avoid duplications in the traversal for
        // this node
        visitedNodesLocal = new TIntHashSet();
      }
      // for inner nodes, recurse
      for (ConcRel child : concept.getChildren()) {
        // if we've already visited a node, then don't bother adding
        // that node's leaves - we already have them
        if (!visitedNodesLocal.contains(child.getNodeIndex())) {
          leaves.addAll(getLeaves(child, leafCache, icInfoMap, cg, w,
              visitedNodesLocal));
        }
      }
      // add this node to the set of visited nodes so we know not to
      // revisit. This is only of importance if the caller gave us
      // a non-empty set.
      if (visitedNodes != null && visitedNodes != visitedNodesLocal) {
        visitedNodes.add(concept.getNodeIndex());
        visitedNodes.addAll(visitedNodesLocal);
      }
      // update the leaf count if we haven't done so already
      if (needLeaves) {
        icInfo.setLeafCount(leaves.size());
        // output leaves if desired
        if (w != null) {
          w.write(concept.getConceptID());
          w.write("\t");
          w.write(Integer.toString(leaves.size()));
          w.write("\t");
          TIntIterator iter = leaves.iterator();
          while (iter.hasNext()) {
            w.write(cg.getConceptList().get(iter.next())
                .getConceptID());
            w.write(" ");
          }
View Full Code Here

      }
    }
    log.info("computing leaf counts");
    @SuppressWarnings("unchecked")
    SoftReference<TIntSet>[] leafCache = (SoftReference<TIntSet>[]) Array
        .newInstance((new SoftReference<TIntSet>(new TIntHashSet()))
            .getClass(), cg.getConceptList().size());
    // compute leaf count of all concepts in this graph
    try {
      w = this.getOutputFile(conceptGraphName, conceptGraphDir, "leaf");
      // for (String leaf : leafSet) {
View Full Code Here

                return false;
        return true;
    }

    public static TIntHashSet getAllDummyIndicesT(Tensor tensor) {
        TIntHashSet set = new TIntHashSet();
        appendAllIndicesNamesT(tensor, set);
        set.removeAll(IndicesUtils.getIndicesNames(tensor.getIndices().getFree()));
        return set;
    }
View Full Code Here

        set.removeAll(IndicesUtils.getIndicesNames(tensor.getIndices().getFree()));
        return set;
    }

    public static TIntHashSet getAllIndicesNamesT(Tensor... tensors) {
        TIntHashSet set = new TIntHashSet();
        for (Tensor tensor : tensors)
            appendAllIndicesNamesT(tensor, set);
        return set;
    }
View Full Code Here

            return null;
        return buffer.getSign();
    }

    public static void assertIndicesConsistency(Tensor t) {
        assertIndicesConsistency(t, new TIntHashSet());
    }
View Full Code Here

TOP

Related Classes of gnu.trove.set.hash.TIntHashSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.