Skip to content

Commit

Permalink
fix for using PkgBenchmarks instead (#94)
Browse files Browse the repository at this point in the history
* fix for using PkgBenchmarks instead

* srand to fix Float32 failure
  • Loading branch information
fredrikekre authored May 7, 2018
1 parent 6391974 commit f99f9e1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 144 deletions.
6 changes: 3 additions & 3 deletions benchmark/benchmark_ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ function Ψ(C, μ, Kb)
T = ForwardDiff.valtype(eltype(C))
detC = det(C)
J = sqrt(detC)
Ĉ = detC^(T(-1 / 3)) * C
return (T(μ) * (tr(Ĉ) - 3) / 2 + T(Kb) * (J - 1)^2)
Ĉ = detC^(convert(T, -1 / 3)) * C
return (convert(T, μ) * (tr(Ĉ) - 3) / 2 + convert(T, Kb) * (J - 1)^2)
end

function S(C, μ, Kb)
T = ForwardDiff.valtype(eltype(C))
I = one(C)
J = sqrt(det(C))
invC = inv(C)
return T(μ) * det(C)^(T(-1/3)) * (I - tr(C) * invC / 3) + T(Kb) * (J - 1) * J * invC
return convert(T, μ) * det(C)^(convert(T, -1/3)) * (I - tr(C) * invC / 3) + convert(T, Kb) * (J - 1) * J * invC
end

const μ = 1e10;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ for dim in (ALL_DIMENSIONS ? (1,2,3) : (3,))
# other
for (i, V2t) in enumerate((V2, V2sym))
TensorType = i == 2 ? "SymmetricTensor" : "Tensor"
for f in (norm, trace, vol, det, inv, transpose, symmetric, skew, eig, mean, dev)
for f in (norm, tr, vol, det, inv, transpose, symmetric, skew, eig, mean, dev)
(i == 1 || typeof(V2t) <: Tensor || T == dT) && f == eig && continue
SUITE["other"]["$f($TensorType{2, $dim, $T})"] = @benchmarkable $f($V2t)
end
Expand Down
39 changes: 39 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Tensors
using BenchmarkTools
using ForwardDiff

const SUITE = BenchmarkGroup()
const ALL_DIMENSIONS = true
const MIXED_SYM_NONSYM = true
const MIXED_ELTYPES = true

const dT = ForwardDiff.Dual{Nothing,Float64,4}

function create_tensors()
tensor_dict = Dict{Tuple{Int, Int, DataType}, AbstractTensor}()
symtensor_dict = Dict{Tuple{Int, Int, DataType}, AbstractTensor}()
for dim in 1:3
for order in (1,2,4)
for T in (Float32, Float64)
tensor_dict[(dim, order, T)] = rand(Tensor{order, dim, T})
if order != 1
symtensor_dict[(dim, order, T)] = rand(SymmetricTensor{order, dim, T})
else
symtensor_dict[(dim, order, T)] = rand(Tensor{order, dim, T})
end
end
tensor_dict[(dim, order, dT)] = Tensor{order, dim, dT}(([ForwardDiff.Dual(rand(5)...,) for i in 1:length(rand(Tensor{order, dim}))]...,))
if order != 1
symtensor_dict[(dim, order, dT)] = SymmetricTensor{order, dim, dT}(([ForwardDiff.Dual(rand(5)...,) for i in 1:length(rand(SymmetricTensor{order, dim}).data)]...,))
else
symtensor_dict[(dim, order, dT)] = Tensor{order, dim, dT}(([ForwardDiff.Dual(rand(5)...,) for i in 1:length(rand(Tensor{order, dim}).data)]...,))
end
end
end
return tensor_dict, symtensor_dict
end

tensor_dict, symtensor_dict = create_tensors()

include("benchmark_functions.jl")
include("benchmark_ad.jl")
70 changes: 0 additions & 70 deletions benchmark/generate_report.jl

This file was deleted.

70 changes: 0 additions & 70 deletions benchmark/runbenchmarks.jl

This file was deleted.

1 change: 1 addition & 0 deletions test/test_ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ S(C) = S(C, μ, Kb)
end # loop dim

@testsection "vector calculus identities" begin
srand(1234)
φ(x) = norm(x)^4
ϕ(x) = sum(x)
A(x) = Vec{3}((x[1]*x[2]^3*x[3], x[1]*x[2]*x[3]^3, x[1]^3*x[2]*x[3]))
Expand Down

0 comments on commit f99f9e1

Please sign in to comment.