Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia

sudo: required

services:
- docker

os:
- linux
- osx

julia:
- 0.5
- 0.6
- 0.7
- 1.0
- nightly

matrix:
allow_failures:
- julia: 0.5

# matrix:
# allow_failures:
# - julia: nightly

notifications:
email: false

# uncomment the following lines to override the default test script
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("ConstraintPropagation"); Pkg.test("ConstraintPropagation"; coverage=true)'

after_success:
- julia -e 'Pkg.add("Documenter")'
- julia -e 'using Pkg; Pkg.add("Documenter")'
- julia -e 'cd(Pkg.dir("IntervalConstraintProgramming")); include(joinpath("docs", "make.jl"))'
- julia -e 'cd(Pkg.dir("IntervalConstraintProgramming")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder()); Codecov.submit(process_folder())'
11 changes: 5 additions & 6 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
julia 0.6 0.7
IntervalArithmetic 0.9 0.14
IntervalRootFinding 0.2 0.3
IntervalContractors 0.2 0.3
MacroTools 0.3

julia 0.7
IntervalArithmetic 0.15
IntervalRootFinding 0.4
IntervalContractors 0.3
MacroTools 0.4
39 changes: 24 additions & 15 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

platform:
- x86 # 32-bit
- x64 # 64-bit

# # Uncomment the following lines to allow failures on nightly julia
# # (tests will run but not make your overall status red)
# matrix:
# allow_failures:
# - julia_version: nightly

branches:
only:
Expand All @@ -17,18 +26,18 @@ notifications:
on_build_status_changed: false

install:
# Download most recent Julia Windows binary
- 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
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"ConstraintPropagation\"); Pkg.build(\"ConstraintPropagation\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"ConstraintPropagation\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
15 changes: 7 additions & 8 deletions src/ast.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const symbol_numbers = Dict{Symbol, Int}()


doc"""Return a new, unique symbol like _z3_"""
"""Return a new, unique symbol like _z3_"""
function make_symbol(s::Symbol) # default is :z

i = get(symbol_numbers, s, 0)
Expand All @@ -17,7 +16,7 @@ end
make_symbol(c::Char) = make_symbol(Symbol(c))

let current_symbol = 'a'
function make_symbol()
global function make_symbol()
current_sym = current_symbol

if current_sym < 'z'
Expand All @@ -36,7 +35,7 @@ function make_symbols(n::Integer)
end

# The following function is not used
doc"""Check if a symbol like `:a` has been uniqued to `:_a_1_`"""
"""Check if a symbol like `:a` has been uniqued to `:_a_1_`"""
function isuniqued(s::Symbol)
ss = string(s)
contains(ss, "_") && isdigit(ss[end-1])
Expand All @@ -46,21 +45,21 @@ end

# Combine Assignment and FunctionAssignment ?

immutable Assignment
struct Assignment
lhs
op
args
end

immutable FunctionAssignment
struct FunctionAssignment
f # function name
args # input arguments
return_arguments
intermediate # tuple of intermediate variables
end

# Close to single assignment form
type FlatAST
mutable struct FlatAST
top # topmost variable(s)
input_variables::Set{Symbol}
intermediate::Vector{Symbol} # generated vars
Expand Down Expand Up @@ -103,7 +102,7 @@ function flatten(ex)
end


doc"""`flatten!` recursively converts a Julia expression into a "flat" (one-dimensional)
"""`flatten!` recursively converts a Julia expression into a "flat" (one-dimensional)
structure, stored in a FlatAST object. This is close to SSA (single-assignment form,
https://en.wikipedia.org/wiki/Static_single_assignment_form).

Expand Down
8 changes: 4 additions & 4 deletions src/code_generation.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
doc"""
"""
A generated function, with the code that generated it
"""
immutable GeneratedFunction{F}
struct GeneratedFunction{F}
f::F
code::Expr
end
Expand All @@ -10,7 +10,7 @@ end

# GeneratedFunction(code::Expr) = GeneratedFunction(eval(code), code)

(f::GeneratedFunction{F}){F}(x...) = f.f(x...)
(f::GeneratedFunction{F})(x...) where {F} = f.f(x...)


function make_tuple(args)
Expand Down Expand Up @@ -179,7 +179,7 @@ function forward_backward(flatAST::FlatAST)
end


doc"""
"""
Generate code for an anonymous function with given
input arguments, output arguments, and code block.
"""
Expand Down
17 changes: 9 additions & 8 deletions src/contractor.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

doc"""
`Contractor` represents a `Contractor` from $\mathbb{R}^N$ to $\mathbb{R}^N$.
"""
`Contractor` represents a `Contractor` from ``\\mathbb{R}^N`` to ``\\mathbb{R}^N``.
Nout is the output dimension of the forward part.
"""
immutable Contractor{N, Nout, F1<:Function, F2<:Function}
struct Contractor{N, Nout, F1<:Function, F2<:Function}
variables::Vector{Symbol} # input variables
forward::GeneratedFunction{F1}
backward::GeneratedFunction{F2}
Expand Down Expand Up @@ -32,7 +32,7 @@ function Contractor(variables::Vector{Symbol}, top, forward, backward, expressio
Contractor{N, Nout, typeof(forward.f), typeof(backward.f)}(variables, forward, backward, expression)
end

function Base.show{N,Nout,F1,F2}(io::IO, C::Contractor{N,Nout,F1,F2})
function Base.show(io::IO, C::Contractor{N,Nout,F1,F2}) where {N,Nout,F1,F2}
println(io, "Contractor in $(N) dimensions:")
println(io, " - forward pass contracts to $(Nout) dimensions")
println(io, " - variables: $(C.variables)")
Expand All @@ -41,8 +41,8 @@ end



function (C::Contractor{N,Nout,F1,F2}){N,Nout,F1,F2,T}(
A::IntervalBox{Nout,T}, X::IntervalBox{N,T})
function (C::Contractor{N,Nout,F1,F2})(
A::IntervalBox{Nout,T}, X::IntervalBox{N,T}) where {N,Nout,F1,F2,T}

output, intermediate = C.forward(X)

Expand All @@ -67,7 +67,8 @@ function (C::Contractor{N,Nout,F1,F2}){N,Nout,F1,F2,T}(
end

# allow 1D contractors to take Interval instead of IntervalBox for simplicty:
(C::Contractor{N,1,F1,F2}){N,F1,F2,T}(A::Interval{T}, X::IntervalBox{N,T}) = C(IntervalBox(A), X)

(C::Contractor{N,1,F1,F2})(A::Interval{T}, X::IntervalBox{N,T}) where {N,F1,F2,T} = C(IntervalBox(A), X)

function make_contractor(expr::Expr)
# println("Entering Contractor(ex) with ex=$ex")
Expand Down Expand Up @@ -109,7 +110,7 @@ function make_contractor(expr::Expr)
end


doc"""Usage:
"""Usage:
```
C = @contractor(x^2 + y^2)
A = -∞..1 # the constraint interval
Expand Down
19 changes: 9 additions & 10 deletions src/functions.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@


doc"""
"""
A `ConstraintFunction` contains the created forward and backward
code
"""
type ConstraintFunction{F <: Function, G <: Function}
mutable struct ConstraintFunction{F <: Function, G <: Function}
input::Vector{Symbol} # input arguments for forward function
output::Vector{Symbol} # output arguments for forward function
forward::F
Expand All @@ -14,15 +14,15 @@ type ConstraintFunction{F <: Function, G <: Function}
expression::Expr
end

function Base.show{F,G}(io::IO, f::ConstraintFunction{F,G})
function Base.show(io::IO, f::ConstraintFunction{F,G}) where {F,G}
println(io, "ConstraintFunction:")
println(io, " - input arguments: $(f.input)")
println(io, " - output arguments: $(f.output)")
print(io, " - expression: $(MacroTools.striplines(f.expression))")
end


immutable FunctionArguments
struct FunctionArguments
input
return_arguments
intermediate
Expand All @@ -33,12 +33,11 @@ end
const registered_functions = Dict{Symbol, FunctionArguments}()


@doc """
`@function` registers a function to be used in forwards and backwards mode.

Example: `@function f(x, y) = x^2 + y^2`
""" # this docstring does not work!

# """
# `@function` registers a function to be used in forwards and backwards mode.
#
# Example: `@function f(x, y) = x^2 + y^2`
# """ # this docstring does not work!
@eval macro ($(:function))(ex) # workaround to define macro @function

(f, args, code) = match_function(ex)
Expand Down
12 changes: 6 additions & 6 deletions src/paving.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
typealias SubPaving{N,T} Vector{IntervalBox{N,T}}
const SubPaving{N,T} = Vector{IntervalBox{N,T}}

type Paving{N,T}
struct Paving{N,T}
separator::Separator # parametrize!
inner::SubPaving{N,T}
boundary::SubPaving{N,T}
ϵ::Float64
end


function setdiff{N,T}(x::IntervalBox{N,T}, subpaving::SubPaving{N,T})
function setdiff(x::IntervalBox{N,T}, subpaving::SubPaving{N,T}) where {N,T}
working = [x]
new_working = IntervalBox{N,T}[]

Expand Down Expand Up @@ -37,16 +37,16 @@ function setdiff{N,T}(x::IntervalBox{N,T}, subpaving::SubPaving{N,T})

end

setdiff{N,T}(X::SubPaving{N,T}, Y::SubPaving{N,T}) = vcat([setdiff(x, Y) for x in X]...)
setdiff(X::SubPaving{N,T}, Y::SubPaving{N,T}) where {N,T} = vcat([setdiff(x, Y) for x in X]...)

function setdiff{N,T}(x::IntervalBox{N,T}, paving::Paving{N,T})
function setdiff(x::IntervalBox{N,T}, paving::Paving{N,T}) where {N,T}
Y = setdiff(x, paving.inner)
Z = setdiff(Y, paving.boundary)
return Z
end


function show{N,T}(io::IO, p::Paving{N,T})
function show(io::IO, p::Paving{N,T}) where {N,T}
print(io, """Paving:
- tolerance ϵ = $(p.ϵ)
- inner approx. of length $(length(p.inner))
Expand Down
Loading