Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.TensorIterator


    @Override
    public Tensor transform(Tensor tensor) {
        if (!(tensor instanceof Product))
            return tensor;
        Fraction fraction = null;
        TensorIterator iterator = tensor.iterator();
        Tensor current;
        while (iterator.hasNext()) {
            current = iterator.next();
            if (current instanceof Fraction) {
                fraction = (Fraction) current;
                iterator.remove();
                break;
            }
        }
        if (fraction == null)
            return tensor;
View Full Code Here


        Fraction fraction = (Fraction) tensor;
        if (!(fraction.getNumerator() instanceof Sum))
            return tensor;
        Sum numerator = (Sum) fraction.getNumerator();
        Sum result = new Sum();
        TensorIterator iterator = numerator.iterator();
        result.add(new Fraction(iterator.next(), fraction.getDenominator()));
        while (iterator.hasNext())
            result.add(new Fraction(iterator.next(), fraction.getDenominator().clone()));
        return result;
    }
View Full Code Here

    public NativeReccursionTransformation(IterationGuide guide) {
        this.guide = guide;
    }

    protected void innerTransform(Tensor tensor, T parameter) {
        TensorIterator it = tensor.iterator();
        Tensor t, newT;
        while (it.hasNext()) {
            t = it.next();
            //TODO diskuss
            if (guide.letInside(it, t) != GuidePermit.Enter)
                continue;
            newT = transform(t, preprocessParameter(parameter, it));
            if (newT == null) {
                it.remove();
                continue;
            }
            if (newT != t)
                it.set(newT);
        }
    }
View Full Code Here

        if (!(tensor instanceof Product))
            return tensor;
        //was required by cc.redberry-physics
        if (except.is(tensor))
            return tensor;
        TensorIterator productIterator = tensor.iterator();
        ArrayList<Product> products = new ArrayList<>();
        ArrayList<Product> newProducts;
        products.add(new Product());
        Tensor t = null;
        int oldSize, i;
        Sum sum;
        boolean sumsExists = false;
        while (productIterator.hasNext()) {
            t = productIterator.next();
            if (t instanceof Sum && !except.is(t)) {
                sumsExists = true;
                sum = (Sum) t;
                oldSize = products.size();
                newProducts = new ArrayList<>(oldSize * sum.size());
 
View Full Code Here

        if (!(tensor instanceof Product))
            return tensor;

        //remember integrals
        final List<Integral> integrals = new ArrayList<>();
        TensorIterator iterator = tensor.iterator();
        Tensor current;
        while (iterator.hasNext()) {
            current = iterator.next();
            if (current instanceof Integral) {
                integrals.add((Integral) current);
                iterator.remove();
            }
        }
        //no any integrals in the expression
        if (integrals.isEmpty())
            return tensor;

        //only integrals
        if (((Product) tensor).isEmpty())
            return new Product(integrals);

        //remember integration vars for each integral
        final List<Map<Integer, SimpleTensor>> vars = new ArrayList<>();
        for (final Integral i : integrals) {
            final Map<Integer, SimpleTensor> map = new HashMap<>();
            for (final SimpleTensor s : i.vars())
                map.put(s.getName(), s);
            vars.add(map);
        }

        //main routine
        iterator = tensor.iterator();
        Collection<SimpleTensor> tempVars;
        while (iterator.hasNext()) {
            current = iterator.next();
            //vars in current
            tempVars = TensorUtils.getDiffSimpleTensorContent(current);

            out_for:
            for (int i = 0; i < integrals.size(); ++i) {
                final Map<Integer, SimpleTensor> map = vars.get(i);

                for (SimpleTensor st : tempVars)
                    if (map.containsKey(st.getName()))
                        continue out_for;

                //current can be placed under current integral
                final Integral integral = integrals.get(i);
                integrals.set(i, new Integral(new Product(current, integral.target()), integral.vars()));
                iterator.remove();
            }
        }

        Product result = new Product();
        result.add(tensor);
View Full Code Here

    public Tensor transform(final Tensor tensor) {
        if (tensor instanceof Integral)
            return tensor;
        if (!(tensor instanceof Product))
            return tensor;
        final TensorIterator iterator = tensor.iterator();
        Tensor current;
        final List<Integral> integrals = new ArrayList<>();
        while (iterator.hasNext()) {
            current = iterator.next();
            if (current instanceof Integral) {
                integrals.add((Integral) current);
                iterator.remove();
            }
        }
        ((Product) tensor).add(mergeIntegrals(integrals));
        return tensor.equivalent();
    }
View Full Code Here

    @Override
    public Tensor transform(final Tensor tensor) {
        if (!(tensor instanceof Sum))
            return tensor;
        final IntegralIP iP = new IntegralIP();
        final TensorIterator iterator = tensor.iterator();
        Tensor current;
        while (iterator.hasNext()) {
            current = iterator.next();
            if (current instanceof Integral) {
                iP.put((Integral) current);
                iterator.remove();
            }
        }
        ((Sum) tensor).add(iP.result());
        return tensor.equivalent();
    }
View Full Code Here

    }

    private Tensor getDerivative(Tensor target, SimpleTensor var) {
        if (target instanceof Sum) {
            Sum sum = (Sum) target;
            TensorIterator it = sum.iterator();
            Tensor current, derivative;
            Sum res = new Sum();
            while (it.hasNext()) {
                current = it.next();
                derivative = getDerivative(current, var);
                if (derivative == null)
                    continue;//it.remove();
                else res.add(derivative);// if (derivative != current)
                    //it.set(derivative);
View Full Code Here

    @Override
    public Tensor transform(Tensor tensor) {
        if (!(tensor instanceof Product))
            return tensor;
        CollectPowersInputPort port = new CollectPowersInputPort();
        TensorIterator iterator = tensor.iterator();
        Tensor current;
        while (iterator.hasNext()) {
            current = iterator.next();
            if ((current instanceof SimpleTensor && current.getIndices() instanceof EmptyIndices)
                    || current instanceof AbstractScalarFunction) {
                port.put(current);
                iterator.remove();
            }
        }
        if (port.isEmpty())
            return tensor;
        ((Product) tensor).addFirst(port.getResult());
View Full Code Here

        CollectTerms act = new CollectTerms(new PatternSplitCriteria(currentPattern));
        target = act.transform(target);
        if (!(target instanceof Sum))
            return target;
        for (Tensor term : target) {
            TensorIterator it = term.iterator();
            Tensor multiplyer;
            while (it.hasNext()) {
                multiplyer = it.next();
                if (multiplyer instanceof Sum)
                    it.set(collect1(multiplyer)); //                    break;
            }
        }
        return target;
    }
View Full Code Here

TOP

Related Classes of cc.redberry.core.tensor.TensorIterator

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.