Package cc.redberry.core.indexmapping

Examples of cc.redberry.core.indexmapping.IndexMappingBuffer


            BijectionContainer bc = new SumBijectionPort(from, current).take();
            if (bc == null)
                continue;

            IndexMappingBuffer buffer = bc.buffer;
            Tensor newTo;
            if (symbolic)
                newTo = to;
            else {
                int[] forbidden = new int[iterator.forbiddenIndices().size()];
View Full Code Here


            if (!(current instanceof Product))
                continue;

            while (current instanceof Product) {
                Product cp = (Product) current;
                IndexMappingBuffer buffer = null;

                final Tensor[] currentIndexless = cp.getIndexless();
                int[] indexlessBijection;
                IndexlessBijectionsPort indexlessPort = new IndexlessBijectionsPort(fromIndexless, currentIndexless);
                while ((indexlessBijection = indexlessPort.take()) != null) {
                    buffer = IndexMappings.createBijectiveProductPort(fromIndexless, extract(currentIndexless, indexlessBijection)).take();
                    if (buffer != null)
                        break;
                }
                if (buffer == null)
                    break;

                boolean sign = buffer.getSignum();
                buffer = null;
                ProductContent currentContent = cp.getContent();
                final Tensor[] currentData = currentContent.getDataCopy();
                int[] dataBijection;
                ProductsBijectionsPort dataPort = new ProductsBijectionsPort(fromContent, currentContent);
                while ((dataBijection = dataPort.take()) != null) {
                    buffer = IndexMappings.createBijectiveProductPort(fromData, extract(currentData, dataBijection)).take();
                    if (buffer != null)
                        break;
                }
                if (buffer == null)
                    break;

                buffer.addSignum(sign);
                Tensor newTo;
                if (symbolic)
                    newTo = to;
                else {
                    int[] forbidden = new int[iterator.forbiddenIndices().size()];
View Full Code Here

    @Override
    public Tensor transform(Tensor tensor) {
        SubstitutionIterator iterator = new SubstitutionIterator(tensor);
        Tensor current;
        while ((current = iterator.next()) != null) {
            IndexMappingBuffer buffer =
                    IndexMappings.getFirst(from, current);
            if (buffer == null)
                continue;
            Tensor newTo;
            if (symbolic)
View Full Code Here

        OUT:
        while ((current = iterator.next()) != null) {
            if (!(current instanceof TensorField))
                continue;
            TensorField currentField = (TensorField) current;
            IndexMappingBuffer buffer = IndexMappings.simpleTensorsPort(from, currentField).take();
            if (buffer == null)
                continue;


            Indices[] fromIndices = from.getArgIndices(), currentIndices = currentField.getArgIndices();
View Full Code Here

                factorNodes.add(new FactorNode(split.factor, split.getBuilder()));
        }
    }

    static Boolean compareFactors(Tensor u, Tensor v) {
        IndexMappingBuffer buffer;
        if (u.getIndices().size() == 0)
            buffer = IndexMappings.createPort(u, v).take();
        else {
            int[] fromIndices = u.getIndices().getFree().getAllIndices().copy();
            for (int i = 0; i < fromIndices.length; ++i)
                fromIndices[i] = IndicesUtils.getNameWithType(fromIndices[i]);
            buffer = IndexMappings.createPort(new IndexMappingBufferTester(fromIndices, false), u, v).take();
        }
        if (buffer == null)
            return null;
        assert buffer.isEmpty();
        return buffer.getSignum();
    }
View Full Code Here

    @Override
    Tensor newTo_(Tensor currentNode, SubstitutionIterator iterator) {
        TensorField currentField = (TensorField) currentNode;
        TensorField from = (TensorField) this.from;
        IndexMappingBuffer buffer = IndexMappings.simpleTensorsPort(from, currentField).take();
        if (buffer == null)
            return currentNode;

        Indices[] fromIndices = from.getArgIndices(), currentIndices = currentField.getArgIndices();

        List<Tensor> argFrom = new ArrayList<>(), argTo = new ArrayList<>();
        Tensor fArg;
        int[] cIndices, fIndices;
        int i;
        for (i = from.size() - 1; i >= 0; --i) {
            if (IndexMappings.mappingExists(currentNode.get(i), from.get(i)))
                continue;
            fIndices = fromIndices[i].getAllIndices().copy();
            cIndices = currentIndices[i].getAllIndices().copy();

            assert cIndices.length == fIndices.length;

            fArg = ApplyIndexMapping.applyIndexMapping(from.get(i), fIndices, cIndices, new int[0]);

            argFrom.add(fArg);
            argTo.add(currentNode.get(i));
        }

        Tensor newTo = to;
        newTo = new SubstitutionTransformation(
                argFrom.toArray(new Tensor[argFrom.size()]),
                argTo.toArray(new Tensor[argTo.size()]),
                false).transform(newTo);
        if (!TensorUtils.isSymbolic(newTo))
            newTo = ApplyIndexMapping.applyIndexMapping(newTo, buffer, iterator.getForbidden());
        else if (buffer.getSign())
            newTo = Tensors.negate(newTo);
        return newTo;
    }
View Full Code Here

            Tensor riman2 = Tensors.parse(e1);

            long start = System.currentTimeMillis();
            for (int i = 0; i < 1000; ++i) {
                MappingsPort mp = IndexMappings.createPort(riman1, riman2);
                IndexMappingBuffer buffera;
                while ((buffera = mp.take()) != null);
            }
            time += System.currentTimeMillis() - start;
        }
        return time;
View Full Code Here

                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();
View Full Code Here

                continue;
            current = iterator.tensor();
            if (!(current instanceof TensorField))
                continue;
            TensorField currentField = (TensorField) current;
            IndexMappingBuffer buffer =
                    IndexMappingUtils.tryGetPositiveWithoutDiffStates(IndexMappings.createPortForSimpleTensor(from, currentField, allowDiffStates));
            if (buffer == null)
                continue;

            assert from.getArgs().length == currentField.getArgs().length;
View Full Code Here


        IntArrayList uncontractedIndicesToCollect = TensorUtils.getContractedIndicesNames(split.term, split.factoredOut);
        IntArrayList uncontractedIndicesCollected = TensorUtils.getContractedIndicesNames(term, factors.getElements().get(0));

        IndexMappingBuffer concurentBuffer = null;
        if (factors.size() > 30){//TODO refacor in future
            concurentBuffer = IndexMappings.getFirst(toCollect, collectedTensor, allowDiffStates);}
        else {
            List<IndexMappingBuffer> buffers = IndexMappingUtils.createAllMappings(toCollect, collectedTensor, allowDiffStates);
            //finding best mapping
            //botleneck for very huge sums
            int concurrence = 0, currentConcurrence;

            boolean sign = false;
            for (IndexMappingBuffer buffer : buffers) {
                currentConcurrence = 0;

                for (Map.Entry<Integer, IndexMappingBufferRecord> entry : buffer.getMap().entrySet()) {
                    int indexToCollect = entry.getKey();
                    int indexCollected = entry.getValue().getIndexName();
                    if (indexToCollect == indexCollected || (uncontractedIndicesToCollect.contains(indexToCollect) && uncontractedIndicesCollected.contains(indexCollected)))
                        currentConcurrence++;
                    if (entry.getValue().diffStatesInitialized())
                        currentConcurrence--;
                }
                if (concurentBuffer == null
                        || currentConcurrence > concurrence
                        || (sign && !buffer.getSignum()
                        && (currentConcurrence >= concurrence))) {
                    concurentBuffer = buffer;
                    concurrence = currentConcurrence;
                }
            }
        }

        IndexMappingDirectAllowingUnmapped mappingToCollect = new IndexMappingDirectAllowingUnmapped();
        IndexMappingDirectAllowingUnmapped mappingCollectedTensor = new IndexMappingDirectAllowingUnmapped();

        //building index generator
        IntArrayList usedIndices = new IntArrayList(TensorUtils.getAllIndicesNames(split.factoredOut));
        usedIndices.addAll(factorsIndicesNames);
        usedIndices.addAll(termIndicesNames);
        IndexGenerator ig = new IndexGenerator(usedIndices.toArray());

        List<Tensor> mkCollectedList = new ArrayList<>();

        for (Map.Entry<Integer, IndexMappingBufferRecord> entry : concurentBuffer.getMap().entrySet()) {

            int indexCollected, indexToCollect, rawState = ((entry.getValue().getStates() & 1) ^ 1) << 31;
            boolean diffStatesInit = entry.getValue().diffStatesInitialized();
            indexCollected = rawState | entry.getValue().getIndexName();
            indexToCollect = (diffStatesInit ? 0x80000000 : 0) ^ (rawState | entry.getKey());

            SimpleTensor mkCollected;
            SimpleTensor mkToCollect;

            if (indexToCollect == indexCollected)
                continue;
            else if (uncontractedIndicesToCollect.contains(getNameWithType(indexToCollect))
                    && uncontractedIndicesCollected.contains(getNameWithType(indexCollected)))
                mappingToCollect.add(inverseIndexState(indexToCollect),
                        inverseIndexState(indexCollected));
            else if (uncontractedIndicesToCollect.contains(getNameWithType(indexToCollect))) {
                mkCollected = CC.createMetricOrKronecker(inverseIndexState(indexToCollect), indexCollected);

                factorsIndicesNames.add(getNameWithType(indexCollected));
                factorsIndicesNames.add(getNameWithType(indexToCollect));

                termIndicesNames.replaceFirst(getNameWithType(indexCollected), getNameWithType(indexToCollect));
                mappingCollectedTensor.add(indexCollected, indexToCollect);
                mkCollectedList.add(mkCollected);
            } else if (uncontractedIndicesCollected.contains(getNameWithType(indexCollected))) {
                mkToCollect = CC.createMetricOrKronecker(indexToCollect, inverseIndexState(indexCollected));
                split.factoredOut.add(mkToCollect);
            } else {
                int newIndex = ig.generate(getType(indexToCollect));
                factorsIndicesNames.add(getNameWithType(indexCollected));
                factorsIndicesNames.add(newIndex);
                termIndicesNames.replaceFirst(getNameWithType(indexCollected), newIndex);

                newIndex = getRawStateInt(indexCollected) | newIndex;

                mkCollected = CC.createKronecker(indexCollected, inverseIndexState(newIndex));
                mkToCollect = CC.createMetricOrKronecker(indexToCollect, inverseIndexState(newIndex));
                mappingCollectedTensor.add(indexCollected, newIndex);

                mkCollectedList.add(mkCollected);
                split.factoredOut.add(mkToCollect);
            }
        }
        if (!mkCollectedList.isEmpty())
            for (Tensor p : factors)
                ((Product) p).add(mkCollectedList);
        if (concurentBuffer.getSignum())
            split.factoredOut.addFirst(TensorNumber.createMINUSONE());
        if (!mappingToCollect.isEmpty())
            ApplyIndexMappingDirectTransformation.INSTANCE.perform(split.factoredOut, mappingToCollect);
        factors.add(split.factoredOut);
        factorsIndicesNames.addAll(TensorUtils.getAllIndicesNames(split.factoredOut));
View Full Code Here

TOP

Related Classes of cc.redberry.core.indexmapping.IndexMappingBuffer

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.