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

[WIP] Update for Julia 0.7 and 1.0 #96

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: julia
os:
- linux
julia:
- 0.5
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.5
julia 0.7
Copy link
Author

Choose a reason for hiding this comment

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

Is it fine to drop both Julia 0.5 and 0.6 support on master? Otherwise some compatibility additions are needed.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, absolutely!

Gtk
GtkReactive 0.0.3
Cairo 0.5.1
Expand Down
16 changes: 8 additions & 8 deletions src/ProfileView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ using .PVTree

include("svgwriter.jl")

immutable TagData
struct TagData
ip::UInt
status::Int
end
const TAGNONE = TagData(UInt(0), -1)

type ProfileData
mutable struct ProfileData
img
lidict
imgtags
Expand All @@ -33,11 +33,11 @@ const gccolor = colorant"red"
const colors = distinguishable_colors(13, [bkg,fontcolor,gccolor],
lchoices=Float64[65, 70, 75, 80],
cchoices=Float64[0, 50, 60, 70],
hchoices=linspace(0, 330, 24))[4:end]
hchoices=range(0, stop=330, length=24))[4:end]

function have_display()
!is_unix() && return true
is_apple() && return true
!Sys.isunix() && return true
Sys.isapple() && return true
return haskey(ENV, "DISPLAY")
end

Expand All @@ -53,12 +53,12 @@ function __init__()
@eval begin
view(data = Profile.fetch(); C = false, lidict = nothing, colorgc = true, fontsize = 12, combine = true, pruned = []) = ProfileViewGtk.view(data; C=C, lidict=lidict, colorgc=colorgc, fontsize=fontsize, combine=combine, pruned=pruned)

closeall() = ProfileViewGtk.closeall()
@doc """
closeall()

Closes all windows opened by ProfileView.
""" -> closeall
"""
closeall() = ProfileViewGtk.closeall()
end
end
pop!(LOAD_PATH)
Expand Down Expand Up @@ -105,7 +105,7 @@ function prepare_data(data, lidict)
bt, uip, counts, lidict, lkup
end

prepare_data(::Void, ::Void) = nothing, nothing, nothing, nothing, nothing
prepare_data(::Nothing, ::Nothing) = nothing, nothing, nothing, nothing, nothing

function prepare_image(bt, uip, counts, lidict, lkup, C, colorgc, combine,
pruned)
Expand Down
2 changes: 1 addition & 1 deletion src/ProfileViewGtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using Graphics

using Gtk.GConstants.GdkModifierType: SHIFT, CONTROL, MOD1

type ZoomCanvas
mutable struct ZoomCanvas
bb::BoundingBox # in user-coordinates
c::Canvas
end
Expand Down
2 changes: 1 addition & 1 deletion src/pvtree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using ..Tree
export PVData, buildgraph!, prunegraph!

# ProfileView data we need attached to each node of the graph:
type PVData
mutable struct PVData
ip::UInt # the instruction pointer
hspan::UnitRange{Int} # horizontal span (used as the x-axis in display)
status::Int # nonzero for special handling, (e.g., gc events)
Expand Down
23 changes: 12 additions & 11 deletions src/tree.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Tree

import Base: start, done, next, show
import Base: iterate, show

export Node,
addchild,
Expand All @@ -16,30 +16,30 @@ export Node,
# Any missing links (e.g., "c" does not have a sibling) link back to itself (c.sibling == c)
# With this organization, no arrays need to be allocated.

type Node{T}
mutable struct Node{T}
data::T
parent::Node{T}
child::Node{T}
sibling::Node{T}

# Constructor for the root of the tree
function (::Type{Node{T}}){T}(data::T)
function (::Type{Node{T}})(data::T) where T
Copy link
Owner

Choose a reason for hiding this comment

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

These can change to the newer and much easier syntax, function Node{T})(data) where T.

n = new{T}(data)
n.parent = n
n.child = n
n.sibling = n
n
end
# Constructor for all others
function (::Type{Node{T}}){T}(data::T, parent::Node)
function (::Type{Node{T}})(data::T, parent::Node) where T
Copy link
Owner

Choose a reason for hiding this comment

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

here too

n = new{T}(data, parent)
n.child = n
n.sibling = n
n
end
end
Node{T}(data::T) = Node{T}(data)
Node{T}(data::T, parent::Node{T}) = Node{T}(data, parent)
Node(data::T) where {T} = Node{T}(data)
Node(data::T, parent::Node{T}) where {T} = Node{T}(data, parent)
Copy link
Owner

Choose a reason for hiding this comment

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

Now that I know more I'd write this as Node(data, parent::Node{T}) where T (dropping the ::T on data). Having the parent is enough to specify the T we need, and any data that can be converted to T will then work.

Completely optional, however.


function lastsibling(sib::Node)
newsib = sib.sibling
Expand All @@ -50,7 +50,7 @@ function lastsibling(sib::Node)
sib
end

function addsibling{T}(oldersib::Node{T}, data::T)
function addsibling(oldersib::Node{T}, data::T) where T
Copy link
Owner

Choose a reason for hiding this comment

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

likewise here

if oldersib.sibling != oldersib
error("Truncation of sibling list")
end
Expand All @@ -59,7 +59,7 @@ function addsibling{T}(oldersib::Node{T}, data::T)
youngersib
end

function addchild{T}(parent::Node{T}, data::T)
function addchild(parent::Node{T}, data::T) where T
newc = Node(data, parent)
prevc = parent.child
if prevc == parent
Expand All @@ -80,9 +80,10 @@ show(io::IO, n::Node) = print(io, n.data)
# for c in parent
# # do something
# end
start(n::Node) = n.child
done(n::Node, state::Node) = n == state
next(n::Node, state::Node) = state, state == state.sibling ? n : state.sibling
function iterate(n::Node, state = n.child)
n == state && return nothing
return state, state == state.sibling ? n : state.sibling
end

function showedges(io::IO, parent::Node, printfunc = identity)
str = printfunc(parent.data)
Expand Down
6 changes: 3 additions & 3 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ function profile_test(n)
for i = 1:n
A = randn(100,100,20)
m = maximum(A)
Afft = fft(A)
Am = mapslices(sum, A, 2)
# Afft = fft(A)
Copy link
Author

Choose a reason for hiding this comment

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

I assume the fft call is only intended to provide some nontrivial amount of computations that can be profiled. With FFTW having been moved out of Base, it might be better to replace it with something that doesn't require a testing dependency. Or is it fine to just skip it?

Copy link
Owner

Choose a reason for hiding this comment

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

Agreed better not to use fft. You can either replace it or skip it, either is fine with me.

Am = mapslices(sum, A, dims = 2)
B = A[:,:,5]
Bsort = mapslices(sort, B, 1)
Bsort = mapslices(sort, B, dims = 1)
b = rand(100)
C = B.*b
end
Expand Down
5 changes: 3 additions & 2 deletions test/tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ root = Tree.Node(0)
@assert Tree.isleaf(root)
nchildren = 0
for c in root
nchildren += 1
global nchildren += 1
end
@assert nchildren == 0
c1 = Tree.addchild(root, 1)
Expand All @@ -17,7 +17,7 @@ c22 = Tree.addchild(c2, 5)
nchildren = 0
for c in root
@assert !Tree.isroot(c)
nchildren += 1
global nchildren += 1
end
@assert nchildren == 3
@assert Tree.isleaf(c1)
Expand All @@ -30,5 +30,6 @@ end
children2 = [c21,c22]
i = 0
for c in c2
global i
@assert c == children2[i+=1]
end