Package cc.redberry.core.indexmapping

Examples of cc.redberry.core.indexmapping.IndexMappingBuffer


        OUT:
        while ((state = iterator.next()) != null) {
            if (state != TraverseState.Entering)
                continue;
            current = iterator.tensor();
            IndexMappingBuffer buffer =
                    IndexMappingUtils.tryGetPositiveWithoutDiffStates(IndexMappings.createPort(from, current, allowDiffStates));
            if (buffer == null)
                continue;
            for (Derivative derivative : iterator.derivativeStack)
                for (i = 0; i < derivative.getDerivativeOrder(); ++i)
                    if (IndexMappings.mappingExists(from, derivative.getVariation(i), true) //TODO Simple tensor optimization
                            || TensorUtils.contains(to, derivative.getVariation(i)))
                        throw new InconsistentSubstitutionException("TODO message");
            Tensor newTo = to.clone();
            if (!allowDiffStates || !IndexMappingUtils.containsDiffStates(buffer))
                newTo = ApplyIndexMappingTransformation.INSTANCE.perform(newTo, new IndexMappingImpl(iterator.usedIndices(), buffer));
            else
                newTo = ApplyIndexMappingUtils.applyIndexMappingWithDiffStates(newTo, buffer, iterator.usedIndices());
            if (buffer.getSignum() == true)
                newTo = new Product(TensorNumber.createMINUSONE(), newTo);
            iterator.set(newTo);
        }
        Tensor result = tensorWrapper.getInnerTensor();
        result.setParent(parent);
View Full Code Here


    private boolean compare(Tensor from, Tensor to) {
           int[] fromIndices = from.getIndices().getFreeIndices().getAllIndices().copy();
        for (int i = 0; i < fromIndices.length; ++i)
            fromIndices[i] = IndicesUtils.getNameWithType(fromIndices[i]);
        OutputPortUnsafe<IndexMappingBuffer> provider = IndexMappings.createPort(new IndexMappingBufferTester(fromIndices, CC.withMetric()), from, to);
        IndexMappingBuffer buffer;
        if ((buffer = provider.take()) != null) {
            buffer.removeContracted();
            assert buffer.isEmpty();
            return buffer.getSignum() == true;
        }
        return false;
    }
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

        return from.getClass();
    }
   
    @Override
    public Tensor transform(Tensor tensor) {
        IndexMappingBuffer im = IndexMappings.getFirst(from, tensor, false);
        if (im == null)
            return tensor;
        Tensor newTo = to.clone();
        (new IndexMappingImpl(new int[0],im)).apply(newTo);
        return newTo;
View Full Code Here

    public boolean mergeFrom(EqualsSplit split) {
        int[] fromIndices = term.getIndices().getFreeIndices().getAllIndices().copy();
        for (int i = 0; i < fromIndices.length; ++i)
            fromIndices[i] = IndicesUtils.getNameWithType(fromIndices[i]);
        OutputPortUnsafe<IndexMappingBuffer> provider = IndexMappings.createPort(new IndexMappingBufferTester(fromIndices, CC.withMetric()), term, split.term);
        IndexMappingBuffer buffer;
        boolean sign = false;
        if ((buffer = provider.take()) != null) {
            buffer.removeContracted();
            assert buffer.isEmpty();
            sign = buffer.getSignum();
        }
        if (buffer == null)
            return false;
        factors.add(sign == false ? split.factoredOut : new Product(TensorNumber.createMINUSONE(), split.factoredOut));
        return true;
View Full Code Here

            if (_current.getName() != from.getName())
                continue;
            OutputPortUnsafe<IndexMappingBuffer> opu = IndexMappings.createPortForSimpleTensor(from, _current, allowDiffStates);


            IndexMappingBuffer buffer;
            //TODO refactor throw off if (i.e. spread this code in inheritors)
            if (allowDiffStates)
                buffer = IndexMappingUtils.tryGetPositiveWithoutDiffStates(opu);
            else
                buffer = IndexMappingUtils.tryGetPositive(opu);

            if (buffer == null)
                continue;

            Tensor newTo = getNewTo(_current, from, to);
            if (newTo == null)
                continue;


            if (allowDiffStates)
                if (!IndexMappingUtils.containsDiffStates(buffer))
                    newTo = ApplyIndexMappingUtils.applyIndexMappingWithoutDiffStates(newTo, buffer, getUsedIndices());
                else
                    newTo = ApplyIndexMappingUtils.applyIndexMappingWithDiffStates(newTo, buffer, getUsedIndices());
            else
                newTo = ApplyIndexMappingUtils.applyIndexMappingWithDiffStates(newTo, buffer, getUsedIndices());

            //TODO discuss with Dmitry
            if (buffer.getSignum())
                if (Derivative.onVarsIndicator.is(iterator)) {
                    derivativeVarChangedSignum ^= true;
                    iterator.set(Transformations.contractMetrics(newTo));
                } else
                    iterator.set(new Product(TensorNumber.createMINUSONE(), newTo));
View Full Code Here

    private static Boolean compare(Tensor from, Tensor to) {
        int[] fromIndices = from.getIndices().getFreeIndices().getAllIndices().copy();
        for (int i = 0; i < fromIndices.length; ++i)
            fromIndices[i] = IndicesUtils.getNameWithType(fromIndices[i]);
        OutputPortUnsafe<IndexMappingBuffer> provider = IndexMappings.createPort(new IndexMappingBufferTester(fromIndices, CC.withMetric()), from, to);
        IndexMappingBuffer buffer;
        if ((buffer = provider.take()) != null) {
            buffer.removeContracted();
            assert buffer.isEmpty();
            return buffer.getSignum();
        }
        return null;
    }
View Full Code Here

            if (!(current instanceof Product))
                continue;
            final ProductContent currentContent = (ProductContent) current.getContent();
            ProductsBijectionsPort bijectionsPort = new ProductsBijectionsPort(from.getContent(), currentContent);
            int[] bijection;
            IndexMappingBuffer buffer = null;
            while ((bijection = bijectionsPort.take()) != null) {
                OutputPortUnsafe<IndexMappingBuffer> opu = IndexMappings.createBijectiveProductPort(data, dataTo(currentContent.getDataCopy(), bijection), allowDiffStates);
                buffer = opu.take();
                if (buffer != null)
                    break;
            }
            if (buffer == null)
                continue;
            //Processing new Product
            Arrays.sort(bijection);
            Product resulting = new Product();
            for (i = 0; i < currentContent.size(); ++i)
                if (Arrays.binarySearch(bijection, i) < 0)
                    resulting.add(currentContent.get(i));
            if (!currentContent.getFactor().isOne())
                resulting.add(new TensorNumber(currentContent.getFactor()));
            Tensor newTo = to.clone();
            if (!allowDiffStates || !IndexMappingUtils.containsDiffStates(buffer))
                newTo = ApplyIndexMappingTransformation.INSTANCE.perform(newTo, new IndexMappingImpl(iterator.usedIndices(), buffer));
            else
                newTo = ApplyIndexMappingUtils.applyIndexMappingWithDiffStates(newTo, buffer, iterator.usedIndices());
            if (buffer.getSignum())
                newTo = new Product(TensorNumber.createMINUSONE(), newTo);
            resulting.add(newTo);
            //CHECKSTYLE  a*a = 2  in a*a*a*a  -> 2*a*a
            iterator.set(Transformations.calculateNumbers(resulting.equivalent()));
        }
View Full Code Here

        OUT:
        while ((state = iterator.next()) != null) {
            if (state != TraverseState.Entering)//CHACKSTYLE
                continue;
            current = iterator.tensor();
            IndexMappingBuffer buffer =
                    IndexMappingUtils.tryGetPositiveWithoutDiffStates(IndexMappings.createPort(from, current, allowDiffStates));
            if (buffer == null)
                continue;
            for (Derivative derivative : iterator.derivativeStack)
                for (i = 0; i < derivative.getDerivativeOrder(); ++i)
                    if (IndexMappings.mappingExists(from, derivative.getVariation(i), true) //TODO Simple tensor optimization
                            || TensorUtils.contains(to, derivative.getVariation(i)))
                        throw new InconsistentSubstitutionException("TODO message");
            Tensor newTo = to.clone();
            if (!allowDiffStates || !IndexMappingUtils.containsDiffStates(buffer))
                newTo = ApplyIndexMappingTransformation.INSTANCE.perform(newTo, new IndexMappingImpl(iterator.usedIndices(), buffer));
            else
                newTo = ApplyIndexMappingUtils.applyIndexMappingWithDiffStates(newTo, buffer, iterator.usedIndices());
            if (buffer.getSignum() == true)
                newTo = new Product(TensorNumber.createMINUSONE(), newTo);
            iterator.set(newTo);
        }
        Tensor result = tensorWrapper.getInnerTensor();
        result.setParent(parent);
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

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.