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 #ifndef MATRIX_H
21 #include <matrix.h>
22 #endif
23 
24 #define ap_assert(cond) arb_assert(cond)
25 
26 CONSTEXPR_INLINE long matrix_halfsize(long entries, bool inclusive_diagonal) {
27  return triangular_number(inclusive_diagonal ? entries : entries-1);
28 }
29 
30 typedef double AP_FLOAT;
31 
32 class AW_root;
33 class AW_window;
34 
35 struct AP_smatrix : public symmetric_matrix<AP_FLOAT> {
36  AP_smatrix(size_t Size_) : symmetric_matrix<AP_FLOAT>(Size_) {}
37 };
38 
39 class AP_matrix : virtual Noncopyable {
40  AP_FLOAT **m;
41  long size;
42 public:
43  AP_matrix(long si);
44  ~AP_matrix();
45 
46  void set(int i, int j, AP_FLOAT val) { m[i][j] = val; };
47  AP_FLOAT get(int i, int j) { return m[i][j]; };
48 
49  long get_size() const { return size; }
50 };
51 
52 class AP_userdef_matrix : public AP_matrix { // derived from Noncopyable
53  char **x_description; // optional description, strdupped
54  char **y_description;
55  char *awar_prefix;
56 
57  void set_desc(char**& which_desc, int idx, const char *desc);
58 
59 public:
60  AP_userdef_matrix(long si, const char *awar_prefix_)
61  : AP_matrix(si),
62  x_description(NULp),
63  y_description(NULp),
64  awar_prefix(ARB_strdup(awar_prefix_))
65  {}
67 
68  void normize(); // set average non diag element to 1.0 (only for described elements)
69 
70  void set_x_description(int idx, const char *desc) { set_desc(x_description, idx, desc); }
71  void set_y_description(int idx, const char *desc) { set_desc(y_description, idx, desc); }
72  void set_descriptions(int idx, const char *desc) { set_x_description(idx, desc); set_y_description(idx, desc); }
73 
74  void create_awars(AW_root *awr);
75  void update_from_awars(AW_root *awr);
76  void create_input_fields(AW_window *aww);
77 };
78 
79 #else
80 #error AP_matrix.hxx included twice
81 #endif // AP_MATRIX_HXX
void set_x_description(int idx, const char *desc)
Definition: AP_matrix.hxx:70
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
void set(int i, int j, AP_FLOAT val)
Definition: AP_matrix.hxx:46
void create_input_fields(AW_window *aww)
Definition: AP_matrix.cxx:82
CONSTEXPR_INLINE long triangular_number(const long N)
Definition: triangular.h:18
double AP_FLOAT
Definition: AP_matrix.hxx:30
AP_smatrix(size_t Size_)
Definition: AP_matrix.hxx:36
#define CONSTEXPR_INLINE
Definition: cxxforward.h:111
void set_descriptions(int idx, const char *desc)
Definition: AP_matrix.hxx:72
AP_matrix(long si)
Definition: AP_matrix.cxx:24
void update_from_awars(AW_root *awr)
Definition: AP_matrix.cxx:67
CONSTEXPR_INLINE long matrix_halfsize(long entries, bool inclusive_diagonal)
Definition: AP_matrix.hxx:26
void create_awars(AW_root *awr)
Definition: AP_matrix.cxx:47
#define NULp
Definition: cxxforward.h:116
long get_size() const
Definition: AP_matrix.hxx:49
AP_userdef_matrix(long si, const char *awar_prefix_)
Definition: AP_matrix.hxx:60
void set_y_description(int idx, const char *desc)
Definition: AP_matrix.hxx:71