26 #if defined (HAVE_CONFIG_H)
43 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
44 # include <memory_resource>
78 extern OCTINTERP_API
const mxArray *
198 int num_keys,
const char **keys);
248 std::cerr <<
"xmalloc (" <<
n <<
") = " << ptr << std::endl;
255 xrealloc (
void *ptr,
size_t n)
257 void *newptr = std::realloc (ptr,
n);
260 std::cerr <<
"xrealloc (" << ptr <<
", " <<
n <<
") = " << newptr
271 std::cerr <<
"xfree (" << ptr <<
")" << std::endl;
278 max_str_len (
mwSize m,
const char **str)
295 template <
typename T>
299 static const bool is_complex =
false;
306 static const bool is_complex =
true;
313 static const bool is_complex =
true;
316 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
318 class mx_deleting_memory_resource :
public std::pmr::memory_resource
322 void * do_allocate (std::size_t bytes,
size_t )
324 void *ptr = xmalloc (bytes);
327 throw std::bad_alloc ();
332 void do_deallocate (
void *ptr, std::size_t ,
338 bool do_is_equal (
const std::pmr::memory_resource& other)
const noexcept
340 return this ==
dynamic_cast<const mx_deleting_memory_resource *
> (&other);
344 class mx_preserving_memory_resource :
public std::pmr::memory_resource
348 void * do_allocate (std::size_t bytes,
size_t )
350 void *ptr = xmalloc (bytes);
353 throw std::bad_alloc ();
358 void do_deallocate (
void * , std::size_t ,
362 bool do_is_equal (
const std::pmr::memory_resource& other)
const noexcept
364 return this ==
dynamic_cast<const mx_preserving_memory_resource *
> (&other);
370 static mx_deleting_memory_resource the_mx_deleting_memory_resource;
371 static mx_preserving_memory_resource the_mx_preserving_memory_resource;
373 static std::pmr::memory_resource *current_mx_memory_resource = &the_mx_deleting_memory_resource;
380 : m_interleaved (interleaved)
384 calc_single_subscript_internal (
mwSize ndims,
const mwSize *dims,
402 mwSize n = (nsubs <= ndims ? nsubs : ndims);
407 retval = dims[
n] * retval + subs[
n];
426 static inline void * maybe_mark_foreign (
void *ptr);
428 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
429 static inline void maybe_disown_ptr (
void *ptr);
432 #define VOID_MUTATION_METHOD(FCN_NAME, ARG_LIST) \
433 void FCN_NAME ARG_LIST { request_mutation (); }
435 #define CONST_VOID_MUTATION_METHOD(FCN_NAME, ARG_LIST) \
436 void FCN_NAME ARG_LIST const { request_mutation (); }
438 #define MUTATION_METHOD(RET_TYPE, FCN_NAME, ARG_LIST, RET_VAL) \
439 RET_TYPE FCN_NAME ARG_LIST { request_mutation (); return RET_VAL; }
441 #define CONST_MUTATION_METHOD(RET_TYPE, FCN_NAME, ARG_LIST, RET_VAL) \
442 RET_TYPE FCN_NAME ARG_LIST const { request_mutation (); return RET_VAL; }
444 #define GET_DATA_METHOD(RT, FCN_NAME, ID, COMPLEXITY) \
445 RT * FCN_NAME (void) const { return get_data<RT> (ID, COMPLEXITY); }
451 mxArray_octave_value () =
delete;
453 mxArray_octave_value (
bool interleaved,
const octave_value& ov)
454 :
mxArray_base (interleaved), m_val (ov), m_mutate_flag (
false),
462 mxArray_octave_value& operator = (
const mxArray_octave_value&) =
delete;
464 mxArray_base *
dup (
void)
const {
return new mxArray_octave_value (*
this); }
468 mxArray *retval = m_val.as_mxArray (m_interleaved);
485 m_class_name =
nullptr;
503 ~mxArray_octave_value (
void)
511 int iscell (
void)
const {
return m_val.iscell (); }
513 int is_char (
void)
const {
return m_val.is_string (); }
515 int is_complex (
void)
const {
return m_val.iscomplex (); }
517 int is_double (
void)
const {
return m_val.is_double_type (); }
521 int is_int16 (
void)
const {
return m_val.is_int16_type (); }
523 int is_int32 (
void)
const {
return m_val.is_int32_type (); }
525 int is_int64 (
void)
const {
return m_val.is_int64_type (); }
527 int is_int8 (
void)
const {
return m_val.is_int8_type (); }
529 int is_logical (
void)
const {
return m_val.islogical (); }
531 int is_numeric (
void)
const {
return m_val.isnumeric (); }
533 int is_single (
void)
const {
return m_val.is_single_type (); }
535 int is_sparse (
void)
const {
return m_val.issparse (); }
537 int is_struct (
void)
const {
return m_val.isstruct (); }
539 int is_uint16 (
void)
const {
return m_val.is_uint16_type (); }
541 int is_uint32 (
void)
const {
return m_val.is_uint32_type (); }
543 int is_uint64 (
void)
const {
return m_val.is_uint64_type (); }
545 int is_uint8 (
void)
const {
return m_val.is_uint8_type (); }
547 int is_range (
void)
const {
return m_val.is_range (); }
549 int isreal (
void)
const {
return m_val.isreal (); }
553 return (is_logical_scalar () && m_val.is_true ());
556 mwSize get_m (
void)
const {
return m_val.rows (); }
565 for (
mwIndex i = m_ndims - 1; i > 0; i--)
575 m_ndims = m_val.ndims ();
582 for (
mwIndex i = 0; i < m_ndims; i++)
604 int isempty (
void)
const {
return m_val.isempty (); }
611 return m_ndims == 2 && m_dims[0] == 1 && m_dims[1] == 1;
618 std::string cn = m_val.class_name ();
622 else if (cn ==
"single")
624 else if (cn ==
"char")
626 else if (cn ==
"logical")
628 else if (cn ==
"cell")
630 else if (cn ==
"struct")
632 else if (cn ==
"function_handle")
634 else if (cn ==
"int8")
636 else if (cn ==
"uint8")
638 else if (cn ==
"int16")
640 else if (cn ==
"uint16")
642 else if (cn ==
"int32")
644 else if (cn ==
"uint32")
646 else if (cn ==
"int64")
648 else if (cn ==
"uint64")
658 std::string s = m_val.class_name ();
672 if (m_val.is_classdef_object ())
681 retval =
new mxArray (m_interleaved, pval);
690 if (m_val.is_classdef_object ())
708 if (m_val.issparse ())
711 const void *m_data = m_val.mex_get_data ();
712 if (m_data ==
nullptr)
715 if (m_val.islogical ())
716 return *
static_cast<const bool *
> (m_data);
717 else if (m_val.isreal ())
718 return *
static_cast<const double *
> (m_data);
720 return *
static_cast<const double *
> (m_data);
723 return m_val.scalar_value (
true);
730 void *retval =
const_cast<void *
> (m_val.mex_get_data ());
732 if (retval && (m_val.isreal () || m_interleaved))
734 maybe_mark_foreign (retval);
742 template <
typename T>
747 void *ptr =
const_cast<void *
> (m_val.mex_get_data (class_id, complexity));
749 T *retval =
static_cast<T *
> (ptr);
751 if (retval && (complexity ==
mxREAL || m_interleaved))
753 maybe_mark_foreign (retval);
789 void *retval =
nullptr;
791 if (is_numeric () && isreal ())
824 return static_cast<mwIndex *
> (maybe_mark_foreign (ptr));
832 return static_cast<mwIndex *
> (maybe_mark_foreign (ptr));
869 if (m_val.is_string () && nel < buflen)
873 const char *p = tmp.
data ();
875 for (
mwIndex i = 0; i < nel; i++)
892 if (m_val.is_string ())
902 const char *p = tmp.
data ();
904 for (
mwIndex i = 0; i < nel; i++)
919 return calc_single_subscript_internal (m_ndims, m_dims, nsubs, subs);
952 void request_mutation (
void)
const
957 m_mutate_flag =
true;
966 mxArray_octave_value (
const mxArray_octave_value& arg)
967 :
mxArray_base (arg), m_val (arg.m_val), m_mutate_flag (arg.m_mutate_flag),
969 m_ndims (arg.m_ndims),
976 for (
mwIndex i = 0; i < m_ndims; i++)
977 m_dims[i] = arg.m_dims[i];
985 mutable bool m_mutate_flag;
992 mutable char *m_class_name;
1004 mxArray_matlab () =
delete;
1010 mxArray_matlab& operator = (
const mxArray_matlab&) =
delete;
1012 ~mxArray_matlab (
void)
1022 int is_complex (
void)
const {
return m_is_complex; }
1049 int is_sparse (
void)
const {
return 0; }
1063 return (is_logical_scalar ()
1064 &&
static_cast<mxLogical *
> (get_data ())[0] != 0);
1073 for (
mwSize i = m_ndims - 1 ; i > 0 ; i--)
1098 if (m_dims ==
nullptr)
1101 for (
int i = 0; i < m_ndims; i++)
1102 m_dims[i] = dims[i];
1115 mwSize retval = m_dims[0];
1117 for (
mwIndex i = 1; i < m_ndims; i++)
1118 retval *= m_dims[i];
1127 return m_ndims == 2 && m_dims[0] == 1 && m_dims[1] == 1;
1153 default:
return "unknown";
1161 strcpy (m_class_name, name);
1397 return calc_single_subscript_internal (m_ndims, m_dims, nsubs, subs);
1427 mxArray_matlab (
bool interleaved,
bool is_complex,
mxClassID id,
1429 :
mxArray_base (interleaved), m_class_name (nullptr), m_id (id),
1430 m_is_complex (is_complex), m_ndims (ndims < 2 ? 2 : ndims),
1444 for (
mwIndex i = 0; i < ndims; i++)
1445 m_dims[i] = dims[i];
1447 for (
mwIndex i = m_ndims - 1; i > 1; i--)
1456 mxArray_matlab (
bool interleaved,
bool is_complex,
mxClassID id,
1458 :
mxArray_base (interleaved), m_class_name (nullptr), m_id (id),
1459 m_is_complex (is_complex), m_ndims (dv.ndims ()),
1462 for (
mwIndex i = 0; i < m_ndims; i++)
1465 for (
mwIndex i = m_ndims - 1; i > 1; i--)
1474 mxArray_matlab (
bool interleaved,
bool is_complex,
mxClassID id,
1476 :
mxArray_base (interleaved), m_class_name (nullptr), m_id (id),
1477 m_is_complex (is_complex), m_ndims (2),
1484 mxArray_matlab (
const mxArray_matlab& val)
1486 m_id (val.m_id), m_is_complex (val.m_is_complex), m_ndims (val.m_ndims),
1489 for (
mwIndex i = 0; i < m_ndims; i++)
1490 m_dims[i] = val.m_dims[i];
1493 void set_complexity (
bool is_complex) { m_is_complex = is_complex; }
1496 dims_to_dim_vector (
void)
const
1498 mwSize nd = get_number_of_dimensions ();
1505 for (
mwIndex i = 0; i < nd; i++)
1526 class mxArray_base_full :
public mxArray_matlab
1530 mxArray_base_full () =
delete;
1532 mxArray_base_full (
bool interleaved,
bool is_complex,
mxClassID id,
1534 : mxArray_matlab (interleaved, is_complex, id, ndims, dims),
1535 m_pr (
mxArray::alloc (init, get_number_of_elements (), get_element_size ()))
1538 mxArray_base_full (
bool interleaved,
bool is_complex,
mxClassID id,
1540 : mxArray_matlab (interleaved, is_complex, id, dv),
1541 m_pr (
mxArray::calloc (get_number_of_elements (), get_element_size ()))
1544 mxArray_base_full (
bool interleaved,
bool is_complex,
mxClassID id,
1546 : mxArray_matlab (interleaved, is_complex, id,
m,
n),
1547 m_pr (
mxArray::alloc (init, get_number_of_elements (), get_element_size ()))
1550 mxArray_base_full (
bool interleaved,
mxClassID id,
double val)
1551 : mxArray_matlab (interleaved, false, id, 1, 1),
1552 m_pr (
mxArray::calloc (get_number_of_elements (), get_element_size ()))
1554 double *dpr =
static_cast<double *
> (m_pr);
1559 : mxArray_matlab (interleaved, false, id, 1, 1),
1560 m_pr (
mxArray::calloc (get_number_of_elements (), get_element_size ()))
1566 mxArray_base_full (
bool interleaved,
const char *str)
1568 str ? (
strlen (str) ? 1 : 0) : 0,
1570 m_pr (
mxArray::calloc (get_number_of_elements (), get_element_size ()))
1573 mwSize nel = get_number_of_elements ();
1574 for (
mwIndex i = 0; i < nel; i++)
1579 mxArray_base_full (
bool interleaved,
mwSize m,
const char **str)
1580 : mxArray_matlab (interleaved, false,
mxCHAR_CLASS,
m, max_str_len (
m, str)),
1581 m_pr (
mxArray::calloc (get_number_of_elements (), get_element_size ()))
1591 const char *ptr = str[j];
1593 std::size_t tmp_len =
strlen (ptr);
1595 for (std::size_t i = 0; i < tmp_len; i++)
1596 cpr[
m*i+j] =
static_cast<mxChar> (ptr[i]);
1598 for (std::size_t i = tmp_len; i < static_cast<std::size_t> (nc); i++)
1599 cpr[
m*i+j] =
static_cast<mxChar> (
' ');
1606 mxArray_base_full& operator = (
const mxArray_base_full&) =
delete;
1610 return new mxArray_base_full (*
this);
1613 ~mxArray_base_full (
void)
1618 double get_scalar (
void)
const
1624 switch (get_class_id ())
1627 retval = *(
static_cast<double *
> (m_pr));
1631 retval = *(
static_cast<float *
> (m_pr));
1635 retval = *(
static_cast<mxChar *
> (m_pr));
1639 retval = *(
static_cast<bool *
> (m_pr));
1643 retval = *(
static_cast<int8_t *
> (m_pr));
1647 retval = *(
static_cast<uint8_t *
> (m_pr));
1651 retval = *(
static_cast<int16_t *
> (m_pr));
1655 retval = *(
static_cast<uint16_t *
> (m_pr));
1659 retval = *(
static_cast<int32_t *
> (m_pr));
1663 retval = *(
static_cast<uint32_t *
> (m_pr));
1667 retval = *(
static_cast<int64_t *
> (m_pr));
1671 retval = *(
static_cast<uint64_t *
> (m_pr));
1681 void * get_data (
void)
const {
return m_pr; }
1683 void set_data (
void *pr) { m_pr = pr; }
1690 mxDouble * get_doubles (
void)
const
1692 return static_cast<mxDouble *
> (m_pr);
1695 mxSingle * get_singles (
void)
const
1697 return static_cast<mxSingle *
> (m_pr);
1700 mxInt8 * get_int8s (
void)
const
1702 return static_cast<mxInt8 *
> (m_pr);
1705 mxInt16 * get_int16s (
void)
const
1707 return static_cast<mxInt16 *
> (m_pr);
1710 mxInt32 * get_int32s (
void)
const
1712 return static_cast<mxInt32 *
> (m_pr);
1715 mxInt64 * get_int64s (
void)
const
1717 return static_cast<mxInt64 *
> (m_pr);
1720 mxUint8 * get_uint8s (
void)
const
1722 return static_cast<mxUint8 *
> (m_pr);
1725 mxUint16 * get_uint16s (
void)
const
1727 return static_cast<mxUint16 *
> (m_pr);
1730 mxUint32 * get_uint32s (
void)
const
1732 return static_cast<mxUint32 *
> (m_pr);
1735 mxUint64 * get_uint64s (
void)
const
1737 return static_cast<mxUint64 *
> (m_pr);
1822 int get_string (
char *buf,
mwSize buflen)
const
1826 mwSize nel = get_number_of_elements ();
1828 if (! (nel < buflen))
1839 for (
mwIndex i = 0; i < nel; i++)
1840 buf[i] =
static_cast<char> (ptr[i]);
1848 char * array_to_string (
void)
const
1852 mwSize nel = get_number_of_elements ();
1860 for (
mwIndex i = 0; i < nel; i++)
1861 buf[i] =
static_cast<char> (ptr[i]);
1875 switch (get_class_id ())
1878 return (is_complex ()
1879 ? fp_to_ov<Complex> (dv) : fp_to_ov<double> (dv));
1882 return (is_complex ()
1883 ? fp_to_ov<FloatComplex> (dv) : fp_to_ov<float> (dv));
1886 return int_to_ov<mxChar, charNDArray, char> (dv);
1889 return int_to_ov<mxLogical, boolNDArray, bool> (dv);
1892 return int_to_ov<int8_t, int8NDArray, octave_int8> (dv);
1895 return int_to_ov<uint8_t, uint8NDArray, octave_uint8> (dv);
1898 return int_to_ov<int16_t, int16NDArray, octave_int16> (dv);
1901 return int_to_ov<uint16_t, uint16NDArray, octave_uint16> (dv);
1904 return int_to_ov<int32_t, int32NDArray, octave_int32> (dv);
1907 return int_to_ov<uint32_t, uint32NDArray, octave_uint32> (dv);
1910 return int_to_ov<int64_t, int64NDArray, octave_int64> (dv);
1913 return int_to_ov<uint64_t, uint64NDArray, octave_uint64> (dv);
1924 mxArray_base_full (
const mxArray_base_full& val)
1925 : mxArray_matlab (val),
1926 m_pr (
mxArray::
malloc (get_number_of_elements () * get_element_size ()))
1929 memcpy (m_pr, val.m_pr, get_number_of_elements () * get_element_size ());
1932 template <
typename ELT_T>
1938 ELT_T *ppr =
static_cast<ELT_T *
> (m_pr);
1940 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
1942 if (current_mx_memory_resource == &the_mx_deleting_memory_resource)
1944 octave::unwind_action act ([=] () { maybe_disown_ptr (m_pr); });
1958 ELT_T *ptr = val.fortran_vec ();
1960 mwSize nel = get_number_of_elements ();
1962 for (
mwIndex i = 0; i < nel; i++)
1970 template <
typename ELT_T,
typename ARRAY_T,
typename ARRAY_ELT_T>
1975 error (
"complex integer types are not supported");
1977 ELT_T *ppr =
static_cast<ELT_T *
> (m_pr);
1984 ARRAY_ELT_T *ptr = val.fortran_vec ();
1986 mwSize nel = get_number_of_elements ();
1988 for (
mwIndex i = 0; i < nel; i++)
2003 class mxArray_interleaved_full :
public mxArray_base_full
2007 mxArray_interleaved_full () =
delete;
2011 : mxArray_base_full (true, flag ==
mxCOMPLEX, id, ndims, dims, init)
2016 : mxArray_base_full (true, flag ==
mxCOMPLEX, id, dv)
2021 : mxArray_base_full (true, flag ==
mxCOMPLEX, id,
m,
n, init)
2024 mxArray_interleaved_full (
mxClassID id,
double val)
2025 : mxArray_base_full (true, id, val)
2029 : mxArray_base_full (true, id, val)
2032 mxArray_interleaved_full (
const char *str)
2033 : mxArray_base_full (true, str)
2037 mxArray_interleaved_full (
mwSize m,
const char **str)
2038 : mxArray_base_full (true,
m, str)
2044 mxArray_interleaved_full& operator = (
const mxArray_interleaved_full&) =
delete;
2048 return new mxArray_interleaved_full (*
this);
2051 ~mxArray_interleaved_full (
void) =
default;
2059 mxArray_interleaved_full (
const mxArray_interleaved_full& val)
2060 : mxArray_base_full (val)
2064 class mxArray_separate_full :
public mxArray_base_full
2068 mxArray_separate_full () =
delete;
2072 : mxArray_base_full (false, flag ==
mxCOMPLEX, id, ndims, dims, init),
2074 ?
mxArray::alloc (init, get_number_of_elements (), get_element_size ())
2080 : mxArray_base_full (false, flag ==
mxCOMPLEX, id, dv),
2082 ?
mxArray::calloc (get_number_of_elements (), get_element_size ())
2088 : mxArray_base_full (false, flag ==
mxCOMPLEX, id,
m,
n, init),
2090 ? (
mxArray::alloc (init, get_number_of_elements (), get_element_size ()))
2094 mxArray_separate_full (
mxClassID id,
double val)
2095 : mxArray_base_full (false, id, val), m_pi (nullptr)
2099 : mxArray_base_full (false, id, val), m_pi (nullptr)
2102 mxArray_separate_full (
const char *str)
2103 : mxArray_base_full (false, str), m_pi (nullptr)
2107 mxArray_separate_full (
mwSize m,
const char **str)
2108 : mxArray_base_full (false,
m, str), m_pi (nullptr)
2114 mxArray_separate_full& operator = (
const mxArray_separate_full&) =
delete;
2118 return new mxArray_separate_full (*
this);
2121 ~mxArray_separate_full (
void)
2126 void * get_imag_data (
void)
const {
return m_pi; }
2128 void set_imag_data (
void *pi)
2132 set_complexity (m_pi !=
nullptr);
2187 if (! is_complex ())
2188 return mxArray_base_full::as_octave_value ();
2194 switch (get_class_id ())
2197 return to_ov<double> (dv);
2200 return to_ov<float> (dv);
2211 error (
"complex integer types are not supported");
2222 mxArray_separate_full (
const mxArray_separate_full& val)
2223 : mxArray_base_full (val),
2225 ?
mxArray::
malloc (get_number_of_elements () * get_element_size ())
2229 memcpy (m_pi, val.m_pi, get_number_of_elements () * get_element_size ());
2234 template <
typename T>
2238 mwSize nel = get_number_of_elements ();
2240 T *ppr =
static_cast<T *
> (m_pr);
2247 std::complex<T> *ptr = val.fortran_vec ();
2249 T *ppi =
static_cast<T *
> (m_pi);
2251 for (
mwIndex i = 0; i < nel; i++)
2252 ptr[i] = std::complex<T> (ppr[i], ppi[i]);
2263 class mxArray_base_sparse :
public mxArray_matlab
2267 mxArray_base_sparse () =
delete;
2269 mxArray_base_sparse (
bool interleaved,
bool is_complex,
2271 : mxArray_matlab (interleaved, is_complex, id,
m,
n),
2273 m_nzmax (nzmax > 0 ? nzmax : 1),
2276 m_pr (
mxArray::calloc (m_nzmax, get_element_size ()))
2281 mxArray_base_sparse (
const mxArray_base_sparse& val)
2282 : mxArray_matlab (val), m_nzmax (val.m_nzmax),
2288 memcpy (m_ir, val.m_ir, m_nzmax * sizeof (
mwIndex));
2291 memcpy (m_jc, val.m_jc, (val.get_n () + 1) * sizeof (
mwIndex));
2294 memcpy (m_pr, val.m_pr, m_nzmax * get_element_size ());
2302 mxArray_base_sparse& operator = (
const mxArray_base_sparse&) =
delete;
2306 return new mxArray_base_sparse (*
this);
2309 ~mxArray_base_sparse (
void)
2316 int is_sparse (
void)
const {
return 1; }
2318 void * get_data (
void)
const {
return m_pr; }
2320 void set_data (
void *pr) { m_pr = pr; }
2322 mxDouble * get_doubles (
void)
const
2324 return static_cast<mxDouble *
> (m_pr);
2344 mwIndex * get_ir (
void)
const {
return m_ir; }
2346 mwIndex * get_jc (
void)
const {
return m_jc; }
2348 mwSize get_nzmax (
void)
const {
return m_nzmax; }
2350 void set_ir (
mwIndex *ir) { m_ir = ir; }
2352 void set_jc (
mwIndex *jc) { m_jc = jc; }
2354 void set_nzmax (
mwSize nzmax)
2357 m_nzmax = (nzmax > 0 ? nzmax : 1);
2366 switch (get_class_id ())
2369 return is_complex () ? to_ov<Complex> (dv):
to_ov<double> (dv);
2372 error (
"single precision sparse data type not supported");
2375 return to_ov<bool> (dv);
2386 template <
typename ELT_T>
2390 ELT_T *ppr =
static_cast<ELT_T *
> (m_pr);
2392 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
2394 if (current_mx_memory_resource == &the_mx_deleting_memory_resource)
2396 octave::unwind_action act ([=] ()
2398 maybe_disown_ptr (m_pr);
2399 maybe_disown_ptr (m_ir);
2400 maybe_disown_ptr (m_jc);
2405 ppr, m_ir, m_jc, current_mx_memory_resource));
2410 ppr, m_ir, m_jc, current_mx_memory_resource));
2421 for (
mwIndex i = 0; i < m_nzmax; i++)
2423 val.xdata (i) = ppr[i];
2424 val.xridx (i) = m_ir[i];
2427 for (
mwIndex i = 0; i <
n + 1; i++)
2428 val.xcidx (i) = m_jc[i];
2448 class mxArray_interleaved_sparse :
public mxArray_base_sparse
2452 mxArray_interleaved_sparse () =
delete;
2456 : mxArray_base_sparse (true, flag ==
mxCOMPLEX, id,
m,
n, nzmax)
2461 mxArray_interleaved_sparse (
const mxArray_interleaved_sparse& val)
2462 : mxArray_base_sparse (val)
2470 mxArray_interleaved_sparse& operator = (
const mxArray_interleaved_sparse&) =
delete;
2474 return new mxArray_interleaved_sparse (*
this);
2477 ~mxArray_interleaved_sparse (
void) =
default;
2484 class mxArray_separate_sparse :
public mxArray_base_sparse
2488 mxArray_separate_sparse () =
delete;
2492 : mxArray_base_sparse (false, flag ==
mxCOMPLEX, id,
m,
n, nzmax),
2494 ?
mxArray::calloc (m_nzmax, get_element_size ())
2500 mxArray_separate_sparse (
const mxArray_separate_sparse& val)
2501 : mxArray_base_sparse (val),
2507 memcpy (m_pi, val.m_pi, m_nzmax * get_element_size ());
2515 mxArray_separate_sparse& operator = (
const mxArray_separate_sparse&) =
delete;
2519 return new mxArray_separate_sparse (*
this);
2522 ~mxArray_separate_sparse (
void)
2527 void * get_imag_data (
void)
const {
return m_pi; }
2529 void set_imag_data (
void *pi)
2532 set_complexity (m_pi !=
nullptr);
2543 if (! is_complex ())
2544 return mxArray_base_sparse::as_octave_value ();
2550 switch (get_class_id ())
2554 double *ppr =
static_cast<double *
> (m_pr);
2555 double *ppi =
static_cast<double *
> (m_pi);
2560 for (
mwIndex i = 0; i < m_nzmax; i++)
2562 val.xdata (i) =
Complex (ppr[i], ppi[i]);
2563 val.xridx (i) = m_ir[i];
2566 for (
mwIndex i = 0; i < get_n () + 1; i++)
2567 val.xcidx (i) = m_jc[i];
2574 error (
"single precision sparse data type not supported");
2591 class mxArray_struct :
public mxArray_matlab
2595 mxArray_struct () =
delete;
2597 mxArray_struct (
bool interleaved,
mwSize ndims,
const mwSize *dims,
2598 int num_keys,
const char **keys)
2599 : mxArray_matlab (interleaved, false,
mxSTRUCT_CLASS, ndims, dims),
2600 m_nfields (num_keys),
2601 m_fields (static_cast<char **> (
mxArray::calloc (m_nfields,
2604 get_number_of_elements (),
2610 mxArray_struct (
bool interleaved,
const dim_vector& dv,
int num_keys,
2613 m_nfields (num_keys),
2614 m_fields (static_cast<char **> (
mxArray::calloc (m_nfields,
2617 get_number_of_elements (),
2623 mxArray_struct (
bool interleaved,
mwSize m,
mwSize n,
int num_keys,
2626 m_nfields (num_keys),
2627 m_fields (static_cast<char **> (
mxArray::calloc (m_nfields,
2630 get_number_of_elements (),
2638 mxArray_struct (
const mxArray_struct& val)
2639 : mxArray_matlab (val), m_nfields (val.m_nfields),
2641 * sizeof (char *)))),
2643 get_number_of_elements ()
2646 for (
int i = 0; i < m_nfields; i++)
2649 mwSize nel = get_number_of_elements ();
2651 for (
mwIndex i = 0; i < nel * m_nfields; i++)
2654 m_data[i] = (ptr ? ptr->
dup () :
nullptr);
2663 mxArray_struct& operator = (
const mxArray_struct& val) =
delete;
2665 void init (
const char **keys)
2667 for (
int i = 0; i < m_nfields; i++)
2671 mxArray_base * dup (
void)
const {
return new mxArray_struct (*
this); }
2673 ~mxArray_struct (
void)
2675 for (
int i = 0; i < m_nfields; i++)
2680 mwSize ntot = m_nfields * get_number_of_elements ();
2682 for (
mwIndex i = 0; i < ntot; i++)
2688 int add_field (
const char *key)
2694 m_fields =
static_cast<char **
>
2695 (
mxRealloc (m_fields, m_nfields *
sizeof (
char *)));
2701 mwSize nel = get_number_of_elements ();
2703 mwSize ntot = m_nfields * nel;
2706 new_data =
static_cast<mxArray **
>
2715 for (
mwIndex i = 0; i < ntot; i++)
2717 if (++
n == m_nfields)
2719 new_data[j++] =
nullptr;
2723 new_data[j++] = m_data[k++];
2730 retval = m_nfields - 1;
2737 void remove_field (
int key_num)
2739 if (key_num >= 0 && key_num < m_nfields)
2741 mwSize nel = get_number_of_elements ();
2743 mwSize ntot = m_nfields * nel;
2745 int new_nfields = m_nfields - 1;
2747 char **new_fields =
static_cast<char **
>
2754 for (
int i = 0; i < key_num; i++)
2755 new_fields[i] = m_fields[i];
2757 for (
int i = key_num + 1; i < m_nfields; i++)
2758 new_fields[i-1] = m_fields[i];
2760 if (new_nfields > 0)
2766 for (
mwIndex i = 0; i < ntot; i++)
2771 new_data[j++] = m_data[k++];
2773 if (++
n == m_nfields)
2778 m_nfields = new_nfields;
2783 m_fields = new_fields;
2790 return key_num >= 0 && key_num < m_nfields
2791 ? m_data[m_nfields * index + key_num] :
nullptr;
2794 void set_field_by_number (
mwIndex index,
int key_num,
mxArray *val);
2796 int get_number_of_fields (
void)
const {
return m_nfields; }
2798 const char * get_field_name_by_number (
int key_num)
const
2800 return key_num >= 0 && key_num < m_nfields ? m_fields[key_num] :
nullptr;
2803 int get_field_number (
const char *key)
const
2807 for (
int i = 0; i < m_nfields; i++)
2809 if (!
strcmp (key, m_fields[i]))
2819 void * get_data (
void)
const {
return m_data; }
2821 void set_data (
void *data) { m_data =
static_cast<mxArray **
> (data); }
2831 mwSize ntot = m_nfields * get_number_of_elements ();
2833 for (
int i = 0; i < m_nfields; i++)
2840 for (
mwIndex j = i; j < ntot; j += m_nfields)
2843 m.assign (keys[i], c);
2860 class mxArray_cell :
public mxArray_matlab
2864 mxArray_cell () =
delete;
2866 mxArray_cell (
bool interleaved,
mwSize ndims,
const mwSize *dims)
2867 : mxArray_matlab (interleaved, false,
mxCELL_CLASS, ndims, dims),
2871 mxArray_cell (
bool interleaved,
const dim_vector& dv)
2872 : mxArray_matlab (interleaved, false,
mxCELL_CLASS, dv),
2883 mxArray_cell (
const mxArray_cell& val)
2884 : mxArray_matlab (val),
2887 mwSize nel = get_number_of_elements ();
2889 for (
mwIndex i = 0; i < nel; i++)
2892 m_data[i] = (ptr ? ptr->
dup () :
nullptr);
2901 mxArray_cell& operator = (
const mxArray_cell&) =
delete;
2903 mxArray_base * dup (
void)
const {
return new mxArray_cell (*
this); }
2905 ~mxArray_cell (
void)
2907 mwSize nel = get_number_of_elements ();
2909 for (
mwIndex i = 0; i < nel; i++)
2917 return idx >= 0 && idx < get_number_of_elements () ? m_data[idx] :
nullptr;
2922 void * get_data (
void)
const {
return m_data; }
2924 void set_data (
void *data) { m_data =
static_cast<mxArray **
> (data); }
2932 mwSize nel = get_number_of_elements ();
2936 for (
mwIndex i = 0; i < nel; i++)
2950 : m_rep (create_rep (interleaved, ov)), m_name (nullptr)
2955 : m_rep (create_rep (interleaved, id, ndims, dims, flag, init)),
2961 : m_rep (create_rep (interleaved, id, dv, flag)), m_name (nullptr)
2966 : m_rep (create_rep (interleaved, id,
m,
n, flag, init)), m_name (nullptr)
2970 : m_rep (create_rep (interleaved, id, val)), m_name (nullptr)
2974 : m_rep (create_rep (interleaved, id, val)), m_name (nullptr)
2978 : m_rep (create_rep (interleaved, str)), m_name (nullptr)
2982 : m_rep (create_rep (interleaved,
m, str)), m_name (nullptr)
2987 : m_rep (create_rep (interleaved, id,
m,
n, nzmax, flag)), m_name (nullptr)
2993 : m_rep (new mxArray_struct (interleaved, ndims, dims, num_keys, keys)),
2999 : m_rep (new mxArray_struct (interleaved, dv, num_keys, keys)),
3005 : m_rep (new mxArray_struct (interleaved,
m,
n, num_keys, keys)),
3010 : m_rep (new mxArray_cell (interleaved, ndims, dims)), m_name (nullptr)
3014 : m_rep (new mxArray_cell (interleaved, dv)), m_name (nullptr)
3018 : m_rep (new mxArray_cell (interleaved,
m,
n)), m_name (nullptr)
3052 mxArray::create_rep (
bool interleaved,
const octave_value& ov)
3054 return new mxArray_octave_value (interleaved, ov);
3062 return new mxArray_interleaved_full (
id, ndims, dims, flag, init);
3064 return new mxArray_separate_full (
id, ndims, dims, flag, init);
3072 return new mxArray_interleaved_full (
id, dv, flag);
3074 return new mxArray_separate_full (
id, dv, flag);
3082 return new mxArray_interleaved_full (
id,
m,
n, flag, init);
3084 return new mxArray_separate_full (
id,
m,
n, flag, init);
3088 mxArray::create_rep (
bool interleaved,
mxClassID id,
double val)
3091 return new mxArray_interleaved_full (
id, val);
3093 return new mxArray_separate_full (
id, val);
3100 return new mxArray_interleaved_full (
id, val);
3102 return new mxArray_separate_full (
id, val);
3106 mxArray::create_rep (
bool interleaved,
const char *str)
3109 return new mxArray_interleaved_full (str);
3111 return new mxArray_separate_full (str);
3115 mxArray::create_rep (
bool interleaved,
mwSize m,
const char **str)
3118 return new mxArray_interleaved_full (
m, str);
3120 return new mxArray_separate_full (
m, str);
3128 return new mxArray_interleaved_sparse (
id,
m,
n, nzmax, flag);
3130 return new mxArray_separate_sparse (
id,
m,
n, nzmax, flag);
3134 mxArray::maybe_mutate (
void)
const
3147 m_rep = new_val->m_rep;
3148 new_val->m_rep =
nullptr;
3164 : m_curr_mex_fcn (
f), m_memlist (), m_arraylist (), m_fname (nullptr) { }
3166 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (mex)
3171 while (! m_memlist.empty ())
3173 auto p = m_memlist.begin ();
3175 m_memlist.erase (p);
3179 while (! m_arraylist.empty ())
3181 auto p = m_arraylist.begin ();
3183 m_arraylist.erase (p);
3186 if (! (m_memlist.empty () && m_arraylist.empty ()))
3187 error (
"mex: %s: cleanup failed", function_name ());
3192 const char * function_name (
void)
const
3202 std::string nm = fcn->
name ();
3213 void * malloc_unmarked (std::size_t
n)
3215 void *ptr = xmalloc (
n);
3220 error (
"%s: failed to allocate %zd bytes of memory",
3221 function_name (),
n);
3232 void *ptr = malloc_unmarked (
n);
3240 void * calloc_unmarked (std::size_t
n, std::size_t t)
3242 void *ptr = malloc_unmarked (
n*t);
3244 memset (ptr, 0,
n*t);
3250 void * calloc (std::size_t
n, std::size_t t)
3252 void *ptr = calloc_unmarked (
n, t);
3262 void * realloc (
void *ptr, std::size_t
n)
3268 auto p_local = m_memlist.find (ptr);
3269 auto p_global = s_global_memlist.find (ptr);
3271 v = xrealloc (ptr,
n);
3275 if (p_local != m_memlist.end ())
3277 m_memlist.erase (p_local);
3278 m_memlist.insert (v);
3281 if (p_global != s_global_memlist.end ())
3283 s_global_memlist.erase (p_global);
3284 s_global_memlist.insert (v);
3295 void free (
void *ptr)
3301 auto p = s_global_memlist.find (ptr);
3303 if (p != s_global_memlist.end ())
3305 s_global_memlist.erase (p);
3311 p = m_foreign_memlist.find (ptr);
3313 if (p != m_foreign_memlist.end ())
3314 m_foreign_memlist.erase (p);
3317 warning (
"mxFree: skipping memory not allocated by mxMalloc, mxCalloc, or mxRealloc");
3324 void mark (
void *ptr)
3327 if (m_memlist.find (ptr) != m_memlist.end ())
3328 warning (
"%s: double registration ignored", function_name ());
3331 m_memlist.insert (ptr);
3336 void unmark (
void *ptr)
3338 auto p = m_memlist.find (ptr);
3340 if (p != m_memlist.end ())
3341 m_memlist.erase (p);
3344 warning (
"%s: value not marked", function_name ());
3350 m_arraylist.insert (ptr);
3354 void unmark_array (
mxArray *ptr)
3356 auto p = m_arraylist.find (ptr);
3358 if (p != m_arraylist.end ())
3359 m_arraylist.erase (p);
3363 void mark_foreign (
void *ptr)
3366 if (m_foreign_memlist.find (ptr) != m_foreign_memlist.end ())
3367 warning (
"%s: double registration ignored", function_name ());
3370 m_foreign_memlist.insert (ptr);
3374 void unmark_foreign (
void *ptr)
3376 auto p = m_foreign_memlist.find (ptr);
3378 if (p != m_foreign_memlist.end ())
3379 m_foreign_memlist.erase (p);
3382 warning (
"%s: value not marked", function_name ());
3391 bool interleaved = m_curr_mex_fcn.use_interleaved_complex ();
3393 return mark_array (
new mxArray (interleaved, ov));
3397 bool free_value (
mxArray *ptr)
3399 bool inlist =
false;
3401 auto p = m_arraylist.find (ptr);
3403 if (p != m_arraylist.end ())
3406 m_arraylist.erase (p);
3411 warning (
"mex::free_value: skipping memory not allocated by mex::make_value");
3419 return m_curr_mex_fcn;
3423 int trap_feval_error = 0;
3426 void global_mark (
void *ptr)
3429 if (s_global_memlist.find (ptr) != s_global_memlist.end ())
3430 warning (
"%s: double registration ignored", function_name ());
3433 s_global_memlist.insert (ptr);
3437 void global_unmark (
void *ptr)
3439 auto p = s_global_memlist.find (ptr);
3441 if (p != s_global_memlist.end ())
3442 s_global_memlist.erase (p);
3445 warning (
"%s: value not marked", function_name ());
3455 std::set<void *> m_memlist;
3458 std::set<mxArray *> m_arraylist;
3462 std::set<void *> m_foreign_memlist;
3465 mutable char *m_fname;
3468 static std::set<void *> s_global_memlist;
3473 std::set<void *> mex::s_global_memlist;
3496 static inline void *
3497 maybe_mark_foreign (
void *ptr)
3505 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
3508 maybe_disown_ptr (
void *ptr)
3521 maybe_unmark_array (
mxArray *ptr)
3529 template <
typename T>
3531 maybe_unmark (T *ptr)
3540 mxArray_struct::set_field_by_number (
mwIndex index,
int key_num,
mxArray *val)
3542 if (key_num >= 0 && key_num < m_nfields)
3543 m_data[m_nfields * index + key_num] = maybe_unmark_array (val);
3549 if (idx >= 0 && idx < get_number_of_elements ())
3550 m_data[idx] = maybe_unmark_array (val);
3580 return std::numeric_limits<double>::epsilon ();
3612 ?
mex_context->realloc (ptr, size) : xrealloc (ptr, size));
3625 maybe_mark_array (
mxArray *ptr)
3634 return maybe_mark_array (
new mxArray (
true, ndims, dims));
3640 return maybe_mark_array (
new mxArray (
false, ndims, dims));
3646 return maybe_mark_array (
new mxArray (
true,
m,
n));
3652 return maybe_mark_array (
new mxArray (
false,
m,
n));
3670 return maybe_mark_array (
new mxArray (
true,
m, str));
3676 return maybe_mark_array (
new mxArray (
false,
m, str));
3743 return maybe_mark_array (
new mxArray (
true, class_id, ndims, dims, flag));
3750 return maybe_mark_array (
new mxArray (
false, class_id, ndims, dims, flag));
3757 return maybe_mark_array (
new mxArray (
true, class_id,
m,
n, flag));
3764 return maybe_mark_array (
new mxArray (
false, class_id,
m,
n, flag));
3771 return maybe_mark_array (
new mxArray (
true, class_id, ndims, dims, flag,
3779 return maybe_mark_array (
new mxArray (
false, class_id, ndims, dims, flag,
3787 return maybe_mark_array (
new mxArray (
true, class_id,
m,
n, flag,
false));
3794 return maybe_mark_array (
new mxArray (
false, class_id,
m,
n, flag,
false));
3826 return maybe_mark_array (
new mxArray (
true, str));
3832 return maybe_mark_array (
new mxArray (
false, str));
3837 int num_keys,
const char **keys)
3839 return maybe_mark_array (
new mxArray (
true, ndims, dims, num_keys, keys));
3846 return maybe_mark_array (
new mxArray (
false, ndims, dims, num_keys, keys));
3853 return maybe_mark_array (
new mxArray (
true,
m,
n, num_keys, keys));
3860 return maybe_mark_array (
new mxArray (
false,
m,
n, num_keys, keys));
3867 return maybe_mark_array (ptr->
dup ());
4034 return ptr->
get_m ();
4040 return ptr->
get_n ();
4078 (maybe_unmark (
const_cast<mwSize *
> (dims))),
4086 return static_cast<double *
> (ptr->
get_data ());
4228 return ptr->
set_int8s (maybe_unmark (data));
4234 return ptr->
set_int16s (maybe_unmark (data));
4240 return ptr->
set_int32s (maybe_unmark (data));
4246 return ptr->
set_int64s (maybe_unmark (data));
4252 return ptr->
set_uint8s (maybe_unmark (data));
4318 const mxArray *property_value)
4320 ptr->
set_property (idx, property_name, property_value);
4477 volatile int nargout = nargout_arg;
4479 int nargin = args.
length ();
4481 for (
int i = 0; i < nargin; i++)
4484 int nout = (nargout == 0 ? 1 : nargout);
4486 for (
int i = 0; i < nout; i++)
4487 argout[i] =
nullptr;
4490 octave::unwind_protect_var<mex *> restore_var (
mex_context);
4492 mex context (mex_fcn);
4494 for (
int i = 0; i < nargin; i++)
4495 argin[i] = context.make_value (args(i));
4505 F77_INT tmp_nargout = nargout;
4508 fcn (tmp_nargout, argout, tmp_nargin, argin);
4514 fcn (nargout, argout, nargin, argin);
4521 if (nargout == 0 && argout[0])
4533 for (
int i = 0; i < nargout; i++)
4539 OCTAVE_END_NAMESPACE(
octave)
4550 mx_to_ov_args (
int nargin,
mxArray *argin[])
4560 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
4567 octave::unwind_protect_var<std::pmr::memory_resource *>
4568 upv (current_mx_memory_resource, &the_mx_preserving_memory_resource);
4572 for (
int i = 0; i < nargin; i++)
4580 mxArray *argin[],
const char *fname)
4586 bool execution_error =
false;
4592 octave::tree_evaluator& tw = interp.get_evaluator ();
4594 octave::unwind_action act
4595 ([&tw] (
const std::list<octave::octave_lvalue> *lvl)
4597 tw.set_lvalue_list (lvl);
4598 }, tw.lvalue_list ());
4600 tw.set_lvalue_list (
nullptr);
4602 retval = interp.feval (fname, args, nargout);
4604 catch (
const octave::execution_exception&)
4612 interp.recover_from_exception ();
4614 execution_error =
true;
4625 int num_to_copy = retval.
length ();
4627 if (nargout < retval.
length ())
4628 num_to_copy = nargout;
4630 for (
int i = 0; i < num_to_copy; i++)
4639 while (num_to_copy < nargout)
4640 argout[num_to_copy++] =
nullptr;
4642 return execution_error ? 1 : 0;
4647 mxArray *argin[],
const char *fname)
4655 const char *field_names[] = {
"identifier",
"message",
"case",
"stack"};
4658 std::string msg =
"mexCallMATLABWithTrap: function call <"
4659 + std::string (fname) +
"> failed";
4684 bool execution_error =
false;
4690 ret = interp.eval_string (std::string (s),
false, parse_status, 0);
4692 catch (
const octave::execution_exception&)
4694 interp.recover_from_exception ();
4696 execution_error =
true;
4699 if (parse_status || execution_error)
4713 bool execution_error =
false;
4719 ret = interp.eval_string (std::string (s),
false, parse_status, 0);
4721 catch (
const octave::execution_exception&)
4723 interp.recover_from_exception ();
4725 execution_error =
true;
4728 if (parse_status || execution_error)
4730 const char *field_names[] = {
"identifier",
"message",
"case",
"stack"};
4733 std::string msg =
"mexEvalStringWithTrap: eval of <"
4734 + std::string (s) +
"> failed";
4750 if (s[
len - 1] ==
'\n')
4752 std::string s_tmp (s,
len - 1);
4769 if (fmt &&
strlen (fmt) > 0)
4774 sprintf (tmpfmt,
"%s: %s", fname, fmt);
4776 va_start (args, fmt);
4795 if (s[
len - 1] ==
'\n')
4797 std::string s_tmp (s,
len - 1);
4798 warning (
"%s\n", s_tmp.c_str ());
4817 if (fmt &&
strlen (fmt) > 0)
4822 sprintf (tmpfmt,
"%s: %s", fname, fmt);
4824 va_start (args, fmt);
4835 va_start (args, fmt);
4850 if (!
strcmp (space,
"global"))
4851 val = interp.global_varval (name);
4856 octave::unwind_protect frame;
4858 bool caller = !
strcmp (space,
"caller");
4859 bool base = !
strcmp (space,
"base");
4868 octave::tree_evaluator& tw = interp.get_evaluator ();
4870 frame.add (&octave::tree_evaluator::restore_frame, &tw,
4871 tw.current_call_stack_frame_number ());
4873 tw.goto_base_frame ();
4876 val = interp.varval (name);
4879 mexErrMsgTxt (
"mexGetVariable: symbol table does not exist");
4907 if (name[0] ==
'\0')
4910 if (! name || name[0] ==
'\0')
4915 if (!
strcmp (space,
"global"))
4917 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
4924 octave::unwind_protect_var<std::pmr::memory_resource *>
4925 upv (current_mx_memory_resource, &the_mx_preserving_memory_resource);
4934 octave::unwind_protect frame;
4936 bool caller = !
strcmp (space,
"caller");
4937 bool base = !
strcmp (space,
"base");
4946 octave::tree_evaluator& tw = interp.get_evaluator ();
4948 frame.add (&octave::tree_evaluator::restore_frame, &tw,
4949 tw.current_call_stack_frame_number ());
4951 tw.goto_base_frame ();
4954 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
4961 octave::unwind_protect_var<std::pmr::memory_resource *>
4962 upv (current_mx_memory_resource,
4963 &the_mx_preserving_memory_resource);
4969 mexErrMsgTxt (
"mexPutVariable: symbol table does not exist");
4978 maybe_unmark_array (ptr);
5045 retval = interp.mislocked (fname);
5074 #if defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR)
5081 octave::unwind_protect_var<std::pmr::memory_resource *>
5082 upv (current_mx_memory_resource, &the_mx_preserving_memory_resource);
5089 return (ret ? 0 : 1);
5109 interp.munlock (fname);
octave_value to_ov(const cdef_object &obj)
N Dimensional Array with copy-on-write semantics.
const T * data() const
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
void resize(int n, int fill_value=0)
virtual int set_int8s(mxInt8 *data)=0
virtual int set_complex_singles(mxComplexSingle *data)=0
OCTAVE_NORETURN void err_invalid_type(const char *op) const
virtual mxInt8 * get_int8s() const =0
virtual bool is_octave_value() const
virtual void set_n(mwSize n)=0
virtual void set_cell(mwIndex idx, mxArray *val)=0
virtual int add_field(const char *key)=0
virtual mxComplexDouble * get_complex_doubles() const =0
virtual mwIndex * get_jc() const =0
virtual void set_nzmax(mwSize nzmax)=0
virtual int set_uint16s(mxUint16 *data)=0
virtual mxDouble * get_doubles() const =0
virtual int is_logical() const =0
virtual int is_uint64() const =0
virtual char * array_to_string() const =0
virtual int set_uint64s(mxUint64 *data)=0
virtual int get_string(char *buf, mwSize buflen) const =0
virtual bool is_scalar() const =0
virtual mxSingle * get_singles() const =0
virtual mwIndex calc_single_subscript(mwSize nsubs, mwIndex *subs) const =0
virtual mxArray * get_cell(mwIndex) const
virtual int set_doubles(mxDouble *data)=0
virtual int set_int64s(mxInt64 *data)=0
virtual int is_complex() const =0
virtual mxComplexSingle * get_complex_singles() const =0
virtual octave_value as_octave_value() const =0
virtual void set_imag_data(void *pi)=0
virtual int is_numeric() const =0
virtual mxArray * get_field_by_number(mwIndex index, int key_num) const =0
virtual int set_int16s(mxInt16 *data)=0
virtual int is_double() const =0
virtual mwSize * get_dimensions() const =0
virtual int set_singles(mxSingle *data)=0
virtual int is_char() const =0
virtual void set_m(mwSize m)=0
virtual void set_data(void *pr)=0
virtual int is_logical_scalar_true() const =0
virtual void * get_data() const =0
virtual mxInt16 * get_int16s() const =0
virtual int is_uint16() const =0
virtual double get_scalar() const =0
virtual mwSize get_nzmax() const =0
std::size_t get_numeric_element_size(std::size_t size) const
virtual mxArray_base * dup() const =0
virtual int iscell() const =0
virtual void set_property(mwIndex, const char *, const mxArray *)
virtual int set_complex_doubles(mxComplexDouble *data)=0
virtual void * get_imag_data() const =0
virtual int isempty() const =0
virtual mwSize get_number_of_elements() const =0
virtual mxArray * as_mxArray() const
virtual void set_jc(mwIndex *jc)=0
virtual std::size_t get_element_size() const =0
virtual int set_uint32s(mxUint32 *data)=0
virtual mxUint64 * get_uint64s() const =0
virtual mxUint8 * get_uint8s() const =0
virtual int set_uint8s(mxUint8 *data)=0
virtual bool mutation_needed() const
virtual mxInt32 * get_int32s() const =0
virtual mwIndex * get_ir() const =0
virtual int set_dimensions(mwSize *dims_arg, mwSize ndims_arg)=0
virtual mxUint16 * get_uint16s() const =0
virtual int is_int16() const =0
virtual int is_single() const =0
virtual void set_class_name(const char *name_arg)=0
virtual mxUint32 * get_uint32s() const =0
virtual mxArray * mutate() const
virtual mwSize get_number_of_dimensions() const =0
virtual int is_function_handle() const =0
virtual int is_uint8() const =0
virtual mwSize get_m() const =0
virtual int is_int8() const =0
virtual int is_int32() const =0
virtual int get_number_of_fields() const =0
virtual void set_ir(mwIndex *ir)=0
virtual void remove_field(int key_num)=0
virtual int is_uint32() const =0
virtual mxArray * get_property(mwIndex, const char *) const
virtual const char * get_field_name_by_number(int key_num) const =0
virtual int is_int64() const =0
virtual void set_field_by_number(mwIndex index, int key_num, mxArray *val)=0
virtual const char * get_class_name() const =0
virtual int is_struct() const =0
virtual mxInt64 * get_int64s() const =0
virtual int get_field_number(const char *key) const =0
virtual mwSize get_n() const =0
virtual int set_int32s(mxInt32 *data)=0
virtual int is_sparse() const =0
virtual mxClassID get_class_id() const =0
int set_uint8s(mxUint8 *data)
int set_complex_singles(mxComplexSingle *data)
mxUint8 * get_uint8s() const
int is_logical_scalar() const
int set_uint32s(mxUint32 *data)
int get_number_of_fields() const
mxInt64 * get_int64s() const
mxUint64 * get_uint64s() const
double get_scalar() const
void set_name(const char *name)
char * array_to_string() const
void * get_imag_data() const
mwSize get_number_of_dimensions() const
void set_property(mwIndex idx, const char *pname, const mxArray *pval)
std::size_t get_element_size() const
int set_singles(mxSingle *data)
mwSize * get_dimensions() const
const char * get_class_name() const
int set_uint16s(mxUint16 *data)
static void * alloc(bool init, std::size_t n, std::size_t t)
mxArray * get_property(mwIndex idx, const char *pname) const
int is_function_handle() const
mxInt16 * get_int16s() const
int set_uint64s(mxUint64 *data)
mwIndex calc_single_subscript(mwSize nsubs, mwIndex *subs) const
mwSize get_number_of_elements() const
int set_dimensions(mwSize *dims_arg, mwSize ndims_arg)
mxUint16 * get_uint16s() const
static char * strsave(const char *str)
mxComplexSingle * get_complex_singles() const
static void * calloc(std::size_t n, std::size_t t)
mxArray(bool interleaved, const octave_value &ov)
int set_complex_doubles(mxComplexDouble *data)
int get_field_number(const char *key) const
mxArray * get_field_by_number(mwIndex index, int key_num) const
int add_field(const char *key)
mxInt32 * get_int32s() const
static octave_value as_octave_value(const mxArray *ptr, bool null_is_empty=true)
int set_int32s(mxInt32 *data)
int set_int64s(mxInt64 *data)
int set_doubles(mxDouble *data)
void set_nzmax(mwSize nzmax)
int is_logical_scalar_true() const
octave_value as_octave_value() const
int set_int16s(mxInt16 *data)
mxClassID get_class_id() const
mxSingle * get_singles() const
const char * get_field_name_by_number(int key_num) const
mxUint32 * get_uint32s() const
int get_string(char *buf, mwSize buflen) const
int is_class(const char *name_arg) const
int set_int8s(mxInt8 *data)
void set_class_name(const char *name_arg)
mxDouble * get_doubles() const
void set_field_by_number(mwIndex index, int key_num, mxArray *val)
void set_cell(mwIndex idx, mxArray *val)
mxArray * get_cell(mwIndex idx) const
mxComplexDouble * get_complex_doubles() const
static void * malloc(std::size_t n)
void set_imag_data(void *pi)
mxInt8 * get_int8s() const
void remove_field(int key_num)
const char * get_name() const
octave_value get_property(octave_idx_type idx, const std::string &name) const
void set_property(octave_idx_type idx, const std::string &name, const octave_value &pval)
octave_classdef * classdef_object_value(bool=false)
void * mex_fcn_ptr() const
void atexit(void(*fcn)())
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
octave_idx_type length() const
mxArray * as_mxArray(bool interleaved=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void warning(const char *fmt,...)
void vwarning_with_id(const char *id, const char *fmt, va_list args)
void verror_with_id(const char *id, const char *fmt, va_list args)
void() error(const char *fmt,...)
#define panic_impossible()
octave_f77_int_type F77_INT
bool set_property_in_handle(double handle, const std::string &property, const octave_value &arg, const std::string &fcn)
octave_value get_property_from_handle(double handle, const std::string &property, const std::string &fcn)
interpreter & __get_interpreter__()
tree_evaluator & __get_evaluator__()
double lo_ieee_nan_value()
double lo_ieee_inf_value()
#define lo_ieee_isfinite(x)
F77_RET_T(F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, const F77_INT &, const F77_INT &, const F77_INT &, F77_INT &, F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, F77_DBLE *, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, F77_INT *, F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE const F77_DBLE * f
char * strsave(const char *s)
void mxSetIr(mxArray *ptr, mwIndex *ir)
mxUint16 * mxGetUint16s(const mxArray *p)
void mxSetCell(mxArray *ptr, mwIndex idx, mxArray *val)
bool mxIsUint16(const mxArray *ptr)
std::size_t mxGetM(const mxArray *ptr)
int mxSetDoubles(mxArray *p, mxDouble *d)
mxDouble * mxGetDoubles(const mxArray *p)
void mexWarnMsgIdAndTxt(const char *id, const char *fmt,...)
int mxSetUint8s(mxArray *p, mxUint8 *d)
#define CONST_MUTATION_METHOD(RET_TYPE, FCN_NAME, ARG_LIST, RET_VAL)
void * mxGetData(const mxArray *ptr)
void * mxMalloc(std::size_t n)
mwIndex mxCalcSingleSubscript(const mxArray *ptr, mwSize nsubs, mwIndex *subs)
int mxSetInt16s(mxArray *p, mxInt16 *d)
mxInt64 * mxGetInt64s(const mxArray *p)
bool mxIsFunctionHandle(const mxArray *ptr)
bool mxIsStruct(const mxArray *ptr)
int mxGetFieldNumber(const mxArray *ptr, const char *key)
void mexErrMsgTxt(const char *s)
void mxSetField(mxArray *ptr, mwIndex index, const char *key, mxArray *val)
mxArray * mxCreateCellMatrix_interleaved(mwSize m, mwSize n)
void(* cmex_fptr)(int nlhs, mxArray **plhs, int nrhs, mxArray **prhs)
bool mxIsUint32(const mxArray *ptr)
void mxSetProperty(mxArray *ptr, mwIndex idx, const char *property_name, const mxArray *property_value)
int mxSetComplexDoubles(mxArray *p, mxComplexDouble *d)
mxUint64 * mxGetUint64s(const mxArray *p)
bool mxIsComplex(const mxArray *ptr)
mxArray * mxCreateCharArray_interleaved(mwSize ndims, const mwSize *dims)
mxComplexDouble * mxGetComplexDoubles(const mxArray *p)
mxArray * mxCreateString(const char *str)
mxArray * mxCreateSparseLogicalMatrix_interleaved(mwSize m, mwSize n, mwSize nzmax)
mxArray * mxCreateCellArray(mwSize ndims, const mwSize *dims)
int mxSetUint32s(mxArray *p, mxUint32 *d)
int mxSetInt8s(mxArray *p, mxInt8 *d)
mxArray * mxCreateNumericMatrix(mwSize m, mwSize n, mxClassID class_id, mxComplexity flag)
int mexAtExit(void(*f)(void))
int mxSetUint16s(mxArray *p, mxUint16 *d)
bool mxIsFinite(const double v)
mxSingle * mxGetSingles(const mxArray *p)
bool mxIsScalar(const mxArray *ptr)
bool mxIsFromGlobalWS(const mxArray *)
void mxSetFieldByNumber(mxArray *ptr, mwIndex index, int key_num, mxArray *val)
const char * mxGetClassName(const mxArray *ptr)
bool mxIsLogicalScalarTrue(const mxArray *ptr)
int mxSetInt32s(mxArray *p, mxInt32 *d)
mxArray * mxCreateSparse(mwSize m, mwSize n, mwSize nzmax, mxComplexity flag)
mxArray * mxCreateStructArray(mwSize ndims, const mwSize *dims, int num_keys, const char **keys)
void * mxGetImagData(const mxArray *ptr)
mxClassID mxGetClassID(const mxArray *ptr)
bool mxIsLogical(const mxArray *ptr)
mxArray * mxGetProperty(const mxArray *ptr, mwIndex idx, const char *property_name)
std::map< std::string, int > mex_lock_count
void mexWarnMsgTxt(const char *s)
mxInt16 * mxGetInt16s(const mxArray *p)
void mxSetData(mxArray *ptr, void *pr)
const char * mexFunctionName(void)
mwIndex * mxGetIr(const mxArray *ptr)
int mxSetUint64s(mxArray *p, mxUint64 *d)
mxInt8 * mxGetInt8s(const mxArray *p)
bool mxIsInt64(const mxArray *ptr)
mxArray * mxGetFieldByNumber(const mxArray *ptr, mwIndex index, int key_num)
mxArray * mexCallMATLABWithTrap(int nargout, mxArray *argout[], int nargin, mxArray *argin[], const char *fname)
int mxSetDimensions(mxArray *ptr, const mwSize *dims, mwSize ndims)
std::size_t mxGetNumberOfElements(const mxArray *ptr)
octave_value_list call_mex(octave_mex_function &mex_fcn, const octave_value_list &args, int nargout_arg)
int mexPrintf(const char *fmt,...)
bool mxIsChar(const mxArray *ptr)
bool mxIsInf(const double v)
bool mxIsUint8(const mxArray *ptr)
void mxDestroyArray(mxArray *ptr)
void mxSetNzmax(mxArray *ptr, mwSize nzmax)
bool mxIsSingle(const mxArray *ptr)
void mexErrMsgIdAndTxt(const char *id, const char *fmt,...)
F77_RET_T(* fmex_fptr)(F77_INT &nlhs, mxArray **plhs, F77_INT &nrhs, mxArray **prhs)
int mxAddField(mxArray *ptr, const char *key)
void mexMakeMemoryPersistent(void *ptr)
bool mxIsInt8(const mxArray *ptr)
mxComplexSingle * mxGetComplexSingles(const mxArray *p)
std::size_t mxGetElementSize(const mxArray *ptr)
void mxSetImagData(mxArray *ptr, void *pi)
mxArray * mxCreateLogicalArray(mwSize ndims, const mwSize *dims)
int mxMakeArrayReal(mxArray *ptr)
int mexCallMATLAB(int nargout, mxArray *argout[], int nargin, mxArray *argin[], const char *fname)
bool mxIsNaN(const double v)
mxArray * mxCreateCharArray(mwSize ndims, const mwSize *dims)
mxUint8 * mxGetUint8s(const mxArray *p)
void mxSetPr(mxArray *ptr, double *pr)
mxArray * mexEvalStringWithTrap(const char *s)
mxArray * mexGetVariable(const char *space, const char *name)
bool mxIsClass(const mxArray *ptr, const char *name)
mxArray * mxCreateString_interleaved(const char *str)
int mxMakeArrayComplex(mxArray *ptr)
mxInt32 * mxGetInt32s(const mxArray *p)
mxArray * mxCreateUninitNumericMatrix_interleaved(mwSize m, mwSize n, mxClassID class_id, mxComplexity flag)
int mxGetNumberOfFields(const mxArray *ptr)
#define GET_DATA_METHOD(RT, FCN_NAME, ID, COMPLEXITY)
mxArray * mxCreateCellArray_interleaved(mwSize ndims, const mwSize *dims)
void * mxCalloc(std::size_t n, std::size_t size)
mxArray * mxCreateNumericArray_interleaved(mwSize ndims, const mwSize *dims, mxClassID class_id, mxComplexity flag)
mwIndex * mxGetJc(const mxArray *ptr)
int mexPutVariable(const char *space, const char *name, const mxArray *ptr)
void mxSetN(mxArray *ptr, mwSize n)
mxArray * mxCreateNumericArray(mwSize ndims, const mwSize *dims, mxClassID class_id, mxComplexity flag)
int mxSetInt64s(mxArray *p, mxInt64 *d)
mxArray * mxCreateSparseLogicalMatrix(mwSize m, mwSize n, mwSize nzmax)
bool mxIsInt32(const mxArray *ptr)
double * mxGetPi(const mxArray *ptr)
mxArray * mxCreateCharMatrixFromStrings_interleaved(mwSize m, const char **str)
void * mxRealloc(void *ptr, std::size_t size)
int mexIsGlobal(const mxArray *ptr)
void mxSetJc(mxArray *ptr, mwIndex *jc)
bool mxIsInt16(const mxArray *ptr)
const mwSize * mxGetDimensions(const mxArray *ptr)
int mxSetComplexSingles(mxArray *p, mxComplexSingle *d)
mxArray * mxCreateCellMatrix(mwSize m, mwSize n)
int mexEvalString(const char *s)
void mexSetTrapFlag(int flag)
mwSize mxGetNzmax(const mxArray *ptr)
mxArray * mxCreateLogicalScalar(mxLogical val)
void mxSetClassName(mxArray *ptr, const char *name)
const mxArray * mexGetVariablePtr(const char *space, const char *name)
mxUint32 * mxGetUint32s(const mxArray *p)
bool mxIsNumeric(const mxArray *ptr)
mxArray * mxCreateSparse_interleaved(mwSize m, mwSize n, mwSize nzmax, mxComplexity flag)
mxArray * mxCreateDoubleMatrix(mwSize nr, mwSize nc, mxComplexity flag)
bool mxIsCell(const mxArray *ptr)
void mexMakeArrayPersistent(mxArray *ptr)
mxArray * mxCreateCharMatrixFromStrings(mwSize m, const char **str)
double mxGetScalar(const mxArray *ptr)
#define VOID_MUTATION_METHOD(FCN_NAME, ARG_LIST)
void mxRemoveField(mxArray *ptr, int key_num)
int mxGetString(const mxArray *ptr, char *buf, mwSize buflen)
const char * mxGetFieldNameByNumber(const mxArray *ptr, int key_num)
mxArray * mxCreateStructMatrix(mwSize rows, mwSize cols, int num_keys, const char **keys)
bool mxIsLogicalScalar(const mxArray *ptr)
mxArray * mxCreateDoubleScalar(double val)
mxArray * mxCreateUninitNumericArray(mwSize ndims, const mwSize *dims, mxClassID class_id, mxComplexity flag)
std::size_t mxGetN(const mxArray *ptr)
mxArray * mxCreateNumericMatrix_interleaved(mwSize m, mwSize n, mxClassID class_id, mxComplexity flag)
mwSize mxGetNumberOfDimensions(const mxArray *ptr)
mxLogical * mxGetLogicals(const mxArray *ptr)
mxArray * mxCreateUninitNumericMatrix(mwSize m, mwSize n, mxClassID class_id, mxComplexity flag)
double * mxGetPr(const mxArray *ptr)
int mexSet(double handle, const char *property, mxArray *val)
#define MUTATION_METHOD(RET_TYPE, FCN_NAME, ARG_LIST, RET_VAL)
const mxArray * mexGet(double handle, const char *property)
mxArray * mxCreateStructMatrix_interleaved(mwSize rows, mwSize cols, int num_keys, const char **keys)
bool mxIsEmpty(const mxArray *ptr)
mxArray * mxCreateLogicalArray_interleaved(mwSize ndims, const mwSize *dims)
mxArray * mxGetField(const mxArray *ptr, mwIndex index, const char *key)
char * mxArrayToString(const mxArray *ptr)
mxArray * mxCreateLogicalMatrix_interleaved(mwSize m, mwSize n)
mxChar * mxGetChars(const mxArray *ptr)
const mxArray * mexGet_interleaved(double handle, const char *property)
bool mxIsSparse(const mxArray *ptr)
bool mxIsUint64(const mxArray *ptr)
mxArray * mxCreateDoubleScalar_interleaved(double val)
bool mxIsDouble(const mxArray *ptr)
mxArray * mxGetCell(const mxArray *ptr, mwIndex idx)
mxArray * mxCreateStructArray_interleaved(mwSize ndims, const mwSize *dims, int num_keys, const char **keys)
mxArray * mxCreateLogicalScalar_interleaved(mxLogical val)
void mxSetPi(mxArray *ptr, double *pi)
mxArray * mxCreateUninitNumericArray_interleaved(mwSize ndims, const mwSize *dims, mxClassID class_id, mxComplexity flag)
int mxSetSingles(mxArray *p, mxSingle *d)
void mxSetM(mxArray *ptr, mwSize m)
mxArray * mxCreateLogicalMatrix(mwSize m, mwSize n)
mxArray * mxCreateDoubleMatrix_interleaved(mwSize nr, mwSize nc, mxComplexity flag)
mxArray * mxDuplicateArray(const mxArray *ptr)
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
std::size_t vformat(std::ostream &os, const char *fmt, va_list args)
std::complex< double > Complex
std::complex< float > FloatComplex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
T::size_type strlen(const typename T::value_type *str)
bool strcmp(const T &str_a, const T &str_b)
Octave string utility functions.
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))