summaryrefslogtreecommitdiff
path: root/src/bin_values.c
blob: 70009c1608be170c836b35b9e2479cb12fdc9aac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include "fracture.h"

double *bin_values(graph_t *network, unsigned int width, double *values) {
	double *binned = calloc(pow(width, 2), sizeof(double));
	unsigned int *num_binned = calloc(pow(width, 2), sizeof(unsigned int));
	for (unsigned int i = 0; i < network->ne; i++) {
		if (values[i] != 0) {
			unsigned int x = ((int)(network->ex[2 * i] * width)) % width;
			unsigned int y = ((int)(network->ex[2 * i + 1] * width)) % width;
			binned[width * x + y] += fabs(values[i]);
			num_binned[width * x + y]++;
		}
	}

	for (unsigned int i = 0; i < pow(width, 2); i++) {
		if (num_binned[i] != 0) {
			binned[i] /= num_binned[i];
		}
	}

	return binned;
}