Mercurial > jwe > octave
comparison libinterp/corefcn/mxarray.h @ 28131:4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
* mexproto.h, mex.cc, mxarray.h (mxMakeArrayReal, mxMakeArrayComplex,
mxGetDoubles, mxGetSingles, mxGetInt8s, mxGetInt16s, mxGetInt32s,
mxGetInt64s, mxGetUint8s, mxGetUint16s, mxGetUint32s, mxGetUint64s,
mxGetComplexDoubles, mxGetComplexSingles, mxSetDoubles, mxSetSingles,
mxSetInt8s, mxSetInt16s, mxSetInt32s, mxSetInt64s, mxSetUint8s,
mxSetUint16s, mxSetUint32s, mxSetUint64s, mxSetComplexDoubles,
mxSetComplexSingles): New functions. Provide corresponding member
functions in mxArray class hierarchy to handle the actual operations.
(mxGetComplexInt8s, mxGetComplexInt16s, mxGetComplexInt32s,
mxGetComplexInt64s, mxGetComplexUint8s, mxGetComplexUint16s,
mxGetComplexUint32s, mxGetComplexUint64s, mxSetComplexInt8s,
mxSetComplexInt16s, mxSetComplexInt32s, mxSetComplexInt64s,
mxSetComplexUint8s, mxSetComplexUint16s, mxSetComplexUint32s,
mxSetComplexUint64s): Add prototypes and functions, but leave
commented out since we don't have complex integer data.
(class mxArray_number, class mxArray_sparse):
Handle interleaved complex data. In mxArray_octave_value and
mxArray_matlab constructors, handle interleaved flag in constructor to
determine data layout to use when creating mxArray_number or
mxArray_sparse objects.
(mex::make_value): Check flag in mex function to determine whether to
create arrays with interleaved complex.
* ov.h, ov.cc, ov-base.h, ov-base.cc, ov-base-diag.h, ov-base-diag.cc,
ov-bool-mat.h, ov-bool-mat.cc, ov-bool-sparse.h, ov-bool-sparse.cc,
ov-bool.h, ov-bool.cc, ov-cell.h, ov-cell.cc, ov-ch-mat.h,
ov-ch-mat.cc, ov-class.h, ov-class.cc, ov-complex.h, ov-complex.cc,
ov-cx-mat.h, ov-cx-mat.cc, ov-cx-sparse.h, ov-cx-sparse.cc,
ov-float.h, ov-float.cc, ov-flt-complex.h, ov-flt-complex.cc,
ov-flt-cx-mat.h, ov-flt-cx-mat.cc, ov-flt-re-mat.h, ov-flt-re-mat.cc,
ov-intx.h, ov-lazy-idx.h, ov-perm.h, ov-perm.cc, ov-range.h,
ov-range.cc, ov-re-mat.h, ov-re-mat.cc, ov-re-sparse.h,
ov-re-sparse.cc, ov-scalar.h, ov-scalar.cc, ov-struct.h, ov-struct.cc:
In all as_mxArray methods, handle new interleaved input to optionally
create objects that will use interleaved complex data.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 18 Feb 2020 13:16:41 -0500 |
parents | 4963f23b145c |
children | 665c9ed14c97 |
comparison
equal
deleted
inserted
replaced
28130:0a88a4743096 | 28131:4c21f99b4ad5 |
---|---|
88 | 88 |
89 class mxArray_base | 89 class mxArray_base |
90 { | 90 { |
91 protected: | 91 protected: |
92 | 92 |
93 mxArray_base (void) { } | 93 mxArray_base (bool interleaved); |
94 | 94 |
95 public: | 95 public: |
96 | 96 |
97 virtual mxArray_base * dup (void) const = 0; | 97 virtual mxArray_base * dup (void) const = 0; |
98 | 98 |
195 } | 195 } |
196 | 196 |
197 virtual void set_property (mwIndex /*idx*/, const char * /*pname*/, | 197 virtual void set_property (mwIndex /*idx*/, const char * /*pname*/, |
198 const mxArray * /*pval*/) | 198 const mxArray * /*pval*/) |
199 { | 199 { |
200 err_invalid_type (); | 200 err_invalid_type ("set_property"); |
201 } | 201 } |
202 | 202 |
203 virtual mxArray * get_cell (mwIndex /*idx*/) const | 203 virtual mxArray * get_cell (mwIndex /*idx*/) const |
204 { | 204 { |
205 err_invalid_type (); | 205 err_invalid_type ("get_cell"); |
206 } | 206 } |
207 | 207 |
208 virtual void set_cell (mwIndex idx, mxArray *val) = 0; | 208 virtual void set_cell (mwIndex idx, mxArray *val) = 0; |
209 | 209 |
210 virtual double get_scalar (void) const = 0; | 210 virtual double get_scalar (void) const = 0; |
211 | 211 |
212 virtual void * get_data (void) const = 0; | 212 virtual void * get_data (void) const = 0; |
213 | 213 |
214 virtual mxDouble * get_doubles (void) const = 0; | |
215 virtual mxSingle * get_singles (void) const = 0; | |
216 virtual mxInt8 * get_int8s (void) const = 0; | |
217 virtual mxInt16 * get_int16s (void) const = 0; | |
218 virtual mxInt32 * get_int32s (void) const = 0; | |
219 virtual mxInt64 * get_int64s (void) const = 0; | |
220 virtual mxUint8 * get_uint8s (void) const = 0; | |
221 virtual mxUint16 * get_uint16s (void) const = 0; | |
222 virtual mxUint32 * get_uint32s (void) const = 0; | |
223 virtual mxUint64 * get_uint64s (void) const = 0; | |
224 | |
225 virtual mxComplexDouble * get_complex_doubles (void) const = 0; | |
226 virtual mxComplexSingle * get_complex_singles (void) const = 0; | |
227 #if 0 | |
228 /* We don't have these yet. */ | |
229 virtual mxComplexInt8 * get_complex_int8s (void) const = 0; | |
230 virtual mxComplexInt16 * get_complex_int16s (void) const = 0; | |
231 virtual mxComplexInt32 * get_complex_int32s (void) const = 0; | |
232 virtual mxComplexInt64 * get_complex_int64s (void) const = 0; | |
233 virtual mxComplexUint8 * get_complex_uint8s (void) const = 0; | |
234 virtual mxComplexUint16 * get_complex_uint16s (void) const = 0; | |
235 virtual mxComplexUint32 * get_complex_uint32s (void) const = 0; | |
236 virtual mxComplexUint64 * get_complex_uint64s (void) const = 0; | |
237 #endif | |
238 | |
214 virtual void * get_imag_data (void) const = 0; | 239 virtual void * get_imag_data (void) const = 0; |
215 | 240 |
216 virtual void set_data (void *pr) = 0; | 241 virtual void set_data (void *pr) = 0; |
242 | |
243 virtual int set_doubles (mxDouble *data) = 0; | |
244 virtual int set_singles (mxSingle *data) = 0; | |
245 virtual int set_int8s (mxInt8 *data) = 0; | |
246 virtual int set_int16s (mxInt16 *data) = 0; | |
247 virtual int set_int32s (mxInt32 *data) = 0; | |
248 virtual int set_int64s (mxInt64 *data) = 0; | |
249 virtual int set_uint8s (mxUint8 *data) = 0; | |
250 virtual int set_uint16s (mxUint16 *data) = 0; | |
251 virtual int set_uint32s (mxUint32 *data) = 0; | |
252 virtual int set_uint64s (mxUint64 *data) = 0; | |
253 | |
254 virtual int set_complex_doubles (mxComplexDouble *data) = 0; | |
255 virtual int set_complex_singles (mxComplexSingle *data) = 0; | |
256 #if 0 | |
257 /* We don't have these yet. */ | |
258 virtual int set_complex_int8s (mxComplexInt8 *data) = 0; | |
259 virtual int set_complex_int16s (mxComplexInt16 *data) = 0; | |
260 virtual int set_complex_int32s (mxComplexInt32 *data) = 0; | |
261 virtual int set_complex_int64s (mxComplexInt64 *data) = 0; | |
262 virtual int set_complex_uint8s (mxComplexUint8 *data) = 0; | |
263 virtual int set_complex_uint16s (mxComplexUint16 *data) = 0; | |
264 virtual int set_complex_uint32s (mxComplexUint32 *data) = 0; | |
265 virtual int set_complex_uint64s (mxComplexUint64 *data) = 0; | |
266 #endif | |
217 | 267 |
218 virtual void set_imag_data (void *pi) = 0; | 268 virtual void set_imag_data (void *pi) = 0; |
219 | 269 |
220 virtual mwIndex * get_ir (void) const = 0; | 270 virtual mwIndex * get_ir (void) const = 0; |
221 | 271 |
258 | 308 |
259 virtual octave_value as_octave_value (void) const = 0; | 309 virtual octave_value as_octave_value (void) const = 0; |
260 | 310 |
261 protected: | 311 protected: |
262 | 312 |
263 mxArray_base (const mxArray_base&) { } | 313 // If TRUE, we are using interleaved storage for complex numeric arrays. |
264 | 314 bool m_interleaved; |
265 OCTAVE_NORETURN void err_invalid_type (void) const | 315 |
266 { | 316 mxArray_base (const mxArray_base&) = default; |
267 error ("invalid type for operation"); | 317 |
318 size_t get_numeric_element_size (size_t size) const | |
319 { | |
320 return (m_interleaved | |
321 ? is_complex () ? 2 * size : size | |
322 : size); | |
323 } | |
324 | |
325 OCTAVE_NORETURN void err_invalid_type (const char *op) const | |
326 { | |
327 error ("%s: invalid type for mxArray::%s", get_class_name (), op); | |
268 } | 328 } |
269 }; | 329 }; |
270 | 330 |
271 // The main interface class. The representation can be based on an | 331 // The main interface class. The representation can be based on an |
272 // octave_value object or a separate object that tries to reproduce | 332 // octave_value object or a separate object that tries to reproduce |
274 | 334 |
275 class mxArray | 335 class mxArray |
276 { | 336 { |
277 public: | 337 public: |
278 | 338 |
279 mxArray (const octave_value& ov); | 339 mxArray (bool interleaved, const octave_value& ov); |
280 | 340 |
281 mxArray (mxClassID id, mwSize ndims, const mwSize *dims, | 341 mxArray (bool interleaved, mxClassID id, mwSize ndims, const mwSize *dims, |
282 mxComplexity flag = mxREAL, bool init = true); | 342 mxComplexity flag = mxREAL, bool init = true); |
283 | 343 |
284 mxArray (mxClassID id, const dim_vector& dv, mxComplexity flag = mxREAL); | 344 mxArray (bool interleaved, mxClassID id, const dim_vector& dv, |
285 | 345 mxComplexity flag = mxREAL); |
286 mxArray (mxClassID id, mwSize m, mwSize n, | 346 |
347 mxArray (bool interleaved, mxClassID id, mwSize m, mwSize n, | |
287 mxComplexity flag = mxREAL, bool init = true); | 348 mxComplexity flag = mxREAL, bool init = true); |
288 | 349 |
289 mxArray (mxClassID id, double val); | 350 mxArray (bool interleaved, mxClassID id, double val); |
290 | 351 |
291 mxArray (mxClassID id, mxLogical val); | 352 mxArray (bool interleaved, mxClassID id, mxLogical val); |
292 | 353 |
293 mxArray (const char *str); | 354 mxArray (bool interleaved, const char *str); |
294 | 355 |
295 mxArray (mwSize m, const char **str); | 356 mxArray (bool interleaved, mwSize m, const char **str); |
296 | 357 |
297 mxArray (mxClassID id, mwSize m, mwSize n, mwSize nzmax, | 358 mxArray (bool interleaved, mxClassID id, mwSize m, mwSize n, mwSize nzmax, |
298 mxComplexity flag = mxREAL); | 359 mxComplexity flag = mxREAL); |
299 | 360 |
300 mxArray (mwSize ndims, const mwSize *dims, int num_keys, const char **keys); | 361 mxArray (bool interleaved, mwSize ndims, const mwSize *dims, int num_keys, |
301 | 362 const char **keys); |
302 mxArray (const dim_vector& dv, int num_keys, const char **keys); | 363 |
303 | 364 mxArray (bool interleaved, const dim_vector& dv, int num_keys, |
304 mxArray (mwSize m, mwSize n, int num_keys, const char **keys); | 365 const char **keys); |
305 | 366 |
306 mxArray (mwSize ndims, const mwSize *dims); | 367 mxArray (bool interleaved, mwSize m, mwSize n, int num_keys, |
307 | 368 const char **keys); |
308 mxArray (const dim_vector& dv); | 369 |
309 | 370 mxArray (bool interleaved, mwSize ndims, const mwSize *dims); |
310 mxArray (mwSize m, mwSize n); | 371 |
372 mxArray (bool interleaved, const dim_vector& dv); | |
373 | |
374 mxArray (bool interleaved, mwSize m, mwSize n); | |
311 | 375 |
312 mxArray * dup (void) const | 376 mxArray * dup (void) const |
313 { | 377 { |
314 mxArray *retval = rep->as_mxArray (); | 378 mxArray *retval = rep->as_mxArray (); |
315 | 379 |
426 | 490 |
427 double get_scalar (void) const { return rep->get_scalar (); } | 491 double get_scalar (void) const { return rep->get_scalar (); } |
428 | 492 |
429 void * get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); } | 493 void * get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); } |
430 | 494 |
495 mxDouble * get_doubles (void) const | |
496 { DO_MUTABLE_METHOD (mxDouble *, get_doubles ()); } | |
497 | |
498 mxSingle * get_singles (void) const | |
499 { DO_MUTABLE_METHOD (mxSingle *, get_singles ()); } | |
500 | |
501 mxInt8 * get_int8s (void) const | |
502 { DO_MUTABLE_METHOD (mxInt8 *, get_int8s ()); } | |
503 | |
504 mxInt16 * get_int16s (void) const | |
505 { DO_MUTABLE_METHOD (mxInt16 *, get_int16s ()); } | |
506 | |
507 mxInt32 * get_int32s (void) const | |
508 { DO_MUTABLE_METHOD (mxInt32 *, get_int32s ()); } | |
509 | |
510 mxInt64 * get_int64s (void) const | |
511 { DO_MUTABLE_METHOD (mxInt64 *, get_int64s ()); } | |
512 | |
513 mxUint8 * get_uint8s (void) const | |
514 { DO_MUTABLE_METHOD (mxUint8 *, get_uint8s ()); } | |
515 | |
516 mxUint16 * get_uint16s (void) const | |
517 { DO_MUTABLE_METHOD (mxUint16 *, get_uint16s ()); } | |
518 | |
519 mxUint32 * get_uint32s (void) const | |
520 { DO_MUTABLE_METHOD (mxUint32 *, get_uint32s ()); } | |
521 | |
522 mxUint64 * get_uint64s (void) const | |
523 { DO_MUTABLE_METHOD (mxUint64 *, get_uint64s ()); } | |
524 | |
525 mxComplexDouble * get_complex_doubles (void) const | |
526 { DO_MUTABLE_METHOD (mxComplexDouble *, get_complex_doubles ()); } | |
527 | |
528 mxComplexSingle * get_complex_singles (void) const | |
529 { DO_MUTABLE_METHOD (mxComplexSingle *, get_complex_singles ()); } | |
530 | |
531 #if 0 | |
532 /* We don't have these yet. */ | |
533 mxComplexInt8 * get_complex_int8s (void) const | |
534 { DO_MUTABLE_METHOD (mxComplexInt8 *, get_complex_int8s ()); } | |
535 | |
536 mxComplexInt16 * get_complex_int16s (void) const | |
537 { DO_MUTABLE_METHOD (mxComplexInt16 *, get_complex_int16s ()); } | |
538 | |
539 mxComplexInt32 * get_complex_int32s (void) const | |
540 { DO_MUTABLE_METHOD (mxComplexInt32 *, get_complex_int32s ()); } | |
541 | |
542 mxComplexInt64 * get_complex_int64s (void) const | |
543 { DO_MUTABLE_METHOD (mxComplexInt64 *, get_complex_int64s ()); } | |
544 | |
545 mxComplexUint8 * get_complex_uint8s (void) const | |
546 { DO_MUTABLE_METHOD (mxComplexUint8 *, get_complex_uint8s ()); } | |
547 | |
548 mxComplexUint16 * get_complex_uint16s (void) const | |
549 { DO_MUTABLE_METHOD (mxComplexUint16 *, get_complex_uint16s ()); } | |
550 | |
551 mxComplexUint32 * get_complex_uint32s (void) const | |
552 { DO_MUTABLE_METHOD (mxComplexUint32 *, get_complex_uint32s ()); } | |
553 | |
554 mxComplexUint64 * get_complex_uint64s (void) const | |
555 { DO_MUTABLE_METHOD (mxComplexUint64 *, get_complex_uint64s ()); } | |
556 #endif | |
557 | |
431 void * get_imag_data (void) const | 558 void * get_imag_data (void) const |
432 { DO_MUTABLE_METHOD (void *, get_imag_data ()); } | 559 { DO_MUTABLE_METHOD (void *, get_imag_data ()); } |
433 | 560 |
434 void set_data (void *pr) { DO_VOID_MUTABLE_METHOD (set_data (pr)); } | 561 void set_data (void *pr) { DO_VOID_MUTABLE_METHOD (set_data (pr)); } |
562 | |
563 int set_doubles (mxDouble *data) | |
564 { DO_MUTABLE_METHOD (int, set_doubles (data)); } | |
565 | |
566 int set_singles (mxSingle *data) | |
567 { DO_MUTABLE_METHOD (int, set_singles (data)); } | |
568 | |
569 int set_int8s (mxInt8 *data) | |
570 { DO_MUTABLE_METHOD (int, set_int8s (data)); } | |
571 | |
572 int set_int16s (mxInt16 *data) | |
573 { DO_MUTABLE_METHOD (int, set_int16s (data)); } | |
574 | |
575 int set_int32s (mxInt32 *data) | |
576 { DO_MUTABLE_METHOD (int, set_int32s (data)); } | |
577 | |
578 int set_int64s (mxInt64 *data) | |
579 { DO_MUTABLE_METHOD (int, set_int64s (data)); } | |
580 | |
581 int set_uint8s (mxUint8 *data) | |
582 { DO_MUTABLE_METHOD (int, set_uint8s (data)); } | |
583 | |
584 int set_uint16s (mxUint16 *data) | |
585 { DO_MUTABLE_METHOD (int, set_uint16s (data)); } | |
586 | |
587 int set_uint32s (mxUint32 *data) | |
588 { DO_MUTABLE_METHOD (int, set_uint32s (data)); } | |
589 | |
590 int set_uint64s (mxUint64 *data) | |
591 { DO_MUTABLE_METHOD (int, set_uint64s (data)); } | |
592 | |
593 int set_complex_doubles (mxComplexDouble *data) | |
594 { DO_MUTABLE_METHOD (int, set_complex_doubles (data)); } | |
595 | |
596 int set_complex_singles (mxComplexSingle *data) | |
597 { DO_MUTABLE_METHOD (int, set_complex_singles (data)); } | |
598 | |
599 #if 0 | |
600 /* We don't have these yet. */ | |
601 int set_complex_int8s (mxComplexInt8 *data) | |
602 { DO_MUTABLE_METHOD (int, set_complex_int8s (data)); } | |
603 | |
604 int set_complex_int16s (mxComplexInt16 *data) | |
605 { DO_MUTABLE_METHOD (int, set_complex_int16s (data)); } | |
606 | |
607 int set_complex_int32s (mxComplexInt32 *data) | |
608 { DO_MUTABLE_METHOD (int, set_complex_int32s (data)); } | |
609 | |
610 int set_complex_int64s (mxComplexInt64 *data) | |
611 { DO_MUTABLE_METHOD (int, set_complex_int64s (data)); } | |
612 | |
613 int set_complex_uint8s (mxComplexUint8 *data) | |
614 { DO_MUTABLE_METHOD (int, set_complex_uint8s (data)); } | |
615 | |
616 int set_complex_uint16s (mxComplexUint16 *data) | |
617 { DO_MUTABLE_METHOD (int, set_complex_uint16s (data)); } | |
618 | |
619 int set_complex_uint32s (mxComplexUint32 *data) | |
620 { DO_MUTABLE_METHOD (int, set_complex_uint32s (data)); } | |
621 | |
622 int set_complex_uint64s (mxComplexUint64 *data) | |
623 { DO_MUTABLE_METHOD (int, set_complex_uint64s (data)); } | |
624 #endif | |
435 | 625 |
436 void set_imag_data (void *pi) { DO_VOID_MUTABLE_METHOD (set_imag_data (pi)); } | 626 void set_imag_data (void *pi) { DO_VOID_MUTABLE_METHOD (set_imag_data (pi)); } |
437 | 627 |
438 mwIndex * get_ir (void) const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); } | 628 mwIndex * get_ir (void) const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); } |
439 | 629 |
513 char *name; | 703 char *name; |
514 | 704 |
515 mxArray (mxArray_base *r, const char *n) | 705 mxArray (mxArray_base *r, const char *n) |
516 : rep (r), name (mxArray::strsave (n)) { } | 706 : rep (r), name (mxArray::strsave (n)) { } |
517 | 707 |
708 static mxArray_base * | |
709 create_rep (bool interleaved, const octave_value& ov); | |
710 | |
711 static mxArray_base * | |
712 create_rep (bool interleaved, mxClassID id, mwSize ndims, | |
713 const mwSize *dims, mxComplexity flag, bool init); | |
714 | |
715 static mxArray_base * | |
716 create_rep (bool interleaved, mxClassID id, const dim_vector& dv, | |
717 mxComplexity flag); | |
718 | |
719 static mxArray_base * | |
720 create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n, | |
721 mxComplexity flag, bool init); | |
722 | |
723 static mxArray_base * | |
724 create_rep (bool interleaved, mxClassID id, double val); | |
725 | |
726 static mxArray_base * | |
727 create_rep (bool interleaved, mxClassID id, mxLogical val); | |
728 | |
729 static mxArray_base * | |
730 create_rep (bool interleaved, const char *str); | |
731 | |
732 static mxArray_base * | |
733 create_rep (bool interleaved, mwSize m, const char **str); | |
734 | |
735 static mxArray_base * | |
736 create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n, | |
737 mwSize nzmax, mxComplexity flag); | |
738 | |
518 void maybe_mutate (void) const; | 739 void maybe_mutate (void) const; |
519 }; | 740 }; |
520 | 741 |
521 #undef DO_MUTABLE_METHOD | 742 #undef DO_MUTABLE_METHOD |
522 #undef DO_VOID_MUTABLE_METHOD | 743 #undef DO_VOID_MUTABLE_METHOD |