Skip to content
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

Fix https://github.com/DiffSharp/DiffSharp/issues/27 #31

Merged
merged 3 commits into from
Jul 20, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DiffSharp/Symbolic.Float32.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module ExprOps =
| SpecificCall <@ (-) @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ (%%at:float32) - %%bt @@>
| SpecificCall <@ (*) @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ (%%at:float32) * %%b + %%a * %%bt @@>
| SpecificCall <@ (/) @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ ((%%at:float32) * %%b - %%a * %%bt) / (%%b * %%b)@@>
| SpecificCall <@ op_Exponentiation @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ ((%%a:float32) ** %%b) * ((%%b * %%at / %%a) + ((log %%a) * %%bt)) @@>
| SpecificCall <@ op_Exponentiation @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ if (%%a <> 0.0f) then ((%%a:float32) ** %%b) * ((%%b * %%at / %%a) + ((log %%a) * %%bt)) else 0.0f @@>
| SpecificCall <@ atan2 @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ ((%%at:float32) * %%b - %%a * %%bt) / (%%a * %%a + %%b * %%b) @@>
| SpecificCall <@ (~-) @> (_, _, [a]) -> let at = diffExpr v a in <@@ -(%%at:float32) @@>
| SpecificCall <@ log @> (_, _, [a]) -> let at = diffExpr v a in <@@ (%%at:float32) / %%a @@>
Expand Down
2 changes: 1 addition & 1 deletion src/DiffSharp/Symbolic.Float64.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module ExprOps =
| SpecificCall <@ (-) @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ (%%at:float) - %%bt @@>
| SpecificCall <@ (*) @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ (%%at:float) * %%b + %%a * %%bt @@>
| SpecificCall <@ (/) @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ ((%%at:float) * %%b - %%a * %%bt) / (%%b * %%b)@@>
| SpecificCall <@ op_Exponentiation @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ ((%%a:float) ** %%b) * ((%%b * %%at / %%a) + ((log %%a) * %%bt)) @@>
| SpecificCall <@ op_Exponentiation @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ if (%%a <> 0.0) then ((%%a:float) ** %%b) * ((%%b * %%at / %%a) + ((log %%a) * %%bt)) else 0.0 @@>
| SpecificCall <@ atan2 @> (_, _, [a; b]) -> let at, bt = diffExpr v a, diffExpr v b in <@@ ((%%at:float) * %%b - %%a * %%bt) / (%%a * %%a + %%b * %%b) @@>
| SpecificCall <@ (~-) @> (_, _, [a]) -> let at = diffExpr v a in <@@ -(%%at:float) @@>
| SpecificCall <@ log @> (_, _, [a]) -> let at = diffExpr v a in <@@ (%%at:float) / %%a @@>
Expand Down
1 change: 1 addition & 0 deletions tests/DiffSharp.Tests/DiffSharp.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="Tests.fs" />
<Compile Include="Backend.OpenBLAS.fs" />
<Compile Include="AD.Float32.fs" />
<Compile Include="Symbolic.fs" />
<None Include="Script.fsx" />
<Content Include="paket.references" />
<Content Include="app.config" />
Expand Down
41 changes: 41 additions & 0 deletions tests/DiffSharp.Tests/Symbolic.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Symbolic

open FsCheck.NUnit
open DiffSharp.Util
open DiffSharp.Tests
open NUnit.Framework

module Float64 =
open DiffSharp.Symbolic.Float64
[<ReflectedDefinition>]
let f2 x = x**2.0

[<Test>]
// See https://github.com/DiffSharp/DiffSharp/issues/27
let ``Diff.Of.Exponential.At.Zero``() =
let dy = diff <@ f2 @>
Assert.True( Util.(=~) (dy 0.0, 0.0))

[<Test>]
let ``Diff.Of.Exponential.At.One``() =
let dy = diff <@ f2 @>
Assert.True(Util.(=~) (dy 1.0, 2.0))

module Float32 =
open DiffSharp.Symbolic.Float32

[<ReflectedDefinition>]
let f2 x = x**2.0f

[<Test>]
// See https://github.com/DiffSharp/DiffSharp/issues/27
let ``Diff.Of.Exponential.At.Zero``() =
printfn "testing"
let dy = diff <@ f2 @>
Assert.True(Util.(=~) (dy 0.0f, 0.0f))

[<Test>]
let ``Diff.Of.Exponential.At.One``() =
let dy = diff <@ f2 @>
Assert.True(Util.(=~) (dy 1.0f, 2.0f))