import unittest
import pandas as pd
import numpy as np
import numba
import h5py
import hpat
from hpat.tests.test_utils import (count_array_REPs, count_parfor_REPs,
                            count_parfor_OneDs, count_array_OneDs, dist_IR_contains)


class TestML(unittest.TestCase):
    def test_logistic_regression(self):
        def test_impl(n, d):
            iterations = 3
            X = np.ones((n,d))+.5
            Y = np.ones(n)
            D = X.shape[1]
            w = np.ones(D)-0.5
            for i in range(iterations):
                w -= np.dot(((1.0 / (1.0 + np.exp(-Y * np.dot(X,w))) - 1.0) * Y), X)
            return w

        hpat_func = hpat.jit(test_impl)
        n = 11
        d = 4
        np.testing.assert_allclose(hpat_func(n, d), test_impl(n, d))
        self.assertEqual(count_array_OneDs(), 3)
        self.assertEqual(count_parfor_OneDs(), 3)

    def test_logistic_regression_acc(self):
        def test_impl(N, D):
            iterations = 3
            g = 2 * np.ones(D) - 1
            X = 2 * np.ones((N, D)) - 1
            Y = (np.dot(X, g) > 0.0) == (np.ones(N) > .90)

            w = 2 * np.ones(D) - 1
            for i in range(iterations):
                w -= np.dot(((1.0 / (1.0 + np.exp(-Y * np.dot(X, w))) - 1.0) * Y), X)
                #R = np.dot(X,w) > 0.0
                #accuracy = np.sum(R == Y) / N
            return w

        hpat_func = hpat.jit(test_impl)
        n = 11
        d = 4
        #np.testing.assert_allclose(hpat_func(n, d), test_impl(n, d))
        #self.assertEqual(count_array_OneDs(), 3)
        #self.assertEqual(count_parfor_OneDs(), 3)

    def test_linear_regression(self):
        def test_impl(N, D):
            p = 2
            iterations = 3
            X = np.ones((N, D)) + .5
            Y = np.ones((N, p))
            alphaN = 0.01 / N
            w = np.zeros((D, p))
            for i in range(iterations):
                w -= alphaN * np.dot(X.T, np.dot(X, w) - Y)
            return w

        hpat_func = hpat.jit(test_impl)
        n = 11
        d = 4
        np.testing.assert_allclose(hpat_func(n, d), test_impl(n, d))
        self.assertEqual(count_array_OneDs(), 5)
        self.assertEqual(count_parfor_OneDs(), 3)

if __name__ == "__main__":
    unittest.main()

@@ -2226,16 +2226,677 @@
 (), 3)%0A%0A
+    def test_kde(self):%0A        def test_impl(n):%0A            X = np.ones(n)%0A            b = 0.5%0A            points = np.array(%5B-1.0, 2.0, 5.0%5D)%0A            N = points.shape%5B0%5D%0A            exps = 0%0A            for i in hpat.prange(n):%0A                p = X%5Bi%5D%0A                d = (-(p - points)**2) / (2 * b**2)%0A                m = np.min(d)%0A                exps += m - np.log(b * N)+np.log(np.sum(np.exp(d - m)))%0A            return exps%0A%0A        hpat_func = hpat.jit(test_impl)%0A        n = 11%0A        np.testing.assert_approx_equal(hpat_func(n), test_impl(n))%0A        self.assertEqual(count_array_OneDs(), 1)%0A        self.assertEqual(count_parfor_OneDs(), 2)%0A%0A
 if __nam

test kde