Package cc.redberry.core.tensor.iterator

Examples of cc.redberry.core.tensor.iterator.FromParentToChildIterator


    public Tensor transform(Tensor t) {
        return factorSymbolicTerms(t);
    }

    private static Tensor factorSymbolicTerms(Tensor tensor) {
        FromParentToChildIterator iterator = new FromParentToChildIterator(tensor);
        Tensor c;
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            Tensor remainder = c, temp;
            IntArrayList symbolicPositions = new IntArrayList();
            for (int i = c.size() - 1; i >= 0; --i) {
                temp = c.get(i);
                if (isSymbolic(temp)) {
                    symbolicPositions.add(i);
                    if (remainder instanceof Sum)
                        remainder = ((Sum) remainder).remove(i);
                    else remainder = Complex.ZERO;
                }
            }
            Tensor symbolicPart = ((Sum) c).select(symbolicPositions.toArray());
            symbolicPart = factorSymbolicTerm(symbolicPart);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt));
                remainder = sb.build();
            } else
                remainder = factorSymbolicTerms(remainder);
            iterator.set(Tensors.sum(symbolicPart, remainder));
        }
        return iterator.result();
    }
View Full Code Here


        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Sum)
                iterator.set(factorOut(c));

        iterator = new FromParentToChildIterator(iterator.result());
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            if (needTogether(c)) {
                c = TogetherTransformation.together(c, true);
View Full Code Here

    public Tensor transform(Tensor t) {
        return factorSymbolicTerms(t);
    }

    private static Tensor factorSymbolicTerms(Tensor tensor) {
        FromParentToChildIterator iterator = new FromParentToChildIterator(tensor);
        Tensor c;
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            Tensor remainder = c, temp;
            IntArrayList symbolicPositions = new IntArrayList();
            for (int i = c.size() - 1; i >= 0; --i) {
                temp = c.get(i);
                if (isSymbolic(temp)) {
                    symbolicPositions.add(i);
                    if (remainder instanceof Sum)
                        remainder = ((Sum) remainder).remove(i);
                    else remainder = Complex.ZERO;
                }
            }
            Tensor symbolicPart = ((Sum) c).select(symbolicPositions.toArray());
            symbolicPart = factorSymbolicTerm(symbolicPart);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt));
                remainder = sb.build();
            } else
                remainder = factorSymbolicTerms(remainder);
            iterator.set(Tensors.sum(symbolicPart, remainder));
        }
        return iterator.result();
    }
View Full Code Here

        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Sum)
                iterator.set(factorOut(c));

        iterator = new FromParentToChildIterator(iterator.result());
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            if (needTogether(c)) {
                c = TogetherTransformation.together(c, true);
View Full Code Here

    public static Tensor factor(Tensor tensor) {
        return factor(tensor, true, JasFactor.ENGINE);
    }

    private static Tensor factorSymbolicTerms(Tensor tensor, FactorizationEngine factorizationEngine) {
        FromParentToChildIterator iterator = new FromParentToChildIterator(tensor);
        Tensor c;
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            Tensor remainder = c, temp;
            IntArrayList symbolicPositions = new IntArrayList();
            for (int i = c.size() - 1; i >= 0; --i) {
                temp = c.get(i);
                if (isSymbolic(temp)) {
                    symbolicPositions.add(i);
                    if (remainder instanceof Sum)
                        remainder = ((Sum) remainder).remove(i);
                    else remainder = Complex.ZERO;
                }
            }
            Tensor symbolicPart = ((Sum) c).select(symbolicPositions.toArray());
            symbolicPart = factorSymbolicTerm(symbolicPart, factorizationEngine);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt, factorizationEngine));
                remainder = sb.build();
            } else
                remainder = factorSymbolicTerms(remainder, factorizationEngine);
            iterator.set(Tensors.sum(symbolicPart, remainder));
        }
        return iterator.result();
    }
View Full Code Here

        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Sum)
                iterator.set(factorOut(c, factorizationEngine));

        iterator = new FromParentToChildIterator(iterator.result());
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            if (needTogether(c)) {
                c = TogetherTransformation.together(c, true);
View Full Code Here

    public static Tensor factor(Tensor tensor) {
        return factor(tensor, true, JasFactor.ENGINE);
    }

    private static Tensor factorSymbolicTerms(Tensor tensor, FactorizationEngine factorizationEngine) {
        FromParentToChildIterator iterator = new FromParentToChildIterator(tensor);
        Tensor c;
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            Tensor remainder = c, temp;
            IntArrayList symbolicPositions = new IntArrayList();
            for (int i = c.size() - 1; i >= 0; --i) {
                temp = c.get(i);
                if (isSymbolic(temp)) {
                    symbolicPositions.add(i);
                    if (remainder instanceof Sum)
                        remainder = ((Sum) remainder).remove(i);
                    else remainder = Complex.ZERO;
                }
            }
            Tensor symbolicPart = ((Sum) c).select(symbolicPositions.toArray());
            symbolicPart = factorSymbolicTerm(symbolicPart, factorizationEngine);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt, factorizationEngine));
                remainder = sb.build();
            } else
                remainder = factorSymbolicTerms(remainder, factorizationEngine);
            iterator.set(Tensors.sum(symbolicPart, remainder));
        }
        return iterator.result();
    }
View Full Code Here

                if (c instanceof Sum)
                    iterator.set(factorOut(c, factorizationEngine));
            sum = iterator.result();
        }

        TreeIterator iterator = new FromParentToChildIterator(sum);
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            if (needTogether(c)) {
                c = TogetherTransformation.together(c, true);
                if (c instanceof Product) {
                    TensorBuilder pb = null;
                    for (int i = c.size() - 1; i >= 0; --i) {
                        if (c.get(i) instanceof Sum) {
                            if (pb == null) {
                                pb = c.getBuilder();
                                for (int j = c.size() - 1; j > i; --j)
                                    pb.put(c.get(j));
                            }
                            pb.put(factorSum1(c.get(i), factorizationEngine));
                        } else if (pb != null)
                            pb.put(c.get(i));
                    }
                    iterator.set(pb == null ? c : pb.build());
                } else iterator.set(c);
            } else
                iterator.set(factorSum1(c, factorizationEngine));
        }
        return iterator.result();
    }
View Full Code Here

    public Tensor transform(Tensor t) {
        return factorSymbolicTerms(t);
    }

    private static Tensor factorSymbolicTerms(Tensor tensor) {
        FromParentToChildIterator iterator = new FromParentToChildIterator(tensor);
        Tensor c;
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            Tensor remainder = c, temp;
            IntArrayList symbolicPositions = new IntArrayList();
            for (int i = c.size() - 1; i >= 0; --i) {
                temp = c.get(i);
                if (isSymbolic(temp)) {
                    symbolicPositions.add(i);
                    if (remainder instanceof Sum)
                        remainder = ((Sum) remainder).remove(i);
                    else remainder = Complex.ZERO;
                }
            }
            Tensor symbolicPart = ((Sum) c).select(symbolicPositions.toArray());
            symbolicPart = factorSymbolicTerm(symbolicPart);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt));
                remainder = sb.build();
            } else
                remainder = factorSymbolicTerms(remainder);
            iterator.set(Tensors.sum(symbolicPart, remainder));
        }
        return iterator.result();
    }
View Full Code Here

        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Sum)
                iterator.set(factorOut(c));

        iterator = new FromParentToChildIterator(iterator.result());
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            if (needTogether(c)) {
                c = TogetherTransformation.together(c, true);
View Full Code Here

TOP

Related Classes of cc.redberry.core.tensor.iterator.FromParentToChildIterator

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.