use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.
the class SumFilterTest method intBlockSum3x3IsFasterThanBlockSumNxN.
@Test
public void intBlockSum3x3IsFasterThanBlockSumNxN() {
org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
rand = new gdsc.core.utils.Random(-30051977);
SumFilter filter = new SumFilter();
ArrayList<int[]> dataSet = intCreateSpeedData(ITER3);
ArrayList<Long> fastTimes = new ArrayList<Long>();
// Initialise
filter.blockSumNxN(intClone(dataSet.get(0)), primes[0], primes[0], 1);
filter.blockSum3x3(intClone(dataSet.get(0)), primes[0], primes[0]);
for (int width : primes) for (int height : primes) {
ArrayList<int[]> dataSet2 = new ArrayList<int[]>(dataSet.size());
for (int[] data : dataSet) dataSet2.add(intClone(data));
long time = System.nanoTime();
for (int[] data : dataSet2) filter.blockSum3x3(data, width, height);
time = System.nanoTime() - time;
fastTimes.add(time);
}
long slowTotal = 0, fastTotal = 0;
int index = 0;
@SuppressWarnings("unused") long boxSlowTotal = 0, boxFastTotal = 0;
for (int width : primes) for (int height : primes) {
ArrayList<int[]> dataSet2 = new ArrayList<int[]>(dataSet.size());
for (int[] data : dataSet) dataSet2.add(intClone(data));
long time = System.nanoTime();
for (int[] data : dataSet2) filter.blockSumNxN(data, width, height, 1);
time = System.nanoTime() - time;
long fastTime = fastTimes.get(index++);
slowTotal += time;
fastTotal += fastTime;
boxSlowTotal += time;
boxFastTotal += fastTime;
if (debug)
System.out.printf("int blockSumNxN [%dx%d] %d => blockSum3x3 %d = %.2fx\n", width, height, time, fastTime, speedUpFactor(time, fastTime));
//if (TestSettings.ASSERT_SPEED_TESTS) Assert.assertTrue(String.format("Not faster: [%dx%d] %d > %d", width, height,
// blockTime, time), blockTime < time);
}
System.out.printf("int blockSumNxN %d => blockSum3x3 %d = %.2fx\n", slowTotal, fastTotal, speedUpFactor(slowTotal, fastTotal));
if (TestSettings.ASSERT_SPEED_TESTS)
Assert.assertTrue(String.format("Not faster: %d > %d", fastTotal, slowTotal), fastTotal < slowTotal);
}
use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.
the class SumFilterTest method floatBlockSumInternalNxNIsFasterThanBlockSumNxN.
@Test
public void floatBlockSumInternalNxNIsFasterThanBlockSumNxN() {
org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
rand = new gdsc.core.utils.Random(-300519);
SumFilter filter = new SumFilter();
ArrayList<float[]> dataSet = floatCreateSpeedData(ITER);
ArrayList<Long> fastTimes = new ArrayList<Long>();
// Initialise
filter.blockSumNxNInternal(floatClone(dataSet.get(0)), primes[0], primes[0], boxSizes[0]);
filter.blockSumNxN(floatClone(dataSet.get(0)), primes[0], primes[0], boxSizes[0]);
for (int boxSize : boxSizes) for (int width : primes) for (int height : primes) {
ArrayList<float[]> dataSet2 = new ArrayList<float[]>(dataSet.size());
for (float[] data : dataSet) dataSet2.add(floatClone(data));
long time = System.nanoTime();
for (float[] data : dataSet2) filter.blockSumNxNInternal(data, width, height, boxSize);
time = System.nanoTime() - time;
fastTimes.add(time);
}
long slowTotal = 0, fastTotal = 0;
int index = 0;
for (int boxSize : boxSizes) {
long boxSlowTotal = 0, boxFastTotal = 0;
for (int width : primes) for (int height : primes) {
ArrayList<float[]> dataSet2 = new ArrayList<float[]>(dataSet.size());
for (float[] data : dataSet) dataSet2.add(floatClone(data));
long time = System.nanoTime();
for (float[] data : dataSet2) filter.blockSumNxN(data, width, height, boxSize);
time = System.nanoTime() - time;
long fastTime = fastTimes.get(index++);
slowTotal += time;
fastTotal += fastTime;
boxSlowTotal += time;
boxFastTotal += fastTime;
if (debug)
System.out.printf("float blockSumNxN [%dx%d] @ %d : %d => blockSumNxNInternal %d = %.2fx\n", width, height, boxSize, time, fastTime, speedUpFactor(time, fastTime));
//if (TestSettings.ASSERT_SPEED_TESTS) Assert.assertTrue(String.format("Not faster: [%dx%d] @ %d : %d > %d", width, height, boxSize,
// blockTime, time), blockTime < time);
}
//if (debug)
System.out.printf("float blockSumNxN %d : %d => blockSumNxNInternal %d = %.2fx\n", boxSize, boxSlowTotal, boxFastTotal, speedUpFactor(boxSlowTotal, boxFastTotal));
if (TestSettings.ASSERT_SPEED_TESTS)
Assert.assertTrue(String.format("Not faster: Block %d : %d > %d", boxSize, boxFastTotal, boxSlowTotal), boxFastTotal < boxSlowTotal);
}
System.out.printf("float blockSumNxN %d => blockSumNxNInternal %d = %.2fx\n", slowTotal, fastTotal, speedUpFactor(slowTotal, fastTotal));
if (TestSettings.ASSERT_SPEED_TESTS)
Assert.assertTrue(String.format("Not faster: %d > %d", fastTotal, slowTotal), fastTotal < slowTotal);
}
use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.
the class SumFilterTest method intRollingBlockSum3x3IsFasterThanBlockSum3x3.
@Test
public void intRollingBlockSum3x3IsFasterThanBlockSum3x3() {
org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
rand = new gdsc.core.utils.Random(-30051977);
SumFilter filter = new SumFilter();
ArrayList<int[]> dataSet = intCreateSpeedData(ITER3);
ArrayList<Long> fastTimes = new ArrayList<Long>();
// Initialise
filter.rollingBlockSum3x3(intClone(dataSet.get(0)), primes[0], primes[0]);
filter.blockSum3x3(intClone(dataSet.get(0)), primes[0], primes[0]);
for (int width : primes) for (int height : primes) {
ArrayList<int[]> dataSet2 = new ArrayList<int[]>(dataSet.size());
for (int[] data : dataSet) dataSet2.add(intClone(data));
long time = System.nanoTime();
for (int[] data : dataSet2) filter.rollingBlockSum3x3(data, width, height);
time = System.nanoTime() - time;
fastTimes.add(time);
}
long slowTotal = 0, fastTotal = 0;
int index = 0;
@SuppressWarnings("unused") long boxSlowTotal = 0, boxFastTotal = 0;
for (int width : primes) for (int height : primes) {
ArrayList<int[]> dataSet2 = new ArrayList<int[]>(dataSet.size());
for (int[] data : dataSet) dataSet2.add(intClone(data));
long time = System.nanoTime();
for (int[] data : dataSet2) filter.blockSum3x3(data, width, height);
time = System.nanoTime() - time;
long fastTime = fastTimes.get(index++);
slowTotal += time;
fastTotal += fastTime;
boxSlowTotal += time;
boxFastTotal += fastTime;
if (debug)
System.out.printf("int blockSum3x3 [%dx%d] %d => rollingBlockSum3x3 %d = %.2fx\n", width, height, time, fastTime, speedUpFactor(time, fastTime));
//if (TestSettings.ASSERT_SPEED_TESTS) Assert.assertTrue(String.format("Not faster: [%dx%d] %d > %d", width, height,
// blockTime, time), blockTime < time);
}
System.out.printf("int blockSum3x3 %d => rollingBlockSum3x3 %d = %.2fx\n", slowTotal, fastTotal, speedUpFactor(slowTotal, fastTotal));
if (TestSettings.ASSERT_SPEED_TESTS)
Assert.assertTrue(String.format("Not faster: %d > %d", fastTotal, slowTotal), fastTotal < slowTotal);
}
use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.
the class SumFilterTest method floatStripedBlockSum3x3IsFasterThanStripedBlockSumNxN.
@Test
public void floatStripedBlockSum3x3IsFasterThanStripedBlockSumNxN() {
org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
rand = new gdsc.core.utils.Random(-30051977);
SumFilter filter = new SumFilter();
ArrayList<float[]> dataSet = floatCreateSpeedData(ITER3);
ArrayList<Long> fastTimes = new ArrayList<Long>();
// Initialise
filter.stripedBlockSumNxN(floatClone(dataSet.get(0)), primes[0], primes[0], 1);
filter.stripedBlockSum3x3(floatClone(dataSet.get(0)), primes[0], primes[0]);
for (int width : primes) for (int height : primes) {
ArrayList<float[]> dataSet2 = new ArrayList<float[]>(dataSet.size());
for (float[] data : dataSet) dataSet2.add(floatClone(data));
long time = System.nanoTime();
for (float[] data : dataSet2) filter.stripedBlockSum3x3(data, width, height);
time = System.nanoTime() - time;
fastTimes.add(time);
}
long slowTotal = 0, fastTotal = 0;
int index = 0;
@SuppressWarnings("unused") long boxSlowTotal = 0, boxFastTotal = 0;
for (int width : primes) for (int height : primes) {
ArrayList<float[]> dataSet2 = new ArrayList<float[]>(dataSet.size());
for (float[] data : dataSet) dataSet2.add(floatClone(data));
long time = System.nanoTime();
for (float[] data : dataSet2) filter.stripedBlockSumNxN(data, width, height, 1);
time = System.nanoTime() - time;
long fastTime = fastTimes.get(index++);
slowTotal += time;
fastTotal += fastTime;
boxSlowTotal += time;
boxFastTotal += fastTime;
if (debug)
System.out.printf("float stripedBlockSumNxN [%dx%d] %d => stripedBlockSum3x3 %d = %.2fx\n", width, height, time, fastTime, speedUpFactor(time, fastTime));
//if (TestSettings.ASSERT_SPEED_TESTS) Assert.assertTrue(String.format("Not faster: [%dx%d] %d > %d", width, height,
// stripedBlockTime, time), stripedBlockTime < time);
}
System.out.printf("float stripedBlockSumNxN %d => stripedBlockSum3x3 %d = %.2fx\n", slowTotal, fastTotal, speedUpFactor(slowTotal, fastTotal));
if (TestSettings.ASSERT_SPEED_TESTS)
Assert.assertTrue(String.format("Not faster: %d > %d", fastTotal, slowTotal), fastTotal < slowTotal);
}
use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.
the class FilterTest method floatRollingBlockSumNxNInternalIsFasterThanRollingBlockAverageNxNInternal.
@Test
public void floatRollingBlockSumNxNInternalIsFasterThanRollingBlockAverageNxNInternal() {
org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
rand = new gdsc.core.utils.Random(-300519);
SumFilter filter = new SumFilter();
AverageFilter filter2 = new AverageFilter();
int iter = 50;
ArrayList<float[]> dataSet = new ArrayList<float[]>(iter);
for (int i = iter; i-- > 0; ) {
dataSet.add(floatCreateData(primes[0], primes[0]));
}
ArrayList<Long> fastTimes = new ArrayList<Long>();
// Initialise
filter.rollingBlockSumNxNInternal(floatClone(dataSet.get(0)), primes[0], primes[0], boxSizes[0]);
filter2.rollingBlockAverageNxNInternal(floatClone(dataSet.get(0)), primes[0], primes[0], boxSizes[0]);
for (int boxSize : boxSizes) for (int width : primes) for (int height : primes) {
ArrayList<float[]> dataSet2 = new ArrayList<float[]>(iter);
for (float[] data : dataSet) dataSet2.add(floatClone(data));
long time = System.nanoTime();
for (float[] data : dataSet2) filter.rollingBlockSumNxNInternal(data, width, height, boxSize);
time = System.nanoTime() - time;
fastTimes.add(time);
}
long slowTotal = 0, fastTotal = 0;
int index = 0;
for (int boxSize : boxSizes) {
long boxSlowTotal = 0, boxFastTotal = 0;
for (int width : primes) for (int height : primes) {
ArrayList<float[]> dataSet2 = new ArrayList<float[]>(iter);
for (float[] data : dataSet) dataSet2.add(floatClone(data));
long time = System.nanoTime();
for (float[] data : dataSet2) filter2.rollingBlockAverageNxNInternal(data, width, height, boxSize);
time = System.nanoTime() - time;
long fastTime = fastTimes.get(index++);
slowTotal += time;
fastTotal += fastTime;
boxSlowTotal += time;
boxFastTotal += fastTime;
if (debug)
System.out.printf("float rollingBlockAverageNxNInternal [%dx%d] @ %d : %d => rollingBlockSumNxNInternal %d = %.2fx\n", width, height, boxSize, time, fastTime, speedUpFactor(time, fastTime));
//Assert.assertTrue(String.format("Not faster: [%dx%d] @ %d : %d > %d", width, height, boxSize,
// blockTime, time), blockTime < time);
}
//if (debug)
System.out.printf("float rollingBlockAverageNxNInternal %d : %d => rollingBlockSumNxNInternal %d = %.2fx\n", boxSize, boxSlowTotal, boxFastTotal, speedUpFactor(boxSlowTotal, boxFastTotal));
// Assert.assertTrue(String.format("Not faster: Block %d : %d > %d", boxSize, boxFastTotal, boxSlowTotal),
// boxFastTotal < boxSlowTotal);
}
System.out.printf("float rollingBlockAverageNxNInternal %d => rollingBlockSumNxNInternal %d = %.2fx\n", slowTotal, fastTotal, speedUpFactor(slowTotal, fastTotal));
if (TestSettings.ASSERT_SPEED_TESTS)
Assert.assertTrue(String.format("Not faster: %d > %d", fastTotal, slowTotal), fastTotal < slowTotal);
}
Aggregations