Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.TensorIterator


    }

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


    @Override
    public Tensor tensorEquvivalent() {
        if (!initialized)
            return pairProduct(factoredOut, term);
        TensorIterator it = factors.iterator();
        Tensor equivalent;
        Tensor current;
        while (it.hasNext()) {
            current = it.next();
            equivalent = current.equivalent();
            if (current != equivalent)
                it.set(equivalent);
        }
        return pairProduct(Transformations.calculateNumbers(factors), term.equivalent());
    }
View Full Code Here

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

    }

    @Override
    public PatternSplit split(Tensor tensor) {
        if (tensor instanceof Product) {
            TensorIterator it = tensor.iterator();
            Tensor current;
            Product factored = new Product();
            while (it.hasNext()) {
                current = it.next();
                if (splitPattern.factorOut(current)) {
                    factored.add(current);
                    it.remove();
                }
            }
            if (factored.isEmpty())
                factored.add(TensorNumber.createONE());
            if (((Product) tensor).isEmpty())
View Full Code Here

            }
            wrapper.write();
            return newSum;
        } else if (tensor instanceof Product) {
            Product p = new Product();
            TensorIterator iterator = tensor.iterator();
            Tensor current;
            Tensor temp = null;
            int[] lower = ind.getLower().copy();
            int[] upper = ind.getUpper().copy();
            int[] total = new int[length * 2];
            while (iterator.hasNext()) {
                current = iterator.next();
                if (!indicator.is(current)) {
                    p.add(current.clone());
                    continue;
                }
                if (temp == null) {
View Full Code Here

    @Override
    public Tensor tensorEquvivalent() {
        if (!initialized)
            return pairProduct(factoredOut, term);
        TensorIterator it = factors.iterator();
        Tensor equivalent;
        Tensor current;
        while (it.hasNext()) {
            current = it.next();
            equivalent = current.equivalent();
            if (current != equivalent)
                it.set(equivalent);
        }
        return pairProduct(Transformations.calculateNumbers(factors), term.equivalent());
    }
View Full Code Here

    @Override
    public Tensor transform(Tensor tensor) {
        if (!(tensor instanceof Sum))
            return tensor;
        Fraction result = null;
        TensorIterator iterator = tensor.iterator();
        Tensor current;
        while (iterator.hasNext()) {
            current = iterator.next();
            if (current instanceof Fraction) {
                if (result == null)
                    result = (Fraction) current;
                else
                    result = sumPair(result, current);
                iterator.remove();
            }
        }
        if (result == null)
            return tensor;
        if (((Sum) tensor).isEmpty())
View Full Code Here

        return new Fraction(new Sum(f1.getNumerator(), f), f1.getDenominator());
    }

    private static Struct calcStruct(Tensor t1, Tensor t2) {
        if (t1 instanceof Product && !(t2 instanceof Product)) {
            TensorIterator iterator = t1.iterator();
            boolean commonDetected = false;
            Tensor current;
            while (iterator.hasNext()) {
                current = iterator.next();
                if (TTest.testParity(current, t2)) {
                    iterator.remove();
                    commonDetected = true;
                    break;
                }
            }
            if (commonDetected)
                return new Struct(null, t1.equivalent().clone(), new Product(t1, t2));
            else
                return new Struct(t2.clone(), t1.clone(), new Product(t1, t2));
        }
        if (!(t1 instanceof Product) && t2 instanceof Product)
            return calcStruct(t2, t1).inverse();
        if (t1 instanceof Product && t2 instanceof Product) {
            Product _t1 = (Product) t1;
            Product _t2 = (Product) t2;
            _t1.sort();
            _t2.sort();
            TensorIterator iterator1 = _t1.iterator(), iterator2 = _t2.iterator();
            Tensor current1 = iterator1.next(), current2 = iterator2.next();
            int hash1 = current1.hashCode(), hash2 = current2.hashCode(), oldSize = 0;
            boolean process = false;

            List<Tensor> common = new ArrayList<>();
            List<Tensor> equalsHash1 = new ArrayList<>();

            while (true) {
                if (hash1 < hash2) {
                    if (!iterator1.hasNext())
                        break;
                    current1 = iterator1.next();

                } else if (hash2 < hash1) {
                    if (!iterator2.hasNext())
                        break;
                    current2 = iterator2.next();
                    hash2 = current2.hashCode();
                    process = process && hash2 == equalsHash1.get(0).hashCode();
                    if (process) {
                        for (int i = equalsHash1.size() - 1; i >= oldSize; --i)
                            if (TTest.testParity(equalsHash1.get(i), current2)) {
                                iterator2.remove();
//                                current2 = iterator2.next();

                                common.add(equalsHash1.remove(i));
                                break;
                            }
                        oldSize = equalsHash1.size();
                    }
                } else if (TTest.testParity(current1, current2)) {
                    common.add(current1);
                    iterator1.remove();
                    iterator2.remove();
                    if (!iterator1.hasNext() || !iterator2.hasNext())
                        break;
                    current1 = iterator1.next();
                    current2 = iterator2.next();
                } else {
                    process = true;
                    equalsHash1.add(current1);
                    iterator1.remove();
                    if (!iterator1.hasNext())
                        continue;
                    current1 = iterator1.next();
                }
                hash1 = current1.hashCode();
                hash2 = current2.hashCode();
            }
            _t1.add(equalsHash1);
View Full Code Here

    @Override
    public Tensor transform(Tensor tensor) {
        if (!(tensor instanceof Product))
            return tensor;
        List<Tensor> denominators = new ArrayList<>();
        TensorIterator iterator = tensor.iterator();
        Tensor current;
        while (iterator.hasNext()) {
            current = iterator.next();
            if (current instanceof Fraction) {
                Fraction frac = (Fraction) current;
                iterator.set(frac.getNumerator());
                denominators.add(frac.getDenominator());
            }
        }
        if (denominators.isEmpty())
            return tensor;
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.