Logo AND Algorithmique Numérique Distribuée

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