Commit 353075f5 authored by Philipp Frank's avatar Philipp Frank
Browse files


parent c2d2eb28
Pipeline #93595 passed with stages
in 11 minutes and 13 seconds
......@@ -82,6 +82,14 @@ def _clip_helper(v, a_min, a_max):
tmp2 = np.where(tmp == a_max, 0., tmp2)
return (tmp, tmp2)
def _step_helper(v, grad):
if np.issubdtype(v.dtype, np.complexfloating):
raise TypeError("Argument must not be complex")
r = np.zeros(v.shape)
r[v>=0.] = 1.
if grad:
return (r, np.zeros(v.shape))
return r
def softplus(v):
fv = np.empty(v.shape, dtype=np.float64 if np.isrealobj(v) else np.complex128)
......@@ -144,5 +152,6 @@ ptw_dict = {
"exponentiate": (exponentiate, _exponentiate_helper),
"arcsin": (np.arcsin, lambda v: (np.arcsin(v), 1./np.sqrt(1.-v**2))),
"arccos": (np.arccos, lambda v: (np.arccos(v), -1./np.sqrt(1.-v**2))),
"arctan": (np.arctan, lambda v: (np.arctan(v), 1./(1.+v**2)))
"arctan": (np.arctan, lambda v: (np.arctan(v), 1./(1.+v**2))),
"unitstep": (lambda v: _step_helper(v, False), lambda v: _step_helper(v, True))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment