From f7e9f2534ed946f99353ea25a67ac6af8d41a956 Mon Sep 17 00:00:00 2001 From: PhilippPlank <32519998+PhilippPlank@users.noreply.github.com> Date: Fri, 23 Sep 2022 19:25:50 +0200 Subject: [PATCH] Fix issue 334 (#364) * Update models.py Changed calculation of wrapped_current. * Update models.py fixed linting * Remove unused sign_of_curr from models.py Co-authored-by: Marcus G K Williams <168222+mgkwill@users.noreply.github.com> --- src/lava/proc/lif/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lava/proc/lif/models.py b/src/lava/proc/lif/models.py index 6ec8837ae..b62f99668 100644 --- a/src/lava/proc/lif/models.py +++ b/src/lava/proc/lif/models.py @@ -143,12 +143,12 @@ def subthr_dynamics(self, activation_in: np.ndarray): # Check if value of current is within bounds of 24-bit. Overflows are # handled by wrapping around modulo 2 ** 23. E.g., (2 ** 23) + k # becomes k and -(2**23 + k) becomes -k - sign_of_curr = np.sign(decayed_curr) - # when decayed_curr is 0, we don't care about its sign. But np.mod - # needs something non-zero to avoid the divide-by-zero warning - sign_of_curr[sign_of_curr == 0] = 1 - wrapped_curr = np.mod(decayed_curr, - sign_of_curr * self.max_uv_val) + wrapped_curr = np.where(decayed_curr > self.max_uv_val, + decayed_curr - 2 * self.max_uv_val, + decayed_curr) + wrapped_curr = np.where(wrapped_curr <= -self.max_uv_val, + decayed_curr + 2 * self.max_uv_val, + wrapped_curr) self.u[:] = wrapped_curr # Update voltage # --------------