forked from khigashi1987/Labeled-LDA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.c
37 lines (32 loc) · 769 Bytes
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
util.c
*/
#include <stdio.h>
#include <string.h>
#include "util.h"
char *strconcat(const char *s, const char *t){
static char z[BUFSIZ];
strcpy(z, s);
strcat(z, t);
return z;
}
void normalize_matrix_row(double **dst, double **src, int rows, int cols){
int i, j;
double z;
for(i = 0;i < rows;i++){
for(j = 0, z = 0;j < cols;j++)
z += src[i][j];
for(j = 0;j < cols;j++)
dst[i][j] = src[i][j] / z;
}
}
void normalize_matrix_col(double **dst, double **src, int rows, int cols){
int i, j;
double z;
for(j = 0;j < cols;j++){
for(i = 0, z = 0;i < rows;i++)
z += src[i][j];
for(i = 0;i < rows;i++)
dst[i][j] = src[i][j] / z;
}
}