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

Implement getspace only for instances #993

Merged
merged 4 commits into from
Nov 24, 2019
Merged

Conversation

devmotion
Copy link
Member

@devmotion devmotion commented Nov 23, 2019

According to the Julia documentation, one should implement methods only for either instances or types, if possibly. This PR removes unneeded implementations of getspace for types.


@inline floatof(::Type{T}) where {T <: Real} = typeof(one(T)/one(T))
@inline floatof(::Type) = Real
Copy link
Member

@mohamed82008 mohamed82008 Nov 23, 2019

Choose a reason for hiding this comment

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

This method is needed for type unstable code and when type inference fails. The input to this comes from Core.Compiler.return_type which returns Any in some cases.

@mohamed82008
Copy link
Member

Thanks for the PR. Looks good to me, other than the one comment above.

@devmotion devmotion changed the title Implement getspace and floatof only for instances and types, respectively Implement getspace only for instances Nov 24, 2019
@inline floatof(::Type{T}) where {T <: Real} = typeof(one(T)/one(T))
@inline floatof(::Type) = Real
floatof(::Type{T}) where {T <: Real} = typeof(one(T)/one(T))
floatof(::Type{Any}) = Real # fallback if type inference failed
Copy link
Member

Choose a reason for hiding this comment

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

I would just get rid of Any here. For example, Core.Compiler.return_type can also return Union{} sometimes. Number may also not be impossible to get as input here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I somehow assumed it would always return Any if type inference fails.

Copy link
Member

@mohamed82008 mohamed82008 left a comment

Choose a reason for hiding this comment

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

LGTM

@devmotion
Copy link
Member Author

I don't see how the HMC reverse diff test error would be related to this PR.

@mohamed82008
Copy link
Member

Ya it's probably just a tolerance thing. Please increase the number of samples in that test and see if it passes.

@devmotion
Copy link
Member Author

devmotion commented Nov 24, 2019

Maybe we should just fix a seed? The test passes for all other OS and Julia versions. Probably that should be done for the distribution test that fails from time to time as well.

@yebai yebai merged commit 199ec33 into TuringLang:master Nov 24, 2019
@devmotion devmotion deleted the getspace branch November 24, 2019 21:00
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