Package cc.redberry.core.tensor.iterator

Examples of cc.redberry.core.tensor.iterator.TreeTraverseIterator$LinkedPointer


        return applyIndexMapping(tensor, new IndexMapper(_from, _to));
    }

    public static Tensor applyIndexMapping(Tensor tensor, IndexMapper mapper) {
        TreeTraverseIterator iterator = new TreeTraverseIterator(tensor, TraverseGuide.EXCEPT_FUNCTIONS_AND_FIELDS);
        TraverseState state;
        SimpleIndices oldIndices, newIndices;
        SimpleTensor simpleTensor;
        while ((state = iterator.next()) != null) {
            if (state == TraverseState.Leaving)
                continue;
            if (!(iterator.current() instanceof SimpleTensor))
                continue;
            simpleTensor = (SimpleTensor) iterator.current();
            oldIndices = simpleTensor.getIndices();
            newIndices = oldIndices.applyIndexMapping(mapper);
            if (oldIndices != newIndices)
                if (simpleTensor instanceof TensorField)
                    iterator.set(Tensors.setIndicesToField((TensorField) simpleTensor, newIndices));
                else
                    iterator.set(Tensors.setIndicesToSimpleTensor(simpleTensor, newIndices));
        }
        return iterator.result();
    }
View Full Code Here


    private RemoveDueToSymmetry() {
    }

    @Override
    public Tensor transform(Tensor t) {
        TreeTraverseIterator iterator = new TreeTraverseIterator(t);
        TraverseState state;
        Tensor c;
        while ((state = iterator.next()) != null) {
            if (state != TraverseState.Leaving)
                continue;
            c = iterator.current();
            if (TensorUtils.isZeroDueToSymmetry(c))
                iterator.set(Complex.ZERO);
        }
        return iterator.result();
    }
View Full Code Here

    public static Tensor expand(Tensor tensor, Transformation... transformations) {
        return expand(tensor, Indicator.TRUE_INDICATOR, transformations);
    }

    public static Tensor expand(Tensor tensor, Indicator<Tensor> indicator, Transformation[] transformations) {
        TreeTraverseIterator iterator = new TreeTraverseIterator(tensor, TraverseGuide.EXCEPT_FUNCTIONS_AND_FIELDS);
        TraverseState state;
        Tensor current;
        while ((state = iterator.next()) != null) {
            if (state != TraverseState.Leaving)
                continue;
            current = iterator.current();
            if (current instanceof Product && indicator.is(current))
                iterator.set(expandProductOfSums(current, indicator, transformations));
            else if (current instanceof Power && current.get(0) instanceof Sum
                    && TensorUtils.isNatural(current.get(1)) && indicator.is(current))
                iterator.set(expandPower((Sum) current.get(0), ((Complex) current.get(1)).getReal().intValue(), transformations));
        }
        return iterator.result();
    }
View Full Code Here

            temp = expandPairOfSums((Sum) temp, (Sum) renameDummy(argument, mapper), transformations);
        return temp;
    }

    private static Tensor renameDummy(Tensor tensor, IndexMapper mapper) {
        TreeTraverseIterator iterator = new TreeTraverseIterator(tensor);
        TraverseState state;
        SimpleIndices oldIndices, newIndices;
        SimpleTensor simpleTensor;
        while ((state = iterator.next()) != null) {
            if (state != TraverseState.Leaving)
                continue;

            if (!(iterator.current() instanceof SimpleTensor))
                continue;
            simpleTensor = (SimpleTensor) iterator.current();
            oldIndices = simpleTensor.getIndices();
            newIndices = oldIndices.applyIndexMapping(mapper);
            if (oldIndices != newIndices)
                if (simpleTensor instanceof TensorField)
                    iterator.set(Tensors.setIndicesToField((TensorField) simpleTensor, newIndices));
                else
                    iterator.set(Tensors.setIndicesToSimpleTensor(simpleTensor, newIndices));
        }
        return iterator.result();
    }
View Full Code Here

        Tensor M = Tensors.parse("M");
        Tensor M8 = Tensors.parse("Power[M,8]");
        Tensor pT = Tensors.parse("pT");
        Tensor s = Tensors.parse("s");
        for (int i = 0; i < 1000; ++i) {
            TreeTraverseIterator iterator = new TreeTraverseIterator(target);

            while (iterator.next() != null)
                if (TensorUtils.equalsExactly(iterator.current(), pT))
                    iterator.set(M8);
                else if (TensorUtils.equalsExactly(iterator.current(), s))
                    iterator.set(AllToM);
            iterator.result();
        }
    }
View Full Code Here

        Tensor M2 = Tensors.parse("Power[M,2]");
        Tensor pT = Tensors.parse("pT");
        Tensor s = Tensors.parse("s");


        TreeTraverseIterator iterator;
        long start, stop;
        boolean status;
        int i;


        start = System.currentTimeMillis();
        Tensor ptM = null;
        for (i = 0; i < 100; ++i) {
            iterator = new TreeTraverseIterator(target);
            while (iterator.next() != null)
                if (TensorUtils.equalsExactly(iterator.current(), pT))
                    iterator.set(M);
            ptM = iterator.result();
        }
        stop = System.currentTimeMillis();
        status = TensorUtils.equalsExactly(ptM, pTToM);
        System.out.println("pT -> M : " + status + ". Time: " + (stop - start) + " ms");

        start = System.currentTimeMillis();
        Tensor sM = null;
        for (i = 0; i < 100; ++i) {
            iterator = new TreeTraverseIterator(target);
            while (iterator.next() != null)
                if (TensorUtils.equalsExactly(iterator.current(), s))
                    iterator.set(M2);
            sM = iterator.result();
        }
        status = TensorUtils.equalsExactly(sM, sToM);
        stop = System.currentTimeMillis();
        System.out.println("s -> M^2 : " + status + ". Time: " + (stop - start) + " ms");

        start = System.currentTimeMillis();
        Tensor allM = null;
        for (i = 0; i < 100; ++i) {
            iterator = new TreeTraverseIterator(target);
            while (iterator.next() != null)
                if (TensorUtils.equalsExactly(iterator.current(), pT))
                    iterator.set(M);
                else if (TensorUtils.equalsExactly(iterator.current(), s))
                    iterator.set(M2);
            allM = iterator.result();
        }
        status = TensorUtils.equalsExactly(allM, AllToM);
        stop = System.currentTimeMillis();
        System.out.println("pT-> M and s -> M^2 : " + status + ". Time: " + (stop - start) + " ms");
    }
View Full Code Here

        Tensor M = Tensors.parse("M");
        Tensor M8 = Tensors.parse("Power[M,8]");
        Tensor pT = Tensors.parse("pT");
        Tensor s = Tensors.parse("s");
        for (int i = 0; i < 1000; ++i) {
            TreeTraverseIterator iterator = new TreeTraverseIterator(target);

            while (iterator.next() != null)
                if (TensorUtils.equalsExactly(iterator.current(), pT))
                    iterator.set(M8);
                else if (TensorUtils.equalsExactly(iterator.current(), s))
                    iterator.set(AllToM);
            iterator.result();
        }
    }
View Full Code Here

        Tensor M2 = Tensors.parse("Power[M,2]");
        Tensor pT = Tensors.parse("pT");
        Tensor s = Tensors.parse("s");


        TreeTraverseIterator iterator;
        long start, stop;
        boolean status;
        int i;


        start = System.currentTimeMillis();
        Tensor ptM = null;
        for (i = 0; i < 100; ++i) {
            iterator = new TreeTraverseIterator(target);
            while (iterator.next() != null)
                if (TensorUtils.equalsExactly(iterator.current(), pT))
                    iterator.set(M);
            ptM = iterator.result();
        }
        stop = System.currentTimeMillis();
        status = TensorUtils.equalsExactly(ptM, pTToM);
        System.out.println("pT -> M : " + status + ". Time: " + (stop - start) + " ms");

        start = System.currentTimeMillis();
        Tensor sM = null;
        for (i = 0; i < 100; ++i) {
            iterator = new TreeTraverseIterator(target);
            while (iterator.next() != null)
                if (TensorUtils.equalsExactly(iterator.current(), s))
                    iterator.set(M2);
            sM = iterator.result();
        }
        status = TensorUtils.equalsExactly(sM, sToM);
        stop = System.currentTimeMillis();
        System.out.println("s -> M^2 : " + status + ". Time: " + (stop - start) + " ms");

        start = System.currentTimeMillis();
        Tensor allM = null;
        for (i = 0; i < 100; ++i) {
            iterator = new TreeTraverseIterator(target);
            while (iterator.next() != null)
                if (TensorUtils.equalsExactly(iterator.current(), pT))
                    iterator.set(M);
                else if (TensorUtils.equalsExactly(iterator.current(), s))
                    iterator.set(M2);
            allM = iterator.result();
        }
        status = TensorUtils.equalsExactly(allM, AllToM);
        stop = System.currentTimeMillis();
        System.out.println("pT-> M and s -> M^2 : " + status + ". Time: " + (stop - start) + " ms");
    }
View Full Code Here

    private EliminateFromSymmetriesTransformation() {
    }

    @Override
    public Tensor transform(Tensor t) {
        TreeTraverseIterator iterator = new TreeTraverseIterator(t);
        TraverseState state;
        Tensor c;
        while ((state = iterator.next()) != null) {
            if (state != TraverseState.Leaving)
                continue;
            c = iterator.current();
            if (TensorUtils.isZeroDueToSymmetry(c))
                iterator.set(Complex.ZERO);
        }
        return iterator.result();
    }
View Full Code Here

        this.guide = TraverseGuide.ALL;
    }

    @Override
    public Tensor transform(Tensor t) {
        TreeTraverseIterator iterator = new TreeTraverseIterator(t, guide);
        TraverseState currentState;
        Tensor currentTensor, newTensor;
        while ((currentState = iterator.next()) != null) {
            if (currentState != state)
                continue;
            currentTensor = newTensor = iterator.current();

            for (Transformation transformation : transformations)
                newTensor = transformation.transform(newTensor);
            if (currentTensor != newTensor)
                iterator.set(newTensor);
        }
        return iterator.result();
    }
View Full Code Here

TOP

Related Classes of cc.redberry.core.tensor.iterator.TreeTraverseIterator$LinkedPointer

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.