Skip to contentSkip to Content
DocsAPI ReferenceState Accessspires_copy_reservoir_state

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

ParameterTypeDescription
rspires_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 malloc and owned by the caller. You must call free() on the pointer when it is no longer needed.
  • Snapshot semantics. The returned array is a copy. Subsequent calls to spires_step or 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_state to 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

Last updated on