Skip to content

fixes for Julia v0.7 #3

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

Merged
merged 1 commit into from
Jul 19, 2018
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- nightly
matrix:
allow_failures:
Expand All @@ -14,4 +14,4 @@ notifications:
git:
depth: 99999999
after_success:
- julia -e 'cd(Pkg.dir("DiffTests")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.6
julia 0.7-beta2
14 changes: 6 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
Expand Down
27 changes: 15 additions & 12 deletions src/DiffTests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module DiffTests

using LinearAlgebra: det, norm, dot, tr
using Statistics: mean

#=
These functions are organized in sets based on input/output type. They are unary and not
in-place unless otherwised specified. These functions have been written with the following
Expand Down Expand Up @@ -44,9 +47,9 @@ end

const NUMBER_TO_ARRAY_FUNCS = (num2arr_1,)

#################################
# f!(y::Array, x::Number)::Void #
#################################
####################################
# f!(y::Array, x::Number)::Nothing #
####################################

function num2arr_1!(y, x)
fill!(y, zero(x))
Expand All @@ -64,7 +67,7 @@ const INPLACE_NUMBER_TO_ARRAY_FUNCS = (num2arr_1!,)

vec2num_1(x) = (exp(x[1]) + log(x[3]) * x[4]) / x[5]
vec2num_2(x) = x[1]*x[2] + sin(x[1])
vec2num_3(x) = vecnorm(x' .* x)
vec2num_3(x) = norm(x' .* x)
vec2num_4(x) = ((sum(x) + prod(x)); 1)
vec2num_5(x) = sum((-x).^3)
vec2num_6(x) = sum([ifelse(i > 0, i, 0) for i in x])
Expand Down Expand Up @@ -124,7 +127,7 @@ mat2num_1(x) = det(first(x) * inv(x * x) + x)
function mat2num_2(x)
a = reshape(x, length(x), 1)
b = reshape(copy(x), 1, length(x))
return trace(log.((1 .+ (a * b)) .+ a .- b))
return tr(log.((1 .+ (a * b)) .+ a .- b))
end

function mat2num_3(x)
Expand All @@ -134,9 +137,9 @@ function mat2num_3(x)
return sum(map(n -> sqrt(abs(n) + n^2) * 0.5, A))
end

mat2num_4(x) = mean(sum(sin.(x) * x, 2))
mat2num_4(x) = mean(sum(sin.(x) * x, dims=2))

softmax(x) = sum(exp.(x) ./ sum(exp.(x), 2))
softmax(x) = sum(exp.(x) ./ sum(exp.(x), dims=2))

const MATRIX_TO_NUMBER_FUNCS = (det, mat2num_1, mat2num_2, mat2num_3, mat2num_4, softmax)

Expand All @@ -157,8 +160,8 @@ const BINARY_BROADCAST_OPS = ((a, b) -> broadcast(+, a, b),

const BINARY_MATRIX_TO_MATRIX_FUNCS = (+, -, *, /, \,
BINARY_BROADCAST_OPS...,
A_mul_Bt, At_mul_B, At_mul_Bt,
A_mul_Bc, Ac_mul_B, Ac_mul_Bc)
(a, b) -> a * transpose(b), (a, b) -> transpose(a) * b, (a, b) -> transpose(a) * transpose(b),
(a, b) -> a * adjoint(b), (a, b) -> adjoint(a) * b, (a, b) -> adjoint(a) * adjoint(b))

###########################################
# f(::Matrix, ::Matrix, ::Matrix)::Number #
Expand All @@ -170,9 +173,9 @@ neural_step(x1, w1, w2) = sigmoid(dot(w2[1:size(w1, 2)], relu(w1 * x1[1:size(w1,

const TERNARY_MATRIX_TO_NUMBER_FUNCS = (neural_step,)

################################
# f!(y::Array, x::Array)::Void #
################################
###################################
# f!(y::Array, x::Array)::Nothing #
###################################
# Credit for `chebyquad!`, `brown_almost_linear!`, and `trigonometric!` goes to
# Kristoffer Carlsson (@KristofferC).

Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DiffTests
using Base.Test
using Test

n = rand()
x, y = rand(5, 5), rand(26)
Expand Down Expand Up @@ -42,12 +42,12 @@ for f in DiffTests.BINARY_MATRIX_TO_MATRIX_FUNCS
@test isa(f(A, B), Array)
end

# f! returns Void
# f! returns Nothing

for f! in DiffTests.INPLACE_ARRAY_TO_ARRAY_FUNCS
@test isa(f!(y, x), Void)
@test isa(f!(y, x), Nothing)
end

for f! in DiffTests.INPLACE_NUMBER_TO_ARRAY_FUNCS
@test isa(f!(y, n), Void)
@test isa(f!(y, n), Nothing)
end