Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7f84fa0879f319cf97cb6acaec74dee56aa99d66
[simgrid.git] / include / xbt / matrix.h
1 /* xbt_matrix_t management functions                                        */
2
3 /* Copyright (c) 2006 Martin Quinson. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef XBT_MATRIX_H
9 #define XBT_MATRIX_H
10
11 #include "xbt/misc.h"
12 #include "xbt/function_types.h"
13
14 SG_BEGIN_DECL()
15
16      typedef struct {
17        unsigned int lines, rows;
18        unsigned long elmsize;
19
20        char *data;
21        void_f_pvoid_t free_f;
22      } s_xbt_matrix_t, *xbt_matrix_t;
23
24
25   /** @brief Retrieve the address of a cell (not its content)
26    *  @hideinitializer */
27 #define xbt_matrix_get_ptr(mat,l,c) \
28   ((void*)&(mat)->data[(c)*(mat)->lines*(mat)->elmsize + (l)*(mat)->elmsize])
29
30   /** @brief Quick retrieval of scalar content
31    *  @hideinitializer */
32 #define xbt_matrix_get_as(mat,l,c,type) *(type*)xbt_matrix_get_ptr(mat,l,c)
33
34 XBT_PUBLIC(xbt_matrix_t) xbt_matrix_new(int lines, int rows,
35                                         const unsigned long elmsize,
36                                         void_f_pvoid_t const free_f);
37 XBT_PUBLIC(xbt_matrix_t) xbt_matrix_new_sub(xbt_matrix_t from,
38                                             int lsize, int rsize,
39                                             int lpos, int rpos,
40                                             pvoid_f_pvoid_t const cpy_f);
41
42 XBT_PUBLIC(void) xbt_matrix_free(xbt_matrix_t matrix);
43 XBT_PUBLIC(void) xbt_matrix_free_voidp(void *d);
44
45 XBT_PUBLIC(void) xbt_matrix_copy_values(xbt_matrix_t dest, xbt_matrix_t src,
46                                         unsigned int lsize,
47                                         unsigned int rsize,
48                                         unsigned int lpos_dst,
49                                         unsigned int rpos_dst,
50                                         unsigned int lpos_src,
51                                         unsigned int rpos_src,
52                                         pvoid_f_pvoid_t const cpy_f);
53
54 XBT_PUBLIC(void) xbt_matrix_dump(xbt_matrix_t matrix, const char *name,
55                                  int coords, void_f_pvoid_t display_fun);
56 XBT_PUBLIC(void) xbt_matrix_dump_display_double(void *d);
57
58
59 XBT_PUBLIC(xbt_matrix_t) xbt_matrix_double_new_zeros(int lines, int rows);
60 XBT_PUBLIC(xbt_matrix_t) xbt_matrix_double_new_id(int lines, int rows);
61 XBT_PUBLIC(xbt_matrix_t) xbt_matrix_double_new_rand(int lines, int rows);
62 XBT_PUBLIC(xbt_matrix_t) xbt_matrix_double_new_seq(int lines, int rows);
63 XBT_PUBLIC(int) xbt_matrix_double_is_seq(xbt_matrix_t mat);
64 XBT_PUBLIC(xbt_matrix_t) xbt_matrix_double_new_mult(xbt_matrix_t A,
65                                                     xbt_matrix_t B);
66 XBT_PUBLIC(void) xbt_matrix_double_addmult(xbt_matrix_t A, xbt_matrix_t B,
67                                            /*OUT*/ xbt_matrix_t C);
68 SG_END_DECL()
69 #endif /* XBT_MATRIX_H */