ARB
AP_matrix.hxx
Go to the documentation of this file.
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_STRING_H
18 #include <arb_string.h>
19 #endif
20 
21 #define ap_assert(cond) arb_assert(cond)
22 
23 CONSTEXPR_INLINE long matrix_halfsize(long entries, bool inclusive_diagonal) {
24  return inclusive_diagonal ? entries*(entries+1)/2L : (entries-1)*entries/2L;
25 }
26 
27 typedef double AP_FLOAT;
28 
29 class AW_root;
30 class AW_window;
31 
32 class AP_smatrix : virtual Noncopyable {
33  // Symmetrical Matrix (upper triangular matrix)
34 
35  size_t Size;
36  AP_FLOAT **m; // m[i][j] i <= j !!!!
37 
38 public:
39 
40  explicit AP_smatrix(size_t si);
41  ~AP_smatrix();
42 
43  void set(size_t i, size_t j, AP_FLOAT val) { if (i>j) m[i][j] = val; else m[j][i] = val; };
44 
45  AP_FLOAT fast_get(size_t i, size_t j) const { ap_assert(i>=j); return m[i][j]; };
46  AP_FLOAT get(size_t i, size_t j) const { if (i>j) return m[i][j]; else return m[j][i]; };
47 
48  AP_FLOAT get_max_value() const;
49 
50  size_t size() const { return Size; }
51 };
52 
53 class AP_matrix : virtual Noncopyable {
54  AP_FLOAT **m;
55  long size;
56 public:
57  AP_matrix(long si);
58  ~AP_matrix();
59 
60  void set(int i, int j, AP_FLOAT val) { m[i][j] = val; };
61  AP_FLOAT get(int i, int j) { return m[i][j]; };
62 
63  long get_size() const { return size; }
64 };
65 
66 class AP_userdef_matrix : public AP_matrix { // derived from Noncopyable
67  char **x_description; // optional description, strdupped
68  char **y_description;
69  char *awar_prefix;
70 
71  void set_desc(char**& which_desc, int idx, const char *desc);
72 
73 public:
74  AP_userdef_matrix(long si, const char *awar_prefix_)
75  : AP_matrix(si),
76  x_description(NULp),
77  y_description(NULp),
78  awar_prefix(ARB_strdup(awar_prefix_))
79  {}
81 
82  void normize(); // set average non diag element to 1.0 (only for described elements)
83 
84  void set_x_description(int idx, const char *desc) { set_desc(x_description, idx, desc); }
85  void set_y_description(int idx, const char *desc) { set_desc(y_description, idx, desc); }
86  void set_descriptions(int idx, const char *desc) { set_x_description(idx, desc); set_y_description(idx, desc); }
87 
88  void create_awars(AW_root *awr);
89  void update_from_awars(AW_root *awr);
90  void create_input_fields(AW_window *aww);
91 };
92 
93 #else
94 #error AP_matrix.hxx included twice
95 #endif // AP_MATRIX_HXX
AP_FLOAT get_max_value() const
Definition: AP_matrix.cxx:43
void set_x_description(int idx, const char *desc)
Definition: AP_matrix.hxx:84
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
void set(int i, int j, AP_FLOAT val)
Definition: AP_matrix.hxx:60
void create_input_fields(AW_window *aww)
Definition: AP_matrix.cxx:114
double AP_FLOAT
Definition: AP_matrix.hxx:27
#define ap_assert(cond)
Definition: AP_matrix.hxx:21
void set(size_t i, size_t j, AP_FLOAT val)
Definition: AP_matrix.hxx:43
#define CONSTEXPR_INLINE
Definition: cxxforward.h:92
AP_smatrix(size_t si)
Definition: AP_matrix.cxx:24
void set_descriptions(int idx, const char *desc)
Definition: AP_matrix.hxx:86
AP_matrix(long si)
Definition: AP_matrix.cxx:56
void update_from_awars(AW_root *awr)
Definition: AP_matrix.cxx:99
CONSTEXPR_INLINE long matrix_halfsize(long entries, bool inclusive_diagonal)
Definition: AP_matrix.hxx:23
void create_awars(AW_root *awr)
Definition: AP_matrix.cxx:79
AP_FLOAT fast_get(size_t i, size_t j) const
Definition: AP_matrix.hxx:45
#define NULp
Definition: cxxforward.h:97
long get_size() const
Definition: AP_matrix.hxx:63
AP_userdef_matrix(long si, const char *awar_prefix_)
Definition: AP_matrix.hxx:74
void set_y_description(int idx, const char *desc)
Definition: AP_matrix.hxx:85
size_t size() const
Definition: AP_matrix.hxx:50