Stateful Layer Updates#

这些函数显式接收并返回 stateful layer 的局部状态,不读取 MemoryModule 的隐式 memory,也不负责 module 生命周期。


These functions receive and return local state for stateful layers explicitly. They do not read implicit MemoryModule memory and do not manage the module lifecycle.

spikingjelly.activation_based.functional.layer.delay_step(x, queue, delay_steps)[源代码]#

API Language - 中文 | English


  • 中文

执行 Delay 的单步显式状态转移。queue 是按时间从旧到新排列的 tensor tuple。 函数返回 (y, queue_next),不原地修改输入 queue。当 delay_steps=0queue 为空时,输出 y 与输入 x alias;当已有 queue 被消费时,输出 y 与被弹出的 queue 元素 alias。

参数:
  • x (Tensor) -- 当前输入张量

  • queue (Tuple[Tensor, ...]) -- 当前延迟队列状态,元素为 tensor,按旧到新排列

  • delay_steps (int) -- 延迟时间步数,必须是非负整数

返回:

(y, queue_next),其中 y 是当前输出,queue_next 是下一状态

返回类型:

Tuple[Tensor, Tuple[Tensor, ...]]

抛出:

ValueError -- delay_steps 不是非负整数时抛出


  • English

Run one explicit Delay state transition. queue is a tuple of tensors ordered from oldest to newest. The function returns (y, queue_next) and does not mutate the input queue in place. When delay_steps=0 and queue is empty, output y aliases x; when an existing queue item is consumed, y aliases the popped queue item.

参数:
  • x (Tensor) -- Current input tensor

  • queue (Tuple[Tensor, ...]) -- Current delay-queue state with tensor elements ordered from oldest to newest

  • delay_steps (int) -- Number of delayed time steps; must be a non-negative integer

返回:

(y, queue_next), where y is the current output and queue_next is the next state

返回类型:

Tuple[Tensor, Tuple[Tensor, ...]]

抛出:

ValueError -- If delay_steps is not a non-negative integer

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.

spikingjelly.activation_based.functional.layer.neunorm_step(in_spikes, state, weight, momentum, input_scale)[源代码]#

API Language - 中文 | English


  • 中文

执行一次 NeuNorm 状态转移,返回归一化输出和下一状态。函数不读取或修改 module memory。

参数:
  • in_spikes (Tensor) -- 当前输入脉冲,shape 为 [N, C, H, W]

  • state (Tensor) -- 已物化的 NeuNorm 状态,shape 为 [N, 1, H, W]

  • weight (Tensor) -- 可广播到 in_spikes 的 NeuNorm 权重

  • momentum (float) -- 旧状态的系数

  • input_scale (float) -- 通道求和结果的系数

返回:

(output, state_next)

返回类型:

Tuple[Tensor, Tensor]


  • English

Run one NeuNorm state transition and return its normalized output and next state. The function does not read or mutate module memory.

参数:
  • in_spikes (Tensor) -- Current input spikes shaped [N, C, H, W]

  • state (Tensor) -- Materialized NeuNorm state shaped [N, 1, H, W]

  • weight (Tensor) -- NeuNorm weight broadcastable to in_spikes

  • momentum (float) -- Coefficient applied to the previous state

  • input_scale (float) -- Coefficient applied to the channel sum

返回:

(output, state_next)

返回类型:

Tuple[Tensor, Tensor]

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.

spikingjelly.activation_based.functional.layer.synapse_filter_step(x, out_i, reciprocal_tau)[源代码]#

API Language - 中文 | English


  • 中文

执行 SynapseFilter 的单步显式状态转移。函数接收已物化的输出电流状态 out_i 和确定的 reciprocal_tau = 1 / tau,返回下一时刻输出电流。 该函数不读取或修改 MemoryModule memory,也不原地修改 xout_i

参数:
  • x (Tensor) -- 当前输入脉冲或输入电流张量

  • out_i (Tensor) -- 已物化的当前输出电流 tensor state,shape/dtype/device 与 x 兼容

  • reciprocal_tau (float | Tensor) -- 时间常数倒数;非 learnable module 传入 1 / tau, learnable module 传入 w.sigmoid()

返回:

下一时刻输出电流

返回类型:

Tensor


  • English

Run one explicit SynapseFilter state transition. The function receives a materialized output-current state out_i and the selected reciprocal_tau = 1 / tau, then returns the next output current. It does not read or mutate MemoryModule memory and does not mutate x or out_i in place.

参数:
  • x (Tensor) -- Current input spike or input-current tensor

  • out_i (Tensor) -- Materialized current output-current tensor state compatible with x in shape, dtype, and device

  • reciprocal_tau (float | Tensor) -- Reciprocal time constant; non-learnable modules pass 1 / tau and learnable modules pass w.sigmoid()

返回:

Next output current

返回类型:

Tensor

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.