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

Type stability for GPs #155

Closed
kaandocal opened this issue May 30, 2021 · 6 comments
Closed

Type stability for GPs #155

kaandocal opened this issue May 30, 2021 · 6 comments

Comments

@kaandocal
Copy link

kaandocal commented May 30, 2021

It seems like AbstractGPs is not always type stable in the way we'd expect when calling posterior:

using AbstractGPs

gp = GP(Matern32Kernel())

X1 = ColVecs(rand(1, 10))
Y1 = rand(10) 

gp_post = posterior(gp(X1, 0.01), Y1)

X2 = ColVecs(rand(1, 10))
Y2 = rand(10)

typeof(posterior(gp_post(X2, 0.01), Y2)) == typeof(gp_post) # returns false
@devmotion
Copy link
Member

Shouldn't you use

typeof​(​posterior​(​gp​(X2, ​0.01​), Y2))

in your comparison?

BTW your comparison doesn't guarantee type stability, you would want to check if the type can be inferred correctly. This can be done e.g. with @code_warntype and @inferred.

@kaandocal
Copy link
Author

My fault, I forgot the second typeof (the result doesn't change however). Just to clarify, by type stability I meant that adding more observations to a GP changes its type in this case!

@devmotion
Copy link
Member

I can't check it right now but I assume that the problem is a missing vcat definition for ColVecs, so the type changes when concatenating X1 and X2. Does it work with regular vectors for X1 and X2?

@kaandocal
Copy link
Author

That is indeed the problem! For 1-dimensional vectors X1 and X2 it works. I'll create a PR in KernelFunctions.jl.

@willtebbutt
Copy link
Member

@kaandocal is this now resolved as #291 is merged?

@devmotion
Copy link
Member

I'll take that as a yes 🙂

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

No branches or pull requests

3 participants