Skip to content

Conversation

@lkdvos
Copy link
Collaborator

@lkdvos lkdvos commented Feb 8, 2024

This PR adds some functions that were previously missing, such as circshift and indexin.

As a small note, for the implementation of indexin, for large tuples an implementation via a hash map would be more efficient $\mathcal{O}(N)$, but as this package focusses on small tuples, I choose to use a simple $\mathcal{O}(N^2)$ algorithm, which is non-allocating. (I think)

Also, it updates the codecov action, and Aqua tests to reflect the latest versions.
It also adds compat entries for the test dependencies.

@lkdvos
Copy link
Collaborator Author

lkdvos commented Feb 8, 2024

Also closes #18

@lkdvos lkdvos requested a review from Jutho February 9, 2024 14:12
"""
function indexin(a::Tuple, b::Tuple)
return ntuple(i -> findfirst(==(a[i]), b), length(a))
end
Copy link
Owner

Choose a reason for hiding this comment

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

I guess this one is not type stable, because findfirst can return nothing?

One possibility would be to explicitly error when elements are missing, but then it differs from the Base method and we should maybe name it differently.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, the Base method always returns a Vector{Union{Nothing,Int}}, and is therefore type stable. I checked the inferred type of this function, and it's still NTuple{N, Union{Nothing,Int}}, which might be fine as supposedly small type unions are ok.

Copy link
Owner

Choose a reason for hiding this comment

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

Sure. I just hope it doesn't lead to type instabilities further down in methods that use this, but I guess not.

@lkdvos lkdvos merged commit 75ac536 into master Feb 9, 2024
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