Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.Product


        while ((current = iterator.next()) != null) {
            if (!(current instanceof Product))
                continue;

            while (current instanceof Product) {
                Product cp = (Product) current;
                IndexMappingBuffer buffer = null;

                final Tensor[] currentIndexless = cp.getIndexless();
                int[] indexlessBijection;
                IndexlessBijectionsPort indexlessPort = new IndexlessBijectionsPort(fromIndexless, currentIndexless);
                while ((indexlessBijection = indexlessPort.take()) != null) {
                    buffer = IndexMappings.createBijectiveProductPort(fromIndexless, extract(currentIndexless, indexlessBijection)).take();
                    if (buffer != null)
                        break;
                }
                if (buffer == null)
                    break;

                boolean sign = buffer.getSignum();
                buffer = null;
                ProductContent currentContent = cp.getContent();
                final Tensor[] currentData = currentContent.getDataCopy();
                int[] dataBijection;
                ProductsBijectionsPort dataPort = new ProductsBijectionsPort(fromContent, currentContent);
                while ((dataBijection = dataPort.take()) != null) {
                    buffer = IndexMappings.createBijectiveProductPort(fromData, extract(currentData, dataBijection)).take();
                    if (buffer != null)
                        break;
                }
                if (buffer == null)
                    break;

                buffer.addSignum(sign);
                Tensor newTo;
                if (symbolic)
                    newTo = to;
                else {
                    int[] forbidden = new int[iterator.forbiddenIndices().size()];
                    int c = -1;
                    for (Integer f : iterator.forbiddenIndices())
                        forbidden[++c] = f;
                    newTo = ApplyIndexMapping.applyIndexMapping(to, buffer, forbidden);
//                    if (newTo != to)
                    iterator.forbiddenIndices().addAll(TensorUtils.getAllIndicesNames(newTo));
                }

                Arrays.sort(indexlessBijection);
                Arrays.sort(dataBijection);

                ProductBuilder builder = new ProductBuilder();
                builder.put(newTo);

                int i;
                for (i = 0; i < currentIndexless.length; ++i)
                    if (Arrays.binarySearch(indexlessBijection, i) < 0)
                        builder.put(currentIndexless[i]);

                for (i = 0; i < currentData.length; ++i)
                    if (Arrays.binarySearch(dataBijection, i) < 0)
                        builder.put(currentData[i]);

                builder.put(cp.getFactor().divide(fromFactor));
                current = builder.build();
            }
            iterator.set(current);
        }
        return iterator.result();
View Full Code Here


//            CC.resetTensorNames();
            Tensor t = rp.nextProduct(15);
            if (!(t instanceof Product))
                continue;

            Product from = (Product) t, target = from;

            long start = System.nanoTime();
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.getContent());

            int[] bijection;
            boolean good = false;
            int trys = 0;
            OUTER:
View Full Code Here

//            CC.resetTensorNames();
            Tensor t = rp.nextProduct(15);
            if (!(t instanceof Product))
                continue;

            Product from = (Product) t;

            long start = System.nanoTime();
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), from.getContent());

            int[] bijection;
            boolean good = false;
            int trys = 0;
            OUTER:
View Full Code Here

            CC.getNameManager().mapNameDescriptor(descriptors.get(i));
            if (withSymmetries)
                addRandomSymmetries(nameDescriptor);
        }

        Product product = new Product();
        IndicesProvider indicesProvider = new IndicesProvider(random, indicesCount, minFree);
        SimpleIndices ind;
        int scalars = 0;
        while (!descriptors.isEmpty() && product.size() <= maxTensorCount) {
            int descriptorIndex = nextInt(random, descriptors.size());
            NameDescriptor nd = descriptors.get(descriptorIndex);
            if (nd.getIndexTypeStructure().size() == 0)
                if (scalars++ > maxScalarsCount) {
                    descriptors.remove(descriptorIndex);
                    continue;
                }
            ind = indicesProvider.next(nd);
            if (ind == null) {
                descriptors.remove(descriptorIndex);
                continue;
            }
            product.add(new SimpleTensor(nd.getId(), ind));
        }
        return product;
    }
View Full Code Here

    protected Tensor pairProduct(Tensor f, Tensor t) {
        Tensor[] arr = new Tensor[]{f.equivalent(), t.equivalent()};
        for (int i = 0; i < 2; ++i)
            if (arr[i] instanceof TensorNumber && ((TensorNumber) arr[i]).isOne())
                return arr[1 - i];
        return new Product(arr[0], arr[1]);
    }
View Full Code Here

        DescriptiveStatistics timeStats = new DescriptiveStatistics();
        DescriptiveStatistics trysStats = new DescriptiveStatistics();
        int count = 0;
        while (++count < 5000) {
            CC.resetTensorNames();
            Product from = rp.next();
            Product target = from.clone();

            long start = System.nanoTime();
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.getContent());

            int[] bijection;
            boolean good = false;
            int trys = 0;
            OUTER:
View Full Code Here

        DescriptiveStatistics timeStats = new DescriptiveStatistics();
        DescriptiveStatistics trysStats = new DescriptiveStatistics();
        int count = -1;
        while (++count < 100) {
            CC.resetTensorNames();
            Product from = rp.next();
            Product target = from.clone();

            long start = System.nanoTime();
            Tensor[] dataFrom = from.getContent().getDataCopy();
            Tensor[] dataTarget = target.getContent().getDataCopy();
//             if (count == 6)
//                ContractionsGraphDrawer.drawToPngFile(from, "/home/stas/Projects/Durty/", "Huge6");
            if (count == 24)
                ContractionsGraphDrawer.drawToPngFile(from, "/home/stas/Projects/Durty/", "Huge24");
            if (count == 30)
                ContractionsGraphDrawer.drawToPngFile(from, "/home/stas/Projects/Durty/", "Huge30");
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.getContent());

//            List<int[]> bijections = new ArrayList<>();
            int[] bijection;
            boolean good = false;
            int trys = 0;
View Full Code Here

        DescriptiveStatistics timeStats = new DescriptiveStatistics();
        DescriptiveStatistics trysStats = new DescriptiveStatistics();
        int count = 0;
        while (++count < 5000) {
            CC.resetTensorNames();
            Product from = rp.next();
            Product target = from.clone();

            long start = System.nanoTime();
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.getContent());
            Tensor[] dataFrom = from.getContent().getDataCopy();
            Tensor[] dataTarget = target.getContent().getDataCopy();
//            List<int[]> bijections = new ArrayList<>();
            int[] bijection;
            boolean good = false;
            int trys = 0;
            OUTER:
View Full Code Here

            }
            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)
                return TensorNumber.createONE();
            Product kroneckers = new Product();
            Indices targetIndices = sp.getIndices();
            Indices varIndices = var.getIndices();
            for (int i = 0; i < sp.getIndices().size(); ++i)
                kroneckers.add(CC.createMetricOrKronecker(targetIndices.get(i), varIndices.get(i)));
            return kroneckers.equivalent();
        } else if (target.getClass() == TensorField.class) {
            TensorField field = (TensorField) target;
            Tensor[] args = field.getArgs();
            for (int i = 0; i < args.length; ++i)
                if (getDerivative(args[i], var) != null)
                    return Derivative.createFromInversed(target,var);
            return null;
        } else if (target instanceof AbstractScalarFunction) {
            AbstractScalarFunction func = (AbstractScalarFunction) target;
            Tensor der = getDerivative(func.getInnerTensor(), var);
            if (der == null)
                return null;
            if (isOne(der))
                return func.derivative();
            return new Product(func.derivative(), der);
        }
        //TODO get derivative ot derivative
        return null;
    }
View Full Code Here

        //TODO discover case, when factoredNumber == 0
        if (factoredNumber.isOne())
            return term;
        if (termIsOne)
            return factoredNumber;
        return new Product(factoredNumber, term);
    }
View Full Code Here

TOP

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

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.