Search in sources :

Example 11 with SumFilter

use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.

the class SumFilterTest method floatRollingBlockSumNxNInternalIsFasterThanBlockSumNxNInternal.

@Test
public void floatRollingBlockSumNxNInternalIsFasterThanBlockSumNxNInternal() {
    org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
    rand = new gdsc.core.utils.Random(-300519);
    SumFilter filter = new SumFilter();
    ArrayList<float[]> dataSet = floatCreateSpeedData(InternalITER);
    ArrayList<Long> fastTimes = new ArrayList<Long>();
    // Initialise
    filter.blockSumNxNInternal(floatClone(dataSet.get(0)), primes[0], primes[0], boxSizes[0]);
    filter.rollingBlockSumNxNInternal(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.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[]>(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;
            long fastTime = fastTimes.get(index++);
            slowTotal += time;
            fastTotal += fastTime;
            boxSlowTotal += time;
            boxFastTotal += fastTime;
            if (debug)
                System.out.printf("float blockSumNxNInternal [%dx%d] @ %d : %d => rollingBlockSumNxNInternal %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 blockSumNxNInternal %d : %d => rollingBlockSumNxNInternal %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 blockSumNxNInternal %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);
}
Also used : ArrayList(java.util.ArrayList) SumFilter(gdsc.smlm.filters.SumFilter) Test(org.junit.Test)

Example 12 with SumFilter

use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.

the class SumFilterTest method intRollingBlockSum3x3InternalIsFasterThanBlockSum3x3Internal.

@Test
public void intRollingBlockSum3x3InternalIsFasterThanBlockSum3x3Internal() {
    org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
    rand = new gdsc.core.utils.Random(-30051977);
    SumFilter filter = new SumFilter();
    ArrayList<int[]> dataSet = intCreateSpeedData(InternalITER3);
    ArrayList<Long> fastTimes = new ArrayList<Long>();
    // Initialise
    filter.rollingBlockSum3x3Internal(intClone(dataSet.get(0)), primes[0], primes[0]);
    filter.blockSum3x3Internal(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.rollingBlockSum3x3Internal(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.blockSum3x3Internal(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 blockSum3x3Internal [%dx%d] %d => rollingBlockSum3x3Internal %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 blockSum3x3Internal %d => rollingBlockSum3x3Internal %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);
}
Also used : ArrayList(java.util.ArrayList) SumFilter(gdsc.smlm.filters.SumFilter) Test(org.junit.Test)

Example 13 with SumFilter

use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.

the class SumFilterTest method floatRollingBlockSum3x3InternalIsFasterThanStripedBlockSum3x3Internal.

@Test
public void floatRollingBlockSum3x3InternalIsFasterThanStripedBlockSum3x3Internal() {
    org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
    rand = new gdsc.core.utils.Random(-30051977);
    SumFilter filter = new SumFilter();
    ArrayList<float[]> dataSet = floatCreateSpeedData(InternalITER3);
    ArrayList<Long> fastTimes = new ArrayList<Long>();
    // Initialise
    filter.rollingBlockSum3x3Internal(floatClone(dataSet.get(0)), primes[0], primes[0]);
    filter.stripedBlockSum3x3Internal(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.rollingBlockSum3x3Internal(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.stripedBlockSum3x3Internal(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("float stripedBlockSum3x3Internal [%dx%d] %d => rollingBlockSum3x3Internal %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("float stripedBlockSum3x3Internal %d => rollingBlockSum3x3Internal %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);
}
Also used : ArrayList(java.util.ArrayList) SumFilter(gdsc.smlm.filters.SumFilter) Test(org.junit.Test)

Example 14 with SumFilter

use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.

the class SumFilterTest method intRollingBlockSum3x3InternalIsFasterThanRollingBlockSumNxNInternal.

@Test
public void intRollingBlockSum3x3InternalIsFasterThanRollingBlockSumNxNInternal() {
    org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
    rand = new gdsc.core.utils.Random(-30051977);
    SumFilter filter = new SumFilter();
    ArrayList<int[]> dataSet = intCreateSpeedData(InternalITER3);
    ArrayList<Long> fastTimes = new ArrayList<Long>();
    // Initialise
    filter.rollingBlockSum3x3Internal(intClone(dataSet.get(0)), primes[0], primes[0]);
    filter.rollingBlockSumNxNInternal(intClone(dataSet.get(0)), primes[0], primes[0], 1);
    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.rollingBlockSum3x3Internal(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.rollingBlockSumNxNInternal(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 rollingBlockSumNxNInternal [%dx%d] %d => rollingBlockSum3x3Internal %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 rollingBlockSumNxNInternal %d => rollingBlockSum3x3Internal %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);
}
Also used : ArrayList(java.util.ArrayList) SumFilter(gdsc.smlm.filters.SumFilter) Test(org.junit.Test)

Example 15 with SumFilter

use of gdsc.smlm.filters.SumFilter in project GDSC-SMLM by aherbert.

the class SumFilterTest method floatStripedBlockSumNxNInternalIsFasterThanBlockSumNxNInternal.

@Test
public void floatStripedBlockSumNxNInternalIsFasterThanBlockSumNxNInternal() {
    org.junit.Assume.assumeTrue(TestSettings.RUN_SPEED_TESTS);
    rand = new gdsc.core.utils.Random(-300519);
    SumFilter filter = new SumFilter();
    ArrayList<float[]> dataSet = floatCreateSpeedData(InternalITER);
    ArrayList<Long> fastTimes = new ArrayList<Long>();
    // Initialise
    filter.blockSumNxNInternal(floatClone(dataSet.get(0)), primes[0], primes[0], boxSizes[0]);
    filter.stripedBlockSumNxNInternal(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.stripedBlockSumNxNInternal(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.blockSumNxNInternal(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 blockSumNxNInternal [%dx%d] @ %d : %d => stripedBlockSumNxNInternal %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 blockSumNxNInternal %d : %d => stripedBlockSumNxNInternal %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 blockSumNxNInternal %d => stripedBlockSumNxNInternal %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);
}
Also used : ArrayList(java.util.ArrayList) SumFilter(gdsc.smlm.filters.SumFilter) Test(org.junit.Test)

Aggregations

SumFilter (gdsc.smlm.filters.SumFilter)44 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)44 AverageFilter (gdsc.smlm.filters.AverageFilter)1