Permalink
Browse files

ch_ops.py: Allow derivatives to work for ch.sqrt(0.0). This solution …

…is not final though.
  • Loading branch information...
1 parent da173ca commit 9d9c3fffb3a657db22a486a823399b1a27704a1f @mattloper committed Mar 17, 2015
Showing with 6 additions and 1 deletion.
  1. +6 −1 ch_ops.py
View
@@ -238,9 +238,14 @@ class square(UnaryElemwise):
_r = np.square
_d = lambda self, x : x * 2.
+def my_power(a, b):
+ with warnings.catch_warnings():
+ warnings.filterwarnings("ignore",category=RuntimeWarning)
+ return np.nan_to_num(np.power(a, b))
+
class sqrt(UnaryElemwise):
_r = np.sqrt
- _d = lambda self, x : .5 * np.power(x, -0.5)
+ _d = lambda self, x : .5 * my_power(x, -0.5)
class exp(UnaryElemwise):
_r = np.exp

0 comments on commit 9d9c3ff

Please sign in to comment.