Skip to content

Commit

Permalink
add float part
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlinvc committed Mar 23, 2019
1 parent be6d148 commit 44cb2c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/autodiff/numeric.rb
Expand Up @@ -17,3 +17,9 @@ class Integer
dual_op(:+)
dual_op(:-)
end

class Float
extend DualNumConvertible
dual_op(:+)
dual_op(:-)
end
4 changes: 4 additions & 0 deletions test/autodiff_test.rb
Expand Up @@ -21,6 +21,10 @@ def test_gradient_can_do_1_minus_x
assert_equal -1, Autodiff.gradient(0) { |x| 1 - x }
end

def test_gradient_can_do_1_point_5_minus_x
assert_equal -1, Autodiff.gradient(0) { |x| 1.5 - x }
end

def test_gradient_can_handle_x_square
assert_equal 2, Autodiff.gradient(1) { |x| x*x}
end
Expand Down

0 comments on commit 44cb2c1

Please sign in to comment.