changeset 32133:4a37c8bb80b6

new functions to identify and extract elements from full numeric matrices * ov.h (octave_value::is_full_num_matrix, octave_value::checked_full_matrix_elem): New functions. * ov-base.h, ov-base.cc (octave_base_value::is_full_num_matrix, octave_base_value::checked_full_matrix_elebm): New virtual functions. * ov-cell.h (octave_cell::is_full_num_matrix): New function. * ov-base-mat.h, ov-base-mat.h (octave_base_matrix::is_full_matrix, octave_base_matrix::checked_full_matrix_elem): New functions.
author Petter T. <petter.vilhelm@gmail.com>
date Mon, 19 Jun 2023 09:55:13 -0400
parents 020dd00fa64f
children 426c1c5280fe
files libinterp/octave-value/ov-base-mat.cc libinterp/octave-value/ov-base-mat.h libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-base.h libinterp/octave-value/ov-cell.h libinterp/octave-value/ov.h
diffstat 6 files changed, 56 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base-mat.cc	Sun Jun 18 20:24:54 2023 +0200
+++ b/libinterp/octave-value/ov-base-mat.cc	Mon Jun 19 09:55:13 2023 -0400
@@ -573,6 +573,20 @@
 }
 
 template <typename MT>
+octave_value
+octave_base_matrix<MT>::checked_full_matrix_elem (octave_idx_type i) const
+{
+  return m_matrix.checkelem (i);
+}
+
+template <typename MT>
+octave_value
+octave_base_matrix<MT>::checked_full_matrix_elem (octave_idx_type i, octave_idx_type j) const
+{
+  return m_matrix.checkelem (i, j);
+}
+
+template <typename MT>
 bool
 octave_base_matrix<MT>::fast_elem_insert (octave_idx_type n,
     const octave_value& x)
--- a/libinterp/octave-value/ov-base-mat.h	Sun Jun 18 20:24:54 2023 +0200
+++ b/libinterp/octave-value/ov-base-mat.h	Mon Jun 19 09:55:13 2023 -0400
@@ -163,6 +163,8 @@
 
   bool is_matrix_type () const { return true; }
 
+  bool is_full_num_matrix () const { return true; }
+
   bool isnumeric () const { return true; }
 
   bool is_defined () const { return true; }
@@ -207,6 +209,12 @@
   // You should not use it anywhere else.
   const void * mex_get_data () const { return m_matrix.data (); }
 
+  octave_value
+  checked_full_matrix_elem (octave_idx_type i) const;
+
+  octave_value
+  checked_full_matrix_elem (octave_idx_type i, octave_idx_type j) const;
+
 protected:
 
   MT m_matrix;
--- a/libinterp/octave-value/ov-base.cc	Sun Jun 18 20:24:54 2023 +0200
+++ b/libinterp/octave-value/ov-base.cc	Mon Jun 19 09:55:13 2023 -0400
@@ -1504,6 +1504,18 @@
   return octave_value ();
 }
 
+octave_value
+octave_base_value::checked_full_matrix_elem (octave_idx_type) const
+{
+  err_wrong_type_arg ("octave_base_value::checked_full_matrix_elem (octave_idx_type)", type_name ());
+}
+
+octave_value
+octave_base_value::checked_full_matrix_elem (octave_idx_type, octave_idx_type) const
+{
+  err_wrong_type_arg ("octave_base_value::checked_full_matrix_elem (octave_idx_type, octave_idx_type)", type_name ());
+}
+
 bool
 octave_base_value::fast_elem_insert (octave_idx_type, const octave_value&)
 {
--- a/libinterp/octave-value/ov-base.h	Sun Jun 18 20:24:54 2023 +0200
+++ b/libinterp/octave-value/ov-base.h	Mon Jun 19 09:55:13 2023 -0400
@@ -498,6 +498,8 @@
 
   virtual bool is_matrix_type () const { return false; }
 
+  virtual bool is_full_num_matrix () const { return false; }
+
   virtual bool isnumeric () const { return false; }
 
   virtual bool issparse () const { return false; }
@@ -881,6 +883,12 @@
   virtual bool
   fast_elem_insert_self (void *where, builtin_type_t btyp) const;
 
+  virtual octave_value
+  checked_full_matrix_elem (octave_idx_type i) const;
+
+  virtual octave_value
+  checked_full_matrix_elem (octave_idx_type i, octave_idx_type j) const;
+
 protected:
 
   // This should only be called for derived types.
--- a/libinterp/octave-value/ov-cell.h	Sun Jun 18 20:24:54 2023 +0200
+++ b/libinterp/octave-value/ov-cell.h	Mon Jun 19 09:55:13 2023 -0400
@@ -132,6 +132,8 @@
 
   bool is_true () const;
 
+  bool is_full_num_matrix () const { return false; }
+
   Cell cell_value () const { return m_matrix; }
 
   octave_value_list list_value () const;
--- a/libinterp/octave-value/ov.h	Sun Jun 18 20:24:54 2023 +0200
+++ b/libinterp/octave-value/ov.h	Mon Jun 19 09:55:13 2023 -0400
@@ -1530,6 +1530,10 @@
 
 protected:
 
+  // True for the types based on ov-base-mat
+  bool is_full_num_matrix () const
+  { return m_rep->is_full_num_matrix (); }
+
   bool is_function_cache (void) const
   { return m_rep->is_function_cache (); }
 
@@ -1551,6 +1555,14 @@
     return m_rep->fcn_cache_value ();
   }
 
+  octave_value
+  checked_full_matrix_elem (octave_idx_type n) const
+  { return m_rep->checked_full_matrix_elem (n); }
+
+  octave_value
+  checked_full_matrix_elem (octave_idx_type i, octave_idx_type j) const
+  { return m_rep->checked_full_matrix_elem (i, j); }
+
   //! The real representation.
   octave_base_value *m_rep;