Package cc.redberry.core.indexmapping

Examples of cc.redberry.core.indexmapping.IndexMappingDirectAllowingUnmapped


                    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));

        if (!mappingCollectedTensor.isEmpty())
            ApplyIndexMappingDirectTransformation.INSTANCE.perform(collectedTensor, mappingCollectedTensor);

    }
View Full Code Here


                    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));

        if (!mappingCollectedTensor.isEmpty())
            ApplyIndexMappingDirectTransformation.INSTANCE.perform(collectedTensor, mappingCollectedTensor);
        return true;
    }
View Full Code Here

    public Tensor transform(Tensor tensor) {
        if (tensor instanceof SimpleTensor || tensor instanceof Product) {
            Indices indices = tensor.getIndices();
            checked.ensureCapacity(indices.size());
            int index;
            IndexMappingDirectAllowingUnmapped im = new IndexMappingDirectAllowingUnmapped();
            //TODO discover case to put allIndices in ig
            IndexGenerator ig = new IndexGenerator(new IndicesBuilderSorted().append(indices).append(usedNames).asArray());
            for (int i = 0; i < indices.size(); i++) {
                index = indices.get(i);
                if (checked.contains(getNameWithType(index))) {
                    if (Arrays.binarySearch(usedNames, getNameWithType(index)) >= 0) {
                        int newIndex = getRawStateInt(index) | ig.generate(getType(index));
                        im.add(index, newIndex);
                        im.add(inverseIndexState(index), inverseIndexState(newIndex));
                    }
                } else
                    checked.add(getNameWithType(index));
            }
            ApplyIndexMappingDirectTransformation.INSTANCE.perform(tensor, im);
View Full Code Here

    public void transform(Tensor tensor1, Tensor tensor2) {
        Indices indices = new IndicesBuilderSorted().append(tensor1.getIndices()).append(tensor2.getIndices()).getIndices();
        checked.ensureCapacity(indices.size());
        int index;
        IndexMappingDirectAllowingUnmapped im = new IndexMappingDirectAllowingUnmapped();
        //TODO discover case to put allIndices in ig
        IndexGenerator ig = new IndexGenerator(new IndicesBuilderSorted().append(indices).append(usedNames).asArray());
        for (int i = 0; i < indices.size(); i++) {
            index = indices.get(i);
            if (checked.contains(getNameWithType(index))) {
                if (Arrays.binarySearch(usedNames, getNameWithType(index)) >= 0) {
                    int newIndex = getRawStateInt(index) | ig.generate(getType(index));
                    im.add(index, newIndex);
                    im.add(inverseIndexState(index), inverseIndexState(newIndex));
                }
            } else
                checked.add(getNameWithType(index));
        }
        ApplyIndexMappingDirectTransformation.INSTANCE.perform(tensor1, im);
View Full Code Here

                    if (permutation.equals(generatedPermutation.composition(tensorSymmetry)))
                        continue OUT;
            generatedPermutations.add(permutation);

            int[] newIndicesNames = permutation.permute(indicesNames);
            IndexMappingDirectAllowingUnmapped im = new IndexMappingDirectAllowingUnmapped(indicesNames, newIndicesNames);
            generatedTensors.add(ApplyIndexMappingDirectTransformation.INSTANCE.perform(tensor.clone(), im));
        }
        if (generatedTensors.isEmpty())
            return TensorNumber.createZERO();
        if (generatedTensors.size() == 1)
View Full Code Here

    }

    public Tensor renameIndicesAndBuidKroneckers(Tensor tensor) {
        if (tensor instanceof SimpleTensor || tensor instanceof Product) {
            Indices indices = tensor.getIndices();
            IndexMappingDirectAllowingUnmapped im = new IndexMappingDirectAllowingUnmapped();
            IndexMappingDirectAllowingUnmapped renameUsedIndices = null;
            IndexGenerator ig;
           
            ig = new IndexGenerator(TensorUtils.getAllIndicesBuilder(tensor).append(usedIndicesNames).asArray());
            for (int i = 0; i < indices.size(); ++i) {
                int index = indices.get(i);
                if (checked.contains(inverseIndexState(index)))
                    if (usedIndicesNames.length == 0 || Arrays.binarySearch(usedIndicesNames, getNameWithType(index)) < 0) {
//                        uncontracted.add(inverseIndexState(index));
                        int newIndex = getRawStateInt(index) | ig.generate(getType(index));
                        uncontracted.add(getNameWithType(index));
                        uncontracted.add(getNameWithType(newIndex));
                        im.add(index, newIndex);
                    } else {
                        if (renameUsedIndices == null)
                            renameUsedIndices = new IndexMappingDirectAllowingUnmapped();
                        int newIndex = getRawStateInt(index) | ig.generate(getType(index));
                        int kroneckerIndex = getRawStateInt(index) | ig.generate(getType(index));
                        renameUsedIndices.add(index, kroneckerIndex);
                        renameUsedIndices.add(inverseIndexState(index), inverseIndexState(newIndex));
                        im.add(newIndex, kroneckerIndex);
                        uncontracted.add(getNameWithType(newIndex));                       
                        uncontracted.add(getNameWithType(kroneckerIndex));
                    }
                else
View Full Code Here

    @Override
    public Tensor renameIndicesAndBuidKroneckers(Tensor tensor) {
        if (tensor instanceof SimpleTensor || tensor instanceof Product) {
            Indices indices = tensor.getIndices();
            IndexMappingDirectAllowingUnmapped im = new IndexMappingDirectAllowingUnmapped();
            IndexGenerator ig = createIndexGenerator(tensor);
            for (int i = 0; i < indices.size(); ++i) {
                int index = indices.get(i);
                if (checked.contains(inverseIndexState(index))) {
                    int newIndex = getRawStateInt(index) | ig.generate(getType(index));
                    im.add(index, newIndex);
                } else
                    checked.add(index);
            }
            if (im.isEmpty())
                return tensor;
            //biulding kroneckers
            for (Map.Entry<Integer, Integer> entry : im.getMap().entrySet())
                kroneckers.add(CC.createKronecker(entry.getKey(), inverseIndexState(entry.getValue())));
            ApplyIndexMappingDirectTransformation.INSTANCE.perform(tensor, im);
        }
        return tensor;
    }
View Full Code Here

                            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(collectedTerm.getCollectedFactorsIndicesNames());
                    usedIndices.addAll(collectedTerm.getCollectedTermIndicesNames());
                    IndexGenerator ig = new IndexGenerator(usedIndices.toArray());

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

                    for (Map.Entry<Integer, IndexMappingBufferRecord> entry : concurentBuffer.getMap().entrySet()) {
                        int indexCollected, indexToCollect, rawState = ((entry.getValue().getStates() & 1) ^ 1) << 31;
                        indexCollected = rawState | entry.getValue().getIndexName();
                        indexToCollect = rawState | entry.getKey();

                        SimpleTensor kroneckerCollected;
                        SimpleTensor kroneckerToCollect;
                       
                        if (indexToCollect == indexCollected)
                            continue;
                        else if (uncontractedIndicesToCollect.contains(getNameWithType(indexToCollect))
                                && uncontractedIndicesCollected.contains(getNameWithType(indexCollected))) {
                            mappingToCollect.add(inverseIndexState(indexToCollect),
                                    inverseIndexState(indexCollected));
//                            continue;
                        }

                        else if (uncontractedIndicesToCollect.contains(getNameWithType(indexToCollect))) {
                            kroneckerCollected = CC.createKronecker(inverseIndexState(indexToCollect), indexCollected);

                            collectedTerm.getCollectedFactorsIndicesNames().add(getNameWithType(indexCollected));
                            collectedTerm.getCollectedFactorsIndicesNames().add(getNameWithType(indexToCollect));

                            collectedTerm.getCollectedTermIndicesNames().replaceFirst(getNameWithType(indexCollected), getNameWithType(indexToCollect));
                            mappingCollectedTensor.add(indexCollected, indexToCollect);
                            kroneckersCollected.add(kroneckerCollected);
//                            continue;
                        } else if (uncontractedIndicesCollected.contains(getNameWithType(indexCollected))) {
                            kroneckerToCollect = CC.createKronecker(indexToCollect, inverseIndexState(indexCollected));
                            split.factoredOut.add(kroneckerToCollect);
//                            continue;
                        } else {
                            int newIndex = ig.generate(getType(indexToCollect));
                            collectedTerm.getCollectedFactorsIndicesNames().add(getNameWithType(indexCollected));
                            collectedTerm.getCollectedFactorsIndicesNames().add(newIndex);
                            collectedTerm.getCollectedTermIndicesNames().replaceFirst(getNameWithType(indexCollected), newIndex);
//                        uncontractedIndicesCollected.addAll(newIndex);
//                        uncontractedIndicesToCollect.addAll(newIndex);
//                        uncontractedIndicesCollected.addAll(getNameWithType(indexCollected));
//                        uncontractedIndicesToCollect.addAll(getNameWithType(indexToCollect));


                            newIndex = getRawStateInt(indexToCollect) | newIndex;

                            kroneckerCollected = CC.createKronecker(indexCollected, inverseIndexState(newIndex));
                            kroneckerToCollect = CC.createKronecker(indexToCollect, inverseIndexState(newIndex));
                            mappingCollectedTensor.add(indexCollected, newIndex);

                            kroneckersCollected.add(kroneckerCollected);
                            split.factoredOut.add(kroneckerToCollect);
                        }
                    }
                    if (!kroneckersCollected.isEmpty())
                        for (Tensor p : collectedTerm.collectedFactors)
                            ((Product) p).add(kroneckersCollected);
                    if (concurentBuffer.getSignum())
                        split.factoredOut.addFirst(TensorNumber.createMINUSONE());
                    if (!mappingToCollect.isEmpty())
                        ApplyIndexMappingDirectTransformation.INSTANCE.perform(split.factoredOut, mappingToCollect);
                    collectedTerm.collectedFactors.add(split.factoredOut);
                    collectedTerm.getCollectedFactorsIndicesNames().addAll(TensorUtils.getAllIndicesNames(split.factoredOut));

                    if (!mappingCollectedTensor.isEmpty())
                        ApplyIndexMappingDirectTransformation.INSTANCE.perform(collectedTensor, mappingCollectedTensor);
                    continue OUT_FOR;
                }

            UncontractIndices uncontractIndicesTransformation =
View Full Code Here

    @Override
    public Tensor renameIndicesAndBuidKroneckers(Tensor tensor) {
        if (tensor instanceof SimpleTensor || tensor instanceof Product) {
            Indices indices = tensor.getIndices();
            IndexMappingDirectAllowingUnmapped im = new IndexMappingDirectAllowingUnmapped();
            IndexMappingDirectAllowingUnmapped renameUsedIndices = null;
            IndexGenerator ig = createIndexGenerator(tensor);
            for (int i = 0; i < indices.size(); ++i) {
                int index = indices.get(i);
                if (checked.contains(inverseIndexState(index)))
                    if (Arrays.binarySearch(indicesToRenameNames, getNameWithType(index)) < 0) {
//                        uncontracted.addAll(inverseIndexState(index));
                        int newIndex = getRawStateInt(index) | ig.generate(getType(index));
                        im.add(index, newIndex);
                    } else {
                        if (renameUsedIndices == null)
                            renameUsedIndices = new IndexMappingDirectAllowingUnmapped();
                        int newIndex = getRawStateInt(index) | ig.generate(getType(index));
                        int kroneckerIndex = getRawStateInt(index) | ig.generate(getType(index));
                        renameUsedIndices.add(index, kroneckerIndex);
                        renameUsedIndices.add(inverseIndexState(index), inverseIndexState(newIndex));
                        im.add(newIndex, kroneckerIndex);
          
                    }
                else
                    checked.add(index);
View Full Code Here

TOP

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

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.