Skip to content

Conversation

@zero323
Copy link
Member

@zero323 zero323 commented Oct 13, 2015

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
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
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
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
Member

Thanks for the PR!

@SparkQA
Copy link

SparkQA commented Oct 14, 2015

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
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