Package cc.redberry.core.utils

Examples of cc.redberry.core.utils.IntArrayList


                throw new IllegalArgumentException("Levi-Civita have indices with different types.");
    }

    private static Tensor simplifyProduct(Tensor product, SimpleTensor LeviCivita) {
        ProductContent content = ((Product) product).getContent();
        IntArrayList epsPositions = new IntArrayList();
        int i = 0, j = content.size();
        for (i = 0; i < j; ++i) {
            if (isLeviCivita(content.get(i), LeviCivita))
                epsPositions.add(i);
        }
        if (epsPositions.isEmpty())
            return product;
        StructureOfContractions fs = content.getStructureOfContractions();

        j = epsPositions.size();
        Set<Tensor> epsComponent = new HashSet<>(LeviCivita.getIndices().size());
        Tensor temp;
        int toIndex, a, b;
        for (i = 0; i < j; ++i) {
            for (long contraction : fs.contractions[epsPositions.get(i)]) {
                toIndex = getToTensorIndex(contraction);
                if (toIndex == -1)
                    continue;
                temp = content.get(toIndex);
                if (isLeviCivita(temp, LeviCivita))
                    continue;
                epsComponent.add(temp);
            }
            if (epsComponent.isEmpty())
                continue;

            temp = multiply(epsComponent.toArray(new Tensor[epsComponent.size()]));
            epsComponent.clear();
            MappingsPort port = IndexMappings.createPort(temp, temp);
            IndexMappingBuffer buffer;
            Symmetry sym;

            IntArrayList nonPermutable = new IntArrayList();
            int[] indices = temp.getIndices().getFree().getAllIndices().copy();
            int[] epsIndices = content.get(epsPositions.get(i)).getIndices().getFree().getAllIndices().copy();

            boolean contract;
            for (b = 0; b < indices.length; ++b) {
                contract = false;
                for (a = 0; a < epsIndices.length; ++a)
                    if (indices[b] == inverseIndexState(epsIndices[a]))
                        contract = true;
                if (!contract)
                    nonPermutable.add(b);
            }
            int[] nonPermutablePositions = nonPermutable.toArray();

            if (indices.length == 1)
                continue;
            Map<IntArray, Boolean> symmetries = getEpsilonSymmetries(indices.length);
            while ((buffer = port.take()) != null) {
View Full Code Here


                    closed = true;
                    return null;
                }

                int[] bijectionNew = bijection.clone();
                IntArrayList addedBijectionsNew = addedBijections.clone();

                int j, fromTensorIndex, targetTensorIndex;
                long fromContraction, targetContraction;
                PermutationInfo currentInfo = firstInfo;
                do
                    for (j = 0; j < currentInfo.fromContractions.length; ++j) {
                        //Vse tut cherez jopu mi napisali, no vrode pravil'no
                        fromContraction = currentInfo.fromContractions[j];
                        targetContraction = currentInfo.targetContractions[currentInfo.permutation[j]];

                        assert getFromIndexId(fromContraction) == getFromIndexId(targetContraction);

                        fromTensorIndex = getToTensorIndex(fromContraction);
                        targetTensorIndex = getToTensorIndex(targetContraction);

                        if (getToIndexId(fromContraction) != getToIndexId(targetContraction)) {
                            if (!currentInfo.nextAndResetRightChain()) {
                                closed = true;
                                return null;
                            }
                            continue MAIN;
                        }

//                        assert fromTensorIndex != -1;

                        if (targetTensorIndex == -1) { //Not contracted index of target (but from is contracted with some tensor)
                            if (!currentInfo.nextAndResetRightChain()) {
                                closed = true;
                                return null;
                            }
                            continue MAIN;
                        }

                        if (!weakMatch(fromData[fromTensorIndex], targetData[targetTensorIndex])) {
                            if (!currentInfo.nextAndResetRightChain()) {
                                closed = true;
                                return null;
                            }
                            continue MAIN;
                        }

                        if (bijectionNew[fromTensorIndex] == -1) {
                            //Try addAll new bijection
                            if (alreadyContains(bijectionNew, targetTensorIndex)) {
                                if (!currentInfo.nextAndResetRightChain()) {
                                    closed = true;
                                    return null;
                                }
                                continue MAIN;
                            }
                            bijectionNew[fromTensorIndex] = targetTensorIndex;
                            addedBijectionsNew.add(fromTensorIndex);
                        } else if (bijectionNew[fromTensorIndex] != targetTensorIndex) { //Testing weather new bijection is consistent with already exists
                            if (!currentInfo.nextAndResetRightChain()) {
                                closed = true;
                                return null;
                            }
                            continue MAIN;
                        }
                    }
                while ((currentInfo = currentInfo.next) != null);

                innerPort = new InnerPort(bijectionNew, addedBijectionsNew.toArray());
            } while (true);
        }
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().getDiffIds().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

        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

        }

        IntArrayList[] hashReflections = new IntArrayList[from.length];
        int i, j, hash;
        for (i = 0; i < from.length; ++i) {
            hashReflections[i] = new IntArrayList();
            hash = from[i].hashCode();

            for (j = 0; j < to.length; ++j)
                if (to[j].hashCode() >= hash)
                    break;
View Full Code Here

        Tensor c;
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            Tensor remainder = c, temp;
            IntArrayList symbolicPositions = new IntArrayList();
            for (int i = c.size() - 1; i >= 0; --i) {
                temp = c.get(i);
                if (isSymbolic(temp)) {
                    symbolicPositions.add(i);
                    if (remainder instanceof Sum)
                        remainder = ((Sum) remainder).remove(i);
                    else remainder = Complex.ZERO;
                }
            }
            Tensor symbolicPart = ((Sum) c).select(symbolicPositions.toArray());
            symbolicPart = factorSymbolicTerm(symbolicPart, factorizationEngine);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt, factorizationEngine));
View Full Code Here

         * S1:
         * (a+b)*c + a*d + b*d -> (a+b)*c + (a+b)*d
         */
        Tensor temp = tensor;
        int i, j = temp.size();
        IntArrayList nonProductOfSumsPositions = new IntArrayList();
        for (i = 0; i < j; ++i)
            if (!isProductOfSums(temp.get(i)))
                nonProductOfSumsPositions.add(i);
//        if (nonProductOfSumsPositions.size() == tensor.size())
//            //when tensor = a*d + b*d + ... (no sums in products)
//            return JasFactor.factor(tensor);

         /*
         * S2:
         * finding product of sums in tensor with minimal number of multipliers
         * we call this term pivot
         */
        final Term[] terms;
        Int pivotPosition = new Int();
        if (nonProductOfSumsPositions.isEmpty() || nonProductOfSumsPositions.size() == temp.size()) {
            //if nonProductOfSumsPositions.isEmpty(), then tensor already of form (a+b)*c + (a+b)*d
            //or if no any sum in terms, then tensor has form a*c + b*c
            terms = sum2SplitArray((Sum) temp, pivotPosition);
        } else {//if no, we need to rebuild tensor
            SumBuilder sb = new SumBuilder();
            for (i = nonProductOfSumsPositions.size() - 1; i >= 0; --i) {
                assert temp instanceof Sum;
                sb.put(temp.get(nonProductOfSumsPositions.get(i)));
                temp = ((Sum) temp).remove(nonProductOfSumsPositions.get(i));
            }
            Tensor withoutSumsTerm = factorSymbolicTerms(sb.build(), factorizationEngine);
            if (isProductOfSums(withoutSumsTerm)) {
                temp = Tensors.sum(temp, withoutSumsTerm);
                if (!(temp instanceof Sum))
View Full Code Here

        return namespace.get(nextInt(namespace.size()));
    }

    private NameDescriptor nextNameDescriptor(StructureOfIndices typeStructure) {
        //search
        IntArrayList positions = new IntArrayList();
        for (int i = namespace.size() - 1; i >= 0; --i)
            if (namespace.get(i).getStructureOfIndices().equals(typeStructure))
                positions.add(i);
        if (!positions.isEmpty())
            return namespace.get(positions.get(random.nextInt(positions.size())));

        //create new nameDescriptor
        NameDescriptor nameDescriptor = CC.getNameManager().mapNameDescriptor(nextName(), typeStructure);
        if (withSymmetries)
            addRandomSymmetries(nameDescriptor);
View Full Code Here

        return links;
    }

    private PrimitiveSubgraph processGraph(int pivot) {

        IntArrayList positions = new IntArrayList();
        positions.add(pivot);

        IntArrayList stack = new IntArrayList();
        stack.push(pivot);
        used.set(pivot);

        long[] contractions;
        Indices indices;

        int currentPivot, index, toTensorIndex;
        while (!stack.isEmpty()) {

            currentPivot = stack.pop();

            indices = pc.get(currentPivot).getIndices();
            contractions = fcs.contractions[currentPivot];
            for (int i = contractions.length - 1; i >= 0; --i) {
                index = indices.get(i);
                if (getType(index) != type.getType())
                    continue;

                toTensorIndex = getToTensorIndex(contractions[i]);
                if (toTensorIndex == -1 || used.get(toTensorIndex))
                    continue;
                used.set(toTensorIndex);
                positions.add(toTensorIndex);
                stack.push(toTensorIndex);
            }
        }
        return new PrimitiveSubgraph(GraphType.Graph, positions.toArray());
    }
View Full Code Here

    public static Tensor[] allStatesCombinations(Tensor st) {

        Indices indices = st.getIndices().getFree();
        int[] indicesArray = indices.getAllIndices().copy();
        //lowering all indices
        IntArrayList metricIndices = new IntArrayList(),
                nonMetricIndices = new IntArrayList();

        for (int i = 0; i < indices.size(); ++i) {
            if (CC.isMetric(getType(indices.get(i))))
                metricIndices.add(getNameWithType(indices.get(i)));
            else
                nonMetricIndices.add(indices.get(i));
        }


        final int[] metricInds = metricIndices.toArray();
        ArrayList<Tensor> samples = new ArrayList<>(ArithmeticUtils.pow(2, metricInds.length));
        IntCombinationsGenerator gen;
        int[] temp;
        ArrayList<Tensor> combinationArray;
        for (int i = 0; i <= metricInds.length; ++i) {
            gen = new IntCombinationsGenerator(metricInds.length, i);
            combinationArray = new ArrayList<>();
            combinations:
            for (int[] combination : gen) {
                temp = new int[metricInds.length];
                Arrays.fill(temp, 0xFFFFFFFF);
                for (int j = combination.length - 1; j >= 0; --j)
                    temp[combination[j]] = createIndex(j, getType(metricInds[combination[j]]), true);//raise index
                int counter = combination.length;
                for (int j = 0; j < metricInds.length; ++j)
                    if (temp[j] == 0xFFFFFFFF)
                        temp[j] = createIndex(counter++, getType(metricInds[j]), false);//lower index
                IntArrayList _result = nonMetricIndices.clone();
                _result.addAll(temp);
                Tensor renamed = ApplyIndexMapping.applyIndexMapping(st, new Mapping(indicesArray, _result.toArray()));
                //todo bottleneck
                for (Tensor existing : combinationArray)
                    if (TensorUtils.compare1(existing, renamed) != null)
                        continue combinations;
                combinationArray.add(renamed);
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.