sc_neurocore_engine/bindings/
cortical_column.rs1use numpy::{IntoPyArray, PyReadonlyArray1};
12use pyo3::prelude::*;
13use pyo3::types::PyDict;
14
15use crate::cortical_column;
16
17pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
19 module.add_class::<PyCorticalColumn>()?;
20 Ok(())
21}
22
23#[pyclass(
24 name = "CorticalColumnRust",
25 module = "sc_neurocore_engine.sc_neurocore_engine"
26)]
27pub struct PyCorticalColumn {
28 inner: cortical_column::CorticalColumnRust,
29}
30
31#[pymethods]
32impl PyCorticalColumn {
33 #[new]
34 fn new(n: usize, tau: f64, dt: f64, threshold: f64, w_exc: f64, w_inh: f64, seed: u64) -> Self {
35 Self {
36 inner: cortical_column::CorticalColumnRust::new(
37 n, tau, dt, threshold, w_exc, w_inh, seed,
38 ),
39 }
40 }
41
42 fn step<'py>(
43 &mut self,
44 py: Python<'py>,
45 thalamic_input: PyReadonlyArray1<'py, f64>,
46 ) -> PyResult<Py<PyDict>> {
47 let input = thalamic_input.as_slice()?;
48 let spikes = self.inner.step(input);
49 let dict = PyDict::new(py);
50 let names = ["l4", "l23_exc", "l23_inh", "l5", "l6"];
51 for (i, name) in names.iter().enumerate() {
52 dict.set_item(*name, spikes[i].clone().into_pyarray(py))?;
53 }
54 Ok(dict.into())
55 }
56
57 fn reset(&mut self) {
58 self.inner.reset();
59 }
60}