-
Notifications
You must be signed in to change notification settings - Fork 1
/
dblist.h
66 lines (56 loc) · 2.17 KB
/
dblist.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
dblist.h
Copyright (C) 2019 Dongsoo S. Kim
*/
#ifndef DBLIST_H
#define DBLIST_H
#include <stdio.h>
#include <stdbool.h>
#define MAX_GEN_ARGS 2
typedef struct generator_t {
int acnt;
double args[MAX_GEN_ARGS];
double (*func)();
} generator;
typedef struct dblist_t {
int num;
double *val;
} dblist;
dblist dbl_create (int n);
dblist dbl_make (int n, double *vlist);
void dbl_clean (dblist *v);
int dbl_print (FILE *fp, const dblist v, char *format);
int dbl_scan (FILE *fp, dblist *v);
dblist dbl_zeros (int n);
dblist dbl_ones (int n);
dblist dbl_rand_normal (int n, double mean, double stddev);
dblist dbl_rand_uniform(int n, double min, double max);
dblist dbl_rand_exp (int n, double mean);
dblist dbl_range (double start, double end, double delta);
double dbl_sum (const dblist v);
double dbl_mean (const dblist v);
double dbl_stddev (const dblist v);
int dbl_count (const dblist v);
/* flexible random generator */
generator init_norm(double mean, double stddev);
generator init_unif(double min, double max);
generator init_expo(double mean);
dblist dbl_random(int n, generator gen);
dblist map (double (*func)(double, void *), const dblist v, void *arg);
double reduce (double (*func)(double, double, void *), const dblist v, void *arg);
dblist filter (bool (*func)(double, void *), const dblist v, void *arg);
dblist shift_up (const dblist v, int n);
dblist shift_down (const dblist v, int n);
dblist add (const dblist a, const dblist b);
dblist prod (const dblist a, const dblist b);
double dot_prod (const dblist a, const dblist b);
double poly_eval_x (const dblist poly, double x);
dblist poly_eval_xlist (const dblist poly, const dblist xlist);
dblist poly_integrate (const dblist poly);
dblist poly_derive (const dblist poly);
dblist poly_roots (const dblist poly);
dblist poly_poly (const dblist roots);
dblist poly_add (const dblist polya, const dblist polyb);
dblist poly_mul (const dblist polya, const dblist polyb);
dblist poly_div (const dblist polya, const dblist polyb, dblist *mod);
#endif