Skip to content

[SPARK-11084][ML][PYTHON] Check if index can contain non-zero value before binary search#9098

Closed
zero323 wants to merge 1 commit into
apache:masterfrom
zero323:sparse_vector_getitem_improved
Closed

[SPARK-11084][ML][PYTHON] Check if index can contain non-zero value before binary search#9098
zero323 wants to merge 1 commit into
apache:masterfrom
zero323:sparse_vector_getitem_improved

Conversation

@zero323

@zero323 zero323 commented Oct 13, 2015

Copy link
Copy Markdown
Member

At this moment SparseVector.__getitem__ executes np.searchsorted first and checks if result is in an expected range after that. It is possible to check if index can contain non-zero value before executing np.searchsorted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Curious: Is inds.item(-1) faster than inds[-1]? I wasn't sure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

By itself it is slower than using __getitem__ but it returns standard Python scalar and overall it should be marginally faster when index is a standard scalar as well.

If you think that inds[-1] is better it shouldn't really matter. With crude tests I get ~40 ns difference on average (245 ns for [] and, 205 ns for inds)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good, I'd keep what you have.

@jkbradley

Copy link
Copy Markdown
Member

Thanks for the PR!

@SparkQA

SparkQA commented Oct 14, 2015

Copy link
Copy Markdown

Test build #1900 has finished for PR 9098 at commit 7f1e455.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@jkbradley

Copy link
Copy Markdown
Member

LGTM
Merging with master
Thank you!

@asfgit asfgit closed this in 8ac71d6 Oct 16, 2015
@zero323 zero323 deleted the sparse_vector_getitem_improved branch April 6, 2017 11:03
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.

3 participants