-
Notifications
You must be signed in to change notification settings - Fork 37
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
Array Interface Test Suite #331
Comments
I just registered this if you want to try it out. Structured interface tests with traits for free: https://github.com/rafaqz/Interfaces.jl Also let's you split an interface into components, e.g. making Theres an implementation of |
That's definitely interesting and there seems to be a consistent request for some way of guaranteeing that a new type provides valid support for an interface. Reading through the examples, it seems a lot more complex than just implementing a basic test suite composed of clearly documented functions. It would help if you could give an example of how this could be implemented for the multidimensional indices interface. |
@interface ArrayInterface (
mandatory = (
size = x -> length(x) == prod(size(x)),
indices = (
x -> length(eachindex(IndexLinear(), x)) == length(x),
x -> length(CartesianIndices(axes(x))) == length(x),
x -> map((l, c) -> x[l] == x[c], CartesianIndices(axes(x)), eachindex(IndexLinear(), x))
)
),
optional = (
setindex! = x -> false # need to write these...,
broadcast = x -> false,
)
) Then in a package julia> @implements ArrayInterface Array [zeros(10, 10)]
true And we have traits: julia> Interfaces.implements(ArrayInterface, Array)
true
julia> Interfaces.implements(ArrayInterface{:setindex!}, Array)
false Of course we just haven't written |
Pretty much any of this can be changed if you have better ideas, the point was to get something started quickly - and returning Edit: You can also organise that code however you like - the functions could be written separately. The macro doesn't do anything with the E.g: function test_array_indices(x)
lininds = eachindex(IndexLinear(), x)
carinds = CartesianIndices(axes(x))
for (li,ci) = zip(lininds,carinds)
@test x[li] == x[ci]
end
return length(lininds) == length(carinds) == length(x) == prod(size(x))
end
@interface ArrayInterface (mandatory=(indices=test_array_indices,), optional=()) I need to accept |
The examples are really helpful for understanding how to translate this. I'll make an issue with some more questions in the Interface.jl repo so this one can stay on topic for other comments about tests necessary for this to work. |
I've come across comments that it takes many months or years before a new array type is dependable because it takes time to catch all the corner cases and bugs. I think we should be able to get an array to be safely usable for common applications in a much shorter time. It might help if we put together a set of tests for common assumptions that an array should meet so that testing is easier. For example...
We could make that example a bit more verbose and inject some logging so that it's clear where errors come from.
We could also do similar things with stride-layout stuff.
The text was updated successfully, but these errors were encountered: