Joseph Redmon
2016-09-25 481b57a96a9ef29b112caec1bb3e17ffb043ceae
src/utils.c
@@ -135,23 +135,20 @@
    printf("\n");
}
char *find_replace(char *str, char *orig, char *rep)
void find_replace(char *str, char *orig, char *rep, char *output)
{
    static char buffer[4096];
    static char buffer2[4096];
    static char buffer3[4096];
    char buffer[4096] = {0};
    char *p;
    if(!(p = strstr(str, orig)))  // Is 'orig' even in 'str'?
        return str;
    sprintf(buffer, "%s", str);
    if(!(p = strstr(buffer, orig))){  // Is 'orig' even in 'str'?
        sprintf(output, "%s", str);
        return;
    }
    strncpy(buffer2, str, p-str); // Copy characters from 'str' start to 'orig' st$
    buffer2[p-str] = '\0';
    *p = '\0';
    sprintf(buffer3, "%s%s%s", buffer2, rep, p+strlen(orig));
    sprintf(buffer, "%s", buffer3);
    return buffer;
    sprintf(output, "%s%s%s", buffer, rep, p+strlen(orig));
}
float sec(clock_t clocks)
@@ -414,6 +411,13 @@
    }
}
void print_statistics(float *a, int n)
{
    float m = mean_array(a, n);
    float v = variance_array(a, n);
    printf("MSE: %.6f, Mean: %.6f, Variance: %.6f\n", mse_array(a, n), m, v);
}
float variance_array(float *a, int n)
{
    int i;
@@ -585,6 +589,13 @@
    return ((float)rand()/RAND_MAX * (max - min)) + min;
}
float rand_scale(float s)
{
    float scale = rand_uniform(1, s);
    if(rand()%2) return scale;
    return 1./scale;
}
float **one_hot_encode(float *a, int n, int k)
{
    int i;