Skip to content

Commit

Permalink
new constructorof; rework plot recipe (#376)
Browse files Browse the repository at this point in the history
* new constructor; rework plot recipe

* make test support v1
  • Loading branch information
jverzani authored Dec 29, 2021
1 parent 687d788 commit cda63bd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Polynomials"
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
license = "MIT"
author = "JuliaMath"
version = "2.0.20"
version = "2.0.21"

[deps]
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
Expand Down
9 changes: 6 additions & 3 deletions src/contrib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ end
## trick from [ConstructionBase.jl](https://github.com/JuliaObjects/ConstructionBase.jl/blob/b5686b755bd3bee29b181b3cb18fe2effa0f10a2/src/ConstructionBase.jl#L25)
## as noted in https://discourse.julialang.org/t/get-new-type-with-different-parameter/37253/4
##
@generated function constructorof(::Type{T}) where T
getfield(parentmodule(T), nameof(T))
end
#@generated function constructorof(::Type{T}) where T
# getfield(parentmodule(T), nameof(T))
#end

# https://discourse.julialang.org/t/how-do-a-i-get-a-type-stripped-of-parameters/73465/11
constructorof(::Type{T}) where T = Base.typename(T).wrapper
10 changes: 8 additions & 2 deletions src/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ end

poly_label(p::AbstractPolynomial) = sprint(printpoly, p)

@recipe function f(p::AbstractPolynomial, x = poly_interval(p))
#@recipe function f(p::AbstractPolynomial, x = poly_interval(p))
# label --> poly_label(p)
# x, p.(x)
#end

@recipe function f(p::AbstractPolynomial)
label --> poly_label(p)
x, p.(x)
xlims --> extrema(poly_interval(p))
x -> p(x)
end

@recipe function f(p::AbstractPolynomial, a, b)
Expand Down
17 changes: 7 additions & 10 deletions test/StandardBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1376,21 +1376,18 @@ end

@testset "Plotting" begin
p = fromroots([-1, 1]) # x^2 - 1
r = -1.4:0.055999999999999994:1.4
rec = apply_recipe(Dict{Symbol,Any}(), p)
@test getfield(rec[1], 1) == Dict{Symbol,Any}(:label => "-1 + x^2")
@test rec[1].args == (r, p.(r))
@test rec[1].plotattributes[:label] == "-1 + x^2"
@test rec[1].plotattributes[:xlims] == (-1.4, 1.4)


r = -1:0.02:1
rec = apply_recipe(Dict{Symbol,Any}(), p, -1, 1)
@test getfield(rec[1], 1) == Dict{Symbol,Any}(:label => "-1 + x^2")
@test rec[1].args == (r, p.(r))
@test rec[1].plotattributes[:label] == "-1 + x^2"

p = ChebyshevT([1,1,1])
rec = apply_recipe(Dict{Symbol,Any}(), p)
r = -1.0:0.02:1.0 # uses domain(p)
@test rec[1].args == (r, p.(r))

@test match(r"T_0", rec[1].plotattributes[:label]) !== nothing
@test rec[1].plotattributes[:xlims] == (-1.0, 1.0) # uses domain(p)
end

@testset "Promotion" begin
Expand Down Expand Up @@ -1458,7 +1455,7 @@ end
end
end

using MutableArithmetics
import MutableArithmetics
const MA = MutableArithmetics

function alloc_test(f, n)
Expand Down

2 comments on commit cda63bd

@jverzani
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/51388

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.21 -m "<description of version>" cda63bdb585c12231bb1280ce0629f7ce325fd99
git push origin v2.0.21

Please sign in to comment.