Package cc.redberry.performance

Source Code of cc.redberry.performance.ProductBijectionMappingPerformanceTest

/*
* Redberry: symbolic tensor computations.
*
* Copyright (c) 2010-2012:
*   Stanislav Poslavsky   <stvlpos@mail.ru>
*   Bolotin Dmitriy       <bolotin.dmitriy@gmail.com>
*
* This file is part of Redberry.
*
* Redberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Redberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Redberry. If not, see <http://www.gnu.org/licenses/>.
*/
package cc.redberry.performance;

import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
import cc.redberry.core.context.CC;
import cc.redberry.core.tensor.Product;
import cc.redberry.core.tensor.Tensor;
import cc.redberry.core.indexmapping.IndexMappings;
import cc.redberry.transformation.substitutions.n.ProductsBijectionsPort;
import cc.redberry.core.tensor.random.RandomProduct;

/**
*
* @author stas
*/
public class ProductBijectionMappingPerformanceTest {
    public static void main(String[] args) {
        int badCounter = 0;
        CC.getNameManager().reset(-3912578993076521674L);
        RandomProduct rp = new RandomProduct(80, 4,
                new int[]{5, 0, 0, 0}, //Min Free Indices
                new int[]{10, 0, 0, 0}, //Indices count
                new int[]{7, 0, 0, 0}, //Max INdex Per Tensor
                20, 2, true);
        rp.reset(-3806751651286565680L);
        System.out.println("Random Seed = " + rp.getSeed());
        System.out.println("NM Seed = " + CC.getNameManager().getSeed());
        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:
            while (trys++ < 5000 && (bijection = port.take()) != null) {
//                bijections.add(bijection.clone());
                if (IndexMappings.createBijectiveProductPort(dataFrom, dataTo(dataTarget, bijection), false).take() != null) {
                    good = true;
                    break;
                }
            }
//            if (trys == 3169) {
//                ContractionsGraphDrawer.drawToPngFile(from, "/home/stas/Projects/Durty/", "Worst");
//                for (int[] b : bijections)
//                    System.out.println(Arrays.toString(b));
//            }
            double millis = 1E-6 * (System.nanoTime() - start);
            timeStats.addValue(millis);
            trysStats.addValue(trys);

            if (!good)
                throw new RuntimeException();
        }
        System.out.println(timeStats);
        System.out.println(trysStats);
    }

    private static Tensor[] dataTo(final Tensor[] data, final int[] bijection) {
        Tensor[] to = new Tensor[bijection.length];
        for (int i = 0; i < bijection.length; ++i)
            to[i] = data[bijection[i]];
        return to;
    }
}
TOP

Related Classes of cc.redberry.performance.ProductBijectionMappingPerformanceTest

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.