/*
* 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 cc.redberry.core.context.CC;
import cc.redberry.core.indexmapping.IndexMappings;
import cc.redberry.core.tensor.Product;
import cc.redberry.core.tensor.Tensor;
import cc.redberry.core.tensor.random.TRandom;
import cc.redberry.graph.ContractionsGraphDrawer;
import cc.redberry.transformation.substitutions.n.ProductsBijectionsPort;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
/**
*
* @author stas
*/
public class ProductBijectionMappingPerformanceHugeTensorTest {
public static void main(String[] args) {
int badCounter = 0;
// CC.getNameManager().reset(-3912578993076521674L);
// RandomProduct rp = new RandomProduct(10, 4,
// new int[]{10, 0, 0, 0}, //Min Free Indices
// new int[]{180, 0, 0, 0}, //Indices count
// new int[]{4, 0, 0, 0}, //Max INdex Per Tensor
// 170, 2, true);
// rp.reset(-3806751651286565680L);
CC.getNameManager().reset(-3912578993076521674L);
TRandom rp = new TRandom(
4,
10,
new int[]{4, 0, 0, 0},
new int[]{10, 0, 0, 0},
false);
rp.reset(-3806751651286565680L);
System.out.println("Random Seed = " + rp.getSeed());
System.out.println("NM Seed = " + CC.getNameManager().getSeed());
// Product t = rp.nextPermutation();
// ContractionsGraphDrawer.drawToPngFile(t, "/home/stas/Projects/Durty/", "Huge1");
DescriptiveStatistics timeStats = new DescriptiveStatistics();
DescriptiveStatistics trysStats = new DescriptiveStatistics();
int count = -1;
while (++count < 100) {
CC.resetTensorNames();
Product from = rp.nextProduct(15);
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;
OUTER:
while (trys++ < 5000 && (bijection = port.take()) != null)
// System.out.println(Arrays.toString(bijection));
// bijections.add(bijection.clone());
if (IndexMappings.createBijectiveProductPort(dataFrom, dataTo(dataTarget, bijection), false).take() != null) {
good = true;
System.out.println(count + " " + trys);
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;
}
}