spires_copy_reservoir_state
Return a heap-allocated copy of the reservoir’s current neuron state vector.
Signature
double *spires_copy_reservoir_state(spires_reservoir *r);Parameters
| Parameter | Type | Description |
|---|---|---|
r | spires_reservoir * | Handle to the reservoir. Must not be NULL. |
Returns
double * — Pointer to a newly malloc-allocated array of length num_neurons. Element result[j] is the current state (e.g., membrane potential) of neuron j.
Returns NULL if r is NULL or if memory allocation fails.
Example
/* Step the reservoir */
spires_step(r, input_vec);
/* Snapshot the state */
double *state = spires_copy_reservoir_state(r);
if (!state) {
fprintf(stderr, "failed to copy state\n");
return 1;
}
size_t N = spires_num_neurons(r);
for (size_t j = 0; j < N; j++) {
printf("neuron %zu: %.6f\n", j, state[j]);
}
free(state); /* caller must free */Notes
- Ownership. The returned array is allocated with
mallocand owned by the caller. You must callfree()on the pointer when it is no longer needed. - Snapshot semantics. The returned array is a copy. Subsequent calls to
spires_stepor other mutating functions do not affect the copied data. - Allocation-free alternative. If you want to avoid heap allocation (e.g., in a tight loop), use
spires_read_reservoir_stateto copy into a pre-allocated buffer instead. - Thread safety. Do not call this function on a reservoir that is concurrently being mutated by another thread.
See Also
- spires_read_reservoir_state — copy state into a caller-provided buffer (no allocation).
- spires_compute_output — compute the readout output from the current state.
- spires_num_neurons — query the length of the state vector.
Last updated on