Package cc.redberry.core.indexgenerator

Examples of cc.redberry.core.indexgenerator.IndexGenerator


                    factorIndices.getUpper().copy(), factorIndices.getLower().copy()));
            SimpleIndices currentFactorIndices;
            IntArrayList from = new IntArrayList(), to = new IntArrayList();
            ArrayList<Tensor> kroneckers = new ArrayList<>();
            int j, index, newIndex;
            IndexGenerator generator = new IndexGenerator(TensorUtils.getAllIndicesNamesT(tensor).toArray());
            for (int i = 0; i < factors.length; ++i) {
                from.clear();
                to.clear();
                currentFactorIndices = factors[i].getIndices();

                for (j = currentFactorIndices.size() - 1; j >= 0; --j) {
                    index = currentFactorIndices.get(j);
                    if (freeIndices.contains(getNameWithType(index))) {
                        newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index)));
                        from.add(index);
                        to.add(newIndex);
                        kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex)));
                    } else if (IndicesUtils.getState(index) && dummies.contains(getNameWithType(index))) {
                        newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index)));
                        from.add(index);
                        to.add(newIndex);
                        kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex)));
                    }
                }
View Full Code Here


        } else
            return tensor.clone();
    }

    private IndexGenerator createIndexGenerator(Tensor tensor) {
        return new IndexGenerator(new IndicesBuilderSorted().append(indices).append(TensorUtils.getAllIndices(tensor)).asArray());
    }
View Full Code Here

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

        IndexMappingImpl preprocess = new IndexMappingImpl();

        //creating metrics for rising-lowing indices
        int fromIndex, toIndex, fromState, toState;

        IndexGenerator ig = new IndexGenerator(TensorUtils.getAllIndices(target));

        List<SimpleTensor> metrics = new ArrayList<>();
        int i = 0;
        for (; i < from.length; ++i) {
            //diff states mapping detected
            if ((fromState = IndicesUtils.getRawStateInt(from[i])) != (toState = IndicesUtils.getRawStateInt(to[i]))) {

                fromIndex = IndicesUtils.getNameWithType(from[i]);
                toIndex = ig.generate(IndicesUtils.getType(fromIndex));
                preprocess.add(fromIndex, toIndex);

                if (fromState != 0)
                    metrics.add(CC.createMetric(fromIndex, toIndex));
                else
View Full Code Here

        IndexMappingImpl preprocess = new IndexMappingImpl();

        //creating metrics for rising-lowing indices
        int fromIndex, toIndex;

        IndexGenerator ig = new IndexGenerator(TensorUtils.getAllIndices(target));

        List<SimpleTensor> metrics = new ArrayList<>();

        for (Map.Entry<Integer, IndexMappingBufferRecord> entry : indexMappingBuffer.getMap().entrySet()) {
            IndexMappingBufferRecord record = entry.getValue();

            //diff states mapping detected
            if (record.diffStatesInitialized() && !record.isContracted()) {
                fromIndex = entry.getKey().intValue();
                toIndex = ig.generate(IndicesUtils.getType(fromIndex));
                preprocess.add(fromIndex, toIndex);

                byte states = record.getStates();
                if ((states & 1) == 1)
                    metrics.add(CC.createMetric(fromIndex, toIndex));
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));
View Full Code Here

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

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

    }

    @Override
    protected IndexGenerator createIndexGenerator(Tensor tensor) {
        int[] forbidenIndices = TensorUtils.getAllIndicesBuilder(tensor).append(forbidenSortedNames).asArray();
        return new IndexGenerator(forbidenIndices);
    }
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())
View Full Code Here

TOP

Related Classes of cc.redberry.core.indexgenerator.IndexGenerator

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.