8000 [MRG+1] MNT Use std math lib log1p instead of np.log1p in cython inner loops by amueller · Pull Request #11848 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+1] MNT Use std math lib log1p instead of np.log1p in cython inner loops #11848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sklearn/neighbors/binary_tree.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

cimport cython
cimport numpy as np
from libc.math cimport fabs, sqrt, exp, cos, pow, log
from libc.math cimport fabs, sqrt, exp, cos, pow, log, log1p
from libc.stdlib cimport calloc, malloc, free
from libc.string cimport memcpy
from sklearn.utils.lgamma cimport lgamma
Expand Down Expand Up @@ -486,7 +486,7 @@ cdef DTYPE_t _log_kernel_norm(DTYPE_t h, ITYPE_t d,
elif kernel == EXPONENTIAL_KERNEL:
factor = logSn(d - 1) + lgamma(d)
elif kernel == LINEAR_KERNEL:
factor = logVn(d) - np.log1p(d)
factor = logVn(d) - log1p(d)
elif kernel == COSINE_KERNEL:
# this is derived from a chain rule integration
factor = 0
Expand Down
6 changes: 3 additions & 3 deletions sklearn/utils/_logistic_sigmoid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#cython: cdivision=True
#cython: wraparound=False

from libc.math cimport log, exp
from libc.math cimport log1p, exp

import numpy as np
cimport numpy as np
Expand All @@ -13,9 +13,9 @@ ctypedef np.float64_t DTYPE_t
cdef DTYPE_t _inner_log_logistic_sigmoid(DTYPE_t x):
"""Log of the logistic sigmoid function log(1 / (1 + e ** -x))"""
if x > 0:
return -np.log1p(exp(-x))
return -log1p(exp(-x))
else:
return x - np.log1p(exp(x))
return x - log1p(exp(x))


def _log_logistic_sigmoid(int n_samples, int n_features,
Expand Down
0