sc_neurocore_engine/bindings/
stdp_synapse.rs1use pyo3::prelude::*;
12
13use crate::synapses;
14
15pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
17 module.add_class::<StdpSynapse>()?;
18 Ok(())
19}
20
21#[pyclass(
22 name = "StdpSynapse",
23 module = "sc_neurocore_engine.sc_neurocore_engine"
24)]
25pub struct StdpSynapse {
26 inner: synapses::StdpSynapse,
27}
28
29#[pymethods]
30impl StdpSynapse {
31 #[new]
32 #[pyo3(signature = (initial_weight, data_width=16, fraction=8))]
33 fn new(initial_weight: i16, data_width: u32, fraction: u32) -> Self {
34 Self {
35 inner: synapses::StdpSynapse::new(initial_weight, data_width, fraction),
36 }
37 }
38
39 #[allow(clippy::too_many_arguments)]
40 #[pyo3(signature = (pre_spike, post_spike, a_plus=16, a_minus=-16, decay=250, w_min=0, w_max=32767))]
41 fn step(
42 &mut self,
43 pre_spike: bool,
44 post_spike: bool,
45 a_plus: i16,
46 a_minus: i16,
47 decay: i16,
48 w_min: i16,
49 w_max: i16,
50 ) {
51 let params = synapses::StdpParams {
52 a_plus,
53 a_minus,
54 decay,
55 w_min,
56 w_max,
57 };
58 self.inner.step(pre_spike, post_spike, ¶ms);
59 }
60
61 #[getter]
62 fn weight(&self) -> i16 {
63 self.inner.weight
64 }
65
66 #[setter]
67 fn set_weight(&mut self, value: i16) {
68 self.inner.weight = value;
69 }
70}