LAL  7.5.0.1-b72065a
SWIGTest.c
Go to the documentation of this file.
1 //
2 // Copyright (C) 2011--2014 Karl Wette
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with with program; see the file COPYING. If not, write to the
16 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 // MA 02110-1301 USA
18 //
19 
20 // Code for SWIG tests of the LAL bindings.
21 // Author: Karl Wette
22 
23 #include <string.h>
24 #include "swiglal_config.h"
25 #include <lal/LALMalloc.h>
26 #include <lal/SWIGLALTest.h>
27 #include <lal/XLALError.h>
28 #include <lal/Date.h>
29 
30 #ifdef __GNUC__
31 #define UNUSED __attribute__ ((unused))
32 #else
33 #define UNUSED
34 #endif
35 
36 // Test various combinations of 1D and 2D fixed arrays
37 // with structs, struct/enum type, and global variables.
39  2, 3, 5.7, 0.0, "abcde", {1, 2, 3}, {{4, 5, 6}, {7, 8, 9}},
41 };
49 UNUSED const INT4 swig_lal_test_INT4_const_vector[3] = {1, 2, 4};
50 UNUSED const INT4 swig_lal_test_INT4_const_matrix[2][3] = {{1, 2, 4}, {2, 4, 8}};
55 
56 // Test fixed and dynamic arrays typemaps.
57 void swig_lal_test_copyin_array1( REAL8 INPUT[3], REAL8 scale, REAL8 OUTPUT[3] )
58 {
59  for ( int i = 0; i < 3; ++i ) {
60  OUTPUT[i] = scale * INPUT[i];
61  }
62 }
63 void swig_lal_test_copyin_array2( INT4 INPUT[3][2], INT4 scale, INT4 OUTPUT[3][2] )
64 {
65  for ( int i = 0; i < 3; ++i ) {
66  for ( int j = 0; j < 2; ++j ) {
67  OUTPUT[i][j] = scale * INPUT[i][j];
68  }
69  }
70 }
71 void swig_lal_test_copyin_array3( LIGOTimeGPS INPUT[2], REAL8 scale, LIGOTimeGPS OUTPUT[2] )
72 {
73  for ( int i = 0; i < 2; ++i ) {
74  OUTPUT[i] = INPUT[i];
75  XLALGPSMultiply( &OUTPUT[i], scale );
76  }
77 }
78 
79 // Test input views of string array structs.
81 {
82  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length ) {
83  return 0;
84  }
85  for ( size_t i = 0; i < viewin->length; ++i ) {
86  XLALFree( copyout->data[i] );
87  copyout->data[i] = XLALStringDuplicate( viewin->data[i] );
88  }
89  return 1;
90 }
92 {
93  if ( !copyinout || !copyinout->data ) {
94  return 0;
95  }
96  for ( size_t i = 0; i < copyinout->length; ++i ) {
97  XLALStringToUpperCase( copyinout->data[i] );
98  }
99  return 1;
100 }
101 
102 // Test input views of numeric array structs.
104 {
105  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length ) {
106  return 0;
107  }
108  for ( size_t i = 0; i < viewin->length; ++i ) {
109  copyout->data[i] = viewin->data[i];
110  }
111  return 1;
112 }
114 {
115  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->length != viewin->length ) {
116  return 0;
117  }
118  for ( size_t i = 0; i < viewin->length; ++i ) {
119  viewout->data[i] = viewin->data[i];
120  viewin->data[i] = viewin->data[i] * 2.0;
121  }
122  return 1;
123 }
125 {
126  if ( !copyinout || !copyinout->data ) {
127  return 0;
128  }
129  for ( size_t i = 0; i < copyinout->length; ++i ) {
130  copyinout->data[i] = copyinout->data[i] * 3.0;
131  }
132  return 1;
133 }
135 {
136  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length ) {
137  return 0;
138  }
139  for ( size_t i = 0; i < viewin->length; ++i ) {
140  copyout->data[i] = viewin->data[i];
141  }
142  return 1;
143 }
145 {
146  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->length != viewin->length ) {
147  return 0;
148  }
149  for ( size_t i = 0; i < viewin->length; ++i ) {
150  viewout->data[i] = viewin->data[i];
151  viewin->data[i] = viewin->data[i] * 2.0;
152  }
153  return 1;
154 }
156 {
157  if ( !copyinout || !copyinout->data ) {
158  return 0;
159  }
160  for ( size_t i = 0; i < copyinout->length; ++i ) {
161  copyinout->data[i] = copyinout->data[i] * 3.0;
162  }
163  return 1;
164 }
166 {
167  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length ) {
168  return 0;
169  }
170  for ( size_t i = 0; i < viewin->length; ++i ) {
171  copyout->data[i] = viewin->data[i];
172  }
173  return 1;
174 }
176 {
177  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->length != viewin->length ) {
178  return 0;
179  }
180  for ( size_t i = 0; i < viewin->length; ++i ) {
181  viewout->data[i] = viewin->data[i];
182  viewin->data[i] = crectf( crealf( viewin->data[i] ) * 2.0, cimagf( viewin->data[i] ) * 2.0 );
183  }
184  return 1;
185 }
187 {
188  if ( !copyinout || !copyinout->data ) {
189  return 0;
190  }
191  for ( size_t i = 0; i < copyinout->length; ++i ) {
192  copyinout->data[i] = copyinout->data[i] * 3.0;
193  }
194  return 1;
195 }
197 {
198  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length ) {
199  return 0;
200  }
201  for ( size_t i = 0; i < viewin->length; ++i ) {
202  copyout->data[i] = viewin->data[i];
203  }
204  return 1;
205 }
207 {
208  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->length != viewin->length ) {
209  return 0;
210  }
211  for ( size_t i = 0; i < viewin->length; ++i ) {
212  viewout->data[i] = viewin->data[i];
213  viewin->data[i] = crect( creal( viewin->data[i] ) * 2.0, cimag( viewin->data[i] ) * 2.0 );
214  }
215  return 1;
216 }
218 {
219  if ( !copyinout || !copyinout->data ) {
220  return 0;
221  }
222  for ( size_t i = 0; i < copyinout->length; ++i ) {
223  copyinout->data[i] = copyinout->data[i] * 3.0;
224  }
225  return 1;
226 }
228 {
229  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length || copyout->vectorLength != viewin->vectorLength ) {
230  return 0;
231  }
232  const size_t n = viewin->vectorLength;
233  for ( size_t i = 0; i < viewin->length; ++i ) {
234  for ( size_t j = 0; j < n; ++j ) {
235  copyout->data[i * n + j] = viewin->data[i * n + j];
236  }
237  }
238  return 1;
239 }
241 {
242  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->length != viewin->length || viewout->vectorLength != viewin->vectorLength ) {
243  return 0;
244  }
245  const size_t n = viewin->vectorLength;
246  for ( size_t i = 0; i < viewin->length; ++i ) {
247  for ( size_t j = 0; j < n; ++j ) {
248  viewout->data[i * n + j] = viewin->data[i * n + j];
249  viewin->data[i * n + j] = viewin->data[i * n + j] * 2.0;
250  }
251  }
252  return 1;
253 }
255 {
256  if ( !copyinout || !copyinout->data ) {
257  return 0;
258  }
259  const size_t n = copyinout->vectorLength;
260  for ( size_t i = 0; i < copyinout->length; ++i ) {
261  for ( size_t j = 0; j < n; ++j ) {
262  copyinout->data[i * n + j] = copyinout->data[i * n + j] * 3.0;
263  }
264  }
265  return 1;
266 }
268 {
269  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length || copyout->vectorLength != viewin->vectorLength ) {
270  return 0;
271  }
272  const size_t n = viewin->vectorLength;
273  for ( size_t i = 0; i < viewin->length; ++i ) {
274  for ( size_t j = 0; j < n; ++j ) {
275  copyout->data[i * n + j] = viewin->data[i * n + j];
276  }
277  }
278  return 1;
279 }
281 {
282  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->length != viewin->length || viewout->vectorLength != viewin->vectorLength ) {
283  return 0;
284  }
285  const size_t n = viewin->vectorLength;
286  for ( size_t i = 0; i < viewin->length; ++i ) {
287  for ( size_t j = 0; j < n; ++j ) {
288  viewout->data[i * n + j] = viewin->data[i * n + j];
289  viewin->data[i * n + j] = viewin->data[i * n + j] * 2.0;
290  }
291  }
292  return 1;
293 }
295 {
296  if ( !copyinout || !copyinout->data ) {
297  return 0;
298  }
299  const size_t n = copyinout->vectorLength;
300  for ( size_t i = 0; i < copyinout->length; ++i ) {
301  for ( size_t j = 0; j < n; ++j ) {
302  copyinout->data[i * n + j] = copyinout->data[i * n + j] * 3.0;
303  }
304  }
305  return 1;
306 }
308 {
309  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length || copyout->vectorLength != viewin->vectorLength ) {
310  return 0;
311  }
312  const size_t n = viewin->vectorLength;
313  for ( size_t i = 0; i < viewin->length; ++i ) {
314  for ( size_t j = 0; j < n; ++j ) {
315  copyout->data[i * n + j] = viewin->data[i * n + j];
316  }
317  }
318  return 1;
319 }
321 {
322  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->length != viewin->length || viewout->vectorLength != viewin->vectorLength ) {
323  return 0;
324  }
325  const size_t n = viewin->vectorLength;
326  for ( size_t i = 0; i < viewin->length; ++i ) {
327  for ( size_t j = 0; j < n; ++j ) {
328  viewout->data[i * n + j] = viewin->data[i * n + j];
329  viewin->data[i * n + j] = crectf( crealf( viewin->data[i * n + j] ) * 2.0, cimagf( viewin->data[i * n + j] ) * 2.0 );
330  }
331  }
332  return 1;
333 }
335 {
336  if ( !copyinout || !copyinout->data ) {
337  return 0;
338  }
339  const size_t n = copyinout->vectorLength;
340  for ( size_t i = 0; i < copyinout->length; ++i ) {
341  for ( size_t j = 0; j < n; ++j ) {
342  copyinout->data[i * n + j] = copyinout->data[i * n + j] * 3.0;
343  }
344  }
345  return 1;
346 }
348 {
349  if ( !copyout || !copyout->data || !viewin || !viewin->data || copyout->length != viewin->length || copyout->vectorLength != viewin->vectorLength ) {
350  return 0;
351  }
352  const size_t n = viewin->vectorLength;
353  for ( size_t i = 0; i < viewin->length; ++i ) {
354  for ( size_t j = 0; j < n; ++j ) {
355  copyout->data[i * n + j] = viewin->data[i * n + j];
356  }
357  }
358  return 1;
359 }
361 {
362  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->length != viewin->length || viewout->vectorLength != viewin->vectorLength ) {
363  return 0;
364  }
365  const size_t n = viewin->vectorLength;
366  for ( size_t i = 0; i < viewin->length; ++i ) {
367  for ( size_t j = 0; j < n; ++j ) {
368  viewout->data[i * n + j] = viewin->data[i * n + j];
369  viewin->data[i * n + j] = crect( creal( viewin->data[i * n + j] ) * 2.0, cimag( viewin->data[i * n + j] ) * 2.0 );
370  }
371  }
372  return 1;
373 }
375 {
376  if ( !copyinout || !copyinout->data ) {
377  return 0;
378  }
379  const size_t n = copyinout->vectorLength;
380  for ( size_t i = 0; i < copyinout->length; ++i ) {
381  for ( size_t j = 0; j < n; ++j ) {
382  copyinout->data[i * n + j] = copyinout->data[i * n + j] * 3.0;
383  }
384  }
385  return 1;
386 }
387 BOOLEAN swig_lal_test_viewin_gsl_vector_float( gsl_vector_float *copyout, const gsl_vector_float *viewin )
388 {
389  if ( !copyout || !viewin || copyout->size != viewin->size ) {
390  return 0;
391  }
392  gsl_vector_float_memcpy( copyout, viewin );
393  return 1;
394 }
395 BOOLEAN swig_lal_test_viewinout_gsl_vector_float( gsl_vector_float *viewout, gsl_vector_float *viewin )
396 {
397  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->size != viewin->size ) {
398  return 0;
399  }
400  gsl_vector_float_memcpy( viewout, viewin );
401  gsl_vector_float_scale( viewin, 2.0 );
402  return 1;
403 }
404 BOOLEAN swig_lal_test_copyinout_gsl_vector_float( gsl_vector_float *copyinout )
405 {
406  if ( !copyinout || !copyinout->data ) {
407  return 0;
408  }
409  gsl_vector_float_scale( copyinout, 3.0 );
410  return 1;
411 }
412 BOOLEAN swig_lal_test_viewin_gsl_vector( gsl_vector *copyout, const gsl_vector *viewin )
413 {
414  if ( !copyout || !viewin || copyout->size != viewin->size ) {
415  return 0;
416  }
417  gsl_vector_memcpy( copyout, viewin );
418  return 1;
419 }
420 BOOLEAN swig_lal_test_viewinout_gsl_vector( gsl_vector *viewout, gsl_vector *viewin )
421 {
422  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->size != viewin->size ) {
423  return 0;
424  }
425  gsl_vector_memcpy( viewout, viewin );
426  gsl_vector_scale( viewin, 2.0 );
427  return 1;
428 }
430 {
431  if ( !copyinout || !copyinout->data ) {
432  return 0;
433  }
434  gsl_vector_scale( copyinout, 3.0 );
435  return 1;
436 }
437 BOOLEAN swig_lal_test_viewin_gsl_vector_complex_float( gsl_vector_complex_float *copyout, const gsl_vector_complex_float *viewin )
438 {
439  if ( !copyout || !viewin || copyout->size != viewin->size ) {
440  return 0;
441  }
442  gsl_vector_complex_float_memcpy( copyout, viewin );
443  return 1;
444 }
445 BOOLEAN swig_lal_test_viewinout_gsl_vector_complex_float( gsl_vector_complex_float *viewout, gsl_vector_complex_float *viewin )
446 {
447  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->size != viewin->size ) {
448  return 0;
449  }
450  gsl_vector_complex_float_memcpy( viewout, viewin );
451  gsl_complex_float z;
452  GSL_SET_COMPLEX( &z, 2.0, 0.0 );
453  gsl_vector_complex_float_scale( viewin, z );
454  return 1;
455 }
456 BOOLEAN swig_lal_test_copyinout_gsl_vector_complex_float( gsl_vector_complex_float *copyinout )
457 {
458  if ( !copyinout || !copyinout->data ) {
459  return 0;
460  }
461  gsl_complex_float z;
462  GSL_SET_COMPLEX( &z, 3.0, 0.0 );
463  gsl_vector_complex_float_scale( copyinout, z );
464  return 1;
465 }
466 BOOLEAN swig_lal_test_viewin_gsl_vector_complex( gsl_vector_complex *copyout, const gsl_vector_complex *viewin )
467 {
468  if ( !copyout || !viewin || copyout->size != viewin->size ) {
469  return 0;
470  }
471  gsl_vector_complex_memcpy( copyout, viewin );
472  return 1;
473 }
474 BOOLEAN swig_lal_test_viewinout_gsl_vector_complex( gsl_vector_complex *viewout, gsl_vector_complex *viewin )
475 {
476  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->size != viewin->size ) {
477  return 0;
478  }
479  gsl_vector_complex_memcpy( viewout, viewin );
480  gsl_complex z;
481  GSL_SET_COMPLEX( &z, 2.0, 0.0 );
482  gsl_vector_complex_scale( viewin, z );
483  return 1;
484 }
485 BOOLEAN swig_lal_test_copyinout_gsl_vector_complex( gsl_vector_complex *copyinout )
486 {
487  if ( !copyinout || !copyinout->data ) {
488  return 0;
489  }
490  gsl_complex z;
491  GSL_SET_COMPLEX( &z, 3.0, 0.0 );
492  gsl_vector_complex_scale( copyinout, z );
493  return 1;
494 }
495 BOOLEAN swig_lal_test_viewin_gsl_matrix_float( gsl_matrix_float *copyout, const gsl_matrix_float *viewin )
496 {
497  if ( !copyout || !viewin || copyout->size1 != viewin->size1 || copyout->size2 != viewin->size2 ) {
498  return 0;
499  }
500  gsl_matrix_float_memcpy( copyout, viewin );
501  return 1;
502 }
503 BOOLEAN swig_lal_test_viewinout_gsl_matrix_float( gsl_matrix_float *viewout, gsl_matrix_float *viewin )
504 {
505  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->size1 != viewin->size1 || viewout->size2 != viewin->size2 ) {
506  return 0;
507  }
508  gsl_matrix_float_memcpy( viewout, viewin );
509  gsl_matrix_float_scale( viewin, 2.0 );
510  return 1;
511 }
512 BOOLEAN swig_lal_test_copyinout_gsl_matrix_float( gsl_matrix_float *copyinout )
513 {
514  if ( !copyinout || !copyinout->data ) {
515  return 0;
516  }
517  gsl_matrix_float_scale( copyinout, 3.0 );
518  return 1;
519 }
520 BOOLEAN swig_lal_test_viewin_gsl_matrix( gsl_matrix *copyout, const gsl_matrix *viewin )
521 {
522  if ( !copyout || !viewin || copyout->size1 != viewin->size1 || copyout->size2 != viewin->size2 ) {
523  return 0;
524  }
525  gsl_matrix_memcpy( copyout, viewin );
526  return 1;
527 }
528 BOOLEAN swig_lal_test_viewinout_gsl_matrix( gsl_matrix *viewout, gsl_matrix *viewin )
529 {
530  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->size1 != viewin->size1 || viewout->size2 != viewin->size2 ) {
531  return 0;
532  }
533  gsl_matrix_memcpy( viewout, viewin );
534  gsl_matrix_scale( viewin, 2.0 );
535  return 1;
536 }
538 {
539  if ( !copyinout || !copyinout->data ) {
540  return 0;
541  }
542  gsl_matrix_scale( copyinout, 3.0 );
543  return 1;
544 }
545 BOOLEAN swig_lal_test_viewin_gsl_matrix_complex_float( gsl_matrix_complex_float *copyout, const gsl_matrix_complex_float *viewin )
546 {
547  if ( !copyout || !viewin || copyout->size1 != viewin->size1 || copyout->size2 != viewin->size2 ) {
548  return 0;
549  }
550  gsl_matrix_complex_float_memcpy( copyout, viewin );
551  return 1;
552 }
553 BOOLEAN swig_lal_test_viewinout_gsl_matrix_complex_float( gsl_matrix_complex_float *viewout, gsl_matrix_complex_float *viewin )
554 {
555  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->size1 != viewin->size1 || viewout->size2 != viewin->size2 ) {
556  return 0;
557  }
558  gsl_matrix_complex_float_memcpy( viewout, viewin );
559  gsl_complex_float z;
560  GSL_SET_COMPLEX( &z, 2.0, 0.0 );
561  gsl_matrix_complex_float_scale( viewin, z );
562  return 1;
563 }
564 BOOLEAN swig_lal_test_copyinout_gsl_matrix_complex_float( gsl_matrix_complex_float *copyinout )
565 {
566  if ( !copyinout || !copyinout->data ) {
567  return 0;
568  }
569  gsl_complex_float z;
570  GSL_SET_COMPLEX( &z, 3.0, 0.0 );
571  gsl_matrix_complex_float_scale( copyinout, z );
572  return 1;
573 }
574 BOOLEAN swig_lal_test_viewin_gsl_matrix_complex( gsl_matrix_complex *copyout, const gsl_matrix_complex *viewin )
575 {
576  if ( !copyout || !viewin || copyout->size1 != viewin->size1 || copyout->size2 != viewin->size2 ) {
577  return 0;
578  }
579  gsl_matrix_complex_memcpy( copyout, viewin );
580  return 1;
581 }
582 BOOLEAN swig_lal_test_viewinout_gsl_matrix_complex( gsl_matrix_complex *viewout, gsl_matrix_complex *viewin )
583 {
584  if ( !viewout || !viewout->data || !viewin || !viewin->data || viewout->size1 != viewin->size1 || viewout->size2 != viewin->size2 ) {
585  return 0;
586  }
587  gsl_matrix_complex_memcpy( viewout, viewin );
588  gsl_complex z;
589  GSL_SET_COMPLEX( &z, 2.0, 0.0 );
590  gsl_matrix_complex_scale( viewin, z );
591  return 1;
592 }
593 BOOLEAN swig_lal_test_copyinout_gsl_matrix_complex( gsl_matrix_complex *copyinout )
594 {
595  if ( !copyinout || !copyinout->data ) {
596  return 0;
597  }
598  gsl_complex z;
599  GSL_SET_COMPLEX( &z, 3.0, 0.0 );
600  gsl_matrix_complex_scale( copyinout, z );
601  return 1;
602 }
603 
604 // Test dynamic array of pointer access.
606 {
608  XLAL_CHECK_NULL( ap != NULL, XLAL_ENOMEM );
609  ap->length = length;
611  XLAL_CHECK_NULL( ap->data != NULL, XLAL_ENOMEM );
612  for ( UINT4 i = 0; i < ap->length; ++i ) {
614  XLAL_CHECK_NULL( ap->data[i] != NULL, XLAL_ENOMEM );
615  ap->data[i]->length = 2 * length;
616  ap->data[i]->data = ( INT4 * )XLALCalloc( ap->data[i]->length, sizeof( INT4 ) );
617  XLAL_CHECK_NULL( ap->data[i]->data != NULL, XLAL_ENOMEM );
618  for ( UINT4 j = 0; j < ap->data[i]->length; ++j ) {
619  ap->data[i]->data[j] = 42 * length * i + j;
620  }
621  }
622  return ap;
623 }
625 {
626  if ( ap ) {
627  if ( ap->data ) {
628  for ( UINT4 i = 0; i < ap->length; ++i ) {
629  if ( ap->data[i] ) {
630  if ( ap->data[i]->data ) {
631  XLALFree( ap->data[i]->data );
632  }
633  XLALFree( ap->data[i] );
634  }
635  }
636  XLALFree( ap->data );
637  }
638  XLALFree( ap );
639  }
640 }
641 
642 // Test typemaps for strings and double pointers
644  const char *str, const char *empty_str, const char *null_str,
645  swig_lal_test_struct **ptr_ptr, swig_lal_test_struct **ptr_null_ptr, swig_lal_test_struct **null_ptr_ptr
646 )
647 {
648  XLAL_CHECK( str != NULL && strcmp( str, "abcde" ) == 0, XLAL_EFAILED );
649  XLAL_CHECK( empty_str != NULL && strlen( empty_str ) == 0, XLAL_EFAILED );
650  XLAL_CHECK( null_str == NULL, XLAL_EFAILED );
651  XLAL_CHECK( ptr_ptr != NULL && *ptr_ptr != NULL, XLAL_EFAILED );
652  XLAL_CHECK( ptr_null_ptr != NULL && *ptr_null_ptr == NULL, XLAL_EFAILED );
653  XLAL_CHECK( null_ptr_ptr == NULL, XLAL_EFAILED );
654  *ptr_null_ptr = XLALCalloc( 1, sizeof( **ptr_null_ptr ) );
655  XLAL_CHECK( *ptr_null_ptr != NULL, XLAL_ENOMEM );
656  memcpy( *ptr_null_ptr, *ptr_ptr, sizeof( **ptr_null_ptr ) );
657  return XLAL_SUCCESS;
658 }
660  swig_lal_test_struct **ptr_ptr
661 )
662 {
663  XLAL_CHECK( ptr_ptr != NULL, XLAL_EFAILED );
664  if ( *ptr_ptr == NULL ) {
665  *ptr_ptr = XLALCalloc( 1, sizeof( **ptr_ptr ) );
666  XLAL_CHECK( *ptr_ptr != NULL, XLAL_ENOMEM );
667  }
668  ++( *ptr_ptr )->n;
669  return XLAL_SUCCESS;
670 }
671 
672 // Test LIGOTimeGPS operations.
674 {
675  return XLALGPSGetREAL8( &gps );
676 }
677 
678 // Test Python dict to LALDict typemap
679 int swig_lal_test_pydict_to_laldict( LALDict *laldict )
680 {
681  XLAL_CHECK( laldict != NULL, XLAL_EFAULT );
682  {
683  const char *str = XLALDictLookupStringValue( laldict, "str" );
685  XLAL_CHECK( strcmp( str, "A string value" ) == 0, XLAL_EFUNC );
686  }
687  {
688  UINT2 val = XLALDictLookupUINT2Value( laldict, "2-byte-unsigned" );
690  XLAL_CHECK( val == 32767, XLAL_EFUNC );
691  }
692  {
693  UINT4 val = XLALDictLookupUINT4Value( laldict, "4-byte-unsigned" );
695  XLAL_CHECK( val == 123456, XLAL_EFUNC );
696  }
697  {
698  UINT8 val = XLALDictLookupUINT8Value( laldict, "8-byte-unsigned" );
700  XLAL_CHECK( val == 9223372036854775807, XLAL_EFUNC );
701  }
702  {
703  INT2 val = XLALDictLookupINT2Value( laldict, "2-byte-signed" );
705  XLAL_CHECK( val == -32768, XLAL_EFUNC );
706  }
707  {
708  INT4 val = XLALDictLookupINT4Value( laldict, "4-byte-signed" );
710  XLAL_CHECK( val == -123456, XLAL_EFUNC );
711  }
712  {
713  INT8 val = XLALDictLookupINT8Value( laldict, "8-byte-signed" );
715  XLAL_CHECK( val == 9223372036854775807, XLAL_EFUNC );
716  }
717  {
718  REAL4 val = XLALDictLookupREAL4Value( laldict, "single" );
720  XLAL_CHECK( val == 987e6, XLAL_EFUNC );
721  }
722  {
723  REAL8 val = XLALDictLookupREAL8Value( laldict, "double" );
725  XLAL_CHECK( val == -543e-21, XLAL_EFUNC );
726  }
727  {
728  COMPLEX8 val = XLALDictLookupCOMPLEX8Value( laldict, "single complex" );
730  XLAL_CHECK( crealf( val ) == 987e6, XLAL_EFUNC );
731  XLAL_CHECK( cimagf( val ) == -123e4, XLAL_EFUNC );
732  }
733  {
734  COMPLEX16 val = XLALDictLookupCOMPLEX16Value( laldict, "double complex" );
736  XLAL_CHECK( creal( val ) == -543e-21, XLAL_EFUNC );
737  XLAL_CHECK( cimag( val ) == 345e43, XLAL_EFUNC );
738  }
739  return XLAL_SUCCESS;
740 }
741 
742 // Test Python conversion of NumPy integer types
744 {
745  return a + b + c + d;
746 }
748 {
749  return a + b + c + d;
750 }
752 {
753  return a + b + c + d;
754 }
756 {
757  return a + b + c + d;
758 }
const char * XLALDictLookupStringValue(LALDict *dict, const char *key)
Definition: LALDict.c:425
INT4 XLALDictLookupINT4Value(LALDict *dict, const char *key)
COMPLEX8 XLALDictLookupCOMPLEX8Value(LALDict *dict, const char *key)
REAL8 XLALDictLookupREAL8Value(LALDict *dict, const char *key)
INT2 XLALDictLookupINT2Value(LALDict *dict, const char *key)
COMPLEX16 XLALDictLookupCOMPLEX16Value(LALDict *dict, const char *key)
UINT8 XLALDictLookupUINT8Value(LALDict *dict, const char *key)
UINT2 XLALDictLookupUINT2Value(LALDict *dict, const char *key)
UINT4 XLALDictLookupUINT4Value(LALDict *dict, const char *key)
INT8 XLALDictLookupINT8Value(LALDict *dict, const char *key)
REAL4 XLALDictLookupREAL4Value(LALDict *dict, const char *key)
swig_lal_test_enum
Definition: SWIGLALTest.h:40
@ swig_lal_test_enum_b
Definition: SWIGLALTest.h:42
@ swig_lal_test_enum_a
Definition: SWIGLALTest.h:41
@ swig_lal_test_enum_c
Definition: SWIGLALTest.h:43
UNUSED const swig_lal_test_struct swig_lal_test_struct_const
Definition: SWIGTest.c:38
BOOLEAN swig_lal_test_viewin_gsl_matrix_float(gsl_matrix_float *copyout, const gsl_matrix_float *viewin)
Definition: SWIGTest.c:495
BOOLEAN swig_lal_test_copyinout_gsl_vector_float(gsl_vector_float *copyinout)
Definition: SWIGTest.c:404
REAL8 swig_lal_test_numpy_flt_types(REAL4 a, REAL8 b, REAL4 c, REAL8 d)
Definition: SWIGTest.c:751
UNUSED INT4 swig_lal_test_INT4_vector[3]
Definition: SWIGTest.c:47
BOOLEAN swig_lal_test_viewinout_COMPLEX8VectorSequence(COMPLEX8VectorSequence *viewout, COMPLEX8VectorSequence *viewin)
Definition: SWIGTest.c:320
UNUSED INT4 swig_lal_test_INT4_matrix[2][3]
Definition: SWIGTest.c:48
BOOLEAN swig_lal_test_copyinout_COMPLEX16VectorSequence(COMPLEX16VectorSequence *copyinout)
Definition: SWIGTest.c:374
int swig_lal_test_typemaps_string_ptrptr(const char *str, const char *empty_str, const char *null_str, swig_lal_test_struct **ptr_ptr, swig_lal_test_struct **ptr_null_ptr, swig_lal_test_struct **null_ptr_ptr)
Definition: SWIGTest.c:643
UNUSED REAL8 swig_lal_test_REAL8_matrix[2][3]
Definition: SWIGTest.c:52
BOOLEAN swig_lal_test_copyinout_gsl_matrix_float(gsl_matrix_float *copyinout)
Definition: SWIGTest.c:512
INT8 swig_lal_test_numpy_int_types(int a, INT2 b, INT4 c, INT8 d)
Definition: SWIGTest.c:743
UINT8 swig_lal_test_numpy_uint_types(unsigned int a, UINT2 b, UINT4 c, UINT8 d)
Definition: SWIGTest.c:747
BOOLEAN swig_lal_test_viewin_gsl_matrix(gsl_matrix *copyout, const gsl_matrix *viewin)
Definition: SWIGTest.c:520
BOOLEAN swig_lal_test_viewin_COMPLEX8VectorSequence(COMPLEX8VectorSequence *copyout, const COMPLEX8VectorSequence *viewin)
Definition: SWIGTest.c:307
BOOLEAN swig_lal_test_copyinout_REAL4VectorSequence(REAL4VectorSequence *copyinout)
Definition: SWIGTest.c:254
BOOLEAN swig_lal_test_copyinout_REAL8Vector(REAL8Vector *copyinout)
Definition: SWIGTest.c:155
BOOLEAN swig_lal_test_copyinout_gsl_vector_complex_float(gsl_vector_complex_float *copyinout)
Definition: SWIGTest.c:456
UNUSED swig_lal_test_enum swig_lal_test_enum_matrix[2][3]
Definition: SWIGTest.c:45
UNUSED const INT4 swig_lal_test_INT4_const_vector[3]
Definition: SWIGTest.c:49
BOOLEAN swig_lal_test_viewin_gsl_vector_complex_float(gsl_vector_complex_float *copyout, const gsl_vector_complex_float *viewin)
Definition: SWIGTest.c:437
BOOLEAN swig_lal_test_viewin_REAL4VectorSequence(REAL4VectorSequence *copyout, const REAL4VectorSequence *viewin)
Definition: SWIGTest.c:227
BOOLEAN swig_lal_test_viewinout_REAL4Vector(REAL4Vector *viewout, REAL4Vector *viewin)
Definition: SWIGTest.c:113
BOOLEAN swig_lal_test_viewinout_gsl_vector(gsl_vector *viewout, gsl_vector *viewin)
Definition: SWIGTest.c:420
void swig_lal_test_copyin_array3(LIGOTimeGPS INPUT[2], REAL8 scale, LIGOTimeGPS OUTPUT[2])
Definition: SWIGTest.c:71
BOOLEAN swig_lal_test_viewin_REAL8Vector(REAL8Vector *copyout, const REAL8Vector *viewin)
Definition: SWIGTest.c:134
BOOLEAN swig_lal_test_copyinout_gsl_vector(gsl_vector *copyinout)
Definition: SWIGTest.c:429
UNUSED COMPLEX8 swig_lal_test_COMPLEX8_matrix[2][3]
Definition: SWIGTest.c:54
BOOLEAN swig_lal_test_viewin_COMPLEX16Vector(COMPLEX16Vector *copyout, const COMPLEX16Vector *viewin)
Definition: SWIGTest.c:196
BOOLEAN swig_lal_test_viewin_gsl_vector(gsl_vector *copyout, const gsl_vector *viewin)
Definition: SWIGTest.c:412
UNUSED swig_lal_test_struct swig_lal_test_struct_matrix[2][3]
Definition: SWIGTest.c:43
BOOLEAN swig_lal_test_viewin_gsl_vector_complex(gsl_vector_complex *copyout, const gsl_vector_complex *viewin)
Definition: SWIGTest.c:466
BOOLEAN swig_lal_test_viewinout_gsl_matrix_float(gsl_matrix_float *viewout, gsl_matrix_float *viewin)
Definition: SWIGTest.c:503
swig_lal_test_arrayofptrs * swig_lal_test_Create_arrayofptrs(UINT4 length)
Definition: SWIGTest.c:605
BOOLEAN swig_lal_test_copyinout_COMPLEX16Vector(COMPLEX16Vector *copyinout)
Definition: SWIGTest.c:217
BOOLEAN swig_lal_test_viewin_gsl_matrix_complex_float(gsl_matrix_complex_float *copyout, const gsl_matrix_complex_float *viewin)
Definition: SWIGTest.c:545
BOOLEAN swig_lal_test_copyinout_gsl_matrix_complex(gsl_matrix_complex *copyinout)
Definition: SWIGTest.c:593
BOOLEAN swig_lal_test_viewinout_gsl_matrix_complex_float(gsl_matrix_complex_float *viewout, gsl_matrix_complex_float *viewin)
Definition: SWIGTest.c:553
BOOLEAN swig_lal_test_viewinout_REAL4VectorSequence(REAL4VectorSequence *viewout, REAL4VectorSequence *viewin)
Definition: SWIGTest.c:240
int swig_lal_test_pydict_to_laldict(LALDict *laldict)
Definition: SWIGTest.c:679
UNUSED COMPLEX8 swig_lal_test_COMPLEX8_vector[3]
Definition: SWIGTest.c:53
BOOLEAN swig_lal_test_copyinout_LALStringVector(LALStringVector *copyinout)
Definition: SWIGTest.c:91
BOOLEAN swig_lal_test_viewin_LALStringVector(LALStringVector *copyout, const LALStringVector *viewin)
Definition: SWIGTest.c:80
UNUSED REAL8 swig_lal_test_REAL8_vector[3]
Definition: SWIGTest.c:51
BOOLEAN swig_lal_test_viewinout_COMPLEX8Vector(COMPLEX8Vector *viewout, COMPLEX8Vector *viewin)
Definition: SWIGTest.c:175
BOOLEAN swig_lal_test_viewinout_COMPLEX16VectorSequence(COMPLEX16VectorSequence *viewout, COMPLEX16VectorSequence *viewin)
Definition: SWIGTest.c:360
BOOLEAN swig_lal_test_copyinout_gsl_vector_complex(gsl_vector_complex *copyinout)
Definition: SWIGTest.c:485
int swig_lal_test_typemaps_ptrptr(swig_lal_test_struct **ptr_ptr)
Definition: SWIGTest.c:659
UNUSED swig_lal_test_struct swig_lal_test_struct_vector[3]
Definition: SWIGTest.c:42
BOOLEAN swig_lal_test_viewinout_gsl_matrix_complex(gsl_matrix_complex *viewout, gsl_matrix_complex *viewin)
Definition: SWIGTest.c:582
BOOLEAN swig_lal_test_viewinout_gsl_vector_float(gsl_vector_float *viewout, gsl_vector_float *viewin)
Definition: SWIGTest.c:395
BOOLEAN swig_lal_test_viewin_gsl_matrix_complex(gsl_matrix_complex *copyout, const gsl_matrix_complex *viewin)
Definition: SWIGTest.c:574
void swig_lal_test_copyin_array1(REAL8 INPUT[3], REAL8 scale, REAL8 OUTPUT[3])
Definition: SWIGTest.c:57
void swig_lal_test_copyin_array2(INT4 INPUT[3][2], INT4 scale, INT4 OUTPUT[3][2])
Definition: SWIGTest.c:63
BOOLEAN swig_lal_test_viewin_COMPLEX16VectorSequence(COMPLEX16VectorSequence *copyout, const COMPLEX16VectorSequence *viewin)
Definition: SWIGTest.c:347
BOOLEAN swig_lal_test_viewin_gsl_vector_float(gsl_vector_float *copyout, const gsl_vector_float *viewin)
Definition: SWIGTest.c:387
void swig_lal_test_Destroy_arrayofptrs(swig_lal_test_arrayofptrs *ap)
Definition: SWIGTest.c:624
BOOLEAN swig_lal_test_viewin_REAL4Vector(REAL4Vector *copyout, const REAL4Vector *viewin)
Definition: SWIGTest.c:103
BOOLEAN swig_lal_test_viewinout_gsl_matrix(gsl_matrix *viewout, gsl_matrix *viewin)
Definition: SWIGTest.c:528
BOOLEAN swig_lal_test_copyinout_COMPLEX8VectorSequence(COMPLEX8VectorSequence *copyinout)
Definition: SWIGTest.c:334
BOOLEAN swig_lal_test_viewin_REAL8VectorSequence(REAL8VectorSequence *copyout, const REAL8VectorSequence *viewin)
Definition: SWIGTest.c:267
UNUSED const INT4 swig_lal_test_INT4_const_matrix[2][3]
Definition: SWIGTest.c:50
BOOLEAN swig_lal_test_copyinout_REAL8VectorSequence(REAL8VectorSequence *copyinout)
Definition: SWIGTest.c:294
BOOLEAN swig_lal_test_viewinout_COMPLEX16Vector(COMPLEX16Vector *viewout, COMPLEX16Vector *viewin)
Definition: SWIGTest.c:206
BOOLEAN swig_lal_test_copyinout_REAL4Vector(REAL4Vector *copyinout)
Definition: SWIGTest.c:124
BOOLEAN swig_lal_test_viewinout_gsl_vector_complex(gsl_vector_complex *viewout, gsl_vector_complex *viewin)
Definition: SWIGTest.c:474
BOOLEAN swig_lal_test_viewinout_REAL8VectorSequence(REAL8VectorSequence *viewout, REAL8VectorSequence *viewin)
Definition: SWIGTest.c:280
BOOLEAN swig_lal_test_copyinout_COMPLEX8Vector(COMPLEX8Vector *copyinout)
Definition: SWIGTest.c:186
REAL8 swig_lal_test_noptrgps(const LIGOTimeGPS gps)
Definition: SWIGTest.c:673
UNUSED INT4 swig_lal_test_empty_INT4_vector[0]
Definition: SWIGTest.c:46
BOOLEAN swig_lal_test_viewinout_gsl_vector_complex_float(gsl_vector_complex_float *viewout, gsl_vector_complex_float *viewin)
Definition: SWIGTest.c:445
BOOLEAN swig_lal_test_viewin_COMPLEX8Vector(COMPLEX8Vector *copyout, const COMPLEX8Vector *viewin)
Definition: SWIGTest.c:165
BOOLEAN swig_lal_test_copyinout_gsl_matrix_complex_float(gsl_matrix_complex_float *copyinout)
Definition: SWIGTest.c:564
BOOLEAN swig_lal_test_viewinout_REAL8Vector(REAL8Vector *viewout, REAL8Vector *viewin)
Definition: SWIGTest.c:144
BOOLEAN swig_lal_test_copyinout_gsl_matrix(gsl_matrix *copyinout)
Definition: SWIGTest.c:537
UNUSED swig_lal_test_enum swig_lal_test_enum_vector[3]
Definition: SWIGTest.c:44
COMPLEX16 swig_lal_test_numpy_cpx_types(COMPLEX8 a, COMPLEX16 b, COMPLEX8 c, COMPLEX16 d)
Definition: SWIGTest.c:755
#define crect(re, im)
Construct a COMPLEX16 from real and imaginary parts.
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
double complex COMPLEX16
Double-precision floating-point complex number (16 bytes total)
double REAL8
Double precision real floating-point number (8 bytes).
int16_t INT2
Two-byte signed integer.
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
#define crectf(re, im)
Construct a COMPLEX8 from real and imaginary parts.
uint16_t UINT2
Two-byte unsigned integer.
uint32_t UINT4
Four-byte unsigned integer.
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
#define XLALMalloc(n)
Definition: LALMalloc.h:44
#define XLALCalloc(m, n)
Definition: LALMalloc.h:45
#define XLALFree(p)
Definition: LALMalloc.h:47
char * XLALStringDuplicate(const char *s)
Like strdup but uses LAL allocation routines (free with LALFree).
Definition: LALString.c:89
int XLALStringToUpperCase(char *string)
Turn a string in-place into uppercase without using locale-dependent functions.
Definition: LALString.c:182
static const INT4 a
Definition: Random.c:79
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
Definition: XLALError.h:571
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
Definition: XLALError.h:810
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
Definition: XLALError.h:825
@ XLAL_ENOMEM
Memory allocation error.
Definition: XLALError.h:407
@ XLAL_SUCCESS
Success return value (not an error number)
Definition: XLALError.h:401
@ XLAL_EFAULT
Invalid pointer.
Definition: XLALError.h:408
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
Definition: XLALError.h:462
@ XLAL_EFAILED
Generic failure.
Definition: XLALError.h:418
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
Returns the GPS time as a REAL8.
Definition: XLALTime.c:91
LIGOTimeGPS * XLALGPSMultiply(LIGOTimeGPS *gps, REAL8 x)
Multiply a GPS time by a number.
Definition: XLALTime.c:228
Vector of type COMPLEX16, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:172
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:176
COMPLEX16 * data
Pointer to the data array.
Definition: LALDatatypes.h:177
Sequence of COMPLEX16 Vectors, see DATATYPE-VectorSequence types for more details.
Definition: LALDatatypes.h:361
UINT4 vectorLength
The length n of each vector.
Definition: LALDatatypes.h:366
COMPLEX16 * data
Pointer to the data array.
Definition: LALDatatypes.h:367
UINT4 length
The number l of vectors.
Definition: LALDatatypes.h:365
Vector of type COMPLEX8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:163
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:167
COMPLEX8 * data
Pointer to the data array.
Definition: LALDatatypes.h:168
Sequence of COMPLEX8 Vectors, see DATATYPE-VectorSequence types for more details.
Definition: LALDatatypes.h:351
COMPLEX8 * data
Pointer to the data array.
Definition: LALDatatypes.h:357
UINT4 length
The number l of vectors.
Definition: LALDatatypes.h:355
UINT4 vectorLength
The length n of each vector.
Definition: LALDatatypes.h:356
Vector of type CHAR*, ie 'strings', see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:82
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:86
CHAR ** data
Pointer to the data array.
Definition: LALDatatypes.h:87
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458
Vector of type REAL4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:145
REAL4 * data
Pointer to the data array.
Definition: LALDatatypes.h:150
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:149
Sequence of REAL4 Vectors, see DATATYPE-VectorSequence types for more details.
Definition: LALDatatypes.h:331
UINT4 vectorLength
The length n of each vector.
Definition: LALDatatypes.h:336
REAL4 * data
Pointer to the data array.
Definition: LALDatatypes.h:337
UINT4 length
The number l of vectors.
Definition: LALDatatypes.h:335
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
REAL8 * data
Pointer to the data array.
Definition: LALDatatypes.h:159
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:158
Sequence of REAL8 Vectors, see DATATYPE-VectorSequence types for more details.
Definition: LALDatatypes.h:341
UINT4 length
The number l of vectors.
Definition: LALDatatypes.h:345
REAL8 * data
Pointer to the data array.
Definition: LALDatatypes.h:347
UINT4 vectorLength
The length n of each vector.
Definition: LALDatatypes.h:346
swig_lal_test_arrayofdata ** data
Definition: SWIGLALTest.h:342