Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit f8d9d3d

Browse files
author
Ehsan Totoni
committed
test kde
1 parent ad2e989 commit f8d9d3d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

hpat/tests/test_ml.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,25 @@ def test_impl(N, D):
6767
self.assertEqual(count_array_OneDs(), 5)
6868
self.assertEqual(count_parfor_OneDs(), 3)
6969

70+
def test_kde(self):
71+
def test_impl(n):
72+
X = np.ones(n)
73+
b = 0.5
74+
points = np.array([-1.0, 2.0, 5.0])
75+
N = points.shape[0]
76+
exps = 0
77+
for i in hpat.prange(n):
78+
p = X[i]
79+
d = (-(p - points)**2) / (2 * b**2)
80+
m = np.min(d)
81+
exps += m - np.log(b * N)+np.log(np.sum(np.exp(d - m)))
82+
return exps
83+
84+
hpat_func = hpat.jit(test_impl)
85+
n = 11
86+
np.testing.assert_approx_equal(hpat_func(n), test_impl(n))
87+
self.assertEqual(count_array_OneDs(), 1)
88+
self.assertEqual(count_parfor_OneDs(), 2)
89+
7090
if __name__ == "__main__":
7191
unittest.main()

0 commit comments

Comments
 (0)