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 some more interfaces to BaseInterfaces.jl #27

Merged
merged 21 commits into from
Nov 1, 2023
Merged

Conversation

rafaqz
Copy link
Owner

@rafaqz rafaqz commented Oct 14, 2023

This PR adds the start of AbstractSet, AbstractDict, and AbstractArray to BaseInterfaces.jl

Hopefully this will end with interface tests that help people write interfaces for these base types and
know they are correct and complete.

@gdalle thoughts or contributions to the cause would be appreciated!

@codecov-commenter
Copy link

codecov-commenter commented Oct 14, 2023

Codecov Report

Merging #27 (fee8bb5) into main (b23bfa5) will decrease coverage by 3.82%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##             main      #27      +/-   ##
==========================================
- Coverage   86.20%   82.38%   -3.82%     
==========================================
  Files           5        5              
  Lines         145      159      +14     
==========================================
+ Hits          125      131       +6     
- Misses         20       28       +8     
Files Coverage Δ
src/implements.jl 72.72% <50.00%> (-2.28%) ⬇️
src/test.jl 82.60% <75.86%> (-4.77%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@rafaqz rafaqz changed the title add some more interfaces add some more interfaces to BaseInterfaces.jl Oct 15, 2023
@gdalle
Copy link
Collaborator

gdalle commented Oct 15, 2023

Wow, large effort! I'll try to review it in the coming days. Just wondering, did you check out other initiatives like https://github.com/JuliaArrays/ArrayInterface.jl?

@rafaqz
Copy link
Owner Author

rafaqz commented Oct 15, 2023

Yeah, I've been following ArrayInterface for some years.

But ArrayInterface.jl really isn't the same as the base AbstractArray interface. As the docs say:

The purpose of this library is to solidify extensions to the current AbstractArray interface

(emphasis mine)

The idea in BaseInterfaces.jl is just to have a simple definitions of Base Julia interfaces as far as they are documented, or as used in Base where they are not documented. Its a test of Interfaces.jl capacity to represent a range of interfaces, and should be useful for people extending theses interfaces to have a predefined test suit for them. I'm not sure that the @implements declarations will actually be used or useful, but that's ok.

Of course, there will be some overlap in terms of traits as ArrayInterface.jl does include some traits for simple base interface things as well.

@gdalle
Copy link
Collaborator

gdalle commented Oct 26, 2023

Feel free to ping me when this is more or less ready for review!

@rafaqz
Copy link
Owner Author

rafaqz commented Oct 26, 2023

Any time really, feedback would be good. It will be a work in progress untul we register, so we can merge PRs as we go.

@gdalle
Copy link
Collaborator

gdalle commented Oct 26, 2023

Okay cool, I'll try to take a look

Copy link

@Seelengrab Seelengrab left a comment

Choose a reason for hiding this comment

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

Just some quick things I noticed :)

A -> A[begin] isa eltype(A),
A -> A[map(first, axes(A))...] isa eltype(A),
),
indexstyle = A -> IndexStyle(A) in (IndexCartesian(), IndexLinear()),

Choose a reason for hiding this comment

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

This isn't mandatory - there is a default for this.

Copy link
Owner Author

@rafaqz rafaqz Oct 31, 2023

Choose a reason for hiding this comment

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

So it will still always work? Its just saying its mandatory that it returns one of those options.

BaseInterfaces/src/array.jl Show resolved Hide resolved
BaseInterfaces/src/array.jl Show resolved Hide resolved
BaseInterfaces/src/dict.jl Show resolved Hide resolved
BaseInterfaces/src/set.jl Outdated Show resolved Hide resolved
s1 = Base.copymutable(s)
s1 isa typeof(s) && s1 !== s
end,
# TODO is there anything we can actually test here?

Choose a reason for hiding this comment

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

Unfortunately not, since there is no capacity function in Base :/

Copy link
Owner Author

Choose a reason for hiding this comment

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

Its so weird that the hint just disappears and we cant access it.

Choose a reason for hiding this comment

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

Well it's just a hint/suggestion, not a requirement 🤷

BaseInterfaces/src/set.jl Outdated Show resolved Hide resolved
BaseInterfaces/src/set.jl Outdated Show resolved Hide resolved
BaseInterfaces/src/set.jl Outdated Show resolved Hide resolved
A -> eltype(A) isa Type,
A -> eltype(A) == _eltype(A),
),
ndims = (

Choose a reason for hiding this comment

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

This should have a fallback definition already, no? IIRC ndims comes from having size defined already.

Copy link
Owner Author

@rafaqz rafaqz Oct 31, 2023

Choose a reason for hiding this comment

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

Doesnt it use the second type parameter of AbstractArray?

I just wanted to check that was not messed up in the implementation of a custom type. Maybe not totally useful

Choose a reason for hiding this comment

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

True, but that's not an issue because you have to declare where in a subtype the second parameter of a parent type goes. E.g. it doesn't matter that I can swap the parameters around in my definition:

julia> struct MyArr{N,T} <: AbstractArray{T,N} end

julia> ndims(MyArr{2,Int})
2

Copy link
Collaborator

@gdalle gdalle left a comment

Choose a reason for hiding this comment

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

I see that @Seelengrab has reviewed the array, dict and set interfaces, so I'll submit my review on everything except those three files for now

@@ -0,0 +1,12 @@
# BaseInterfaces reference
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a failed .md file

BaseInterfaces/README.md Outdated Show resolved Hide resolved
BaseInterfaces/src/BaseInterfaces.jl Outdated Show resolved Hide resolved
BaseInterfaces/src/iteration.jl Outdated Show resolved Hide resolved
BaseInterfaces/src/iteration.jl Outdated Show resolved Hide resolved
BaseInterfaces/test/runtests.jl Show resolved Hide resolved
BaseInterfaces/test/runtests.jl Outdated Show resolved Hide resolved
@test Interfaces.test(ArrayInterface, Base.Slice, [Base.Slice(100:150)])
@test Interfaces.test(ArrayInterface, Base.IdentityUnitRange, [Base.IdentityUnitRange(100:150)])
@test Interfaces.test(ArrayInterface, Base.CodeUnits, [codeunits("abcde")])
# No `getindex` defined for LogicalIndex
Copy link
Collaborator

Choose a reason for hiding this comment

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

This method will also fail for GPU arrays. Maybe it should be an optional part of the interface?

Copy link
Owner Author

Choose a reason for hiding this comment

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

It only fails with e.g. CUDA.allowscalar(true) on GPU. So thst would need to be false.

The docs really specificially say its one of the main mandatory methods, I kinda want the failed test there to demonstrate the problem...

BaseInterfaces/test/runtests.jl Show resolved Hide resolved
BaseInterfaces/test/runtests.jl Outdated Show resolved Hide resolved
@rafaqz
Copy link
Owner Author

rafaqz commented Nov 1, 2023

Thanks for the feedback, I've implemented most of these and a bunch more. Also fixed up testing and display a lot and accidentally merged it here! But will merge as-is anyway and more can be added in another PR.

@rafaqz rafaqz merged commit bd13c15 into main Nov 1, 2023
7 checks passed
@rafaqz rafaqz deleted the more_interfaces branch November 1, 2023 13:35
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.

4 participants