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

Remove a type restriction in Base.QuadGK.Segment (#19626) #19627

Merged
merged 4 commits into from
Dec 23, 2016

Conversation

ajkeller34
Copy link
Contributor

See #19626

@tkelman
Copy link
Contributor

tkelman commented Dec 16, 2016

is what you're trying to accomplish testable without needing the rest of Unitful.jl? there are some tests for quadgk in test/math..jl

@ajkeller34
Copy link
Contributor Author

I have an idea for how to do this; will get back to you once implemented.

@kshyatt kshyatt added the domain:maths Mathematical functions label Dec 16, 2016
@ajkeller34
Copy link
Contributor Author

I added some tests. If you're wondering why I used a module instead of putting my additions into the quadgk test set, it is because I was running into some namespace issue that caused the tests to fail. I put my new definitions and tests into a module like done here and the tests pass now.


# Necessary with infinite or semi-infinite intervals since !(MockQuantity <: Real)
# and do_quadgk tests if eltype(s) <: Real.
function _do_quadgk{Tw,T<:Real}(f, s::Array{MockQuantity{T},1}, n, ::Type{Tw},
Copy link
Member

Choose a reason for hiding this comment

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

This seems overly complicated. For testing this PR, it should be sufficient to have an f(x) where the integrand f is a MockQuantity, but x is still Float64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I became overexuberant thinking about how I would do this in Unitful.

Base.promote_rule{T,S}(::Type{MockQuantity{T}}, ::Type{MockQuantity{S}}) =
MockQuantity{promote_type(T,S)}
Base.convert{T}(::Type{MockQuantity{T}}, x::MockQuantity) = MockQuantity(T(x.val))

Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need to define promotion rules and conversion for a minimal working example. Just define the minimum number of methods necessary for a test.

using Base.Test
# Begin tests for 19626: Unitful compatibility.
# Define a mock physical quantity type
immutable MockQuantity{T} <: Number
Copy link
Member

Choose a reason for hiding this comment

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

It seems like it should work now even if it is not a subtype of Number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it is not a subtype of Number then I get a failure in vecnorm.

@ajkeller34
Copy link
Contributor Author

I think I have the minimum number of definitions needed to get the test working now. Happy to implement further changes.

isless(a::MockQuantity, b::MockQuantity) = isless(a.val, b.val)

# isless defn. necessary so that default abstol plays nicely with MockQuantity
isless(y::Number, x::MockQuantity) = y == 0 ? isless(MockQuantity(0), x) :
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 pass abstol = MockQuantity(0.0)


# Define a mock physical quantity type
immutable MockQuantity{T} <: Number
val::T
Copy link
Member

Choose a reason for hiding this comment

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

Is the <: Number necessary? I wouldn't bother parameterizing the type. Just make val::Float64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

<: Number is necessary, otherwise I get an error from vecnorm.

@ajkeller34
Copy link
Contributor Author

<: Number is necessary, otherwise I get an error from vecnorm. I have implemented the other changes.

@stevengj stevengj merged commit c428a5f into JuliaLang:master Dec 23, 2016
@ajkeller34 ajkeller34 deleted the quadgk branch December 31, 2016 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants