Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.Tensor


    }

    public Tensor transform(Tensor tensor, boolean tensorFirst) {
        //TODO review
        //Remembing parent
        Tensor parent = tensor.getParent();
        TensorWrapper wrapper = new TensorWrapper(tensor);
        TensorTreeIterator it = TensorTreeIteratorFactory.create(tensorFirst, wrapper);
        Tensor current, old;
        while (it.hasNext()) {
            old = current = it.next();
            for (Transformation transformation : transformations)
                if ((current = transformation.transform(current)) == null)
                    break;
            if (current == null)
                if (AbstractTensorWrapper.onInnerTensorIndicator.is(it))
                    it.set(TensorNumber.createZERO());
                else
                    it.remove();
            else if (old != current)
                it.set(current);
        }
        Tensor result = wrapper.getInnerTensor();
        result.setParent(parent);
        return result;
    }
View Full Code Here


    }

    @Override
    public Tensor transform(Tensor tensor) {
        //TODO review
        Tensor parent = tensor.getParent();
        TensorWrapper wrapper = new TensorWrapper(tensor);

        TensorLastTreeIterator iterator = new TensorLastTreeIterator(wrapper, new Guide(), EquivalentTransformation.INSTANCE);

        Tensor current;
        OUT_FOR:
        while (iterator.hasNext()) {
            current = iterator.next();
            if (current instanceof Sum && ((Sum) current).isEmpty()) {
                subsZero(iterator);
                continue;
            }
            if (current.getClass() != getFromClasss())
                continue;
            T _current = (T) current;
            if (_current.getName() != from.getName())
                continue;
            if (IndexMappings.createPortForSimpleTensor(from, _current, allowDiffStates).take() == null)
                continue;
            if (!canMatch(from, _current))
                continue;

            if (iterator.isUnderIterator(Derivative.onTargetIndicator, Integer.MAX_VALUE)) {
                for (Tensor[] vars : derivativesVars) {
                    int i;
                    if ((i = Arrays.binarySearch(vars, current)) >= 0) {
                        if (!allowDiffStates) {
                            //TODO discover all possibiliyies
                            if (!IndexMappings.mappingExists(from, (SimpleTensor) vars[i], true)) {
                                subsZero(iterator);
                                continue OUT_FOR;
                            }
                        }
                        continue OUT_FOR;
                    }
                }
                subsZero(iterator);
            } else
                subsZero(iterator);
        }
        Tensor result = wrapper.getInnerTensor().equivalent();
        result.setParent(parent);
        return result;
    }
View Full Code Here

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

                    new Sum(
                    s.firstMultiplicand == null ? f1.getNumerator() : new Product(f1.getNumerator(), s.firstMultiplicand),
                    s.secondMultiplicand == null ? f2_.getNumerator() : new Product(f2_.getNumerator(), s.secondMultiplicand)),
                    s.denominator);
        }
        Tensor f = new Product(f1.getDenominator().clone(), f2);
        return new Fraction(new Sum(f1.getNumerator(), f), f1.getDenominator());
    }
View Full Code Here

    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);
            Product denom = new Product();
            denom.add(_t1.clone());
View Full Code Here

            this.secondMultiplicand = secondMultiplicand;
            this.denominator = denominator;
        }

        Struct inverse() {
            Tensor temp;
            temp = firstMultiplicand;
            firstMultiplicand = secondMultiplicand;
            secondMultiplicand = temp;
            return this;
        }
View Full Code Here

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

    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;
        Tensor numer = new Product(tensor.equivalent(), fraction.getDenominator());
        Tensor denom = fraction.getDenominator();
        return new Fraction(numer, denom);
    }
View Full Code Here

    @Override
    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

    @Override
    protected Tensor getNewTo(TensorField current, TensorField from, Tensor to) {
        SimpleTensorSubstitution[] ssts = getArgumentsSubs(from, current);
        if (!allowDiffStates && ssts == null)
            return null;
        Tensor newTo = to.clone();
        for (SimpleTensorSubstitution sst : ssts)
            newTo = sst.transform(newTo);
        return newTo;
    }
View Full Code Here

TOP

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

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.