From 5998daec2d1f6b5bec339d68138b283ff3419723 Mon Sep 17 00:00:00 2001 From: Paxon Date: Tue, 18 Jul 2023 15:53:29 -0700 Subject: [PATCH] adding some docstring, fixing unused imports --- src/lava/proc/graded/models.py | 6 +++++- src/lava/proc/graded/process.py | 10 ---------- src/lava/proc/prodneuron/process.py | 27 ++++++++++++++------------- tests/lava/proc/graded/test_graded.py | 5 +---- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/lava/proc/graded/models.py b/src/lava/proc/graded/models.py index 28803142a..082b35016 100644 --- a/src/lava/proc/graded/models.py +++ b/src/lava/proc/graded/models.py @@ -3,7 +3,6 @@ # See: https://spdx.org/licenses/ import numpy as np -import typing as ty from lava.magma.core.sync.protocols.loihi_protocol import LoihiProtocol from lava.magma.core.model.py.ports import PyInPort, PyOutPort @@ -16,6 +15,8 @@ class AbstractGradedVecModel(PyLoihiProcessModel): + """Implementation of GradedVec""" + a_in = None s_out = None @@ -83,6 +84,7 @@ def run_spk(self) -> None: @requires(CPU) @tag('float') class InvSqrtModelFloat(PyLoihiProcessModel): + """Implementation of InvSqrt in floating point""" a_in = LavaPyType(PyInPort.VEC_DENSE, float) s_out = LavaPyType(PyOutPort.VEC_DENSE, float) @@ -133,6 +135,8 @@ def inv_sqrt(s_fp, n_iters=5, b_fraction=12): @requires(CPU) @tag('fixed_pt') class InvSqrtModelFP(PyLoihiProcessModel): + """Implementation of InvSqrt in fixed point""" + a_in = LavaPyType(PyInPort.VEC_DENSE, np.int32, precision=24) s_out = LavaPyType(PyOutPort.VEC_DENSE, np.int32, precision=24) fp_base: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=24) diff --git a/src/lava/proc/graded/process.py b/src/lava/proc/graded/process.py index a05caa11a..68b00c953 100644 --- a/src/lava/proc/graded/process.py +++ b/src/lava/proc/graded/process.py @@ -2,23 +2,13 @@ # SPDX-License-Identifier: BSD-3-Clause # See: https://spdx.org/licenses/ -import os import numpy as np import typing as ty -from typing import Any, Dict -from enum import IntEnum, unique from lava.magma.core.process.process import AbstractProcess from lava.magma.core.process.variable import Var from lava.magma.core.process.ports.ports import InPort, OutPort -from lava.magma.core.sync.protocols.loihi_protocol import LoihiProtocol -from lava.magma.core.model.py.ports import PyInPort, PyOutPort -from lava.magma.core.model.py.type import LavaPyType -from lava.magma.core.resources import CPU -from lava.magma.core.decorator import implements, requires, tag -from lava.magma.core.model.py.model import PyLoihiProcessModel - def loihi2round(vv): """ diff --git a/src/lava/proc/prodneuron/process.py b/src/lava/proc/prodneuron/process.py index 08d5d88d1..dfa4dc35c 100644 --- a/src/lava/proc/prodneuron/process.py +++ b/src/lava/proc/prodneuron/process.py @@ -10,25 +10,26 @@ class ProdNeuron(AbstractProcess): + """ProdNeuron + + Multiplies two graded inputs. + + Parameters + ---------- + + shape : tuple(int) + Number and topology of ProdNeuron neurons. + vth : int + Threshold + exp : int + Fixed-point base + """ def __init__( self, shape: ty.Tuple[int, ...], vth=1, exp=0) -> None: - """ProdNeuron - - Multiplies two graded inputs. - - Parameters - ---------- - shape : tuple(int) - Number and topology of ProdNeuron neurons. - vth : int - Threshold - exp : int - Fixed-point base - """ super().__init__(shape=shape) self.a_in1 = InPort(shape=shape) diff --git a/tests/lava/proc/graded/test_graded.py b/tests/lava/proc/graded/test_graded.py index 469b7dcf6..d485c15fc 100644 --- a/tests/lava/proc/graded/test_graded.py +++ b/tests/lava/proc/graded/test_graded.py @@ -4,14 +4,13 @@ import unittest import numpy as np -from scipy.sparse import csr_matrix, find +from scipy.sparse import csr_matrix from lava.proc.graded.process import GradedVec, NormVecDelay, InvSqrt from lava.proc.graded.models import inv_sqrt from lava.proc.dense.process import Dense from lava.proc.sparse.process import Sparse from lava.proc import io -from lava.proc import embedded_io as eio from lava.magma.core.run_conditions import RunSteps from lava.magma.core.run_configs import Loihi2SimCfg @@ -145,7 +144,6 @@ def test_invsqrt_calc(self): class TestNormVecDelayProc(unittest.TestCase): def test_norm_vec_delay_out1(self): - fp_base = 12 # base of the decimal point weight_exp = 7 num_steps = 10 @@ -208,7 +206,6 @@ def test_norm_vec_delay_out1(self): self.assertTrue(np.all(expected_out[:, :-1] == out_data[:, 1:])) def test_norm_vec_delay_out2(self): - fp_base = 12 # base of the decimal point weight_exp = 7 num_steps = 10