Package cc.redberry.core.indexmapping

Examples of cc.redberry.core.indexmapping.Mapping


        result[result.length - 1] = factor;
        return Tensors.multiply(result);
    }

    SubsResult atomicSubstitute(PContent content, ForbiddenContainer forbidden, SubstitutionIterator iterator) {
        Mapping mapping = null;
        int[] indexlessBijection, dataBijection;

        IndexlessBijectionsPort indexlessPort
                = new IndexlessBijectionsPort(fromIndexless, content.indexless);

        while ((indexlessBijection = indexlessPort.take()) != null) {
            mapping = createBijectiveProductPort(fromIndexless, extract(content.indexless, indexlessBijection)).take();
            if (mapping != null)
                break;
        }

        if (mapping == null)
            return null;

        boolean sign = mapping.getSign();
        mapping = null;

        Tensor[] currentData;
        if (content.data instanceof Product) {
            ProductContent currentContent = ((Product) content.data).getContent();
            currentData = currentContent.getDataCopy();
            ProductsBijectionsPort dataPort = new ProductsBijectionsPort(fromContent, currentContent);
            while ((dataBijection = dataPort.take()) != null) {
                mapping = createBijectiveProductPort(fromData, extract(currentData, dataBijection)).take();
                if (mapping != null)
                    break;
            }
        } else {
            if (TensorUtils.isOne(content.data)) {
                if (fromContent.size() != 0)
                    return null;
                dataBijection = new int[0];
                currentData = new Tensor[0];
                mapping = Mapping.IDENTITY;
            } else {
                if (fromContent.size() != 1)
                    return null;
                dataBijection = new int[1];
                currentData = new Tensor[]{content.data};
                mapping = getFirst(fromContent.get(0), content.data);
            }
        }

        if (mapping == null)
            return null;

        mapping = mapping.addSign(sign);
        Arrays.sort(indexlessBijection);
        Arrays.sort(dataBijection);

        Tensor[] indexlessRemainder = new Tensor[content.indexless.length - fromIndexless.length];
        ProductBuilder dataRemainder = new ProductBuilder(0,
                (content.data instanceof Product)
                        ? content.data.size()
                        : 1 - fromContent.size());
        int pivot = 0;
        int i, j = 0;
        for (i = 0; i < content.indexless.length; ++i) {
            if (pivot < indexlessBijection.length && i == indexlessBijection[pivot])
                ++pivot;
            else
                indexlessRemainder[j++] = content.indexless[i];
        }
        pivot = 0;
        for (i = 0; i < currentData.length; ++i) {
            if (pivot < dataBijection.length && i == dataBijection[pivot])
                ++pivot;
            else
                dataRemainder.put(currentData[i]);
        }
        Tensor dataRemainderT = dataRemainder.build();

        PContent remainder = new PContent(indexlessRemainder, dataRemainderT);

        Tensor newTo;
        if (toIsSymbolic)
            newTo = mapping.getSign() ? Tensors.negate(to) : to;
        else {
            if (possiblyAddsDummies) {
                if (forbidden.forbidden == null)
                    forbidden.forbidden = new TIntHashSet(iterator.getForbidden());

                TIntHashSet remainderIndices = new TIntHashSet(forbidden.forbidden);
                remainderIndices.addAll(getAllIndicesNamesT(indexlessRemainder));
                remainderIndices.addAll(getAllIndicesNamesT(dataRemainderT));
                newTo = applyIndexMapping(to, mapping, remainderIndices.toArray());
                forbidden.forbidden.addAll(getAllIndicesNamesT(newTo));
            } else {
                TIntHashSet allowed = new TIntHashSet();
                for (int index : indexlessBijection)
                    allowed.addAll(TensorUtils.getAllDummyIndicesT(content.indexless[index]));
                IndicesBuilder ib = new IndicesBuilder();
                for (int index : dataBijection) {
                    allowed.addAll(TensorUtils.getAllDummyIndicesT(currentData[index]));
                    ib.append(currentData[index]);
                }
                allowed.addAll(ib.getIndices().getNamesOfDummies());
                allowed.removeAll(IndicesUtils.getIndicesNames(mapping.getToData()));
                newTo = applyIndexMappingAndRenameAllDummies(to, mapping, allowed.toArray());
            }
        }
        return new SubsResult(newTo, remainder);
    }
View Full Code Here


        super(from, to);
    }

    @Override
    Tensor newTo_(Tensor currentNode, SubstitutionIterator iterator) {
        Mapping mapping =
                IndexMappings.getFirst(from, currentNode);
        if (mapping == null)
            return currentNode;
        return applyIndexMappingToTo(currentNode, to, mapping, iterator);
    }
View Full Code Here

    @Override
    public BijectionContainer take() {
        if (finished)
            return null;
        List<int[]> bijections = new ArrayList<>();
        Mapping buffer;
        int i, b[];
        final int mappersSize = mappers.size();
        OUT:
        while (true) {
            buffer = source.take();
View Full Code Here

            return mapping;
        }

        @Override
        public Mapping take() {
            Mapping buf;
            while (true) {
                if (currentSource != null && (buf = currentSource.take()) != null)
                    return buf;
                if (!permutationGenerator.hasNext())
                    return null;
View Full Code Here

    Tensor newTo_(Tensor currentNode, SubstitutionIterator iterator) {
        SumBijectionPort.BijectionContainer bc = new SumBijectionPort(from, currentNode).take();
        if (bc == null)
            return currentNode;

        Mapping mapping = bc.mapping;
        Tensor newTo = applyIndexMappingToTo(currentNode, to, mapping, iterator);

        SumBuilder builder = new SumBuilder();
        int[] bijection = bc.bijection;
        Arrays.sort(bijection);
View Full Code Here

    private Tensor __newTo(DFromTo fromTo, TensorField currentField,
                           Tensor currentNode, SubstitutionIterator iterator) {

        TensorField from = fromTo.from;
        Mapping mapping = IndexMappings.simpleTensorsPort(from, currentField).take();
        if (mapping == 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.positiveMappingExists(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), new Mapping(fIndices, cIndices), new int[0]);

            argFrom.add(fArg);
            argTo.add(currentNode.get(i));
        }
View Full Code Here

        System.arraycopy(diff, 0, allFreeIndices, freeIndices.length, diff.length);

        SumBuilder builder = new SumBuilder();
        Tensor temp;
        for (Symmetry symmetry : symmetries) {
            temp = applyIndexMapping(tensor, new Mapping(allFreeIndices, permute(allFreeIndices, symmetry)), new int[0]);
            if (symmetry.isAntiSymmetry())
                temp = negate(temp);
            builder.put(temp);
        }
        temp = builder.build();
View Full Code Here

    public Tensor transform(Tensor t) {
        if (!multiplyBySymmetryFactor) {
            SumBuilder sb = new SumBuilder();
            for (Symmetry symmetry : symmetries)
                sb.put(ApplyIndexMapping.applyIndexMappingAutomatically(t,
                        new Mapping(indices, symmetry.permute(indices), symmetry.isAntiSymmetry())));

            return sb.build();
        } else {
            long length = 0;
            SumBuilder sb = new SumBuilder();
            for (Symmetry symmetry : symmetries) {
                sb.put(ApplyIndexMapping.applyIndexMappingAutomatically(t,
                        new Mapping(indices, symmetry.permute(indices), symmetry.isAntiSymmetry())));
                ++length;
            }
            t = sb.build();
            if (t instanceof Sum)
                return FastTensors.multiplySumElementsOnFactor((Sum) t, new Complex(new Rational(1L, length)));
View Full Code Here

        final int[] newIndices = new int[indicesArray.length];
        for (int i = 0; i < indicesArray.length; ++i)
            newIndices[i] = indicesArray[permutation[i]];

        //processing new tensor
        return ApplyIndexMapping.applyIndexMapping(tensor, new Mapping(indicesArray, newIndices), new int[0]);
    }
View Full Code Here

                for (i = 0; i < typeData.length; ++i)
                    factorIndices[position++] = indicesSpace[b][--totalIndicesCounts[b]];
            }

            descriptor = ApplyIndexMapping.applyIndexMapping(descriptor,
                    new Mapping(descriptor.getIndices().getFree().getAllIndices().copy(), factorIndices), forbidden.toArray());
            descriptor = ApplyIndexMapping.renameDummy(descriptor, forbidden.toArray());
            forbidden.addAll(TensorUtils.getAllIndicesNamesT(descriptor));

            pb.put(descriptor);
        }
View Full Code Here

TOP

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

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.