spires_read_weights
Read the reservoir’s recurrent weight matrix into a caller-provided buffer.
Signature
spires_status spires_read_weights(const spires_reservoir *r, double *buffer);Parameters
| Parameter | Type | Description |
|---|---|---|
r | const spires_reservoir * | Handle to the reservoir. Must not be NULL. |
buffer | double * | Output buffer of length num_neurons * num_neurons. Must not be NULL. Filled in row-major order: buffer[i * num_neurons + j] is the synaptic weight from neuron j to neuron i. |
Returns
spires_status — SPIRES_OK on success. On failure:
SPIRES_ERR_INVALID_ARG—rorbufferisNULL.
Example
size_t N = spires_num_neurons(r);
double *W = malloc(N * N * sizeof(double));
if (!W) return 1;
if (spires_read_weights(r, W) != SPIRES_OK) {
free(W);
return 1;
}
/* Inspect a specific connection */
printf("W[0->1] = %.6f\n", W[1 * N + 0]);
free(W);Notes
- No allocation. Unlike
spires_copy_weights, this function writes into a buffer you provide. It is suitable for use in tight loops where you want to avoid repeatedmalloc/freecalls. - Buffer size. The caller must ensure
bufferis at leastnum_neurons * num_neurons * sizeof(double)bytes. Usespires_num_neuronsto querynum_neuronsbefore allocating. - Row-major layout.
buffer[i * N + j]is the connection weight from neuronjto neuroni. Zero entries indicate no connection (sparse matrix stored dense).
See Also
- spires_copy_weights — allocating variant that returns a fresh buffer.
- spires_coarse_grain — compress the reservoir using a weight threshold.
- spires_num_neurons — query the dimension of the weight matrix.
Last updated on