Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.Tensor


     * @param t tensor
     * @return the numerical value of tensor
     */
    public static Tensor toNumeric(Tensor t) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Complex)
                iterator.set(((Complex) c).getNumericValue());

        return iterator.result();
View Full Code Here


        return collectNonScalars(t);
    }

    public static Tensor collectNonScalars(Tensor t) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Sum) {
                //TODO add check whether we need to do this transformation
                SumBuilderSplitingScalars sbss = new SumBuilderSplitingScalars(c.size());
                for (Tensor tt : c)
                    sbss.put(tt);
                iterator.set(sbss.build());
            }
        return iterator.result();
View Full Code Here

     * @param traverseGuide specifies parts of expression to apply the transformation
     * @return the result
     */
    public static Tensor collectScalarFactors(Tensor tensor, TraverseGuide traverseGuide) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(tensor, traverseGuide);
        Tensor current;
        while ((current = iterator.next()) != null) {
            if (current instanceof Product)
                iterator.set(collectScalarFactorsInProduct((Product) current));
        }
        return iterator.result();
View Full Code Here

            //Iterating through seeds
            for (int i = 0; i < seeds.length; ++i) {
                //Index of seed in from array
                int seedFromIndex = seeds[i];
                //Seed tensor (used only to get indices -> index Ids)
                Tensor seedFrom = fromData[seedFromIndex];
                //Seed index in target array (bijection for this tensor should already be provided by upper level port)
                int seedTargetIndex = bijection[seedFromIndex];

                //Diff ids of indices. Cloned because it will be sorted.
                short[] diffIds = seedFrom.getIndices().getPositionsInOrbits().clone(); // (!!!)
                //Sorting with permutation retrieval.
                //This step needed because we use the fastest (we think so)
                //method of collecting indices with the same index id [Permutable indices].
                int[] diffIdsPermutation = ArraysUtils.quickSortP(diffIds);
View Full Code Here

    }

    @Override
    protected Tensor expandProduct(Tensor product) {
        NumeratorDenominator numDen = NumeratorDenominator.getNumeratorAndDenominator(product, NumeratorDenominator.integerDenominatorIndicator);
        Tensor denominator = ExpandTransformation.expand(numDen.denominator, transformations);
        if (numDen.denominator == denominator)
            return product;
        return Tensors.multiply(numDen.numerator, Tensors.reciprocal(denominator));
    }
View Full Code Here

        int lowerCount = indices.getLower().size(), upperCount = indices.getUpper().size();

        IntPermutationsGenerator lowIndicesPermutationsGenerator,
                upperIndicesPermutationGenerator;
        SumBuilder sumBuilder = new SumBuilder();
        Tensor summand;
        List<int[]> generatedPermutations = new ArrayList<>();
        if (upperCount != 0 && lowerCount != 0) {
            lowIndicesPermutationsGenerator = new IntPermutationsGenerator(lowerCount);
            while (lowIndicesPermutationsGenerator.hasNext()) {
                int[] lowerPermutation = lowIndicesPermutationsGenerator.next().clone();
View Full Code Here

    }

    @Override
    public Tensor transform(Tensor tensor) {
        SubstitutionIterator iterator = new SubstitutionIterator(tensor, traverseGuide);
        Tensor current;
        while ((current = iterator.next()) != null) {
            if (current instanceof Product)
                iterator.unsafeSet(expandProduct((Product) current, transformations));
            else if (ExpandUtils.isExpandablePower(current)) {
                Sum sum = (Sum) current.get(0);
                int exponent = ((Complex) current.get(1)).intValue();
                if (exponent == -1)
                    continue;
                boolean symbolic = TensorUtils.isSymbolic(sum),
                        reciprocal = exponent < 0;
                exponent = Math.abs(exponent);
                Tensor temp;
                if (symbolic)
                    temp = ExpandUtils.expandSymbolicPower(sum, exponent, transformations);
                else
                    temp = ExpandUtils.expandPower(sum, exponent, iterator.getForbidden(), transformations);
                if (reciprocal)
View Full Code Here

     */
    public TraverseState next() {

        if (lastState == TraverseState.Leaving) {

            Tensor cur = null;
            if (currentPointer.payload != null)
                cur = currentPointer.payload.onLeaving(currentPointer);

            if (cur != null)
                current = cur;

            currentPointer = currentPointer.previous;
            currentPointer.set(current);
        }

        Tensor next;
        while (true) {
            next = currentPointer.next();
            if (next == null) {
                if (currentPointer.previous == null)
                    return lastState = null;
View Full Code Here

    }

    @Override
    protected Tensor expandProduct(Tensor product) {
        NumeratorDenominator numDen = NumeratorDenominator.getNumeratorAndDenominator(product, NumeratorDenominator.integerDenominatorIndicator);
        Tensor numerator = ExpandTransformation.expand(numDen.numerator, transformations);
        if (numDen.numerator == numerator)
            return product;
        return Tensors.multiply(numerator, Tensors.reciprocal(numDen.denominator));
    }
View Full Code Here

    }

    @Override
    protected Tensor expandProduct(Product product, Transformation[] transformations) {
        NumeratorDenominator numDen = NumeratorDenominator.getNumeratorAndDenominator(product, NumeratorDenominator.integerDenominatorIndicator);
        Tensor denominator = numDen.denominator;

//        assert !isPositiveIntegerPower(denominator);
        if (denominator instanceof Product)
            denominator = ExpandUtils.expandProductOfSums((Product) numDen.denominator, transformations);
        boolean denExpanded = denominator != numDen.denominator;
        denominator = reciprocal(denominator);

        Tensor numerator = numDen.numerator;
        Tensor res = Tensors.multiply(denominator, numerator), temp = res;
        if (res instanceof Product)
            res = ExpandUtils.expandProductOfSums((Product) temp, transformations);
        if (denExpanded || res != temp)
            return res;
        return product;
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.