Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.Sum


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


        return target;
    }

    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);
            }
            if (res.isEmpty())
                return null;
            return res.equivalent();
        } else if (target instanceof Product) {
            Product product = (Product) target;
            Tensor derivative;
            List<Tensor> resultProducts = new ArrayList<>();
            for (int i = 0; i < product.size(); ++i) {
                derivative = getDerivative(product.getElements().get(i), var);
                if (derivative == null)
                    continue;
                Product clone = (Product) product.clone();
                clone.getElements().remove(i);
                if (!isOne(derivative))
                    clone.add(derivative);
                resultProducts.add(clone.equivalent());
            }
            if (resultProducts.isEmpty())
                return null;
            if (resultProducts.size() == 1)
                return resultProducts.get(0);
            return new Sum(resultProducts);
        } else if (target.getClass() == SimpleTensor.class) {
            SimpleTensor sp = (SimpleTensor) target;
            if (sp.getName() != var.getName())
                return null;
            if (sp.getIndices().size() == 0)
View Full Code Here

            return equals.result();
        if (!equals.initialized())
            return symbols.result();
        Tensor s1 = symbols.result();
        Tensor s2 = equals.result();
        return new Sum(s1, s2);
    }
View Full Code Here

        return closed;
    }

    @Override
    public final Tensor result() {
        Sum sum = new Sum();
        for (Split sp : collectedTerms)
            sum.add(sp.tensorEquvivalent());
        Tensor result = sum.equivalent();
        result.setParent(CC.getRootParentTensor());
        return result;
    }
View Full Code Here

    public Tensor randomScalarSum(int size, int maxProductsSize) {
        if (size <= 0 || maxProductsSize <= 0)
            throw new IllegalArgumentException("size <= 0");
        if (size == 1)
            return randomScalarProduct(maxProductsSize);
        Sum sum = new Sum();
        for (int i = 0; i < size; ++i) {
            int randomProductSize = (int) (1 + Math.random() * maxProductsSize);
            sum.add(randomScalarProduct(randomProductSize));
        }
        return sum;
    }
View Full Code Here

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

                    for (int i = 0; i < 10; ++i) { //Each random sum repeatedly tested 1000 times
                        Sum[] sums_ = new Sum[]{sums[0].clone(), sums[1].clone()};
                        long start = System.nanoTime();
                        PairEC pec = new PairEC(sums_[0], sums_[1], NaiveSumCollectIP.FACTORY, ScalarsSplitter.INSTANCE, threads);
                        Sum res = (Sum) pec.result();
//                        System.out.println(res.size() + " " + res);
                        ds.addValue(System.nanoTime() - start);
                    }

                    stats[threads - 1] = ds; //Saving statistics for one thread
View Full Code Here

        return target;
    }

    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);
            }
            if (res.isEmpty())
                return null;
            return res.equivalent();
        } else if (target instanceof Product) {
            Product product = (Product) target;
            Tensor derivative;
            List<Tensor> resultProducts = new ArrayList<>();
            for (int i = 0; i < product.size(); ++i) {
                derivative = getDerivative(product.getElements().get(i), var);
                if (derivative == null)
                    continue;
                Product clone = (Product) product.clone();
                clone.getElements().remove(i);
                if (!isOne(derivative))
                    clone.add(derivative);
                resultProducts.add(clone.equivalent());
            }
            if (resultProducts.isEmpty())
                return null;
            if (resultProducts.size() == 1)
                return resultProducts.get(0);
            return new Sum(resultProducts);
        } else if (target.getClass() == SimpleTensor.class) {
            SimpleTensor sp = (SimpleTensor) target;
            if (sp.getName() != var.getName())
                return null;
            if (sp.getIndices().size() == 0)
View Full Code Here

            IndicesBuilderSimple ib = new IndicesBuilderSimple();
            ib.append(tensor.getIndices()).append(ind);
            return CC.createSimpleTensor(
                    CC.getNameDescriptor(((SimpleTensor) tensor).getName()).getName(), (SimpleIndices) ib.getIndices());
        } else if (tensor instanceof Sum) {
            Sum newSum = new Sum();
            IndexGeneratorWrapper wrapper = new IndexGeneratorWrapper(indexGenerator);
            for (Tensor t : tensor) {
                //TODO review   !!!!!!!!!!!!
                //FIXME review  !!!!!!!!!!!!
//                newSum.add(transform(t, wrapper, ind));
//                BUG bug was detected in cc.redberry physics
//                we used generator instead of wrapper
                newSum.add(transform(t, indexGenerator, ind));
                wrapper.dump();
            }
            wrapper.write();
            return newSum;
        } else if (tensor instanceof Product) {
View Full Code Here

    }

    @Override
    public Tensor result() {
        isClosed = true;
        return new Sum(queue).equivalent();

    }
View Full Code Here

TOP

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

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.