Package gnu.trove.set.hash

Examples of gnu.trove.set.hash.TIntHashSet


        @Override
        public void insureInitialized() {
            if (forbidden != null)
                return;

            forbidden = new TIntHashSet(position.previous().getPayload().getForbidden());
            forbidden.addAll(TensorUtils.getAllIndicesNamesT(tensor));
        }
View Full Code Here


        }

        @Override
        public void submit(TIntSet removed, TIntSet added) {
            insureInitialized();
            assert !(new TIntHashSet(added).removeAll(removed));
            forbidden.addAll(added);
            forbidden.removeAll(removed);
            position.previous().getPayload().submit(removed, added);
        }
View Full Code Here

            //The set of forbidden indices do not contain current sum
            //dummy indices (see getForbidden() e.g. for Product)
            forbidden = position.previous().getPayload().getForbidden();

            //All dummy indices in this sum
            TIntHashSet allDummyIndicesT = TensorUtils.getAllDummyIndicesT(tensor);

            //Creating array to index individual indices origin
            allDummyIndices = allDummyIndicesT.toArray();
            Arrays.sort(allDummyIndices);

            //For performance
            final int size = tensor.size();

            TIntHashSet dummy;
            int i;

            //Allocating origins arrays
            usedArrays = new BitArray[allDummyIndices.length];
            for (i = allDummyIndices.length - 1; i >= 0; --i)
                usedArrays[i] = new BitArray(size);

            //Fulfilling origins array
            for (i = size - 1; i >= 0; --i) {
                dummy = TensorUtils.getAllDummyIndicesT(tensor.get(i));
                TIntIterator iterator = dummy.iterator();

                while (iterator.hasNext())
                    usedArrays[Arrays.binarySearch(allDummyIndices, iterator.next())].set(i);
            }
        }
View Full Code Here

                iIndex = Arrays.binarySearch(allDummyIndices, index = iterator.next());
                usedArrays[iIndex].clear(position.currentIndex());

                if (usedArrays[iIndex].bitCount() == 0) {
                    if (parentRemoved == null)
                        parentRemoved = new TIntHashSet(removed.size());
                    parentRemoved.add(index);
                }
            }
            if (parentRemoved == null)
                parentRemoved = EMPTY_INT_SET;

            //Processing added indices and calculating added set to
            //propagate to position.
            parentAdded = new TIntHashSet(added);
            iterator = parentAdded.iterator();
            while (iterator.hasNext()) {
                //Searching index in initial dummy indices set
                iIndex = Arrays.binarySearch(allDummyIndices, iterator.next());
View Full Code Here

        }

        @Override
        public TIntSet getForbidden() {
            insureInitialized();
            return new TIntHashSet(forbidden);
        }
View Full Code Here

        }

        @Override
        public void submit(TIntSet removed, TIntSet added) {
            insureInitialized();
            assert !(new TIntHashSet(added).removeAll(removed));
            forbidden.addAll(added);
            forbidden.removeAll(removed);
        }
View Full Code Here

                    var = (SimpleTensor) from.get(i);
                    indices = new int[var.getIndices().size()];

                    //lazy initialization
                    if (indices.length != 0 && ig == null) {
                        TIntHashSet forbidden = new TIntHashSet(iterator.getForbidden());
                        forbidden.addAll(TensorUtils.getAllIndicesNamesT(this.from));
                        forbidden.addAll(TensorUtils.getAllIndicesNamesT(this.to));
                        ig = new IndexGeneratorImpl(forbidden.toArray());

                    }

                    for (j = indices.length - 1; j >= 0; --j)
                        indices[j] = setRawState(getRawStateInt(var.getIndices().get(j)),
View Full Code Here

        OutputPortUnsafe<Tensor> nextPort() {
            final int[] tuple = tuplesPort.take();
            if (tuple == null)
                return null;
            TIntHashSet added = new TIntHashSet(initialForbidden);
            ProductBuilder builder = new ProductBuilder();
            builder.put(base.get(tuple[0]));
            for (int i = 1; i < tuple.length; ++i)
                builder.put(ApplyIndexMapping.renameDummy(base.get(tuple[i]), added.toArray(), added));

            return createPort(builder.build());
        }
View Full Code Here

            putNonScalar(tensor);
    }

    private void putNonScalar(Tensor tensor) {
        Indices freeIndices = tensor.getIndices().getFree();
        TIntHashSet freeSet = new TIntHashSet(freeIndices.getAllIndices().copy());

        // Firstly we should check whether adding
        // specified tensor will merge some of the
        // existing components,
        // e.g. if component1 = F_mn*A^n
        //         component2 = H_ij
        //         tensor     = X^im
        // then two of the existing components must be
        // merged into resulting
        //         component = F_mn*A^n*H_ij*X^im

        //components that will be merged
        Set<Component> toMerge = new HashSet<>();
        Component component;
        int index;
        if (!indexToComponent.isEmpty())
            // for each free index in tensor
            for (TIntIterator iterator = freeSet.iterator(); iterator.hasNext(); ) {
                index = iterator.next();
                // this assertion case corresponds to the inconsistent
                // indices exception
                //todo discuss with Dima, may be we must to throw exception here?
                assert !indexToComponent.containsKey(index);

                index = IndicesUtils.inverseIndexState(index);
                component = indexToComponent.remove(index);
                if (component != null) {
                    // free index of tensor (e.g. ^i) is
                    // contracted with index (_i) in component
                    // as result, this index is not free now

                    //removing not free from the set of free indices of tensor
                    iterator.remove();
                    //removing not free from the set of free indices of component
                    component.freeIndices.remove(index);
                    //the component should be merged with this tensor
                    toMerge.add(component);
                }
            }

        if (toMerge.isEmpty()) {
            //no any intersections found
            //so, tensor forms the new connected component
            component = new Component(tensor, freeSet);
            //for each free index of tensor
            for (TIntIterator iterator = freeSet.iterator(); iterator.hasNext(); ) {
                index = iterator.next();
                //we should add the entry new free index <-> new component
                //to the index <-> component mapping
                indexToComponent.put(index, component);
            }
            //adding new unique component to the set of unique components
            components.add(component);
            return;
        }

        // At this point toMerge is not empty
        // we shall merge all of the components from the toMerge
        // set into the first component in the toMerge set

        Iterator<Component> iterator = toMerge.iterator();
        //taking the first component in the toMerge set
        component = iterator.next();
        //adding new tensor to this component
        component.elements.add(tensor);
        //adding all of the new free indices to the free indices of component
        component.freeIndices.addAll(freeSet);

        // We should add additional entries for the new free
        // indices into the free index <-> component mapping

        //for each new free index
        for (TIntIterator tit = freeSet.iterator(); tit.hasNext(); ) {
            index = tit.next();
            //adding additional entries for new free
            //indices in the free index <-> component mapping
            indexToComponent.put(index, component);
        }
View Full Code Here

            this.elements = elements;
            this.freeIndices = freeIndices;
        }

        public Component clone() {
            return new Component(new ArrayList<>(elements), new TIntHashSet(freeIndices));
        }
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.