Skip to main content

sc_neurocore_engine/bindings/
cazelles_map.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Commercial license available
3// © Concepts 1996–2026 Miroslav Šotek. All rights reserved.
4// © Code 2020–2026 Miroslav Šotek. All rights reserved.
5// ORCID: 0009-0009-3560-0851
6// Contact: www.anulum.li | protoscience@anulum.li
7// SC-NeuroCore — Cazelles map PyO3 binding
8
9//! Checked Python binding for the source-faithful scalar map.
10
11use numpy::{IntoPyArray, PyArray1};
12use pyo3::exceptions::PyFloatingPointError;
13use pyo3::prelude::*;
14use pyo3::types::PyDict;
15
16use crate::neurons::CazellesMapNeuron;
17
18py_neuron_default!("CazellesMapNeuron", PyCazellesMapNeuron, CazellesMapNeuron, state x);
19
20pub(super) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
21    module.add_class::<PyCazellesMapNeuron>()?;
22    module.add_function(wrap_pyfunction!(py_cazelles_map_simulate, module)?)?;
23    Ok(())
24}
25
26/// Run the Cazelles et al. (2001) four-branch scalar map.
27#[pyfunction]
28#[pyo3(signature = (x, alpha, x0, x1, x2, x3, x4, a1, a2, a3, a4, b1, b2, b3, b4, exponent, n_steps, current))]
29#[allow(clippy::too_many_arguments)]
30fn py_cazelles_map_simulate<'py>(
31    py: Python<'py>,
32    x: f64,
33    alpha: f64,
34    x0: f64,
35    x1: f64,
36    x2: f64,
37    x3: f64,
38    x4: f64,
39    a1: f64,
40    a2: f64,
41    a3: f64,
42    a4: f64,
43    b1: f64,
44    b2: f64,
45    b3: f64,
46    b4: f64,
47    exponent: u8,
48    n_steps: usize,
49    current: f64,
50) -> PyResult<(Bound<'py, PyArray1<f64>>, i64, f64)> {
51    let mut neuron = CazellesMapNeuron {
52        x,
53        alpha,
54        exponent,
55        x0,
56        x1,
57        x2,
58        x3,
59        x4,
60        a1,
61        a2,
62        a3,
63        a4,
64        b1,
65        b2,
66        b3,
67        b4,
68    };
69    let (trace, events) = neuron
70        .simulate(n_steps, current)
71        .map_err(PyFloatingPointError::new_err)?;
72    Ok((trace.into_pyarray(py), events, neuron.x))
73}