use of uk.ac.sussex.gdsc.smlm.utils.Convolution.ConvolutionValueProcedure in project GDSC-SMLM by aherbert.
the class ConvolutionTest method canComputeScaledConvolutionWithEarlyExit.
@SeededTest
void canComputeScaledConvolutionWithEarlyExit(RandomSeed seed) {
final UniformRandomProvider random = RngUtils.create(seed.getSeed());
int size = 10;
final int sizeLoops = 4;
final int sLoops = 2;
for (int i = 0; i < sizeLoops; i++) {
double sd = 0.5;
for (int j = 0; j < sLoops; j++) {
final double[] data = randomData(random, size);
final double[] kernel = createKernel(sd);
for (int scale = 2; scale < 5; scale++) {
final double[] e = Convolution.convolve(kernel, data, scale);
final double[] o = new double[e.length];
final int limit = data.length;
Convolution.convolve(kernel, data, scale, new ConvolutionValueProcedure() {
int index = 0;
@Override
public boolean execute(double value) {
o[index++] = value;
return index < limit;
}
});
int index = 0;
for (; index < limit; index++) {
Assertions.assertEquals(e[index], o[index]);
}
while (index < o.length) {
Assertions.assertEquals(0, o[index++]);
}
}
sd *= 2;
}
size *= 2;
}
}
use of uk.ac.sussex.gdsc.smlm.utils.Convolution.ConvolutionValueProcedure in project GDSC-SMLM by aherbert.
the class ConvolutionTest method canComputeScaledConvolution.
@SeededTest
void canComputeScaledConvolution(RandomSeed seed) {
final UniformRandomProvider random = RngUtils.create(seed.getSeed());
final TDoubleArrayList list = new TDoubleArrayList();
int size = 10;
for (int i = 0; i < sizeLoops; i++) {
double sd = 0.5;
for (int j = 0; j < sdLoops; j++) {
final double[] data = randomData(random, size);
final double[] kernel = createKernel(sd);
for (int scale = 2; scale < 5; scale++) {
final double[] e = convolve(kernel, data, list, scale);
final double[] o = Convolution.convolve(kernel, data, scale);
final double[] o2 = new double[o.length];
Convolution.convolve(kernel, data, scale, new ConvolutionValueProcedure() {
int index = 0;
@Override
public boolean execute(double value) {
o2[index++] = value;
return true;
}
});
Assertions.assertArrayEquals(e, o);
Assertions.assertArrayEquals(e, o2);
}
sd *= 2;
}
size *= 2;
}
}
Aggregations