sc_neurocore_engine/bindings/trivial/
theta.rs1use numpy::{IntoPyArray, PyArray1};
10use pyo3::exceptions::PyFloatingPointError;
11use pyo3::prelude::*;
12use pyo3::types::PyDict;
13
14use crate::neurons;
15
16py_neuron_default!("ThetaNeuron", PyThetaNeuron, neurons::ThetaNeuron, state theta);
17
18type ThetaCompletePacket<'py> = (Bound<'py, PyArray1<f64>>, Bound<'py, PyArray1<u8>>, f64);
19
20#[pyfunction]
21#[pyo3(signature = (theta, dt, n_steps, current))]
22fn theta_simulate_complete<'py>(
23 py: Python<'py>,
24 theta: f64,
25 dt: f64,
26 n_steps: usize,
27 current: f64,
28) -> PyResult<ThetaCompletePacket<'py>> {
29 let model = neurons::ThetaNeuron { theta, dt };
30 let (phase, events, final_theta) = model
31 .simulate_complete(n_steps, current)
32 .map_err(|error| PyFloatingPointError::new_err(error.to_string()))?;
33 Ok((phase.into_pyarray(py), events.into_pyarray(py), final_theta))
34}
35
36pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
38 module.add_class::<PyThetaNeuron>()?;
39 module.add_function(wrap_pyfunction!(theta_simulate_complete, module)?)?;
40 Ok(())
41}