Skip to content

MAINT Use float64 for accumulators in WeightVector* #25721

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 4 commits into from
Feb 28, 2023
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
9 changes: 5 additions & 4 deletions sklearn/utils/_weight_vector.pxd.tp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ cdef class WeightVector{{name_suffix}}(object):
cdef readonly {{c_type}}[::1] aw
cdef {{c_type}} *w_data_ptr
cdef {{c_type}} *aw_data_ptr
cdef {{c_type}} wscale
cdef {{c_type}} average_a
cdef {{c_type}} average_b

cdef double wscale
cdef double average_a
cdef double average_b
cdef int n_features
cdef {{c_type}} sq_norm
cdef double sq_norm

cdef void add(self, {{c_type}} *x_data_ptr, int *x_ind_ptr,
int xnnz, {{c_type}} c) noexcept nogil
Expand Down
16 changes: 8 additions & 8 deletions sklearn/utils/_weight_vector.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ cdef class WeightVector{{name_suffix}}(object):
"""
cdef int j
cdef int idx
cdef {{c_type}} val
cdef {{c_type}} innerprod = 0.0
cdef {{c_type}} xsqnorm = 0.0
cdef double val
cdef double innerprod = 0.0
cdef double xsqnorm = 0.0

# the next two lines save a factor of 2!
cdef {{c_type}} wscale = self.wscale
Expand Down Expand Up @@ -137,10 +137,10 @@ cdef class WeightVector{{name_suffix}}(object):
"""
cdef int j
cdef int idx
cdef {{c_type}} val
cdef {{c_type}} mu = 1.0 / num_iter
cdef {{c_type}} average_a = self.average_a
cdef {{c_type}} wscale = self.wscale
cdef double val
cdef double mu = 1.0 / num_iter
cdef double average_a = self.average_a
cdef double wscale = self.wscale
cdef {{c_type}}* aw_data_ptr = self.aw_data_ptr

for j in range(xnnz):
Expand Down Expand Up @@ -174,7 +174,7 @@ cdef class WeightVector{{name_suffix}}(object):
"""
cdef int j
cdef int idx
cdef {{c_type}} innerprod = 0.0
cdef double innerprod = 0.0
cdef {{c_type}}* w_data_ptr = self.w_data_ptr
for j in range(xnnz):
idx = x_ind_ptr[j]
Expand Down