Coverage for check_python_install/check_numba.py: 75%

12 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-05-10 06:54 +0200

1""" 

2@file 

3@brief Test for :epkg:`cartopy`. 

4""" 

5import numpy 

6import numba 

7 

8 

9@numba.jit(nopython=True, parallel=True) 

10def logistic_regression(Y, X, w, iterations): 

11 "Fits a logistic regression." 

12 for _ in range(iterations): 

13 w -= numpy.dot(((1.0 / (1.0 + numpy.exp(-Y * numpy.dot(X, w))) - 1.0) * Y), X) 

14 return w 

15 

16 

17def check_numba(): 

18 """ 

19 Runs a sample with :epkg:`numba`. 

20 """ 

21 Y = numpy.random.rand(10).astype(numpy.double) 

22 X = numpy.random.rand(10, 2).astype(numpy.double) 

23 w = numpy.random.rand(2).astype(numpy.double) 

24 return logistic_regression(Y, X, w, 2)