sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
param_generator_uniform.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 The University of Manchester
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
22#include <stdfix.h>
23#include <spin1_api.h>
24#include <stdfix-full-iso.h>
27
32 accum low;
33 accum high;
34};
35
43
51 // Allocate memory for the data
53 spin1_malloc(sizeof(struct param_generator_uniform));
54 struct uniform_params *params_sdram = *region;
55
56 // Copy the parameters in
57 params->params = *params_sdram;
58 *region = &params_sdram[1];
59
60 log_debug("Uniform low = %k, high = %k",
61 params->params.low, params->params.high);
62
63 return params;
64}
65
70static void param_generator_uniform_free(void *generator) {
71 sark_free(generator);
72}
73
79static accum param_generator_uniform_generate(void *generator) {
80 // For each index, generate a uniformly distributed value
81 struct param_generator_uniform *obj = generator;
82 accum range = obj->params.high - obj->params.low;
83 return obj->params.low + (ulrbits(rng_generator(core_rng)) * range);
84}
void log_debug(const char *message,...)
General types associated with generators.
rng_t * core_rng
An RNG that is local to the current core.
static accum param_generator_uniform_generate(void *generator)
How to generate values with the uniform RNG parameter generator.
static void param_generator_uniform_free(void *generator)
How to free any data for the uniform RNG parameter generator.
static void * param_generator_uniform_initialize(void **region)
How to initialise the uniform RNG parameter generator.
The data structure to be passed around for this generator. This includes the parameters and an RNG.
The parameters that can be copied in from SDRAM.
uint32_t rng_generator(rng_t *rng)
Generate a uniformly-distributed random number.
Definition rng.c:26
Random number generator interface.
void sark_free(void *ptr)
region
spike source array region IDs in human readable form
static stdp_params params
Configuration parameters.