spires_read_reservoir_state
Copy the reservoir’s current neuron state vector into a caller-provided buffer.
Signature
spires_status spires_read_reservoir_state(spires_reservoir *r, double *buffer);Parameters
| Parameter | Type | Description |
|---|---|---|
r | spires_reservoir * | Handle to the reservoir. Must not be NULL. |
buffer | double * | Caller-allocated array of at least num_neurons elements. The current state is copied into this buffer. Must not be NULL. |
Returns
spires_status — SPIRES_OK on success, or SPIRES_ERR_INVALID_ARG if r or buffer is NULL.
Example
size_t N = spires_num_neurons(r);
double *buf = malloc(N * sizeof(double));
for (size_t t = 0; t < series_length; t++) {
spires_step(r, &input[t * num_inputs]);
spires_read_reservoir_state(r, buf);
/* Process the state without allocation overhead */
double norm = 0.0;
for (size_t j = 0; j < N; j++) {
norm += buf[j] * buf[j];
}
printf("t=%zu ||x|| = %.6f\n", t, sqrt(norm));
}
free(buf);Notes
- No allocation. Unlike
spires_copy_reservoir_state, this function performs no heap allocation. It is suitable for use in performance-critical loops where allocation overhead or fragmentation is a concern. - Buffer sizing. The buffer must hold at least
num_neuronsdoubles. Usespires_num_neuronsto query the required size. Writing beyond the buffer boundary is undefined behavior. - Snapshot semantics. The data is copied out of the reservoir. Subsequent mutations to the reservoir do not affect the buffer contents.
- Thread safety. Do not call this function on a reservoir that is concurrently being mutated by another thread.
See Also
- spires_copy_reservoir_state — returns a malloc’d copy (simpler API, but allocates).
- spires_compute_output — compute the readout output.
- spires_num_neurons — query the required buffer size.
Last updated on