Package cc.redberry.core.utils

Examples of cc.redberry.core.utils.IntArrayList


            if (permutation[start] == start) {
                ++counter;
                seen.set(start);
                continue;
            }
            IntArrayList cycle = new IntArrayList();
            while (!seen.get(start)) {
                seen.set(start);
                ++counter;
                cycle.add(start);
                start = permutation[start];
            }
            cycles.add(cycle.toArray());
        }
        return cycles.toArray(new int[cycles.size()][]);
    }
View Full Code Here


            //Used to build chain of permutators
            PermutationInfo previousInfo = null;

            //Here added bijections will be collected
            IntArrayList addedBijections = new IntArrayList();

            //Iterating through seeds
            for (int i = 0; i < seeds.length; ++i) {
                //Index of seed in from array
                int seedFromIndex = seeds[i];
                //Seed tensor (used only to get indices -> index Ids)
                Tensor seedFrom = fromData[seedFromIndex];
                //Seed index in target array (bijection for this tensor should already be provided by upper level port)
                int seedTargetIndex = bijection[seedFromIndex];

                //Diff ids of indices. Cloned because it will be sorted.
                short[] diffIds = seedFrom.getIndices().getPositionsInOrbits().clone(); // (!!!)
                //Sorting with permutation retrieval.
                //This step needed because we use the fastest (we think so)
                //method of collecting indices with the same index id [Permutable indices].
                int[] diffIdsPermutation = ArraysUtils.quickSortP(diffIds);

                //Creating array for permutation infos for current bijection.
//                permutationInfos[i] = new ArrayList<>();

                //Iterating through stretches of indices
                for (Stretch stretch : new StretchIteratorS(diffIds))
                    if (stretch.length == 1) { //Indices with unique index id (stretch.length == 1) [Non permutable indices].
                        //Corresponding contraction in from tensor
                        long fromIndexContraction = fromContractions[seedFromIndex][diffIdsPermutation[stretch.from]];
                        //Corresponding contraction in target tensor
                        long targetIndexContraction = targetContractions[seedTargetIndex][diffIdsPermutation[stretch.from]];

                        final int fromTensorIndex = getToTensorIndex(fromIndexContraction); //Index of contracting tensor in from array
                        if (fromTensorIndex == -1) //Not contracted index of from
                            continue;

                        if (getToIndexId(fromIndexContraction) != getToIndexId(targetIndexContraction)) { //Contracts with different index id
                            closed = true;
                            return;
                        }

                        final int targetTensorIndex = getToTensorIndex(targetIndexContraction); //Index of contracting tensor in target array
                        if (targetTensorIndex == -1) {//Not contracted index of target (but from is contracted with some tensor),
                            // so this bijection is impossible
                            closed = true;
                            return;
                        }

                        //Checking weak match between corresponding contracting tensors
                        if (!weakMatch(fromData[fromTensorIndex], targetData[targetTensorIndex])) {
                            //Early termination
                            closed = true;
                            return;
                        }

                        if (bijection[fromTensorIndex] == -1) { //This bijection is free
                            //Adding new bijection
                            if (alreadyContains(bijection, targetTensorIndex)) {
                                closed = true;
                                return;
                            }
                            bijection[fromTensorIndex] = targetTensorIndex;
                            addedBijections.add(fromTensorIndex);
                        } else if (bijection[fromTensorIndex] != targetTensorIndex) { //Testing weather new bijection is consistent with already existing
                            closed = true;
                            return;
                        }
                    } else { //There are several indices with the same index id.
View Full Code Here

     *
     * @param permutation permutation written in one-line notation
     * @return an array of cycles lengths
     */
    public static int[] lengthsOfCycles(final int[] permutation) {
        IntArrayList sizes = new IntArrayList();
        BitArray seen = new BitArray(permutation.length);
        int counter = 0;
        while (counter < permutation.length) {
            int start = seen.nextZeroBit(0);
            if (permutation[start] == start) {
                ++counter;
                seen.set(start);
                continue;
            }
            int size = 0;
            while (!seen.get(start)) {
                seen.set(start);
                ++counter;
                ++size;
                start = permutation[start];
            }
            sizes.add(size);
        }
        return sizes.toArray();
    }
View Full Code Here

     *
     * @param permutation permutation written in one-line notation
     * @return an array of cycles lengths
     */
    public static int[] lengthsOfCycles(final short[] permutation) {
        IntArrayList sizes = new IntArrayList();
        BitArray seen = new BitArray(permutation.length);
        int counter = 0;
        while (counter < permutation.length) {
            int start = seen.nextZeroBit(0);
            if (permutation[start] == start) {
                ++counter;
                seen.set(start);
                continue;
            }
            int size = 0;
            while (!seen.get(start)) {
                seen.set(start);
                ++counter;
                ++size;
                start = permutation[start];
            }
            sizes.add(size);
        }
        return sizes.toArray();
    }
View Full Code Here

     *
     * @param permutation permutation written in one-line notation
     * @return an array of cycles lengths
     */
    public static int[] lengthsOfCycles(final byte[] permutation) {
        IntArrayList sizes = new IntArrayList();
        BitArray seen = new BitArray(permutation.length);
        int counter = 0;
        while (counter < permutation.length) {
            int start = seen.nextZeroBit(0);
            if (permutation[start] == start) {
                ++counter;
                seen.set(start);
                continue;
            }
            int size = 0;
            while (!seen.get(start)) {
                seen.set(start);
                ++counter;
                ++size;
                start = permutation[start];
            }
            sizes.add(size);
        }
        return sizes.toArray();
    }
View Full Code Here

        final IntDistinctTuplesPort combinationsPort;

        public SeedPlanter() {
            int[][] hits = new int[seeds.length][];
            IntArrayList hitList = new IntArrayList();
            for (int seedIndex = 0; seedIndex < seeds.length; ++seedIndex) {
                hitList.clear();
                for (int i = 0; i < targetData.length; ++i)
                    if (weakMatch(fromData[seeds[seedIndex]], targetData[i])
                            && GraphUtils.componentSize(seeds[seedIndex], fromFContractions.components)
                            <= GraphUtils.componentSize(i, targetFContractions.components))
                        hitList.add(i);
                hits[seedIndex] = hitList.toArray();
            }
            combinationsPort = new IntDistinctTuplesPort(hits);
        }
View Full Code Here

        int[] involvedTensors = new int[contractions.length];
        Arrays.fill(involvedTensors, -1);
        IntArrayList[] indicesFrom = new IntArrayList[contractions.length];
        IntArrayList[] indicesTo = new IntArrayList[contractions.length];

        IntArrayList freeIndices = new IntArrayList();
        int tensorsCount = 0;
        for (int i = 0; i < indicesContractions.length; ++i) {
            int tensorIndex = getToTensorIndex(indicesContractions[i]);
            if (tensorIndex == -1) {
                freeIndices.add(i);
                continue;
            }
            if (involvedTensors[tensorIndex] == -1) {
                involvedTensors[tensorIndex] = tensorIndex;
                indicesFrom[tensorIndex] = new IntArrayList();
                indicesTo[tensorIndex] = new IntArrayList();
                ++tensorsCount;
            }
            indicesFrom[tensorIndex].add(i);
            indicesTo[tensorIndex].add(getToIndexId(indicesContractions[i]));
        }
        int f = freeIndices.size() == 0 ? 0 : 1;
        Contraction[] result = new Contraction[tensorsCount + f];
        if (f == 1)
            result[0] = new Contraction(-1, freeIndices.toArray(), null);
        tensorsCount = f;
        for (int i = 0; i < contractions.length; ++i) {
            if (involvedTensors[i] == -1)
                continue;
            result[tensorsCount++] = new Contraction(involvedTensors[i], indicesFrom[i].toArray(), indicesTo[i].toArray());
View Full Code Here

        for (Permutation p : parent.symmetries.getGenerators())
            symmetries.addSymmetry(convertPermutation(p, mapping[0], baseStructure.size()));


        //adding block symmetries of derivatives
        IntArrayList aggregator = new IntArrayList();
        j = 1;
        int cycle[];
        for (i = 0; i < orders.length; ++i) {
            if (structuresOfIndices[i + 1].size() != 0 && orders[i] >= 2) {
                //adding symmetries for indices from each slot
                cycle = Permutations.createBlockCycle(structuresOfIndices[i + 1].size(), 2);
                aggregator.addAll(mapping[j]);
                aggregator.addAll(mapping[j + 1]);
                symmetries.addSymmetry(
                        Permutations.createPermutation(convertPermutation(cycle, aggregator.toArray(), baseStructure.size())));

                if (orders[i] >= 3) {
                    for (k = 2; k < orders[i]; ++k)
                        aggregator.addAll(mapping[j + k]);

                    cycle = Permutations.createBlockCycle(structuresOfIndices[i + 1].size(), orders[i]);
                    symmetries.addSymmetry(
                            Permutations.createPermutation(convertPermutation(cycle, aggregator.toArray(), baseStructure.size())));
                }
                aggregator.clear();
            }
            j += orders[i];
        }
    }
View Full Code Here

                if (i == data.length - 1)
                    break;
                sb.append(",");
            }
        } else if (format.is(Cadabra)) {
            IntArrayList nonMetricIndices = new IntArrayList();
            IntArrayList metricIndices = new IntArrayList(data.length);
            for (int i = 0; i < data.length; ++i)
                if (CC.isMetric(IndicesUtils.getType(data[i])))
                    metricIndices.add(data[i]);
                else
                    nonMetricIndices.add(data[i]);

            if (!metricIndices.isEmpty()) {
                sb.append("_{");
                for (int i = 0, size = metricIndices.size() - 1; ; ++i) {
                    sb.append(Context.get().getIndexConverterManager().getSymbol(metricIndices.get(i), format));
                    if (i == size)
                        break;
                    sb.append(' ');
                }
                sb.append('}');
View Full Code Here

public final class IndicesBuilder {

    private final IntArrayList data;

    public IndicesBuilder() {
        data = new IntArrayList();
    }
View Full Code Here

TOP

Related Classes of cc.redberry.core.utils.IntArrayList

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.