PandA-2024.02
common.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stddef.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 
8 typedef float real_t;
9 
10 real_t* make_empty(size_t size)
11 {
12  return (real_t*)calloc(size, sizeof(real_t));
13 }
14 
15 real_t* make_random(size_t size)
16 {
17  real_t* result = make_empty(size);
18  if (!result) return NULL;
19 
20  real_t* end = result + size;
21  for (real_t* ptr = result; ptr != end; ++ptr) {
22  *ptr = ((real_t)random() / RAND_MAX) * (real_t)(2) - (real_t)(1);
23  }
24 
25  return result;
26 }
27 
28 real_t* make_copy(const real_t* data, size_t size)
29 {
30  real_t* result = make_empty(size);
31  if (!result) return NULL;
32 
33  memcpy(result, data, size*sizeof(real_t));
34  return result;
35 }
36 
37 real_t mse(const real_t* a, const real_t* b, size_t size)
38 {
39  real_t accu = 0;
40  const real_t* a_end = a + size;
41  for (; a != a_end; ++a,++b) {
42  real_t err = (*a - *b);
43  accu += err * err;
44  }
45  return accu / (real_t)(size);
46 }
real_t * make_random(size_t size)
Definition: common.h:15
#define NULL
real_t * make_empty(size_t size)
Definition: common.h:10
float real_t
Definition: common.h:8
real_t * make_copy(const real_t *data, size_t size)
Definition: common.h:28
real_t mse(const real_t *a, const real_t *b, size_t size)
Definition: common.h:37
int result[SIZE]
Definition: adpcm.c:800

Generated on Mon Feb 12 2024 13:02:48 for PandA-2024.02 by doxygen 1.8.13