PageRenderTime 14ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/list_vector.i

#
Swig | 153 lines | 127 code | 22 blank | 4 comment | 0 complexity | 57be3d35b9744f80c86dbad4472ee859 MD5 | raw file
  1/* -*- c -*- */
  2
  3%module list_vector
  4
  5%include "list-vector.i"
  6
  7%multiple_values
  8
  9/* The ordinary, well behaved multi-typemap. */
 10double sum_list(int LISTLENINPUT, double *LISTINPUT);
 11double sum_vector(int VECTORLENINPUT, double *VECTORINPUT);
 12void one_to_seven_list(int *LISTLENOUTPUT, int **LISTOUTPUT);
 13void one_to_seven_vector(int *VECTORLENOUTPUT, int **VECTOROUTPUT);
 14
 15/* Variants with `size_t' instead of `int' length.  */
 16double sum_list2(size_t LISTLENINPUT, double *LISTINPUT);
 17double sum_vector2(size_t VECTORLENINPUT, double *VECTORINPUT);
 18void one_to_seven_list2(size_t *LISTLENOUTPUT, int **LISTOUTPUT);
 19void one_to_seven_vector2(size_t *VECTORLENOUTPUT, int **VECTOROUTPUT);
 20
 21/* Parallel variants */
 22
 23double sum_lists(int PARALLEL_LISTLENINPUT,
 24		 double *PARALLEL_LISTINPUT,
 25		 int *PARALLEL_LISTINPUT,
 26		 int *PARALLEL_LISTINPUT);
 27double sum_lists2(size_t PARALLEL_LISTLENINPUT,
 28		 double *PARALLEL_LISTINPUT,
 29		 int *PARALLEL_LISTINPUT,
 30		 int *PARALLEL_LISTINPUT);
 31void produce_lists(int *PARALLEL_VECTORLENOUTPUT,
 32		   int **PARALLEL_VECTOROUTPUT,
 33		   int **PARALLEL_VECTOROUTPUT,
 34		   double **PARALLEL_VECTOROUTPUT);
 35
 36%{
 37  double sum_list(int length, double *item)
 38  {
 39    int i;
 40    double res = 0.0;
 41    for (i = 0; i<length; i++)
 42      res += item[i];
 43    return res;
 44  }
 45
 46  double sum_list2(size_t length, double *item)
 47  {
 48    size_t i;
 49    double res = 0.0;
 50    for (i = 0; i<length; i++)
 51      res += item[i];
 52    return res;
 53  }
 54
 55
 56  double sum_vector(int length, double *item)
 57  {
 58    int i;
 59    double res = 0.0;
 60    for (i = 0; i<length; i++)
 61      res += item[i];
 62    return res;
 63  }
 64
 65  double sum_vector2(size_t length, double *item)
 66  {
 67    size_t i;
 68    double res = 0.0;
 69    for (i = 0; i<length; i++)
 70      res += item[i];
 71    return res;
 72  }
 73
 74
 75  void one_to_seven_list(int *length_p, int **list_p)
 76  {
 77    int i;
 78    *length_p = 7;
 79    *list_p = malloc(7 * sizeof(int));
 80    for (i = 0; i<7; i++)
 81      (*list_p)[i] = i+1;
 82  }
 83
 84   void one_to_seven_list2(size_t *length_p, int **list_p)
 85  {
 86    size_t i;
 87    *length_p = 7;
 88    *list_p = malloc(7 * sizeof(int));
 89    for (i = 0; i<7; i++)
 90      (*list_p)[i] = i+1;
 91  }
 92
 93   void one_to_seven_vector(int *length_p, int **list_p)
 94  {
 95    int i;
 96    *length_p = 7;
 97    *list_p = malloc(7 * sizeof(int));
 98    for (i = 0; i<7; i++)
 99      (*list_p)[i] = i+1;
100  }
101
102  void one_to_seven_vector2(size_t *length_p, int **list_p)
103  {
104    size_t i;
105    *length_p = 7;
106    *list_p = malloc(7 * sizeof(int));
107    for (i = 0; i<7; i++)
108      (*list_p)[i] = i+1;
109  }
110
111double sum_lists(int len,
112		 double *list1,
113		 int *list2,
114		 int *list3)
115{
116  int i;
117  double sum = 0.0;
118  for (i = 0; i<len; i++)
119    sum += (list1[i] + list2[i] + list3[i]);
120  return sum;
121}
122
123double sum_lists2(size_t len,
124		  double *list1,
125		  int *list2,
126		  int *list3)
127{
128  size_t i;
129  double sum = 0.0;
130  for (i = 0; i<len; i++)
131    sum += (list1[i] + list2[i] + list3[i]);
132  return sum;
133}
134
135void produce_lists(int *len_p,
136		   int **list1_p,
137		   int **list2_p,
138		   double **list3_p)
139{
140  int i;
141  *len_p = 5;
142  *list1_p = malloc(sizeof(int) * 5);
143  *list2_p = malloc(sizeof(int) * 5);
144  *list3_p = malloc(sizeof(double) * 5);
145  for (i = 0; i<5; i++) {
146    (*list1_p)[i] = i;
147    (*list2_p)[i] = i*i;
148    (*list3_p)[i] = 1.5*i;
149  }
150}
151
152  
153%}