27 #include "../lib/cJSON/cJSON.h"
28 #include "../lib/dSFMT/dSFMT.h"
60 clamp(
const double a,
const double min,
const double max)
62 return (a < min) ? min : (a > max) ? max : a;
73 clamp_int(
const int a,
const int min,
const int max)
75 return (a < min) ? min : (a > max) ? max : a;
89 printf(
"argmax() error: N < 1\n");
94 for (
int i = 1; i < N; ++i) {
113 for (
int i = 0; i < bits; ++i) {
117 for (
int i = 0; i < bits; ++i) {
121 int a = (int) (f * pow(2, bits));
122 for (
int i = 0; i < bits; ++i) {
123 binary[bits - 1 - i] = (a % 2) +
'0';
152 const double tol = 1e-5;
153 for (
int i = 0; i < size; ++i) {
154 if (arr1[i] < arr2[i] - tol || arr1[i] > arr2[i] + tol) {
171 for (
int i = 0; i < size; ++i) {
172 if (arr1[i] != arr2[i]) {
static int clamp_int(const int a, const int min, const int max)
Returns an integer clamped within the specified range.
static double clamp(const double a, const double min, const double max)
Returns a float clamped within the specified range.
static bool check_array_eq_int(const int *arr1, const int *arr2, int size)
Checks whether two integer arrays are equal.
int rand_uniform_int(const int min, const int max)
Returns a uniform random integer [min,max] not inclusive of max.
double rand_normal(const double mu, const double sigma)
Returns a random Gaussian with specified mean and standard deviation.
double rand_uniform(const double min, const double max)
Returns a uniform random float [min,max].
static bool check_array_eq(const double *arr1, const double *arr2, int size)
Checks whether two double arrays are approximately equal.
void rand_init(void)
Initialises the pseudo-random number generator.
void utils_json_parse_check(const cJSON *json)
Checks whether JSON parsed correctly.
static void float_to_binary(const double f, char *binary, const int bits)
Generates a binary string from a float.
void rand_init_seed(const uint32_t seed)
Initialises the pseudo-random number generator with a fixed seed.
static void catch_error(const char *ret)
Catches parameter value errors.
static int argmax(const double *X, const int N)
Returns the index of the largest element in vector X.