8000 MNT Use std math lib log1p instead of numpy log1p in cython inner loo… · scikit-learn/scikit-learn@07e909a · GitHub
[go: up one dir, main page]

Skip to content

Commit 07e909a

Browse files
amuellerqinhanmin2014
authored andcommitted
MNT Use std math lib log1p instead of numpy log1p in cython inner loops (#11848)
1 parent f6fd03e commit 07e909a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sklearn/neighbors/binary_tree.pxi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143

144144
cimport cython
145145
cimport numpy as np
146-
from libc.math cimport fabs, sqrt, exp, cos, pow, log
146+
from libc.math cimport fabs, sqrt, exp, cos, pow, log, log1p
147147
from libc.stdlib cimport calloc, malloc, free
148148
from libc.string cimport memcpy
149149
from sklearn.utils.lgamma cimport lgamma
@@ -486,7 +486,7 @@ cdef DTYPE_t _log_kernel_norm(DTYPE_t h, ITYPE_t d,
486486
elif kernel == EXPONENTIAL_KERNEL:
487487
factor = logSn(d - 1) + lgamma(d)
488488
elif kernel == LINEAR_KERNEL:
489-
factor = logVn(d) - np.log1p(d)
489+
factor = logVn(d) - log1p(d)
490490
elif kernel == COSINE_KERNEL:
491491
# this is derived from a chain rule integration
492492
factor = 0

sklearn/utils/_logistic_sigmoid.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#cython: cdivision=True
33
#cython: wraparound=False
44

5-
from libc.math cimport log, exp
5+
from libc.math cimport log1p, exp
66

77
import numpy as np
88
cimport numpy as np
@@ -13,9 +13,9 @@ ctypedef np.float64_t DTYPE_t
1313
cdef DTYPE_t _inner_log_logistic_sigmoid(DTYPE_t x):
1414
"""Log of the logistic sigmoid function log(1 / (1 + e ** -x))"""
1515
if x > 0:
16-
return -np.log1p(exp(-x))
16+
return -log1p(exp(-x))
1717
else:
18-
return x - np.log1p(exp(x))
18+
return x - log1p(exp(x))
1919

2020

2121
def _log_logistic_sigmoid(int n_samples, int n_features,

0 commit comments

Comments
 (0)
0