Skip to content

Commit

Permalink
update to 0.6 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Evizero committed Mar 10, 2017
1 parent 12d3c0a commit ca386cd
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 71 deletions.
48 changes: 13 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ arbitrarily spaced sampling times*

| **Package Status** | **Package Evaluator** | **Build Status** |
|:------------------:|:---------------------:|:-----------------:|
| [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md) | [![Package Evaluator v4](http://pkg.julialang.org/badges/ValueHistories_0.4.svg)](http://pkg.julialang.org/?pkg=ValueHistories&ver=0.4) [![Package Evaluator v5](http://pkg.julialang.org/badges/ValueHistories_0.5.svg)](http://pkg.julialang.org/?pkg=ValueHistories&ver=0.5) | [![Build Status](https://travis-ci.org/JuliaML/ValueHistories.jl.svg?branch=master)](https://travis-ci.org/JuliaML/ValueHistories.jl) [![Build status](https://ci.appveyor.com/api/projects/status/8v1n9hqfnn5jslyn/branch/master?svg=true)](https://ci.appveyor.com/project/Evizero/valuehistories-jl/branch/master) [![Coverage Status](https://coveralls.io/repos/github/JuliaML/ValueHistories.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaML/ValueHistories.jl?branch=master) |
| [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md) | [![ValueHistories](http://pkg.julialang.org/badges/ValueHistories_0.5.svg)](http://pkg.julialang.org/?pkg=ValueHistories) [![ValueHistories](http://pkg.julialang.org/badges/ValueHistories_0.6.svg)](http://pkg.julialang.org/?pkg=ValueHistories) | [![Build Status](https://travis-ci.org/JuliaML/ValueHistories.jl.svg?branch=master)](https://travis-ci.org/JuliaML/ValueHistories.jl) [![Build status](https://ci.appveyor.com/api/projects/status/8v1n9hqfnn5jslyn/branch/master?svg=true)](https://ci.appveyor.com/project/Evizero/valuehistories-jl/branch/master) [![Coverage Status](https://coveralls.io/repos/github/JuliaML/ValueHistories.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaML/ValueHistories.jl?branch=master) |

## Installation

This package is registered in `METADATA.jl` and can be installed as usual

```Julia
```julia
Pkg.add("ValueHistories")
using ValueHistories
```
Expand Down Expand Up @@ -49,7 +49,9 @@ Supported operations for univalue histories:

Here is a little example code showing the basic usage:

```Julia
```julia
using Primes

# Specify the type of value you wish to track
history = QHistory(Float64)

Expand Down Expand Up @@ -83,12 +85,12 @@ QHistory
For easy visualisation we also provide recipes for `Plots.jl`.
Note that this is only supported for `Real` types.

```Julia
```julia
using Plots
plot(history, legend=false)
```

![univalue](https://cloud.githubusercontent.com/assets/10854026/17746218/70d10760-64af-11e6-94c4-b711a9ac018b.png)
![qhistory](https://rawgithub.com/JuliaML/FileStorage/master/ValueHistories/qhistory.svg)

### Multivalue Histories

Expand All @@ -109,7 +111,7 @@ Supported operations for multivalue histories:

Here is a little example code showing the basic usage:

```Julia
```julia
history = MVHistory()

for i=1:100
Expand All @@ -136,7 +138,7 @@ x, y = get(history, :mysin)
x, y = get(history, :mystring)
@assert length(x) == length(y) == 100
@assert typeof(x) <: Vector{Int64}
@assert typeof(y) <: Vector{ASCIIString}
@assert typeof(y) <: Vector{String}
@assert y[1] == "i=1"

# You can also enumerate over the observations
Expand All @@ -152,45 +154,21 @@ history
```
MVHistory{ValueHistories.History{I,V}}
:mysin => 100 elements {Float64,Float64}
:mystring => 100 elements {Int64,ASCIIString}
:mystring => 100 elements {Int64,String}
:mycos => 25 elements {Float32,Float64}
```

For easy visualisation we also provide recipes for `Plots.jl`.
Note that this is only supported for `Real` types.

```Julia
```julia
using Plots
plot(history)
```

![multivalue](https://cloud.githubusercontent.com/assets/10854026/17746217/70d0ad9c-64af-11e6-8453-bf94aad32571.png)


## Benchmarks

Compilation already taken into account. The code can be found [here](https://github.com/Evizero/ValueHistories.jl/blob/master/test/bm_history.jl)

```
Baseline: 100000 loops that accumulates a Float64
0.000127 seconds (5 allocations: 176 bytes)
History: 100000 loops tracking accumulator as Float64
0.003651 seconds (33 allocations: 4.001 MB)
History: Converting result into arrays
0.000010 seconds (3 allocations: 96 bytes)
QHistory: 100000 loops tracking accumulator as Float64
0.002141 seconds (195 allocations: 1.529 MB)
QHistory: Converting result into arrays
0.217000 seconds (1.60 M allocations: 35.067 MB, 3.63% gc time)
MVHistory: 100000 loops tracking accumulator as Float64 and String
0.185134 seconds (1.70 M allocations: 62.937 MB, 31.24% gc time)
MVHistory: Converting result into arrays
0.194542 seconds (1.39 M allocations: 28.914 MB, 25.88% gc time)
```
![mvhistory](https://rawgithub.com/JuliaML/FileStorage/master/ValueHistories/mvhistory.svg)

## License

This code is free to use under the terms of the MIT license.

7 changes: 4 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
julia 0.5-
DataStructures
RecipesBase
julia 0.5
DataStructures 0.5
RecipesBase 0.1
Compat 0.17
16 changes: 9 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ environment:
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
- /release-.*/

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

install:
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile($("http://s3.amazonaws.com/"+$env:JULIAVERSION), "C:\projects\julia-binary.exe")
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia

Expand All @@ -29,4 +31,4 @@ build_script:
Pkg.clone(pwd(), \"ValueHistories\"); Pkg.build(\"ValueHistories\")"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"ValueHistories\")"
- C:\projects\julia\bin\julia -e "Pkg.test(\"ValueHistories\")"
6 changes: 1 addition & 5 deletions src/ValueHistories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ValueHistories

using DataStructures
using RecipesBase
using Compat

export

Expand All @@ -19,9 +20,4 @@ include("qhistory.jl")
include("mvhistory.jl")
include("recipes.jl")

Base.@deprecate_binding VectorUnivalueHistory History
Base.@deprecate_binding QueueUnivalueHistory QHistory
Base.@deprecate_binding DynMultivalueHistory MVHistory


end # module
6 changes: 3 additions & 3 deletions src/abstract.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
abstract ValueHistory
abstract UnivalueHistory{I} <: ValueHistory
abstract MultivalueHistory <: ValueHistory
@compat abstract type ValueHistory end
@compat abstract type UnivalueHistory{I} <: ValueHistory end
@compat abstract type MultivalueHistory <: ValueHistory end

Base.push!(history::UnivalueHistory, iteration, value) =
throw(ArgumentError("The specified arguments are of incompatible type"))
Expand Down
2 changes: 1 addition & 1 deletion src/history.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type History{I,V} <: UnivalueHistory{I}
values::Vector{V}

function History(::Type{V}, ::Type{I})
new(typemin(I), Array(I, 0), Array(V, 0))
new(typemin(I), Array{I}(0), Array{V}(0))
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/mvhistory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Base.get(history::MVHistory, key::Symbol)
l = length(history, key)
k, v = first(history.storage[key])
karray = zeros(typeof(k), l)
varray = Array(typeof(v), l)
varray = Array{typeof(v)}(l)
i = 1
for (k, v) in enumerate(history, key)
karray[i] = k
Expand Down
2 changes: 1 addition & 1 deletion src/qhistory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function Base.get{I,V}(history::QHistory{I,V})
l = length(history)
k, v = front(history.storage)
karray = zeros(I, l)
varray = Array(V, l)
varray = Array{V}(l)
i = 1
for (k, v) in enumerate(history)
karray[i] = k
Expand Down
2 changes: 1 addition & 1 deletion src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
v_vec = [v for (k, v) in filtered]
if length(v_vec) > 0
markershape --> :ellipse
label --> map(string, k_vec)'
label --> reshape(map(string, k_vec), (1,length(k_vec)))
if get(d, :layout, nothing) != nothing
title --> d[:label]
legend --> false
Expand Down
4 changes: 2 additions & 2 deletions test/bm_history.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end

for T in [History, QHistory]

msg("$(T.name.name): $n loops tracking accumulator as Float64")
msg("$(T): $n loops tracking accumulator as Float64")

function g(_history,n)
tmp = 0.
Expand All @@ -41,7 +41,7 @@ for T in [History, QHistory]
_history = T(Float64)
@time g(_history,n)

msg("$(T.name.name): Converting result into arrays")
msg("$(T): Converting result into arrays")

@time x,y = get(_history)
@time x,y = get(_history)
Expand Down
8 changes: 1 addition & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using ValueHistories

if VERSION >= v"0.5-"
using Base.Test
else
using BaseTestNext
const Test = BaseTestNext
end
using Base.Test

tests = [
"tst_history.jl"
Expand Down
6 changes: 3 additions & 3 deletions test/tst_history.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
for T in [History, QHistory]
@testset "$(T.name.name): Basic functions" begin
@testset "$(T): Basic functions" begin
_history = T(Float64)

@test push!(_history, 1, 10.) == Float64(10.)
Expand Down Expand Up @@ -44,11 +44,11 @@ for T in [History, QHistory]
@test convert(Vector{Float64}, a1 + 1) == a2
end

@testset "$(T.name.name): No explicit iteration" begin
@testset "$(T): No explicit iteration" begin
_history = T(Float64)
end

@testset "$(T.name.name): Storing arbitrary types" begin
@testset "$(T): Storing arbitrary types" begin
_history = T(String, UInt8)

for i = 1:100
Expand Down
9 changes: 7 additions & 2 deletions test/tst_mvhistory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ end
@test typeof(a1) <: Vector{Int}
@test typeof(a2) <: Vector{Float64}

@test haskey(_history, Symbol("round(Int,xi)"))
a1, a2 = get(_history, Symbol("round(Int,xi)"))
a1, a2 = if VERSION < v"0.6-"
@test haskey(_history, Symbol("round(Int,xi)"))
get(_history, Symbol("round(Int,xi)"))
else
@test haskey(_history, Symbol("round(Int, xi)"))
get(_history, Symbol("round(Int, xi)"))
end
@test length(a1) == n
@test length(a2) == n
@test typeof(a1) <: Vector{Int}
Expand Down

0 comments on commit ca386cd

Please sign in to comment.