Skip to contentSkip to Content
DocsAPI ReferenceState Accessspires_read_reservoir_state

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

ParameterTypeDescription
rspires_reservoir *Handle to the reservoir. Must not be NULL.
bufferdouble *Caller-allocated array of at least num_neurons elements. The current state is copied into this buffer. Must not be NULL.

Returns

spires_statusSPIRES_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_neurons doubles. Use spires_num_neurons to 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

Last updated on