Skip to content

Conversation

@OmarManzoor
Copy link
Contributor

@OmarManzoor OmarManzoor commented Nov 10, 2022

Reference Issues/PRs

Towards #24875

What does this implement/fix? Explain your changes.

  • Fix Use of the deprecated NumPy API (via Cython) (-Wcpp) warnings in sklearn.linear_model._sgd_fast

Any other comments?

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is just missing the casting to not compare signed and unsigned int.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@OmarManzoor
Copy link
Contributor Author

@jjerphan Should we cast the loop variables to int here as well instead of casting the max_iter?

Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this series of PR, @OmarManzoor!

Here are a few comments before approval.

* Used const with memory views in arguments that aren't expected to be modified

* Used memory view's base attribute to return the underlying numpy array

* Changed the type of epoch to int

* Removed some unused variables
Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM given that CI is green.

Thanks, @OmarManzoor!



cdef bint any_nonfinite(double *w, int n) nogil:
cdef bint any_nonfinite(const double *w, int n) nogil:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjerphan do you think that we should delay the use of const and only restrict to the memoryview when changing it? I know it is a good practice, but we have that many variables that are not defined as const (and pointers), I assume it would be best to have a dedicated PR for a specific function or file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes is necessary for removing the warning (i.e. not using the old NumPy API hence not using cnp.ndarray hence using memoryviews instead) while supporting readonly/memmaped data since the pointer references the buffer of a const-qualified memoryview. I do not think we can get our way around the modification here without casting const- to non-const-qualified variable.

But I agree generally and also think that we must not change signatures to add const-qualifier if they aren't required for removing compilation warnings.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes is necessary for removing the warning

OK I missed it. I thought it was introduced in the last commit. My bad.

@glemaitre glemaitre merged commit 81b7fd4 into scikit-learn:main Nov 15, 2022
@glemaitre
Copy link
Member

Merging then. Thanks @OmarManzoor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants