[go: up one dir, main page]

Skip to content
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

ENH Introduce dtype preservation semantics in DistanceMetric objects. #27006

Merged
merged 10 commits into from
Aug 10, 2023
Prev Previous commit
Next Next commit
Revert "Revert changes to {r}dist return type"
This reverts commit ee4faf4.
  • Loading branch information
Micky774 committed Aug 9, 2023
commit b79ebb0b1b3785d3c406759e8c861bfcad3d46ce
16 changes: 8 additions & 8 deletions sklearn/metrics/_dist_metrics.pxd.tp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ cdef inline float64_t euclidean_rdist{{name_suffix}}(
return d


cdef inline float64_t euclidean_dist_to_rdist{{name_suffix}}(const float64_t dist) except -1 nogil:
cdef inline float64_t euclidean_dist_to_rdist{{name_suffix}}(const {{INPUT_DTYPE_t}} dist) except -1 nogil:
return dist * dist


cdef inline float64_t euclidean_rdist_to_dist{{name_suffix}}(const float64_t dist) except -1 nogil:
cdef inline float64_t euclidean_rdist_to_dist{{name_suffix}}(const {{INPUT_DTYPE_t}} dist) except -1 nogil:
return sqrt(dist)


Expand All @@ -71,21 +71,21 @@ cdef class DistanceMetric{{name_suffix}}(DistanceMetric):
cdef object func
cdef object kwargs

cdef float64_t dist(
cdef {{INPUT_DTYPE_t}} dist(
self,
const {{INPUT_DTYPE_t}}* x1,
const {{INPUT_DTYPE_t}}* x2,
intp_t size,
) except -1 nogil

cdef float64_t rdist(
cdef {{INPUT_DTYPE_t}} rdist(
self,
const {{INPUT_DTYPE_t}}* x1,
const {{INPUT_DTYPE_t}}* x2,
intp_t size,
) except -1 nogil

cdef float64_t dist_csr(
cdef {{INPUT_DTYPE_t}} dist_csr(
self,
const {{INPUT_DTYPE_t}}* x1_data,
const int32_t* x1_indices,
Expand All @@ -98,7 +98,7 @@ cdef class DistanceMetric{{name_suffix}}(DistanceMetric):
const intp_t size,
) except -1 nogil

cdef float64_t rdist_csr(
cdef {{INPUT_DTYPE_t}} rdist_csr(
self,
const {{INPUT_DTYPE_t}}* x1_data,
const int32_t* x1_indices,
Expand Down Expand Up @@ -145,8 +145,8 @@ cdef class DistanceMetric{{name_suffix}}(DistanceMetric):
{{INPUT_DTYPE_t}}[:, ::1] D,
) except -1 nogil

cdef float64_t _rdist_to_dist(self, float64_t rdist) except -1 nogil
cdef {{INPUT_DTYPE_t}} _rdist_to_dist(self, {{INPUT_DTYPE_t}} rdist) except -1 nogil

cdef float64_t _dist_to_rdist(self, float64_t dist) except -1 nogil
cdef {{INPUT_DTYPE_t}} _dist_to_rdist(self, {{INPUT_DTYPE_t}} dist) except -1 nogil

{{endfor}}
Loading