-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -760,6 +760,35 @@ end | |
@test quadgk(cos, 0,0.7,1, norm=abs)[1] ≈ sin(1) | ||
end | ||
|
||
module Test19626 | ||
using Base.Test | ||
|
||
# Define a mock physical quantity type | ||
immutable MockQuantity{T} <: Number | ||
val::T | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
# Following definitions needed for quadgk to work with MockQuantity | ||
import Base: +, -, *, abs, isnan, isinf, isless | ||
+(a::MockQuantity, b::MockQuantity) = MockQuantity(a.val+b.val) | ||
-(a::MockQuantity, b::MockQuantity) = MockQuantity(a.val-b.val) | ||
*(a::MockQuantity, b::Number) = MockQuantity(a.val*b) | ||
abs(a::MockQuantity) = MockQuantity(abs(a.val)) | ||
isnan(a::MockQuantity) = isnan(a.val) | ||
isinf(a::MockQuantity) = isinf(a.val) | ||
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) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just pass |
||
error("Dimensions issue") | ||
|
||
# isapprox only needed for test purposes | ||
Base.isapprox(a::MockQuantity, b::MockQuantity) = isapprox(a.val, b.val) | ||
|
||
# Test physical quantity-valued functions | ||
@test quadgk(x->MockQuantity(x), 0.0, 1.0)[1] ≈ MockQuantity(0.5) | ||
end | ||
|
||
@testset "subnormal flags" begin | ||
# Ensure subnormal flags functions don't segfault | ||
@test any(set_zero_subnormals(true) .== [false,true]) | ||
|
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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 invecnorm
.