Package cc.redberry.core.indexmapping

Examples of cc.redberry.core.indexmapping.IndexMappingImpl


                } else {
                    for (j = 0; j < cIndices.length; ++j) {
                        cIndices[j] = IndicesUtils.getNameWithType(cIndices[j]);
                        fIndices[j] = IndicesUtils.getNameWithType(fIndices[j]);
                    }
                    IndexMappingImpl im = new IndexMappingImpl(new int[0], fIndices, cIndices);
                    fArg = ApplyIndexMappingTransformation.INSTANCE.perform(fArg, im);
                }

                if (!IndexMappings.mappingExists(fromArgs[i], fArg, allowDiffStates))
                    throw new InconsistentSubstitutionException(from, to, current);
                transformations.add(Substitutions.createSubstitution(fArg, currentArgs[i], allowDiffStates));
            }

            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 (!transformations.isEmpty()) {
                for (Transformation transformation : transformations)
                    newTo = transformation.transform(newTo);
                int[] indices = newTo.getIndices().getFreeIndices().getAllIndices().copy();
                for (i = 0; i < indices.length; ++i)
                    indices[i] = IndicesUtils.getNameWithType(indices[i]);
                newTo = ApplyIndexMappingTransformation.INSTANCE.perform(newTo, new IndexMappingImpl(iterator.usedIndices(), indices, indices));
            }
            iterator.set(newTo);
        }
        Tensor result = tensorWrapper.getInnerTensor();
        result.setParent(parent);
View Full Code Here


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

                    //ApplyIndexMappingTransformation (AIM) never produce conflicting indices if
                    //there are no such indices in tensor,
                    //so while transforming in tensor last mode AIM transformation applies only on tensors
                    //without any conflicts, just giving new names for indices from this product
                    IndexMappingImpl indexMapping = new IndexMappingImpl(currentUsedIndices);
                    ApplyIndexMappingTransformation.INSTANCE.perform(multiplyer, indexMapping);

                    //Adding new illegal indices
                    usedIndices =
                            MathUtils.intSetUnion(usedIndices,
                                                  TensorUtils.getAllIndicesNames(multiplyer));
                }
        }
        if (tensor instanceof Derivative) {
            //Very similar to Product case
            Derivative derivative = (Derivative) tensor;

            //Collecting all indices from derivative vars
            TensorIterator it = derivative.iterator();
            IntArrayList usedIndices = new IntArrayList();
            Tensor current;
            while (it.hasNext()) {
                current = it.next();
                if (Derivative.onVarsIndicator.is(it))
                    usedIndices.addAll(TensorUtils.getAllIndicesNames(current));
            }

            //Creating int set from collected indices
            int[] usedIndicesArray = MathUtils.getSortedDistinct(usedIndices.toArray());

            Tensor target = derivative.getTarget();

            //Calculating used indices for AIM transformation
            int[] targetIndices = IndicesUtils.getSortedDistinctIndicesNames(target.getIndices().getFreeIndices());
            int[] currentUsedIndices = MathUtils.intSetDifference(targetIndices, usedIndices.toArray());
            //Applying AIM transformation
            IndexMappingImpl indexMapping = new IndexMappingImpl(currentUsedIndices);
            ApplyIndexMappingTransformation.INSTANCE.perform(target, indexMapping);
        }
        return tensor;
    }
View Full Code Here

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

        //processing new tensor
        IndexMappingImpl im = new IndexMappingImpl(new int[0], indicesNames, newIndicesNames);
        Tensor current = tensor.clone();
        ApplyIndexMappingTransformation.INSTANCE.perform(current, im);
        result.add(current);
    }
View Full Code Here

*/
public class ApplyIndexMappingUtils {
    public static Tensor applyIndexMappingWithoutDiffStates(Tensor target,
            IndexMappingBuffer indexMappingBuffer, int[] usedIndices) {
        return ApplyIndexMappingTransformation.INSTANCE.perform(target,
                new IndexMappingImpl(usedIndices, indexMappingBuffer));
    }
View Full Code Here

    public static Tensor applyIndexMappingWithDiffStates(Tensor target,
            int[] from, int[] to, int[] usedIndices) {
        if (from.length != to.length)
            throw new IllegalArgumentException();
        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
                    metrics.add(CC.createMetric(0x80000000 | fromIndex, 0x80000000 | toIndex));
            }
            from[i] = IndicesUtils.getNameWithType(from[i]);
            to[i] = IndicesUtils.getNameWithType(to[i]);
        }
        //preprocessing conflicting indices
        target = ApplyIndexMappingTransformation.INSTANCE.perform(target, preprocess);

        //adding metrics
        if (!metrics.isEmpty()) {
            Product p = new Product();
            p.add(target);
            p.add(metrics);
            target = p;
        }
        IndexMappingImpl im = new IndexMappingImpl(usedIndices, from, to);
        return ApplyIndexMappingTransformation.INSTANCE.perform(target, im);
    }
View Full Code Here

        return ApplyIndexMappingTransformation.INSTANCE.perform(target, im);
    }

    public static Tensor applyIndexMappingWithDiffStates(Tensor target,
            IndexMappingBuffer indexMappingBuffer, int[] usedIndices) {
        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));
                else
                    metrics.add(CC.createMetric(0x80000000 | fromIndex, 0x80000000 | toIndex));
            }
        }
        //preprocessing conflicting indices
        target = ApplyIndexMappingTransformation.INSTANCE.perform(target, preprocess);

        //adding metrics
        if (!metrics.isEmpty()) {
            Product p = new Product();
            p.add(target);
            p.add(metrics);
            target = p;
        }
        IndexMappingImpl im = new IndexMappingImpl(usedIndices, indexMappingBuffer);
        return ApplyIndexMappingTransformation.INSTANCE.perform(target, im);
    }
View Full Code Here

    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

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

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

TOP

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

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.