Skip to content

Fix Independent MOKernel for single dimension input #144

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

Merged
merged 4 commits into from
Aug 2, 2020

Conversation

sharanry
Copy link
Contributor

@sharanry sharanry commented Aug 1, 2020

Fails for

N = 100
x = rand(Uniform(-1, 1), N)
X = MOInput(x, 2)
k = IndependentMOKernel(MaternKernel())
k(X, X) #error

Fails for 
```julia
N = 100
x = rand(Uniform(-1, 1), N)
X = MOInput(x, 2)
k = IndependentMOKernel(MaternKernel())
k(X, X) #error
```
@theogf
Copy link
Member

theogf commented Aug 1, 2020

Nice catch! Could you also add a test for this?

@sharanry
Copy link
Contributor Author

sharanry commented Aug 1, 2020

@theogf Is this fine?

@theogf
Copy link
Member

theogf commented Aug 1, 2020

Looks good! You can use @test_nothrow instead of checking for a matrix type

@devmotion
Copy link
Member

You can use @test_nothrow instead of checking for a matrix type

Is this a custom thing we define in KernelFunctions? I have never seen it in Base 🤔 IMO you could just remove @test_nothrow - if the call errors, the tests fail anyways.

@sharanry
Copy link
Contributor Author

sharanry commented Aug 1, 2020

You can use @test_nothrow instead of checking for a matrix type

Is this a custom thing we define in KernelFunctions? I have never seen it in Base thinking IMO you could just remove @test_nothrow - if the call errors, the tests fail anyways.

I think @test_nothrows helps by catching the error and letting the other tests after it run irrespective of whether the error occurs.

Edit: There is no such thing as @test_nothrow 😅

@theogf
Copy link
Member

theogf commented Aug 1, 2020

I am sorry! I am at the beach so i did not double check 😅. I meant @test_nowarn

@sharanry sharanry merged commit 937169e into master Aug 2, 2020
@willtebbutt
Copy link
Member

Wait, @sharanry could you explain to me why this is failing? I'm unclear why the previous implementation is incorrect 😬 .

In particular, why is the solution you've implemented the correct one?

@sharanry
Copy link
Contributor Author

sharanry commented Aug 2, 2020

Previously, (κ::IndependentMOKernel) worked with only inputs of the type Tuple{Vector, Int}. However, when working with 1-dim inputs, we might end up with Tuple{<:Real, Int} which wouldn't have been accepted by the old implementation.

@willtebbutt
Copy link
Member

Oh, I see. Would the following not be sufficient:

function (k::IndependentMOKernel)(x::Tuple{Any, Int}, y::Tuple{Any, Int})
    if last(x) == last(y)
        return k.kernel(first(x), first(y))
    else
        return appropriate_zero
    end
end

i.e. I'm not sure that we need two methods, or to assume that the wrapped kernel requires vector inputs.

@sharanry
Copy link
Contributor Author

sharanry commented Aug 2, 2020

That should be sufficient. However, we wouldn't have any checks for the first element of the tuple as you point out. I like it as it is definitely a less constrained way.

Shall I start a new PR for this?

@willtebbutt
Copy link
Member

That should be sufficient. However, we wouldn't have any checks for the first element of the tuple as you point out. I like it as it is definitely a less constrained way.

Do we need a check on the type of the first element of the tuples? Can they not generally be anything?

Shall I start a new PR for this?

That would be good -- better to address this sooner rather than later :)

@sharanry
Copy link
Contributor Author

sharanry commented Aug 2, 2020

Do we need a check on the type of the first element of the tuples? Can they not generally be anything?

I guess not. This is should make the kernels more flexible. For other non-multi-output kernels we do not really perform any check for the inputs.

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