Skip to content

Commit

Permalink
Add fallback for pretty_print (#244)
Browse files Browse the repository at this point in the history
* Add fallback for pretty_print

Fixes #233

* Fix a test

* Bump patch version

* Remove testing Julia 1.2 and 1.3, and add  Julia 1.4
  • Loading branch information
lbenet authored May 22, 2020
1 parent 22781aa commit 48b427d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ os:

julia:
- 1.0
- 1.2
- 1.3
- 1.4
- nightly

notifications:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TaylorSeries"
uuid = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
repo = "https://github.com/JuliaDiff/TaylorSeries.jl.git"
version = "0.10.4"
version = "0.10.5"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand Down
24 changes: 24 additions & 0 deletions src/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ function superscriptify(n::Int)
end


# Fallback
function pretty_print(a::Taylor1)
# z = zero(a[0])
var = _params_Taylor1_.var_name
space = string(" ")
bigO = bigOnotation[end] ?
string("+ 𝒪(", var, superscriptify(a.order+1), ")") :
string("")
# iszero(a) && return string(space, z, space, bigO)
strout::String = space
ifirst = true
for i in eachindex(a)
monom::String = i==0 ? string("") : i==1 ? string(" ", var) :
string(" ", var, superscriptify(i))
@inbounds c = a[i]
# c == z && continue
cadena = numbr2str(c, ifirst)
strout = string(strout, cadena, monom, space)
ifirst = false
end
strout = strout * bigO
strout
end

function pretty_print(a::Taylor1{T}) where {T<:NumberNotSeries}
z = zero(a[0])
var = _params_Taylor1_.var_name
Expand Down
12 changes: 11 additions & 1 deletion test/onevariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ using TaylorSeries

using Test
using LinearAlgebra, SparseArrays
eeuler = Base.MathConstants.e
const eeuler = Base.MathConstants.e

# This is used to check the fallack of pretty_print
struct SymbNumber <: Number
s :: Symbol
end
Base.iszero(::SymbNumber) = false

@testset "Tests for Taylor1 expansions" begin
ta(a) = Taylor1([a,one(a)],15)
Expand Down Expand Up @@ -521,6 +527,10 @@ eeuler = Base.MathConstants.e
@test Taylor1{Float64}(false) == Taylor1([0.0])
@test Taylor1{Int}(true) == Taylor1([1])
@test Taylor1{Int}(false) == Taylor1([0])

# Test fallback pretty_print
st = Taylor1([SymbNumber(:x₀), SymbNumber(:x₁)])
@test string(st) == " SymbNumber(:x₀) + SymbNumber(:x₁) t + 𝒪(t²)"
end

@testset "Test `inv` for `Matrix{Taylor1{Float64}}``" begin
Expand Down

2 comments on commit 48b427d

@lbenet
Copy link
Member Author

@lbenet lbenet commented on 48b427d May 22, 2020

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/15183

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 v0.10.5 -m "<description of version>" 48b427d99291e9f2e845c4b6583501313d23268d
git push origin v0.10.5

Please sign in to comment.