1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : AP_matrix.hxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #ifndef AP_MATRIX_HXX |
---|
12 | #define AP_MATRIX_HXX |
---|
13 | |
---|
14 | #ifndef ARBTOOLS_H |
---|
15 | #include <arbtools.h> |
---|
16 | #endif |
---|
17 | #ifndef ARB_ASSERT_H |
---|
18 | #include <arb_assert.h> |
---|
19 | #endif |
---|
20 | |
---|
21 | #define ap_assert(cond) arb_assert(cond) |
---|
22 | |
---|
23 | typedef double AP_FLOAT; |
---|
24 | |
---|
25 | class AW_root; |
---|
26 | class AW_window; |
---|
27 | |
---|
28 | class AP_smatrix : virtual Noncopyable { |
---|
29 | // Symmetrical Matrix (upper triangular matrix) |
---|
30 | |
---|
31 | size_t Size; |
---|
32 | AP_FLOAT **m; // m[i][j] i <= j !!!! |
---|
33 | |
---|
34 | public: |
---|
35 | |
---|
36 | explicit AP_smatrix(size_t si); |
---|
37 | ~AP_smatrix(); |
---|
38 | |
---|
39 | void set(size_t i, size_t j, AP_FLOAT val) { if (i>j) m[i][j] = val; else m[j][i] = val; }; |
---|
40 | |
---|
41 | AP_FLOAT fast_get(size_t i, size_t j) const { ap_assert(i>=j); return m[i][j]; }; |
---|
42 | AP_FLOAT get(size_t i, size_t j) const { if (i>j) return m[i][j]; else return m[j][i]; }; |
---|
43 | |
---|
44 | AP_FLOAT get_max_value() const; |
---|
45 | |
---|
46 | size_t size() const { return Size; } |
---|
47 | }; |
---|
48 | |
---|
49 | class AP_matrix : virtual Noncopyable { |
---|
50 | AP_FLOAT **m; |
---|
51 | long size; |
---|
52 | char **x_description; // optional description, strdupped |
---|
53 | char **y_description; |
---|
54 | |
---|
55 | void set_desc(char**& which_desc, int idx, const char *desc); |
---|
56 | |
---|
57 | public: |
---|
58 | AP_matrix(long si); |
---|
59 | ~AP_matrix(); |
---|
60 | |
---|
61 | void create_awars(AW_root *awr, const char *awar_prefix); |
---|
62 | void read_awars(AW_root *awr, const char *awar_prefix); |
---|
63 | void normize(); // set average non diag element to 1.0 (only for described elements) |
---|
64 | void create_input_fields(AW_window *aww, const char *awar_prefix); |
---|
65 | |
---|
66 | void set_x_description(int idx, const char *desc) { set_desc(x_description, idx, desc); } |
---|
67 | void set_y_description(int idx, const char *desc) { set_desc(y_description, idx, desc); } |
---|
68 | void set_descriptions(int idx, const char *desc) { set_x_description(idx, desc); set_y_description(idx, desc); } |
---|
69 | |
---|
70 | void set(int i, int j, AP_FLOAT val) { m[i][j] = val; }; |
---|
71 | AP_FLOAT get(int i, int j) { return m[i][j]; }; |
---|
72 | }; |
---|
73 | |
---|
74 | #else |
---|
75 | #error AP_matrix.hxx included twice |
---|
76 | #endif // AP_MATRIX_HXX |
---|