Skip to content

Commit

Permalink
Add test and ensure engine compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Dec 5, 2024
1 parent 3ad9055 commit ebb7138
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
7 changes: 0 additions & 7 deletions src/pyFAI/resources/openCL/medfilt.cl
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ csr_medfilt ( const global float4 *data4,
float sum=0.0f, ratio=1.3f;
float2 acc_sig, acc_nrm, acc_var, acc_nrm2;

// if (tid==0)printf("bin %d start %d stop %d\n",bin_num,start, stop);
// first populate the work4 array from data4
for (int i=start+tid; i<stop; i+=wg)
{
float4 r4, w4;
int idx = indices[i];
float coef = (coefs == ZERO)?1.0f:coefs[i];
r4 = data4[idx];
// if (tid==0)printf("bin %d start %d stop %d i=%d idx=%d coef=%6.4f\n",bin_num,start, stop,i,idx,coef);

w4.s0 = r4.s0 / r4.s2;
w4.s1 = r4.s0 * coef;
Expand Down Expand Up @@ -204,13 +202,8 @@ csr_medfilt ( const global float4 *data4,
acc_nrm2 = dw_plus_dw(acc_nrm2, fp_times_fp(w.s3, w.s3));

}
else{
printf("bin:%d tid:%d qmin:%6.3f qlast:%6.3f qcur:%6.3f qmax:%6.3f\n",
bin_num, tid, qmin, q_last, w.s0,qmax);
}
}
// Now parallel reductions, one after the other :-/
// if (tid==0)printf("bin %d cnt %d acc_sig %6.1f acc_var %6.1f acc_nrm %6.1f acc_nrm2 %6.1f\n",bin_num, cnt, acc_sig.s0, acc_var.s0, acc_nrm.s0, acc_nrm2.s0);
shared_int[tid] = cnt;
cnt = sum_int_reduction(shared_int);

Expand Down
30 changes: 28 additions & 2 deletions src/pyFAI/test/test_medfilt_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "19/11/2024"
__date__ = "05/12/2024"

import unittest
import numpy
Expand All @@ -41,7 +41,7 @@
from .utilstest import UtilsTest
import fabio
from .. import load

from ..opencl import ocl

class TestMedfilt(unittest.TestCase):
"""Test Azimuthal median filtering results
Expand Down Expand Up @@ -119,6 +119,32 @@ def test_cython(self):
self.assertTrue(numpy.allclose(ref.std, obt.std), "std matches")
self.assertTrue(numpy.allclose(ref.sem, obt.sem), "sem matches")

@unittest.skipUnless(ocl, "pyopencl is missing")
def test_opencl(self):
method = list(self.method)
method[-1] = "opencl"
method = tuple(method)
ref = self.ai.integrate1d(self.img, self.npt, unit="2th_rad", method=method, error_model="poisson")
print(ref.method)
engine = self.ai.engines[ref.method].engine
print(engine)
obt = engine.medfilt(self.img,
solidangle=self.ai.solidAngleArray(),
quant_min=0,quant_max=1, # taking all Like this it works like a normal mean
error_model="poisson")

# print(ref.count-obt.count)
# print()
self.assertTrue(numpy.allclose(ref.radial, obt.position), "radial matches")
self.assertTrue(numpy.allclose(ref.sum_signal, obt.signal), "signal matches")
self.assertTrue(numpy.allclose(ref.sum_variance, obt.variance), "variance matches")
self.assertTrue(numpy.allclose(ref.sum_normalization, obt.normalization), "normalization matches")
self.assertTrue(numpy.allclose(ref.sum_normalization2, obt.norm_sq), "norm_sq matches")
# self.assertTrue(numpy.allclose(ref.count, obt.count), "count matches") # not valid with pixel splitting
self.assertTrue(numpy.allclose(ref.intensity, obt.intensity), "intensity matches")
self.assertTrue(numpy.allclose(ref.sigma, obt.sigma), "sigma matches")
self.assertTrue(numpy.allclose(ref.std, obt.std), "std matches")
self.assertTrue(numpy.allclose(ref.sem, obt.sem), "sem matches")


def suite():
Expand Down

0 comments on commit ebb7138

Please sign in to comment.