Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
SWIGOctave.i
Go to the documentation of this file.
1//
2// Copyright (C) 2011--2017, 2022 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// SWIG interface code specific to Octave.
21// Author: Karl Wette
22
23//
24// General SWIG directives and interface code
25//
26
27// In SWIG Octave modules, only variables are namespaced, everything else
28// is inserted in the global symbol table, so we rename only variables
29#define SWIGLAL_MODULE_RENAME_VARIABLES
30
31// Include SWIG Octave headers.
32%include <octcomplex.swg>
33
34// Include Octave headers and set versioning macros.
35%header %{
36extern "C++" {
37#include <octave/ov-cell.h>
38#include <octave/ov-int-traits.h>
39#include <octave/ov-flt-re-mat.h>
40#include <octave/ov-re-mat.h>
41#include <octave/ov-flt-cx-mat.h>
42#include <octave/ov-cx-mat.h>
43#include <octave/Array-util.h>
44}
45%}
46
47// Evaluates true if an octave_value is not empty, false otherwise.
48%header %{
49#define swiglal_not_empty(v) (!(v).is_empty())
50%}
51
52// Name of octave_value containing the SWIG wrapping of the struct whose members are being accessed.
53%header %{
54#define swiglal_self() (args.length() > 0 ? args(0) : octave_value())
55#define swiglal_no_self() (octave_value())
56%}
57
58// Name of octave_value containing the SWIG wrapping of the first argument to a function.
59%header %{
60#define swiglal_1starg() (args.length() > 0 ? args(0) : octave_value())
61%}
62
63// Return a reference to the supplied octave_value; since Octave handles reference counting, just return it.
64%header %{
65#define swiglal_get_reference(v) (v)
66%}
67
68// Remove the first argument (i.e. the XLAL error code) from the output argument list of an
69// Octave SWIG-wrapped function, if the list has more than one output argument.
70%header %{
71#define swiglal_maybe_return_int() \
72 if (_out.length() > 1) _out = _out.slice(1, _out.length() - 1)
73%}
74
75// Evaluates true if an octave_value represents a null pointer, false otherwise.
76%header %{
77#define swiglal_null_ptr(v) (!(v).is_string() && (v).is_matrix_type() && (v).rows() == 0 && (v).columns() == 0)
78%}
79
80// Python-specific function for standard output/error redirection
81%header %{
82SWIGINTERN int swiglal_output_stdouterr(void) {
83
84 // Flush and rewind temporary files
85 fflush(swiglal_tmp_stdout);
86 rewind(swiglal_tmp_stdout);
87 fflush(swiglal_tmp_stderr);
88 rewind(swiglal_tmp_stderr);
89
90 // Write standard output
91 {
92 octave_value_list args = feval("stdout", octave_value_list(), 1);
93 if (args.length() < 1) {
94 return 0;
95 }
96 args.resize(3);
97 args(1) = octave_value(std::string("%s"));
98 char buf[512];
99 while (fgets(buf, sizeof(buf), swiglal_tmp_stdout) != NULL) {
100 args(2) = octave_value(std::string(buf));
101 feval("fprintf", args, 0);
102 }
103 }
104
105 // Write standard error
106 {
107 octave_value_list args = feval("stderr", octave_value_list(), 1);
108 if (args.length() < 1) {
109 return 0;
110 }
111 args.resize(3);
112 args(1) = octave_value(std::string("%s"));
113 char buf[512];
114 while (fgets(buf, sizeof(buf), swiglal_tmp_stderr) != NULL) {
115 args(2) = octave_value(std::string(buf));
116 feval("fprintf", args, 0);
117 }
118 }
119
120 // Close temporary files
121 fclose(swiglal_tmp_stdout);
122 fclose(swiglal_tmp_stderr);
123
124 return 1;
125
126}
127%}
128
129//
130// SWIG directives for operators
131//
132
133// Unary operators which return a new object, and thus require %newobject to be set.
134%define %swiglal_oct_urn_op(NAME, OCTNAME)
135%rename(__##OCTNAME##__) *::__##NAME##__;
136%newobject *::__##NAME##__;
137%enddef
138%swiglal_oct_urn_op(abs, abs);
139%swiglal_oct_urn_op(neg, uminus);
140%swiglal_oct_urn_op(pos, uplus);
141
142// Binary operators, which always must return a new object, and thus require %newobject to be set.
143%define %swiglal_oct_bin_op(NAME)
144%newobject *::__##NAME##__;
145%newobject *::__r##NAME##__;
146%enddef
147%swiglal_oct_bin_op(add);
148%swiglal_oct_bin_op(and);
149%swiglal_oct_bin_op(div);
150%swiglal_oct_bin_op(lshift);
151%swiglal_oct_bin_op(mod);
152%swiglal_oct_bin_op(mul);
153%swiglal_oct_bin_op(or);
154%swiglal_oct_bin_op(pow);
155%swiglal_oct_bin_op(rshift);
156%swiglal_oct_bin_op(sub);
157%swiglal_oct_bin_op(xor);
158
159// Octave __pow__() operator takes 2 arguments, so we ignore the 3rd.
160%typemap(in, numinputs=0) void* SWIGLAL_OP_POW_3RDARG "";
161
162// Comparison operators.
163%typemap(in, numinputs=0, noblock=1) int SWIGLAL_CMP_OP_RETN_HACK "";
164
165//
166// Octave-specific extensions to structs
167//
168
169// Extend a struct TAGNAME.
170%define %swiglal_struct_extend_specific(TAGNAME, OPAQUE, DTORFUNC)
171
172%enddef // %swiglal_struct_extend_specific
173
174//
175// General fragments, typemaps, and macros
176//
177
178// SWIG conversion fragments and typemaps for GSL complex numbers.
179%swig_cplxflt_convn(gsl_complex_float, gsl_complex_float_rect, GSL_REAL, GSL_IMAG);
180%swig_cplxdbl_convn(gsl_complex, gsl_complex_rect, GSL_REAL, GSL_IMAG);
181%typemaps_primitive(%checkcode(CPLXFLT), gsl_complex_float);
182%typemaps_primitive(%checkcode(CPLXDBL), gsl_complex);
183
184// SWIG conversion fragments and typemaps for LAL complex numbers.
185%swig_cplxflt_convn(COMPLEX8, crectf, crealf, cimagf);
186%swig_cplxdbl_convn(COMPLEX16, crect, creal, cimag);
187%typemaps_primitive(%checkcode(CPLXFLT), COMPLEX8);
188%typemaps_primitive(%checkcode(CPLXDBL), COMPLEX16);
189
190// Typemaps which convert to/from the C broken-down date/time struct.
191%typemap(in, fragment=SWIG_AsVal_frag(double)) struct tm* (struct tm temptm) {
192
193 // Convert '$input' to an Octave date number 'datenum'
194 octave_value_list datenum_args;
195 if ($input.is_string()) {
196 datenum_args.append($input);
197 } else {
198 dim_vector dims = $input.dims();
199 if (dims.length() == 2 && dims.num_ones() == 1 && 3 <= dims.numel() && dims.numel() <= 6) {
200 RowVector datevec = $input.row_vector_value();
201 for (int i = 0; i < datevec.numel(); ++i) {
202 datenum_args.append(octave_value(datevec(i)));
203 }
204 }
205 }
206 octave_value_list retn;
207 if (datenum_args.length() > 0) {
208 retn = feval("datenum", datenum_args, 1);
209 }
210 if (retn.length() == 0) {
211 %argument_fail(SWIG_ValueError, "$type", $symname, $argnum);
212 }
213 double datenum = 0;
214 int res = SWIG_AsVal(double)(retn(0), &datenum);
215 if (!SWIG_IsOK(res)) {
216 %argument_fail(res, "$type", $symname, $argnum);
217 }
218
219 // Convert 'datenum' to a C time_t 't', using the following:
220 // 1970-01-01 00:00:00 +0000: 'datenum'=719529, 't'=0
221 // 1970-01-02 00:00:00 +0000: 'datenum'=719530, 't'=86400
222 time_t t = (time_t) llround((datenum - 719529) * 86400);
223
224 // Convert 't' to a C struct tm 'temptm'
225 memset(&temptm, 0, sizeof(temptm));
226 if (gmtime_r(&t, &temptm) == NULL) {
227 %argument_fail(SWIG_RuntimeError, "$type", $symname, $argnum);
228 }
229
230 $1 = &temptm;
231
232}
233%typemap(freearg) struct tm* "";
234%typemap(out) struct tm* {
235
236 // Create an Octave date vector 'datevec'
237 RowVector datevec(6);
238
239 // Assign members 'datevec', converting 'tm' struct date ranges to Octave date ranges
240 datevec(0) = $1->tm_year + 1900; // Octave stores 4-digit years
241 datevec(1) = $1->tm_mon + 1; // Octave months start from 1
242 datevec(2) = $1->tm_mday;
243 datevec(3) = $1->tm_hour;
244 datevec(4) = $1->tm_min;
245 datevec(5) = $1->tm_sec;
246
247 $result = octave_value(datevec);
248
249}
250
251//
252// Interface code to track object parents
253//
254
255// Interface code which tracks the parent structs of SWIG-wrapped struct members, so that the parent
256// struct is not destroyed as long as a SWIG-wrapped object containing any of its members exists.
257%header %{
258
259#include <map>
260
261// Internal map from member pointers to octave_values containing the member parent struct, as well
262// as an internal reference count of how many SWIG-wrapped member objects are extant.
263typedef std::pair<octave_value, int> swiglal_oct_parent;
264typedef std::pair<void*, swiglal_oct_parent> swiglal_oct_parent_pair;
265typedef std::map<void*, swiglal_oct_parent> swiglal_oct_parent_map;
266static swiglal_oct_parent_map* parent_map = 0;
267
268// Store a reference to the parent of ptr in the internal map. If there is already such a reference,
269// increment the internal reference count instead.
270SWIGINTERN void swiglal_store_parent(void* ptr, octave_value parent) {
271 assert(ptr);
272 assert(parent.is_defined());
273 swiglal_oct_parent_map::iterator i = parent_map->find(ptr);
274 if (i == parent_map->end()) {
275 parent_map->insert(swiglal_oct_parent_pair(ptr, swiglal_oct_parent(parent, 1)));
276 }
277 else {
278 ++i->second.second;
279 }
280}
281
282// Check if ptr stored a reference to a parent struct. If there is no parent object, then ptr
283// *really* owns its memory, and it's okay for it to destroy it (so return true). Otherwise,
284// decrement the internal reference count, erase the parent map entry if it reaches zero, and return
285// false to prevent any destructors being called.
286SWIGINTERN bool swiglal_release_parent(void *ptr) {
287 bool retn = true;
288 assert(ptr);
289 swiglal_oct_parent_map::iterator i = parent_map->find(ptr);
290 if (i != parent_map->end()) {
291 retn = false;
292 if (--i->second.second == 0) {
293 parent_map->erase(i);
294 }
295 }
296 return retn;
297}
298
299%} // %header
300%init %{
301
302// Get a pointer to the internal parent map. Look for a global variable ' __SWIGLAL_parent_map__',
303// then try to extract a pointer to the parent map from a SWIG packed object. If the packed object
304// does not yet exist, create a new map, pack its pointer in a SWIG packed object, then assign it to
305// global variable. Thus each binding gets a pointer to the same map.
306{
307 const char* const parent_map_name = "__SWIGLAL_parent_map__";
308 octave_value ov = SWIG_Octave_GetGlobalValue(parent_map_name);
309 int res = SWIG_ConvertPacked(ov, &parent_map, sizeof(parent_map), 0);
310 if (!SWIG_IsOK(res)) {
311 parent_map = new swiglal_oct_parent_map();
312 ov = SWIG_NewPackedObj(&parent_map, sizeof(parent_map), 0);
313 SWIG_Octave_SetGlobalValue(parent_map_name, ov);
314 }
315 assert(parent_map);
316}
317
318%} // %init
319
320//
321// Fragments and typemaps for arrays
322//
323
324// This section implements a series of array view classes, through which arbitrary C array data can
325// be viewed as native Octave matrices, etc.
326
327// Name of array view class for array conversion type ACFTYPE.
328#define %swiglal_oct_array_view_class(ACFTYPE) swiglal_oct_array_view_##ACFTYPE
329
330// Name of helper class for array view class for array conversion type ACFTYPE.
331#define %swiglal_oct_array_view_helper_class(ACFTYPE) swiglal_oct_array_view_helper_##ACFTYPE
332
333// Name of base array view template for array conversion type ACFTYPE.
334#define %swiglal_oct_array_view_tmpl(ACFTYPE) swiglal_oct_array_view<%swiglal_oct_array_view_helper_class(ACFTYPE) >
335
336// String denoting octave_value type of array view class for array conversion type ACFTYPE.
337#define %swiglal_oct_array_view_ovtype(ACFTYPE) "swiglal_oct_array_view_" %str(ACFTYPE)
338
339// Name of fragment containing array view class for array conversion type ACFTYPE.
340#define %swiglal_oct_array_view_frag(ACFTYPE) "swiglal_oct_array_view_" %str(ACFTYPE)
341
342// Name of fragment containing initialisation code for array view class for array conversion type
343// ACFTYPE.
344#define %swiglal_oct_array_view_init_frag(ACFTYPE) "swiglal_oct_array_view_init_" %str(ACFTYPE)
345
346// Fragment defining a base array view template, where all functionality is implemented, and from
347// which ACFTYPE-specific array view classes inherit. The template argument is a helper class which
348// supplied ACFTYPE-specific functions and types.
349%fragment("swiglal_oct_array_view", "header") {
350
351 extern "C++" {
352
353 template<class HELPER>
354 class swiglal_oct_array_view : public octave_base_value {
355
356 private:
357
358 // Instance of the corresponding octave_base_value-derived class of the array view class, for
359 // consulting as to various properties.
360 const typename HELPER::OVClass sloav_class;
361
362 // Keep a reference to the SWIG-wrapped struct containing the C array being viewed, to prevent
363 // it being destroyed if the struct goes out of scope by the array view remains.
364 const octave_value sloav_parent;
365
366 // Parameters of the C array data being viewed, and associated SWIG type information.
367 void *const sloav_ptr;
368 const size_t sloav_esize;
369 const size_t sloav_ndims;
370 const dim_vector sloav_dims;
371 const dim_vector sloav_strides;
372 const bool sloav_isptr;
373 swig_type_info *const sloav_tinfo;
374 const int sloav_tflags;
375
376 // Construct an Octave dim_vector from a C array.
377 static dim_vector sloav_make_dim_vector(const size_t n, const size_t v[]) {
378 dim_vector dv(n, 1);
379 for (size_t i = 0; i < n; ++i) {
380 dv(i) = v[i];
381 }
382 return dv;
383 }
384
385 // Numeric conversion function for converting an array view into an Octave array.
386 static octave_base_value* sloav_numeric_conversion_function(const octave_base_value& v) {
387 const swiglal_oct_array_view& oav = dynamic_cast<const swiglal_oct_array_view&>(v);
388 octave_value ov = oav.sloav_array_out();
389 return new typename HELPER::OVClass(HELPER::ovvalue(ov));
390 }
391
392 // Compute the scalar index of the C array element, and return a pointer to the element itself.
393 void* sloav_get_element_ptr(Array<octave_idx_type>& idx) const {
394 size_t elemidx = 0;
395 for (size_t j = 0; j < sloav_ndims; ++j) {
396 elemidx += idx(j) * sloav_strides(j);
397 }
398 return reinterpret_cast<void*>(reinterpret_cast<char*>(sloav_ptr) + elemidx*sloav_esize);
399 }
400
401 // Increment the Octave array index in row-major order, to match the ordering of the C array.
402 void sloav_increment_idx(Array<octave_idx_type>& idx) const {
403 for (int j = sloav_ndims-1; j >= 0; --j) {
404 if (++idx(j) < sloav_dims(j)) {
405 break;
406 }
407 idx(j) = 0;
408 }
409 }
410
411 public:
412
413 virtual ~swiglal_oct_array_view()
414 { }
415
416 swiglal_oct_array_view()
417 : octave_base_value(), sloav_class(typename HELPER::OVClass()),
418 sloav_parent(), sloav_ptr(0), sloav_esize(0), sloav_ndims(0),
419 sloav_dims(), sloav_strides(),
420 sloav_isptr(false), sloav_tinfo(0), sloav_tflags(0)
421 { }
422
423 swiglal_oct_array_view(const octave_value& parent,
424 void* ptr,
425 const size_t esize,
426 const size_t ndims,
427 const size_t dims[],
428 const size_t strides[],
429 const bool isptr,
430 swig_type_info* tinfo,
431 const int tflags)
432 : octave_base_value(), sloav_class(typename HELPER::OVClass()),
433 sloav_parent(parent), sloav_ptr(ptr), sloav_esize(esize), sloav_ndims(ndims),
434 sloav_dims(sloav_make_dim_vector(ndims, dims)),
435 sloav_strides(sloav_make_dim_vector(ndims, strides)),
436 sloav_isptr(isptr), sloav_tinfo(tinfo), sloav_tflags(tflags)
437 { }
438
439 // Copy the Octave array obj to the C array.
440 int sloav_array_in(octave_value& obj, int *pelemalloc, const int tflags) {
441
442 // Check that C array pointer is valid.
443 if (!sloav_ptr) {
444 return SWIG_MemoryError;
445 }
446
447 // Check that Octave array dimensions are consistent with C array dimensions. 1-D arrays
448 // are a special case, since Octave arrays are always at least 2-dimensional, so need to
449 // check that one of those dimensions is singular.
450 dim_vector objdims = obj.dims();
451 if (sloav_ndims == 1) {
452 if (objdims.length() > 2 || objdims.num_ones() == 0 || objdims.numel() != sloav_dims(0)) {
453 return SWIG_ValueError;
454 }
455 }
456 else if (objdims != sloav_dims) {
457 return SWIG_ValueError;
458 }
459
460 // Iterate over all elements in the C array.
461 Array<octave_idx_type> idx(dim_vector(1, sloav_ndims), 0);
462 std::list<octave_value_list> objidx(1);
463 for (int i = 0; i < objdims.numel(); ++i) {
464
465 // Get the scalar index of the Octave array element, and the element itself.
466 objidx.front()(0) = get_scalar_idx(idx, objdims) + 1;
467 octave_value objelem = obj.subsref(obj.is_cell() ? "{" : "(", objidx);
468
469 // Copy the Octave array element to the C array.
470 int res = HELPER::incall(sloav_parent, objelem, sloav_get_element_ptr(idx), pelemalloc, sloav_esize, sloav_isptr, sloav_tinfo, sloav_tflags | tflags);
471 if (!SWIG_IsOK(res)) {
472 return res;
473 }
474
475 // Increment the Octave array index.
476 sloav_increment_idx(idx);
477
478 }
479
480 return SWIG_OK;
481
482 }
483
484 // Copy the C array to the returned Octave array.
485 octave_value sloav_array_out(const bool copyobj = false) const {
486
487 // Check that C array pointer is valid.
488 if (!sloav_ptr) {
489 return octave_value();
490 }
491
492 // Create a new Octave array.
493 dim_vector objdims = sloav_dims;
494 typename HELPER::OVType objval(objdims);
495 octave_value obj(objval);
496
497 // Iterate over all elements in the C array.
498 Array<octave_idx_type> idx(dim_vector(1, sloav_ndims), 0);
499 std::list<octave_value_list> objidx(1);
500 for (int i = 0; i < objdims.numel(); ++i) {
501
502 // Get the scalar index of the Octave array element.
503 objidx.front()(0) = get_scalar_idx(idx, objdims) + 1;
504
505 // Copy the C array element to the Octave array.
506 octave_value objelem = HELPER::outcall(sloav_parent, copyobj, sloav_get_element_ptr(idx), sloav_esize, sloav_isptr, sloav_tinfo, sloav_tflags);
507 obj = obj.subsasgn(obj.is_cell() ? "{" : "(", objidx, objelem);
508
509 // Increment the Octave array index.
510 sloav_increment_idx(idx);
511
512 }
513
514 return obj;
515
516 }
517
518 // The following methods override virtual methods in octave_base_value.
519
520 // Array dimensions.
521 dim_vector dims() const {
522 return sloav_dims;
523 }
524
525 // Return an Octave array.
526 octave_value full_value() const {
527 return sloav_array_out();
528 }
529
530 // Return an empty Octave array.
531 octave_base_value* empty_clone() const {
532 return sloav_array_out().empty_clone();
533 }
534
535 // Return the numeric conversion function.
536 octave_base_value::type_conv_info numeric_conversion_function() const {
537 return octave_base_value::type_conv_info(sloav_numeric_conversion_function, sloav_class.type_id());
538 }
539
540 // Do indexing without resizing.
541 octave_value do_index_op(const octave_value_list& idx, bool resize_ok) {
542 return sloav_array_out().do_index_op(idx, false);
543 }
544 octave_value_list do_multi_index_op(int nargout, const octave_value_list& idx) {
545 return sloav_array_out().do_multi_index_op(nargout, idx);
546 }
547
548 // Do subscripting on Octave array.
549 octave_value subsref(const std::string& type, const std::list<octave_value_list>& idx) {
550 return sloav_array_out().subsref(type, idx);
551 }
552 octave_value_list subsref(const std::string& type, const std::list<octave_value_list>& idx, int nargout) {
553 return sloav_array_out().subsref(type, idx, nargout);
554 }
555
556 // Do subscript assignment, and copy result back to C array.
557 octave_value subsasgn(const std::string& type, const std::list<octave_value_list>& idx, const octave_value& rhs) {
558 octave_value obj = sloav_array_out().subsasgn(type, idx, rhs);
559 int elemalloc = 0;
560 // When assigning Octave objects to a C array of pointers, assume the struct
561 // who owns the C array takes ownership of the memory of the C array element.
562 // The Octave object wrapping the C array element should therefore disown the
563 // underlying memory.
564 // When assigning Octave objects to a C array of data blocks, however, the C
565 // array just struct-copies the object rather than taking ownership of its
566 // pointer, and so the Octave object should not be disowned so that it can
567 // be garbage-collected later.
568 int res = sloav_array_in(obj, &elemalloc, sloav_isptr ? SWIG_POINTER_DISOWN : 0);
569 if (!SWIG_IsOK(res)) {
570 std::string n = type_name();
571 std::string e = SWIG_ErrorType(res).string_value();
572 error("failed to perform indexed assignment for %s type: %s", n.c_str(), e.c_str());
573 return octave_value();
574 }
575 count++;
576 return octave_value(this);
577 }
578
579 // Save and load from ASCII.
580 bool save_ascii (std::ostream& os) {
581 return sloav_array_out().save_ascii(os);
582 }
583 bool load_ascii(std::istream& is) {
584 octave_value obj = sloav_array_out();
585 int elemalloc = 0;
586 return obj.load_ascii(is) && SWIG_IsOK(sloav_array_in(obj, &elemalloc, 0));
587 }
588
589 // Save and load from binary.
590 bool save_binary(std::ostream& os, bool& save_as_floats) {
591 return sloav_array_out().save_binary(os, save_as_floats);
592 }
593 bool load_binary(std::istream& is, bool swap, oct_mach_info::float_format fmt) {
594 octave_value obj = sloav_array_out();
595 int elemalloc = 0;
596 return obj.load_binary(is, swap, fmt) && SWIG_IsOK(sloav_array_in(obj, &elemalloc, 0));
597 }
598
599 // Save and load from HDF5.
600%#ifdef HAVE_HDF5
601%#if SWIG_OCTAVE_PREREQ(4,0,0)
602 bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats) {
603 return sloav_array_out().save_hdf5(loc_id, name, save_as_floats);
604 }
605%#else
606 bool save_hdf5(hid_t loc_id, const char *name, bool save_as_floats) {
607 return sloav_array_out().save_hdf5(loc_id, name, save_as_floats);
608 }
609%#endif
610%#if SWIG_OCTAVE_PREREQ(4,0,0)
611 bool load_hdf5(octave_hdf5_id loc_id, const char *name) {
612 octave_value obj = sloav_array_out();
613 int elemalloc = 0;
614 return obj.load_hdf5(loc_id, name) && SWIG_IsOK(sloav_array_in(obj, &elemalloc, 0));
615 }
616%#elif SWIG_OCTAVE_PREREQ(3,3,52)
617 bool load_hdf5(hid_t loc_id, const char *name) {
618 octave_value obj = sloav_array_out();
619 int elemalloc = 0;
620 return obj.load_hdf5(loc_id, name) && SWIG_IsOK(sloav_array_in(obj, &elemalloc, 0));
621 }
622%#else
623 bool load_hdf5(hid_t loc_id, const char *name, bool have_h5giterate_bug) {
624 octave_value obj = sloav_array_out();
625 int elemalloc = 0;
626 return obj.load_hdf5(loc_id, name, have_h5giterate_bug) && SWIG_IsOK(sloav_array_in(obj, &elemalloc, 0));
627 }
628%#endif
629%#endif
630
631 // Print array.
632%#if SWIG_OCTAVE_PREREQ(4,0,0)
633 void print(std::ostream &os, bool pr_as_read_syntax = false)
634%#else
635 void print(std::ostream &os, bool pr_as_read_syntax = false) const
636%#endif
637 {
638 return sloav_array_out().print(os, pr_as_read_syntax);
639 }
640
641 // The following methods override virtual const-methods in octave_base_value. These methods
642 // are mapped to the equivalent method of the octave_base_value-derived class of the array
643 // view class.
644
645#define SLOAV_OBV_METH_FROM_CLASS_0(N, R) R N() const { return sloav_class.N(); }
646 SLOAV_OBV_METH_FROM_CLASS_0(is_all_va_args, bool);
647 SLOAV_OBV_METH_FROM_CLASS_0(is_bool_matrix, bool);
648 SLOAV_OBV_METH_FROM_CLASS_0(is_bool_scalar, bool);
649 SLOAV_OBV_METH_FROM_CLASS_0(is_bool_type, bool);
650 SLOAV_OBV_METH_FROM_CLASS_0(is_builtin_function, bool);
651%#if SWIG_OCTAVE_PREREQ(4,4,0)
652 SLOAV_OBV_METH_FROM_CLASS_0(iscell, bool);
653 SLOAV_OBV_METH_FROM_CLASS_0(iscellstr, bool);
654%#else
655 SLOAV_OBV_METH_FROM_CLASS_0(is_cell, bool);
656 SLOAV_OBV_METH_FROM_CLASS_0(is_cellstr, bool);
657%#endif
658 SLOAV_OBV_METH_FROM_CLASS_0(is_char_matrix, bool);
659 SLOAV_OBV_METH_FROM_CLASS_0(is_classdef_meta, bool);
660 SLOAV_OBV_METH_FROM_CLASS_0(is_classdef_object, bool);
661 SLOAV_OBV_METH_FROM_CLASS_0(is_classdef_superclass_ref, bool);
662 SLOAV_OBV_METH_FROM_CLASS_0(is_complex_matrix, bool);
663 SLOAV_OBV_METH_FROM_CLASS_0(is_complex_scalar, bool);
664 SLOAV_OBV_METH_FROM_CLASS_0(is_complex_type, bool);
665 SLOAV_OBV_METH_FROM_CLASS_0(is_constant, bool);
666 SLOAV_OBV_METH_FROM_CLASS_0(is_cs_list, bool);
667 SLOAV_OBV_METH_FROM_CLASS_0(is_defined, bool);
668 SLOAV_OBV_METH_FROM_CLASS_0(is_diag_matrix, bool);
669 SLOAV_OBV_METH_FROM_CLASS_0(is_dld_function, bool);
670 SLOAV_OBV_METH_FROM_CLASS_0(is_double_type, bool);
671 SLOAV_OBV_METH_FROM_CLASS_0(is_float_type, bool);
672 SLOAV_OBV_METH_FROM_CLASS_0(is_function, bool);
673 SLOAV_OBV_METH_FROM_CLASS_0(is_function_handle, bool);
674 SLOAV_OBV_METH_FROM_CLASS_0(is_inline_function, bool);
675 SLOAV_OBV_METH_FROM_CLASS_0(is_int16_type, bool);
676 SLOAV_OBV_METH_FROM_CLASS_0(is_int32_type, bool);
677 SLOAV_OBV_METH_FROM_CLASS_0(is_int64_type, bool);
678 SLOAV_OBV_METH_FROM_CLASS_0(is_int8_type, bool);
679 SLOAV_OBV_METH_FROM_CLASS_0(is_integer_type, bool);
680 SLOAV_OBV_METH_FROM_CLASS_0(is_list, bool);
681 SLOAV_OBV_METH_FROM_CLASS_0(is_magic_colon, bool);
682 SLOAV_OBV_METH_FROM_CLASS_0(is_map, bool);
683 SLOAV_OBV_METH_FROM_CLASS_0(is_matrix_type, bool);
684 SLOAV_OBV_METH_FROM_CLASS_0(is_mex_function, bool);
685 SLOAV_OBV_METH_FROM_CLASS_0(is_null_value, bool);
686 SLOAV_OBV_METH_FROM_CLASS_0(is_numeric_type, bool);
687 SLOAV_OBV_METH_FROM_CLASS_0(is_object, bool);
688 SLOAV_OBV_METH_FROM_CLASS_0(is_perm_matrix, bool);
689 SLOAV_OBV_METH_FROM_CLASS_0(is_range, bool);
690 SLOAV_OBV_METH_FROM_CLASS_0(is_real_matrix, bool);
691 SLOAV_OBV_METH_FROM_CLASS_0(is_real_nd_array, bool);
692 SLOAV_OBV_METH_FROM_CLASS_0(is_real_scalar, bool);
693 SLOAV_OBV_METH_FROM_CLASS_0(is_real_type, bool);
694 SLOAV_OBV_METH_FROM_CLASS_0(is_scalar_type, bool);
695 SLOAV_OBV_METH_FROM_CLASS_0(is_single_type, bool);
696 SLOAV_OBV_METH_FROM_CLASS_0(is_sparse_type, bool);
697 SLOAV_OBV_METH_FROM_CLASS_0(is_sq_string, bool);
698 SLOAV_OBV_METH_FROM_CLASS_0(is_string, bool);
699 SLOAV_OBV_METH_FROM_CLASS_0(is_true, bool);
700 SLOAV_OBV_METH_FROM_CLASS_0(is_uint16_type, bool);
701 SLOAV_OBV_METH_FROM_CLASS_0(is_uint32_type, bool);
702 SLOAV_OBV_METH_FROM_CLASS_0(is_uint64_type, bool);
703 SLOAV_OBV_METH_FROM_CLASS_0(is_uint8_type, bool);
704 SLOAV_OBV_METH_FROM_CLASS_0(is_user_code, bool);
705 SLOAV_OBV_METH_FROM_CLASS_0(is_user_function, bool);
706 SLOAV_OBV_METH_FROM_CLASS_0(is_user_script, bool);
707 SLOAV_OBV_METH_FROM_CLASS_0(isjava, bool);
708 SLOAV_OBV_METH_FROM_CLASS_0(isobject, bool);
709 SLOAV_OBV_METH_FROM_CLASS_0(isstruct, bool);
710#undef SLOAV_OBV_METH_FROM_CLASS_0
711
712 // The following methods override virtual const-methods in octave_base_value. These methods
713 // are mapped to the equivalent method of the Octave array.
714
715#define SLOAV_OBV_METH_FROM_ARRAY_0(N, R) R N() const { return sloav_array_out().N(); }
716#define SLOAV_OBV_METH_FROM_ARRAY_1(N, R, A) R N(A a) const { return sloav_array_out().N(a); }
717#define SLOAV_OBV_METH_FROM_ARRAY_2(N, R, A, B) R N(A a, B b) const { return sloav_array_out().N(a, b); }
718#define SLOAV_OBV_METH_FROM_ARRAY_3(N, R, A, B, C) R N(A a, B b, C c) const { return sloav_array_out().N(a, b, c); }
719#define SLOAV_OBV_METH_FROM_ARRAY_4(N, R, A, B, C, D) R N(A a, B b, C c, D d) const { return sloav_array_out().N(a, b, c, d); }
720#define SLOAV_OBV_METH_FROM_ARRAY_5(N, R, A, B, C, D, E) R N(A a, B b, C c, D d, E e) const { return sloav_array_out().N(a, b, c, d, e); }
721%#if SWIG_OCTAVE_PREREQ(4,2,0)
722 SLOAV_OBV_METH_FROM_ARRAY_0(as_double, octave_value);
723 SLOAV_OBV_METH_FROM_ARRAY_0(as_single, octave_value);
724%#endif
725%#if SWIG_OCTAVE_PREREQ(3,3,52)
726 SLOAV_OBV_METH_FROM_ARRAY_0(map_value, octave_map);
727%#else
728 SLOAV_OBV_METH_FROM_ARRAY_0(map_value, Octave_map);
729%#endif
730 SLOAV_OBV_METH_FROM_ARRAY_0(abs, octave_value);
731 SLOAV_OBV_METH_FROM_ARRAY_0(acos, octave_value);
732 SLOAV_OBV_METH_FROM_ARRAY_0(acosh, octave_value);
733 SLOAV_OBV_METH_FROM_ARRAY_0(angle, octave_value);
734 SLOAV_OBV_METH_FROM_ARRAY_0(arg, octave_value);
735 SLOAV_OBV_METH_FROM_ARRAY_0(asin, octave_value);
736 SLOAV_OBV_METH_FROM_ARRAY_0(asinh, octave_value);
737 SLOAV_OBV_METH_FROM_ARRAY_0(atan, octave_value);
738 SLOAV_OBV_METH_FROM_ARRAY_0(atanh, octave_value);
739 SLOAV_OBV_METH_FROM_ARRAY_0(byte_size, size_t);
740 SLOAV_OBV_METH_FROM_ARRAY_0(ceil, octave_value);
741 SLOAV_OBV_METH_FROM_ARRAY_0(cell_value, Cell);
742 SLOAV_OBV_METH_FROM_ARRAY_0(cellstr_value, Array<std::string>);
743 SLOAV_OBV_METH_FROM_ARRAY_0(conj, octave_value);
744 SLOAV_OBV_METH_FROM_ARRAY_0(cos, octave_value);
745 SLOAV_OBV_METH_FROM_ARRAY_0(cosh, octave_value);
746 SLOAV_OBV_METH_FROM_ARRAY_0(erf, octave_value);
747 SLOAV_OBV_METH_FROM_ARRAY_0(erfc, octave_value);
748 SLOAV_OBV_METH_FROM_ARRAY_0(exp, octave_value);
749 SLOAV_OBV_METH_FROM_ARRAY_0(expm1, octave_value);
750 SLOAV_OBV_METH_FROM_ARRAY_0(finite, octave_value);
751 SLOAV_OBV_METH_FROM_ARRAY_0(fix, octave_value);
752 SLOAV_OBV_METH_FROM_ARRAY_0(floor, octave_value);
753 SLOAV_OBV_METH_FROM_ARRAY_0(gamma, octave_value);
754 SLOAV_OBV_METH_FROM_ARRAY_0(imag, octave_value);
755 SLOAV_OBV_METH_FROM_ARRAY_0(index_vector, idx_vector);
756 SLOAV_OBV_METH_FROM_ARRAY_0(int16_array_value, int16NDArray);
757 SLOAV_OBV_METH_FROM_ARRAY_0(int16_scalar_value, octave_int16);
758 SLOAV_OBV_METH_FROM_ARRAY_0(int32_array_value, int32NDArray);
759 SLOAV_OBV_METH_FROM_ARRAY_0(int32_scalar_value, octave_int32);
760 SLOAV_OBV_METH_FROM_ARRAY_0(int64_array_value, int64NDArray);
761 SLOAV_OBV_METH_FROM_ARRAY_0(int64_scalar_value, octave_int64);
762 SLOAV_OBV_METH_FROM_ARRAY_0(int8_array_value, int8NDArray);
763 SLOAV_OBV_METH_FROM_ARRAY_0(int8_scalar_value, octave_int8);
764 SLOAV_OBV_METH_FROM_ARRAY_0(isinf, octave_value);
765 SLOAV_OBV_METH_FROM_ARRAY_0(isna, octave_value);
766 SLOAV_OBV_METH_FROM_ARRAY_0(isnan, octave_value);
767 SLOAV_OBV_METH_FROM_ARRAY_0(lgamma, octave_value);
768 SLOAV_OBV_METH_FROM_ARRAY_0(log, octave_value);
769 SLOAV_OBV_METH_FROM_ARRAY_0(log10, octave_value);
770 SLOAV_OBV_METH_FROM_ARRAY_0(log1p, octave_value);
771 SLOAV_OBV_METH_FROM_ARRAY_0(log2, octave_value);
772 SLOAV_OBV_METH_FROM_ARRAY_0(matrix_type, MatrixType);
773 SLOAV_OBV_METH_FROM_ARRAY_0(nnz, octave_idx_type);
774 SLOAV_OBV_METH_FROM_ARRAY_0(nzmax, octave_idx_type);
775 SLOAV_OBV_METH_FROM_ARRAY_0(perm_matrix_value, PermMatrix);
776 SLOAV_OBV_METH_FROM_ARRAY_0(range_value, Range);
777 SLOAV_OBV_METH_FROM_ARRAY_0(real, octave_value);
778 SLOAV_OBV_METH_FROM_ARRAY_0(round, octave_value);
779 SLOAV_OBV_METH_FROM_ARRAY_0(roundb, octave_value);
780 SLOAV_OBV_METH_FROM_ARRAY_0(signum, octave_value);
781 SLOAV_OBV_METH_FROM_ARRAY_0(sin, octave_value);
782 SLOAV_OBV_METH_FROM_ARRAY_0(sinh, octave_value);
783 SLOAV_OBV_METH_FROM_ARRAY_0(sqrt, octave_value);
784 SLOAV_OBV_METH_FROM_ARRAY_0(tan, octave_value);
785 SLOAV_OBV_METH_FROM_ARRAY_0(tanh, octave_value);
786 SLOAV_OBV_METH_FROM_ARRAY_0(uint16_array_value, uint16NDArray);
787 SLOAV_OBV_METH_FROM_ARRAY_0(uint16_scalar_value, octave_uint16);
788 SLOAV_OBV_METH_FROM_ARRAY_0(uint32_array_value, uint32NDArray);
789 SLOAV_OBV_METH_FROM_ARRAY_0(uint32_scalar_value, octave_uint32);
790 SLOAV_OBV_METH_FROM_ARRAY_0(uint64_array_value, uint64NDArray);
791 SLOAV_OBV_METH_FROM_ARRAY_0(uint64_scalar_value, octave_uint64);
792 SLOAV_OBV_METH_FROM_ARRAY_0(uint8_array_value, uint8NDArray);
793 SLOAV_OBV_METH_FROM_ARRAY_0(uint8_scalar_value, octave_uint8);
794 SLOAV_OBV_METH_FROM_ARRAY_0(xisalnum, octave_value);
795 SLOAV_OBV_METH_FROM_ARRAY_0(xisalpha, octave_value);
796 SLOAV_OBV_METH_FROM_ARRAY_0(xisascii, octave_value);
797 SLOAV_OBV_METH_FROM_ARRAY_0(xiscntrl, octave_value);
798 SLOAV_OBV_METH_FROM_ARRAY_0(xisdigit, octave_value);
799 SLOAV_OBV_METH_FROM_ARRAY_0(xisgraph, octave_value);
800 SLOAV_OBV_METH_FROM_ARRAY_0(xislower, octave_value);
801 SLOAV_OBV_METH_FROM_ARRAY_0(xisprint, octave_value);
802 SLOAV_OBV_METH_FROM_ARRAY_0(xispunct, octave_value);
803 SLOAV_OBV_METH_FROM_ARRAY_0(xisspace, octave_value);
804 SLOAV_OBV_METH_FROM_ARRAY_0(xisupper, octave_value);
805 SLOAV_OBV_METH_FROM_ARRAY_0(xisxdigit, octave_value);
806 SLOAV_OBV_METH_FROM_ARRAY_0(xtoascii, octave_value);
807 SLOAV_OBV_METH_FROM_ARRAY_0(xtolower, octave_value);
808 SLOAV_OBV_METH_FROM_ARRAY_0(xtoupper, octave_value);
809 SLOAV_OBV_METH_FROM_ARRAY_1(all, octave_value, int);
810 SLOAV_OBV_METH_FROM_ARRAY_1(all_strings, string_vector, bool);
811 SLOAV_OBV_METH_FROM_ARRAY_1(any, octave_value, int);
812 SLOAV_OBV_METH_FROM_ARRAY_1(array_value, NDArray, bool);
813 SLOAV_OBV_METH_FROM_ARRAY_1(bool_array_value, boolNDArray, bool);
814 SLOAV_OBV_METH_FROM_ARRAY_1(bool_matrix_value, boolMatrix, bool);
815 SLOAV_OBV_METH_FROM_ARRAY_1(bool_value, bool, bool);
816 SLOAV_OBV_METH_FROM_ARRAY_1(char_array_value, charNDArray, bool);
817 SLOAV_OBV_METH_FROM_ARRAY_1(char_matrix_value, charMatrix, bool);
818 SLOAV_OBV_METH_FROM_ARRAY_1(complex_array_value, ComplexNDArray, bool);
819 SLOAV_OBV_METH_FROM_ARRAY_1(complex_diag_matrix_value, ComplexDiagMatrix, bool);
820 SLOAV_OBV_METH_FROM_ARRAY_1(complex_matrix_value, ComplexMatrix, bool);
821 SLOAV_OBV_METH_FROM_ARRAY_1(complex_value, Complex, bool);
822 SLOAV_OBV_METH_FROM_ARRAY_1(diag, octave_value, octave_idx_type);
823 SLOAV_OBV_METH_FROM_ARRAY_1(diag_matrix_value, DiagMatrix, bool);
824 SLOAV_OBV_METH_FROM_ARRAY_1(double_value, double, bool);
825 SLOAV_OBV_METH_FROM_ARRAY_1(float_array_value, FloatNDArray, bool);
826 SLOAV_OBV_METH_FROM_ARRAY_1(float_complex_array_value, FloatComplexNDArray, bool);
827 SLOAV_OBV_METH_FROM_ARRAY_1(float_complex_diag_matrix_value, FloatComplexDiagMatrix, bool);
828 SLOAV_OBV_METH_FROM_ARRAY_1(float_complex_matrix_value, FloatComplexMatrix, bool);
829 SLOAV_OBV_METH_FROM_ARRAY_1(float_complex_value, FloatComplex, bool);
830 SLOAV_OBV_METH_FROM_ARRAY_1(float_diag_matrix_value, FloatDiagMatrix, bool);
831 SLOAV_OBV_METH_FROM_ARRAY_1(float_matrix_value, FloatMatrix, bool);
832 SLOAV_OBV_METH_FROM_ARRAY_1(float_value, float, bool);
833 SLOAV_OBV_METH_FROM_ARRAY_1(is_sorted, sortmode, sortmode);
834 SLOAV_OBV_METH_FROM_ARRAY_1(is_sorted_rows, sortmode, sortmode);
835 SLOAV_OBV_METH_FROM_ARRAY_1(matrix_value, Matrix, bool);
836 SLOAV_OBV_METH_FROM_ARRAY_1(reshape, octave_value, const dim_vector&);
837 SLOAV_OBV_METH_FROM_ARRAY_1(sort_rows_ids, Array<octave_idx_type>, sortmode);
838 SLOAV_OBV_METH_FROM_ARRAY_1(sparse_bool_matrix_value, SparseBoolMatrix, bool);
839 SLOAV_OBV_METH_FROM_ARRAY_1(sparse_complex_matrix_value, SparseComplexMatrix, bool);
840 SLOAV_OBV_METH_FROM_ARRAY_1(sparse_matrix_value, SparseMatrix, bool);
841 SLOAV_OBV_METH_FROM_ARRAY_1(string_value, std::string, bool);
842 SLOAV_OBV_METH_FROM_ARRAY_2(int_value, int, bool, bool);
843 SLOAV_OBV_METH_FROM_ARRAY_2(long_value, long int, bool, bool);
844 SLOAV_OBV_METH_FROM_ARRAY_2(permute, octave_value, const Array<int>&, bool);
845 SLOAV_OBV_METH_FROM_ARRAY_2(print_info, void, std::ostream&, bool);
846 SLOAV_OBV_METH_FROM_ARRAY_2(print_raw, void, std::ostream&, bool);
847 SLOAV_OBV_METH_FROM_ARRAY_2(resize, octave_value, const dim_vector&, bool);
848 SLOAV_OBV_METH_FROM_ARRAY_2(short_value, short int, bool, bool);
849 SLOAV_OBV_METH_FROM_ARRAY_2(sort, octave_value, octave_idx_type, sortmode);
850 SLOAV_OBV_METH_FROM_ARRAY_2(uint_value, unsigned int, bool, bool);
851 SLOAV_OBV_METH_FROM_ARRAY_2(ulong_value, unsigned long int, bool, bool);
852 SLOAV_OBV_METH_FROM_ARRAY_2(ushort_value, unsigned short int, bool, bool);
853 SLOAV_OBV_METH_FROM_ARRAY_3(convert_to_str_internal, octave_value, bool, bool, char);
854 SLOAV_OBV_METH_FROM_ARRAY_3(sort, octave_value, Array<octave_idx_type>&, octave_idx_type, sortmode);
855 SLOAV_OBV_METH_FROM_ARRAY_5(write, int, octave_stream&, int, oct_data_conv::data_type, int, oct_mach_info::float_format);
856#undef SLOAV_OBV_METH_FROM_ARRAY_0
857#undef SLOAV_OBV_METH_FROM_ARRAY_1
858#undef SLOAV_OBV_METH_FROM_ARRAY_2
859#undef SLOAV_OBV_METH_FROM_ARRAY_3
860#undef SLOAV_OBV_METH_FROM_ARRAY_4
861#undef SLOAV_OBV_METH_FROM_ARRAY_5
862
863 }; // class swiglal_oct_array_view
864
865 } // extern "C++"
866
867} // fragment swiglal_oct_array_view
868
869// Macro which generates fragments which define ACFTYPE-specific array view classes and conversion
870// functions:
871// - IN/OUTFRAG are names of fragments required by the in/out conversion functions IN/OUTCALL.
872// - OVCLASS is the octave_base_value-derived class of the array view class.
873// - OVTYPE is the type of octave_value array value.
874// - OVVALUE() is the method of octave_value which returns an OVTYPE.
875// - ISOVTYPEEXPR returns true if the octave_value 'obj' is of type OVTYPE.
876%define %swiglal_oct_array_frags(ACFTYPE, INFRAG, OUTFRAG, INCALL, OUTCALL, OVCLASS, OVTYPE, OVVALUE, ISOVTYPEEXPR)
877
878// Register the ACFTYPE-specific array view class as an Octave type.
879%fragment(%swiglal_oct_array_view_init_frag(ACFTYPE), "init") %{
880#if SWIG_OCTAVE_PREREQ(4,4,0)
881 {
882 octave::type_info& typeinfo = octave::interpreter::the_interpreter()->get_type_info();
883 string_vector types = typeinfo.installed_type_names();
884 bool register_octave_array_view_class = true;
885 bool register_octave_swig_packed = true;
886 for (int i = 0; i < types.numel(); ++i) {
887 if (types(i) == %swiglal_oct_array_view_class(ACFTYPE)::static_type_name()) {
888 register_octave_array_view_class = false;
889 }
890 }
891 if (register_octave_array_view_class) {
892 %swiglal_oct_array_view_class(ACFTYPE)::register_type();
893 }
894 }
895#else
896 %swiglal_oct_array_view_class(ACFTYPE)::register_type();
897#endif
898%}
899
900// ACFTYPE-specific array view class fragment.
901%fragment(%swiglal_oct_array_view_frag(ACFTYPE), "header",
902 fragment=%swiglal_oct_array_view_init_frag(ACFTYPE),
903 fragment="swiglal_oct_array_view", fragment=INFRAG, fragment=OUTFRAG)
904%{
905
906 extern "C++" {
907
908 // Helper class which supplies ACFTYPE-specific types and functions to the base template
909 // swiglal_oct_array_view<>.
910 class %swiglal_oct_array_view_helper_class(ACFTYPE) {
911
912 public:
913
914 // Octave array-related types.
915 typedef OVCLASS OVClass;
916 typedef OVTYPE OVType;
917
918 // Extract an OVType from an octave_value.
919 static OVType ovvalue(octave_value& ov) {
920 return ov.OVVALUE();
921 }
922
923 // Convert the octave_value objelem to an array element stored at elemptr.
924 static int incall(const octave_value& parent, octave_value& objelem, void *elemptr, int *pelemalloc, const size_t esize, const bool isptr, swig_type_info *const tinfo, const int tflags)
925 {
926 return INCALL;
927 }
928
929 // Convert the array element stored at elemptr to an octave_value.
930 static octave_value outcall(const octave_value& parent, const bool copyobj, void *elemptr, const size_t esize, const bool isptr, swig_type_info *const tinfo, const int tflags) {
931 return OUTCALL;
932 }
933
934 };
935
936 // ACFTYPE-specific array view class fragment.
937 class OCTINTERP_API %swiglal_oct_array_view_class(ACFTYPE) : public %swiglal_oct_array_view_tmpl(ACFTYPE) {
938
939 private:
940
941 // Octave type constructs.
942#if !SWIG_OCTAVE_PREREQ(4,0,0)
943 DECLARE_OCTAVE_ALLOCATOR;
944#endif
945 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;
946
947 protected:
948
949 public:
950
951 virtual ~%swiglal_oct_array_view_class(ACFTYPE)()
952 { }
953
954 %swiglal_oct_array_view_class(ACFTYPE)()
955 : %swiglal_oct_array_view_tmpl(ACFTYPE)()
956 { }
957
958 %swiglal_oct_array_view_class(ACFTYPE)(const octave_value& parent,
959 void* ptr,
960 const size_t esize,
961 const size_t ndims,
962 const size_t dims[],
963 const size_t strides[],
964 const bool isptr,
965 swig_type_info* tinfo,
966 const int tflags)
967 : %swiglal_oct_array_view_tmpl(ACFTYPE)(parent, ptr, esize, ndims, dims, strides, isptr, tinfo, tflags)
968 { }
969
970 };
971
972 // Octave type constructs.
973#if !SWIG_OCTAVE_PREREQ(4,0,0)
974 DEFINE_OCTAVE_ALLOCATOR(%swiglal_oct_array_view_class(ACFTYPE));
975#endif
976 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(%swiglal_oct_array_view_class(ACFTYPE),
977 %swiglal_oct_array_view_ovtype(ACFTYPE),
978 OVCLASS::static_class_name());
979
980 } // extern "C++"
981
982%} // %swiglal_oct_array_view_frag()
983
984// Input copy conversion fragment for arrays of type ACFTYPE.
985%fragment(%swiglal_array_copyin_frag(ACFTYPE), "header",
986 fragment=%swiglal_oct_array_view_frag(ACFTYPE))
987%{
988 SWIGINTERN int %swiglal_array_copyin_func(ACFTYPE)(const octave_value& parent,
989 octave_value obj,
990 void* ptr,
991 int *pelemalloc,
992 const size_t esize,
993 const size_t ndims,
994 const size_t dims[],
995 const size_t strides[],
996 const bool isptr,
997 swig_type_info *tinfo,
998 const int tflags)
999 {
1000 // Create a local array view, then use its sloav_array_in() member to copy the input Octave
1001 // array to the viewed C array.
1002 %swiglal_oct_array_view_class(ACFTYPE) arrview(parent, ptr, esize, ndims, dims, strides, isptr, tinfo, tflags);
1003 return arrview.sloav_array_in(obj, pelemalloc, 0);
1004 }
1005%}
1006
1007// Output copy conversion fragment for arrays of type ACFTYPE.
1008%fragment(%swiglal_array_copyout_frag(ACFTYPE), "header",
1009 fragment=%swiglal_oct_array_view_frag(ACFTYPE))
1010%{
1011 SWIGINTERN octave_value %swiglal_array_copyout_func(ACFTYPE)(const octave_value& parent,
1012 void* ptr,
1013 const size_t esize,
1014 const size_t ndims,
1015 const size_t dims[],
1016 const size_t strides[],
1017 const bool isptr,
1018 swig_type_info *tinfo,
1019 const int tflags)
1020 {
1021 // Create a local array view, then use its sloav_array_out() member to copy the viewed C array
1022 // to the output Octave array.
1023 %swiglal_oct_array_view_class(ACFTYPE) arrview(parent, ptr, esize, ndims, dims, strides, isptr, tinfo, tflags);
1024 return arrview.sloav_array_out(true);
1025 }
1026%}
1027
1028// Input view conversion fragment for arrays of type ACFTYPE.
1029%fragment(%swiglal_array_viewin_frag(ACFTYPE), "header",
1030 fragment=%swiglal_oct_array_view_frag(ACFTYPE))
1031%{
1032 SWIGINTERN int %swiglal_array_viewin_func(ACFTYPE)(const octave_value& parent,
1033 octave_value obj,
1034 void** ptr,
1035 const size_t esize,
1036 const size_t ndims,
1037 size_t dims[],
1038 const bool isptr,
1039 swig_type_info *tinfo,
1040 const int tflags)
1041 {
1042
1043 // Check that C array pointer is valid.
1044 if (ptr == NULL) {
1045 return SWIG_MemoryError;
1046 }
1047
1048 // Convert 'obj' to the desired OVTYPE, store in 'val'.
1049 OVTYPE val = obj.OVVALUE();
1050
1051 // Check that 'val' has the correct number of dimensions.
1052 // - 1-D arrays are a special case, since Octave arrays are always at least
1053 // 2-dimensional, so need to check that one of those dimensions is singular.
1054 dim_vector valdims = val.dims();
1055 if (ndims == 1) {
1056 if (valdims.length() > 2 || valdims.num_ones() == 0) {
1057 return SWIG_ValueError;
1058 }
1059 }
1060 else if (val.ndims() != %reinterpret_cast(ndims, octave_idx_type)) {
1061 return SWIG_ValueError;
1062 }
1063
1064 // Return dimensions of Octave array.
1065 if (ndims == 1) {
1066 dims[0] = val.numel();
1067 } else {
1068 for (size_t i = 0; i < ndims; ++i) {
1069 dims[i] = valdims(i);
1070 }
1071 }
1072
1073 // Cannot view an array of pointers.
1074 if (isptr) {
1075 return SWIG_TypeError;
1076 }
1077
1078 // Cannot view an array which is not itself an Octave view of a C array.
1079 if (obj.type_name().find("swiglal_oct_array_view_") == 0) {
1080 return SWIG_TypeError;
1081 }
1082
1083 // Since Octave stores arrays in column-major order, we can only view 1-D arrays.
1084 if (ndims != 1) {
1085 return SWIG_ValueError;
1086 }
1087
1088 // Check that 'obj' is of the correct type.
1089 if (!(ISOVTYPEEXPR)) {
1090 return SWIG_TypeError;
1091 }
1092
1093 // Check that the elements of 'val' have the correct size.
1094 if (val.byte_size() != val.numel() * esize) {
1095 return SWIG_TypeError;
1096 }
1097
1098 // Get pointer to Octave array data, a highly complicated and dodgy process! Usually
1099 // mex_get_data() does the job, apart from complex arrays where that creates a copy ...
1100 // in which case try data() and try to detect copying ...
1101 if (obj.is_complex_type() && !obj.is_scalar_type()) {
1102 if (obj.is_double_type()) {
1103 Complex c;
1104 {
1105 const ComplexNDArray t = obj.complex_array_value();
1106 *ptr = %reinterpret_cast(t.data(), void*);
1107 c = *((Complex*) *ptr);
1108 }
1109 if (c != *((Complex*) *ptr)) {
1110 return SWIG_UnknownError;
1111 }
1112 } else if (obj.is_single_type()) {
1113 FloatComplex c;
1114 {
1115 const FloatComplexNDArray t = obj.float_complex_array_value();
1116 *ptr = %reinterpret_cast(t.data(), void*);
1117 c = *((FloatComplex*) *ptr);
1118 }
1119 if (c != *((FloatComplex*) *ptr)) {
1120 return SWIG_UnknownError;
1121 }
1122 } else {
1123 return SWIG_TypeError;
1124 }
1125 } else {
1126 *ptr = %reinterpret_cast(obj.mex_get_data(), void*);
1127 }
1128 if (!*ptr) {
1129 return SWIG_ValueError;
1130 }
1131
1132 return SWIG_OK;
1133
1134 }
1135%}
1136
1137// Output view conversion fragment for arrays of type ACFTYPE.
1138%fragment(%swiglal_array_viewout_frag(ACFTYPE), "header",
1139 fragment=%swiglal_oct_array_view_frag(ACFTYPE))
1140%{
1141 SWIGINTERN octave_value %swiglal_array_viewout_func(ACFTYPE)(const octave_value& parent,
1142 void* ptr,
1143 const size_t esize,
1144 const size_t ndims,
1145 const size_t dims[],
1146 const size_t strides[],
1147 const bool isptr,
1148 swig_type_info *tinfo,
1149 const int tflags)
1150 {
1151 // Return an Octave array view of the C array.
1152 octave_base_value *objval = new %swiglal_oct_array_view_class(ACFTYPE)(parent, ptr, esize, ndims, dims, strides, isptr, tinfo, tflags);
1153 return octave_value(objval);
1154 }
1155%}
1156
1157%enddef // %swiglal_oct_array_frags
1158
1159// Array conversion fragments for generic arrays, e.g. SWIG-wrapped types. Note that input views
1160// are not supported, and so ISOVTYPEEXPR is 'false'.
1161%swiglal_oct_array_frags(SWIGTYPE, "swiglal_as_SWIGTYPE", "swiglal_from_SWIGTYPE",
1162 %arg(swiglal_as_SWIGTYPE(parent, objelem, elemptr, esize, isptr, tinfo, tflags)),
1163 %arg(swiglal_from_SWIGTYPE(parent, copyobj, elemptr, esize, isptr, tinfo, tflags)),
1164 octave_cell, Cell, cell_value, false);
1165
1166// Array conversion fragments for arrays of LAL strings. Note that input views are not supported,
1167// and so ISOVTYPEEXPR is 'false'.
1168%swiglal_oct_array_frags(LALchar, "SWIG_AsLALcharPtrAndSize", "SWIG_FromLALcharPtr",
1169 %arg(SWIG_AsLALcharPtrAndSize(objelem, %reinterpret_cast(elemptr, char**), 0, pelemalloc)),
1170 %arg(SWIG_FromLALcharPtr(*%reinterpret_cast(elemptr, char**))),
1171 octave_cell, Cell, cell_value, false);
1172
1173// Macro which generates array conversion function fragments to/from Octave arrays for real/fragment
1174// TYPEs which use SWIG_AsVal/From fragments.
1175%define %swiglal_oct_array_asvalfrom_frags(TYPE, OVCLASS, OVTYPE, OVVALUE, ISOVTYPEEXPR)
1176%swiglal_oct_array_frags(TYPE, SWIG_AsVal_frag(TYPE), SWIG_From_frag(TYPE),
1177 %arg(SWIG_AsVal(TYPE)(objelem, %reinterpret_cast(elemptr, TYPE*))),
1178 %arg(SWIG_From(TYPE)(*%reinterpret_cast(elemptr, TYPE*))),
1179 OVCLASS, OVTYPE, OVVALUE, ISOVTYPEEXPR);
1180%enddef
1181
1182// Array conversion fragments for integer arrays.
1183%swiglal_oct_array_asvalfrom_frags(int8_t, octave_int8_matrix, intNDArray<octave_int<int8_t> >, int8_array_value, obj.is_int8_type());
1184%swiglal_oct_array_asvalfrom_frags(uint8_t, octave_uint8_matrix, intNDArray<octave_int<uint8_t> >, uint8_array_value, obj.is_uint8_type());
1185%swiglal_oct_array_asvalfrom_frags(int16_t, octave_int16_matrix, intNDArray<octave_int<int16_t> >, int16_array_value, obj.is_int16_type());
1186%swiglal_oct_array_asvalfrom_frags(uint16_t, octave_uint16_matrix, intNDArray<octave_int<uint16_t> >, uint16_array_value, obj.is_uint16_type());
1187%swiglal_oct_array_asvalfrom_frags(int32_t, octave_int32_matrix, intNDArray<octave_int<int32_t> >, int32_array_value, obj.is_int32_type());
1188%swiglal_oct_array_asvalfrom_frags(uint32_t, octave_uint32_matrix, intNDArray<octave_int<uint32_t> >, uint32_array_value, obj.is_uint32_type());
1189%swiglal_oct_array_asvalfrom_frags(int64_t, octave_int64_matrix, intNDArray<octave_int<int64_t> >, int64_array_value, obj.is_int64_type());
1190%swiglal_oct_array_asvalfrom_frags(uint64_t, octave_uint64_matrix, intNDArray<octave_int<uint64_t> >, uint64_array_value, obj.is_uint64_type());
1191
1192// Array conversion fragments for floating-precision real arrays.
1193%swiglal_oct_array_asvalfrom_frags(float, octave_float_matrix, FloatMatrix, float_matrix_value, obj.is_real_type() && obj.is_single_type());
1194%swiglal_oct_array_asvalfrom_frags(double, octave_matrix, Matrix, matrix_value, obj.is_real_type() && obj.is_double_type());
1195
1196// Array conversion fragments for floating-precision complex arrays.
1197%swiglal_oct_array_asvalfrom_frags(gsl_complex_float, octave_float_complex_matrix, FloatComplexMatrix, float_complex_matrix_value, obj.is_complex_type() && obj.is_single_type());
1198%swiglal_oct_array_asvalfrom_frags(gsl_complex, octave_complex_matrix, ComplexMatrix, complex_matrix_value, obj.is_complex_type() && obj.is_double_type());
1199%swiglal_oct_array_asvalfrom_frags(COMPLEX8, octave_float_complex_matrix, FloatComplexMatrix, float_complex_matrix_value, obj.is_complex_type() && obj.is_single_type());
1200%swiglal_oct_array_asvalfrom_frags(COMPLEX16, octave_complex_matrix, ComplexMatrix, complex_matrix_value, obj.is_complex_type() && obj.is_double_type());
1201
1202// Local Variables:
1203// mode: c
1204// End:
#define TYPE
double cosh(double)
double acosh(double)
#define gmtime_r(timep, result)
Definition: GPSTimeNow.c:26
static REAL8TimeSeries * error(const REAL8TimeSeries *s1, const REAL8TimeSeries *s0)
const char *const name
type name
Definition: UserInput.c:193
#define crect(re, im)
Construct a COMPLEX16 from real and imaginary parts.
double complex COMPLEX16
Double-precision floating-point complex number (16 bytes total)
#define crectf(re, im)
Construct a COMPLEX8 from real and imaginary parts.
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)