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

Add support for callable metrics #94

Merged
merged 16 commits into from Sep 3, 2019

Conversation

jgraving
Copy link
Contributor

@jgraving jgraving commented Sep 2, 2019

Issue

See #93

Description of changes

Added the option for callable metrics to the openTSNE.nearest_neighbors module. NNDescent checks if metric is compiled with numba, gives an informative warning, and then attempts to automatically compile it. If the function is already compiled or NNDescent is not being used then the callable is passed without any further checks. Docstrings have also been updated to match other docstrings with multiple types. If you'd like unit tests for this, then please provide guidance on how best to do this.

Includes
  • Code changes
  • Tests
  • Documentation

@pavlin-policar
Copy link
Owner

Thanks for the PR. I am missing tests, so we verify that regular python functions properly get compiled to numba code and a test with already numba compiled code.

Also, as mentioned in #93, it would be great if we could keep things consistent, and that you would add callable support to the BallTree as well.

@jgraving
Copy link
Contributor Author

jgraving commented Sep 3, 2019

I'll try adding tests, but I'm not very familiar and may need some guidance. BallTree doesn't overwrite the openTSNE.nearest_neighbors.KNNIndex.check_metric method, so support for callable metrics is already there.

@jgraving
Copy link
Contributor Author

jgraving commented Sep 3, 2019

Tests are added and passing. Let me know if you want me to add something more.

Copy link
Owner

@pavlin-policar pavlin-policar left a comment

Choose a reason for hiding this comment

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

Thanks, looks good! I've got a couple nitpicks about the empty lines, to keep the formatting and style consistent across the codebase, but otherwise looks good. Please fix these couple cosmetic changes.

openTSNE/nearest_neighbors.py Outdated Show resolved Hide resolved
tests/test_nearest_neighbors.py Outdated Show resolved Hide resolved
tests/test_nearest_neighbors.py Outdated Show resolved Hide resolved
tests/test_nearest_neighbors.py Outdated Show resolved Hide resolved
tests/test_nearest_neighbors.py Outdated Show resolved Hide resolved
@jgraving
Copy link
Contributor Author

jgraving commented Sep 3, 2019

Should be good to go! Style errors are taken care of. I need to find a better linter. Have you seen black? https://black.readthedocs.io/en/stable/index.html I've been thinking about using it for my projects.

@pavlin-policar
Copy link
Owner

Awesome, looks great!

Have you seen black?

Yes, I'm a fan of black. Most of the code in openTSNE is compliant with its style guide, with the exception of cython files and the main tsne.py. The only reason I haven't implemented it fully is that it would introduce a whole lot more line breaks, which would IMO be less readable in this case. Otherwise, I try to use it wherever I can in my other projects.

@pavlin-policar pavlin-policar merged commit 1f14f54 into pavlin-policar:master Sep 3, 2019
pavlin-policar added a commit that referenced this pull request Sep 3, 2019
@pavlin-policar
Copy link
Owner

I forgot to squash your commits before merging, so I had to go through some git-gymnastics to get everything down to one coherent commit. That's why there's another commit in the history here. I didn't want to bother you with this, but next time, it's better that you squash your commits into a single one with a descriptive commit message, or do an interactive rebase to organize your commits. I've taken care of it now, though. Thanks for your contribution 😄

@jgraving
Copy link
Contributor Author

jgraving commented Sep 3, 2019

Ah, sorry about that. I'll keep that in mind for next time. No problem! Glad I could help 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants