Logo AND Algorithmique Numérique Distribuée

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