sc_neurocore_engine/bindings/
lapicque_neuron.rs1use pyo3::prelude::*;
10use pyo3::types::PyDict;
11
12use crate::neuron;
13
14#[pyclass(
15 name = "LapicqueNeuron",
16 module = "sc_neurocore_engine.sc_neurocore_engine"
17)]
18#[derive(Clone)]
19pub struct PyLapicqueNeuron {
20 inner: neuron::LapicqueNeuron,
21}
22
23#[pymethods]
24impl PyLapicqueNeuron {
25 #[new]
26 #[pyo3(signature = (tau=20.0, resistance=1.0, threshold=1.0, dt=1.0))]
27 fn new(tau: f64, resistance: f64, threshold: f64, dt: f64) -> Self {
28 Self {
29 inner: neuron::LapicqueNeuron::new(tau, resistance, threshold, dt),
30 }
31 }
32 fn step(&mut self, current: f64) -> i32 {
33 self.inner.step(current)
34 }
35 fn reset(&mut self) {
36 self.inner.reset();
37 }
38 fn get_state(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
39 let d = PyDict::new(py);
40 d.set_item("v", self.inner.v)?;
41 Ok(d.into_any().unbind())
42 }
43}
44
45pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
47 module.add_class::<PyLapicqueNeuron>()?;
48 Ok(())
49}