Examples of TensorFirstTreeIterator


Examples of cc.redberry.core.tensor.iterators.TensorFirstTreeIterator

    @Override
    public Tensor transform(Tensor tensor) {
        //TODO review
        Tensor parent = tensor.getParent();
        TensorWrapper wrapper = new TensorWrapper(tensor);
        TensorFirstTreeIterator iterator = new TensorFirstTreeIterator(wrapper, new OnLeaving());
        Tensor current;
        while (iterator.hasNext()) {
            current = iterator.next();

            level++;
            if (indicesLevel == -1 && current instanceof Product) {
                firstProduct = current;
                indicesLevel = level;
            }

            if (current.getClass() != getFromClasss())
                continue;
            T _current = (T) current;
            if (_current.getName() != from.getName())
                continue;
            OutputPortUnsafe<IndexMappingBuffer> opu = IndexMappings.createPortForSimpleTensor(from, _current, allowDiffStates);


            IndexMappingBuffer buffer;
            //TODO refactor throw off if (i.e. spread this code in inheritors)
            if (allowDiffStates)
                buffer = IndexMappingUtils.tryGetPositiveWithoutDiffStates(opu);
            else
                buffer = IndexMappingUtils.tryGetPositive(opu);

            if (buffer == null)
                continue;

            Tensor newTo = getNewTo(_current, from, to);
            if (newTo == null)
                continue;


            if (allowDiffStates)
                if (!IndexMappingUtils.containsDiffStates(buffer))
                    newTo = ApplyIndexMappingUtils.applyIndexMappingWithoutDiffStates(newTo, buffer, getUsedIndices());
                else
                    newTo = ApplyIndexMappingUtils.applyIndexMappingWithDiffStates(newTo, buffer, getUsedIndices());
            else
                newTo = ApplyIndexMappingUtils.applyIndexMappingWithDiffStates(newTo, buffer, getUsedIndices());

            //TODO discuss with Dmitry
            if (buffer.getSignum())
                if (Derivative.onVarsIndicator.is(iterator)) {
                    derivativeVarChangedSignum ^= true;
                    iterator.set(Transformations.contractMetrics(newTo));
                } else
                    iterator.set(new Product(TensorNumber.createMINUSONE(), newTo));
            else if (Derivative.onVarsIndicator.is(iterator))
                iterator.set(Transformations.contractMetrics(newTo));
            else
                iterator.set(newTo);
        }
        Tensor result = wrapper.getInnerTensor();
        result.setParent(parent);
        return result;
    }
View Full Code Here

Examples of cc.redberry.core.tensor.iterators.TensorFirstTreeIterator

     * @return false if specified indices are inconsistent and true if not
     */
    //TODO consider different implementation
    public static boolean testIndicesConsistent(final Tensor t) {
        try {
            TensorFirstTreeIterator it = new TensorFirstTreeIterator(t);
            while (it.hasNext())
                it.next().getIndices().testConsistentWithException();
        } catch (InconsistentIndicesException e) {
            return false;
        }
        return true;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.