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

Remove some code duplication in bindings #416

Merged
merged 2 commits into from
Sep 20, 2022

Conversation

dyashuni
Copy link
Contributor

Introduced new functions get_input_array_shapes and get_input_ids_and_check_shapes to remove code duplication
Small refactoring: added spaces

@yurymalkov
Copy link
Member

Thanks! Proposed few cosmetic changes

Copy link
Member

@yurymalkov yurymalkov left a comment

Choose a reason for hiding this comment

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

Oops. Forgot to send the review

python_bindings/bindings.cpp Outdated Show resolved Hide resolved
python_bindings/bindings.cpp Outdated Show resolved Hide resolved
@@ -79,6 +79,45 @@ inline void assert_true(bool expr, const std::string & msg) {
}


inline void get_input_array_shapes(const py::buffer_info& buffer, size_t* rows, size_t* features) {
if (buffer.ndim != 2 && buffer.ndim != 1) throw std::runtime_error("data must be a 1d/2d array");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (buffer.ndim != 2 && buffer.ndim != 1) throw std::runtime_error("data must be a 1d/2d array");
if (buffer.ndim != 2 && buffer.ndim != 1) throw std::runtime_error("Input vector data wrong shape. Data must be a 1D or 2D array");

Copy link
Contributor Author

@dyashuni dyashuni Sep 19, 2022

Choose a reason for hiding this comment

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

I also added logging of actual number of dimensions in the error message

Copy link
Member

@yurymalkov yurymalkov left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@dyashuni dyashuni merged commit 4ab1d61 into nmslib:develop Sep 20, 2022
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.

2 participants