Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
denizyuret committed Aug 19, 2018
1 parent ce0f4f4 commit 29d9c4f
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
Manifest.toml
AutoGrad
foo*
data/**
Expand Down
24 changes: 15 additions & 9 deletions .travis.yml
@@ -1,19 +1,25 @@
language: julia

## https://docs.travis-ci.com/user/languages/julia
## If you leave the julia: key out of your .travis.yml, Travis CI will use the most recent release.
os:
- linux
- osx
julia:
- 0.7
- 1.0
- nightly
os:
- linux
- osx
matrix:
allow_failures:
- julia: nightly ## getting too many warnings
notifications:
email: false
git:
depth: 9999999



## https://docs.travis-ci.com/user/languages/julia

## If you leave the julia: key out of your .travis.yml, Travis CI will use the most recent release.

# matrix:
# allow_failures:
# - julia: nightly ## getting too many warnings

## uncomment the following lines to override the default test script
#script:
Expand Down
12 changes: 11 additions & 1 deletion Project.toml
@@ -1,7 +1,17 @@
name = "AutoGrad"
uuid = "6710c13c-97f1-543f-91c5-74e8f7d95b35"
author = ["Deniz Yuret <denizyuret@gmail.com>"]

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[compat]
SpecialFunctions = "0.7.0"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
27 changes: 26 additions & 1 deletion src/base.jl
@@ -1,5 +1,5 @@
# Use `perl ../deps/imports.pl base.jl` to generate the next line
import Base: !=, !==, *, +, -, /, <, <=, ==, >, >=, \, ^, abs, abs2, all, any, axes, big, ceil, checkbounds, copy, count, div, eachindex, eltype, eps, float, floor, identity, isassigned, isempty, isequal, isfinite, isinf, isinteger, isless, isnan, lastindex, length, maximum, minimum, ndims, one, ones, permutedims, prod, rem, reshape, round, sign, signbit, similar, size, stride, strides, sum, trunc, typemax, typemin, unsafe_trunc, vec, widemul, zero
import Base: !=, !==, *, +, -, /, <, <=, ==, >, >=, \, ^, abs, abs2, all, any, axes, big, ceil, checkbounds, copy, count, div, eachindex, eltype, eps, float, floor, identity, isassigned, isempty, isequal, isfinite, isinf, isinteger, isless, isnan, lastindex, length, maximum, minimum, ndims, oftype, one, ones, permutedims, prod, rem, reshape, round, sign, signbit, similar, size, stride, strides, sum, trunc, typemax, typemin, unsafe_trunc, vec, widemul, zero
import Base.Broadcast: broadcasted

# The following list copied from relevant portions of julia/base/exports.jl
Expand Down Expand Up @@ -334,3 +334,28 @@ dxndx(x1,x2,dy)=(if x2==0; zero(dy); elseif x2==1; dy; elseif x2==2; 2 .* x1 .*
# ifelse,
# objectid,
# sizeof,

### types
# convert,
# getproperty,
# setproperty!,
# fieldoffset,
# fieldname,
# fieldnames,
# fieldcount,
# propertynames,
# isabstracttype,
# isbitstype,
# isprimitivetype,
# isstructtype,
# isconcretetype,
# isdispatchtuple,
@primitive oftype(t,x),dy nothing oftype(x,dy)
# promote,
# promote_rule,
# promote_type,
# instances,
# supertype,
# typeintersect,
# typejoin,
# widen,
11 changes: 6 additions & 5 deletions src/linearalgebra.jl
@@ -1,4 +1,4 @@
import LinearAlgebra: *, adjoint, det, diag, diagm, dot, inv, logabsdet, logdet, lq, norm, qr, svd, tr, transpose, tril, triu
import LinearAlgebra: *, adjoint, det, diag, diagm, dot, inv, kron, logabsdet, logdet, lq, norm, qr, svd, tr, transpose, tril, triu

# julia/stdlib/v0.7/LinearAlgebra/src/LinearAlgebra.jl Functions:
# axpy!
Expand All @@ -16,9 +16,10 @@ import LinearAlgebra: *, adjoint, det, diag, diagm, dot, inv, logabsdet, logdet,
@primitive adjoint(x),dy adjoint(dy)
# adjoint!
@primitive det(x),dy,y dy*y*inv(x)'
@primitive diag(x),dy,y diagm(dy) # alternative: Diagonal(dy) # addtest(:diag, rand(3,3))
@primitive diag(x),dy,y diagm(0=>dy) # alternative: Diagonal(dy)
@primitive diag(x,i),dy,y diagm(i=>dy) # warning: these only works for square matrices
# diagind
@primitive diagm(x),dy,y diag(dy) # addtest(:diagm, rand(3))
# @primitive diagm(x),dy,y diag(dy,x[1]) # TODO: diagm has a pair input
@primitive dot(x1, x2),dy,y dy*x2 dy*x1 # addtestN(:dot, rand(3,2), rand(3,2))
# eigen
# eigen!
Expand Down Expand Up @@ -86,9 +87,9 @@ kron(a, b::Rec) = _kron(a, b)
@primitive transpose(x),dy transpose(dy)
# transpose!
# transpose_type
@primitive tril(x),dy,y dy.*tril(ones(x)) # addtest(:tril, rand(3,3))
@primitive tril(x),dy,y dy.*tril(fill!(similar(x),1)) # addtest(:tril, rand(3,3))
# tril!
@primitive triu(x),dy,y dy.*triu(ones(x)) # addtest(:triu, rand(3,3))
@primitive triu(x),dy,y dy.*triu(fill!(similar(x),1)) # addtest(:triu, rand(3,3))
# triu!

# julia/stdlib/v0.7/LinearAlgebra/src/LinearAlgebra.jl Operators:
Expand Down
9 changes: 5 additions & 4 deletions test/base.jl
Expand Up @@ -56,21 +56,22 @@ using Statistics, LinearAlgebra
end

@testset "power" begin
@test gradcheckN(^,xsquare,x1d[2]) #fails
@test_broken gradcheckN(^,xsquare,x1d[2]) #TODO: integer and matrix powers
@test gradcheckN(bp,abs.(x2d[1]),x1d[2])
@test gradcheckN(bp,abs.(x3d[1]),x1d[2])
@test gradcheckN(bp,abs.(x4d[1]),x1d[2])
end
@test gradcheck(abs,x1d[1])
@test gradcheck(abs2,x1d[1])
@test gradcheck(big,x1d[1]) #fails
@test gradcheck(float,1) #fails
@test gradcheck(big,x1d[1])
@test gradcheck(float,1)
@test gradcheck(maximum,x4d[1])
@test gradcheck(maxabs,x4d[1])
@test gradcheck(minimum,x4d[1])
@test gradcheck(minabs,x4d[1])
@test gradcheck(permutedims,x4d[1],(3,4,2,1))
@test gradcheckN(prod,x1d) #fails
@test_broken gradcheck(prod,x1d) #TODO: gradcheck tuple support so collect not necessary in next line
@test gradcheck(prod,collect(x1d))
@test gradcheck(sum,x4d[1])
@test gradcheck(sumabs,x4d[1])
@test gradcheck(sumabs2,x4d[1])
Expand Down
2 changes: 1 addition & 1 deletion test/cat.jl
Expand Up @@ -13,7 +13,7 @@ include("header.jl")

@test gradcheckN(cat1, x1d...)
@test gradcheckN(cat1, x1d[1], x2d[1]')
#@test gradcheckN(cat1, x1d[1], x2d[1]) #TODO: !!uncat mismatch error!! why is this working in Base.cat?
@test_skip gradcheckN(cat1, x1d[1], x2d[1]) #TODO: !!uncat mismatch error!! why is this working in Base.cat?

@test gradcheckN(cat2, x1d...)
@test gradcheckN(cat2, x1d[1], x2d[1])
Expand Down
4 changes: 2 additions & 2 deletions test/getindex.jl
Expand Up @@ -31,7 +31,7 @@ include("header.jl")
g = grad(f)
for i in (1,1:2,1:2:3,[1,2],[2,2],[],[true,false,true])
#@show i
# @test gradcheck(getindex, t, i) # TODO: gradcheck with tuples broken so we compare array vs tuple
@test_skip gradcheck(getindex, t, i) # TODO: gradcheck with tuples broken so we compare array vs tuple
@test g(t,i)==g(a,i)==nothing || g(t,i) == tuple(g(a,i)...)
end
end
Expand All @@ -40,7 +40,7 @@ include("header.jl")
g = grad(getindex)
d = Dict(1=>rand(), 2=>rand(), 3=> rand())
#@show d
# @test gradcheck(getindex, d, 1) # TODO: gradcheck with dict broken
@test_skip gradcheck(getindex, d, 1) # TODO: gradcheck with dict broken
@test collect(g(d,2)) == Any[(2=>1.0)]
end

Expand Down
2 changes: 1 addition & 1 deletion test/iterate.jl
Expand Up @@ -32,7 +32,7 @@ include("header.jl")
@test gradcheck(itr2,warray)
@test gradcheck(itr1,warray[1])
@test gradcheck(itr2,warray[1])
@test gradcheck(itr3,wdict) #fails
@test gradcheck(itr3,wdict)
@test gradcheck(itr4,warray)
@test gradcheck(itr4,wtuple)
end
16 changes: 9 additions & 7 deletions test/linearalgebra.jl
Expand Up @@ -6,6 +6,7 @@ using LinearAlgebra
w = randn(3,2)
wt = randn(2,3)
wsquare = randn(3,3)
wposdef = wsquare' * wsquare
udg = [1.,2.,3.]
dg = [4.,5.,6.]
ldg = [7.,8.,9.]
Expand Down Expand Up @@ -33,20 +34,21 @@ using LinearAlgebra

@test gradcheck(adjoint,w)
@test gradcheck(det,wsquare)
@test gradcheck(diag,w) #fails
@test gradcheckN(diagm1,udg,dg,ldg) #fails
@test gradcheck(diag,wsquare)
@test_broken gradcheck(diag,w) #TODO no support for non-square matrices yet
@test_skip gradcheckN(diagm1,udg,dg,ldg) #TODO diagm not implemented yet
@test gradcheckN(dot,udg,ldg)
@test gradcheckN(dot,w,copy(w))
@test gradcheck(inv,wsquare)
@test gradcheck(krontest,w,copy(w)) #fails
@test gradcheck(krontest,w,copy(w))
@test gradcheck(logabsdet,wsquare)
@test gradcheck(logdet,wsquare)
@test gradcheck(logdet,wposdef)
@test gradcheck(norm,w,1)
@test gradcheck(norm,w,2)
@test gradcheck(norm,w,Inf)
@test gradcheck(qrtest,w) #iterator error
@test gradcheck(lqtest,w) #iterator error
@test gradcheck(svdtest,w) #iterator error
@test_broken gradcheck(qrtest,w) #TODO iterator error
@test_broken gradcheck(lqtest,w) #TODO iterator error
@test_broken gradcheck(svdtest,w) #TODO iterator error
@test gradcheck(tr,wsquare)
@test gradcheck(transpose,w)
@test gradcheck(tril,w)
Expand Down
2 changes: 1 addition & 1 deletion test/neuralnet.jl
Expand Up @@ -16,7 +16,7 @@ wd = Dict(); for i=1:length(wa); wd[i]=wa[i]; end
@test gradcheckN(n1sum, wa, rand(3,10), rand(2,10))
@test gradcheckN(n1sum, wt, rand(3,10), rand(2,10))
# TODO: This needs more work:
# @test check_grads(n1sumd, wd, rand(3,10), rand(2,10)) # TODO: FAIL
@test_skip check_grads(n1sumd, wd, rand(3,10), rand(2,10)) # TODO: FAIL
end

nothing
1 change: 1 addition & 0 deletions test/rosenbrock.jl
Expand Up @@ -12,6 +12,7 @@ include("header.jl")
@test check_grads(b0,t1)
@test check_grads(b1sum,a1) # TODO: fail with size 2
@test check_grads(b1sum,t1) # TODO: fail with size 2
@test check_grads(b1sum,rand(2)) # fixed?
@time b1sum(rand(10000))
end

Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Expand Up @@ -7,6 +7,7 @@
#include("core.jl")
#include("broadcast.jl")
#include("macros.jl")

@time include("base.jl")
@time include("math.jl")
@time include("statistics.jl")
Expand Down

0 comments on commit 29d9c4f

Please sign in to comment.