Mercurial > octave
changeset 32147:8763a313ab91
new octave_value member function to compute end index for object
* ov.h, ov.cc (octave_value::end_index): New function adapted from
the end_value function defined in pt-eval.cc.
* pt-eval.cc (end_value): Delete static function. Change all calls to
end_value to use end_index instead.
author | Petter T. <petter.vilhelm@gmail.com> |
---|---|
date | Mon, 19 Jun 2023 17:27:37 -0400 |
parents | 18c6b6997055 |
children | dea87a95ad18 |
files | libinterp/octave-value/ov.cc libinterp/octave-value/ov.h libinterp/parse-tree/pt-eval.cc |
diffstat | 3 files changed, 34 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc Mon Jun 19 17:01:18 2023 -0400 +++ b/libinterp/octave-value/ov.cc Mon Jun 19 17:27:37 2023 -0400 @@ -1517,6 +1517,34 @@ return *this; } +octave_idx_type +octave_value::end_index (octave_idx_type index_position, + octave_idx_type num_indices) const +{ + dim_vector dv = dims (); + int ndims = dv.ndims (); + + if (num_indices < ndims) + { + for (int i = num_indices; i < ndims; i++) + dv(num_indices-1) *= dv(i); + + if (num_indices == 1) + { + ndims = 2; + dv.resize (ndims); + dv(1) = 1; + } + else + { + ndims = num_indices; + dv.resize (ndims); + } + } + + return (index_position < ndims ? dv(index_position) : 1); +} + octave_value octave_value::subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
--- a/libinterp/octave-value/ov.h Mon Jun 19 17:01:18 2023 -0400 +++ b/libinterp/octave-value/ov.h Mon Jun 19 17:27:37 2023 -0400 @@ -504,6 +504,10 @@ return m_rep->do_index_op (idx, resize_ok); } + OCTINTERP_API octave_idx_type + end_index (octave_idx_type index_position, + octave_idx_type num_indices) const; + OCTINTERP_API octave_value subsasgn (const std::string& type, const std::list<octave_value_list>& idx, const octave_value& rhs);
--- a/libinterp/parse-tree/pt-eval.cc Mon Jun 19 17:01:18 2023 -0400 +++ b/libinterp/parse-tree/pt-eval.cc Mon Jun 19 17:27:37 2023 -0400 @@ -4964,35 +4964,6 @@ m_debugger_stack.top()->dbquit (all); } -static octave_value end_value (const octave_value& value, - octave_idx_type index_position, - octave_idx_type num_indices) -{ - dim_vector dv = value.dims (); - int ndims = dv.ndims (); - - if (num_indices < ndims) - { - for (int i = num_indices; i < ndims; i++) - dv(num_indices-1) *= dv(i); - - if (num_indices == 1) - { - ndims = 2; - dv.resize (ndims); - dv(1) = 1; - } - else - { - ndims = num_indices; - dv.resize (ndims); - } - } - - return (index_position < ndims - ? octave_value (dv(index_position)) : octave_value (1.0)); -} - octave_value_list tree_evaluator::evaluate_end_expression (const octave_value_list& args) { @@ -5015,7 +4986,7 @@ if (num_indices < 1) error ("end: N must be greater than zero"); - return end_value (args(0), index_position-1, num_indices); + return octave_value (args(0).end_index (index_position-1, num_indices)); } // If m_indexed_object is undefined, then this use of 'end' is @@ -5087,7 +5058,7 @@ (meth, ovl (expr_result, m_index_position+1, m_num_indices), 1); } - return end_value (expr_result, m_index_position, m_num_indices); + return octave_value (expr_result.end_index (m_index_position, m_num_indices)); } octave_value