comparison libinterp/corefcn/cellfun.cc @ 29961:7d6709900da7

eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more Files affected: __betainc__.cc, __contourc__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, balance.cc, besselj.cc, bsxfun.cc, call-stack.cc, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, defaults.cc, dirfns.cc, display.cc, dlmread.cc, dmperm.cc, dot.cc, eig.cc, ellipj.cc, environment.cc, error.cc, event-manager.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, find.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, gsvd.cc, hash.cc, help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jsondecode.cc, jsonencode.cc, load-path.cc, load-save.cc, lookup.cc, lsode.cc, lu.cc, max.cc, mgorth.cc, oct-hist.cc, ordqz.cc, ordschur.cc, pager.cc, pr-output.cc, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, regexp.cc, schur.cc, settings.cc, sighandlers.cc, sparse.cc, spparms.cc, sqrtm.cc, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, symbfact.cc, symtab.cc, syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-struct.cc, ov-typeinfo.cc, ov-usr-fcn.cc, octave.cc, lex.ll, oct-parse.yy, profiler.cc, andpt-eval.cc.
author John W. Eaton <jwe@octave.org>
date Sat, 14 Aug 2021 22:48:52 -0400
parents 32c3a5805893
children f69f749aad9b
comparison
equal deleted inserted replaced
29960:939bef0b66e0 29961:7d6709900da7
66 #include "ov-fcn-handle.h" 66 #include "ov-fcn-handle.h"
67 67
68 OCTAVE_NAMESPACE_BEGIN 68 OCTAVE_NAMESPACE_BEGIN
69 69
70 static octave_value_list 70 static octave_value_list
71 get_output_list (octave::error_system& es, 71 get_output_list (error_system& es,
72 octave_idx_type count, octave_idx_type nargout, 72 octave_idx_type count, octave_idx_type nargout,
73 const octave_value_list& inputlist, 73 const octave_value_list& inputlist,
74 octave_value& func, 74 octave_value& func,
75 octave_value& error_handler) 75 octave_value& error_handler)
76 { 76 {
78 78
79 bool execution_error = false; 79 bool execution_error = false;
80 80
81 try 81 try
82 { 82 {
83 tmp = octave::feval (func, inputlist, nargout); 83 tmp = feval (func, inputlist, nargout);
84 } 84 }
85 catch (const octave::execution_exception& ee) 85 catch (const execution_exception& ee)
86 { 86 {
87 if (error_handler.is_defined ()) 87 if (error_handler.is_defined ())
88 { 88 {
89 octave::interpreter& interp 89 interpreter& interp
90 = octave::__get_interpreter__ ("get_output_list"); 90 = __get_interpreter__ ("get_output_list");
91 91
92 es.save_exception (ee); 92 es.save_exception (ee);
93 interp.recover_from_exception (); 93 interp.recover_from_exception ();
94 94
95 execution_error = true; 95 execution_error = true;
110 + static_cast<octave_idx_type> (1))); 110 + static_cast<octave_idx_type> (1)));
111 111
112 octave_value_list errlist = inputlist; 112 octave_value_list errlist = inputlist;
113 errlist.prepend (msg); 113 errlist.prepend (msg);
114 114
115 tmp = octave::feval (error_handler, errlist, nargout); 115 tmp = feval (error_handler, errlist, nargout);
116 } 116 }
117 else 117 else
118 tmp.clear (); 118 tmp.clear ();
119 } 119 }
120 120
223 223
224 return retval; 224 return retval;
225 } 225 }
226 226
227 static void 227 static void
228 get_mapper_fun_options (octave::symbol_table& symtab, 228 get_mapper_fun_options (symbol_table& symtab,
229 const octave_value_list& args, 229 const octave_value_list& args,
230 int& nargin, bool& uniform_output, 230 int& nargin, bool& uniform_output,
231 octave_value& error_handler) 231 octave_value& error_handler)
232 { 232 {
233 while (nargin > 3 && args(nargin-2).is_string ()) 233 while (nargin > 3 && args(nargin-2).is_string ())
235 std::string arg = args(nargin-2).string_value (); 235 std::string arg = args(nargin-2).string_value ();
236 236
237 std::size_t compare_len 237 std::size_t compare_len
238 = std::max (arg.length (), static_cast<std::size_t> (2)); 238 = std::max (arg.length (), static_cast<std::size_t> (2));
239 239
240 if (octave::string::strncmpi (arg, "uniformoutput", compare_len)) 240 if (string::strncmpi (arg, "uniformoutput", compare_len))
241 uniform_output = args(nargin-1).bool_value (); 241 uniform_output = args(nargin-1).bool_value ();
242 else if (octave::string::strncmpi (arg, "errorhandler", compare_len)) 242 else if (string::strncmpi (arg, "errorhandler", compare_len))
243 { 243 {
244 if (args(nargin-1).is_function_handle () 244 if (args(nargin-1).is_function_handle ()
245 || args(nargin-1).is_inline_function ()) 245 || args(nargin-1).is_inline_function ())
246 { 246 {
247 error_handler = args(nargin-1); 247 error_handler = args(nargin-1);
417 octave_value_list retval; 417 octave_value_list retval;
418 int nargout1 = (nargout < 1 ? 1 : nargout); 418 int nargout1 = (nargout < 1 ? 1 : nargout);
419 419
420 octave_value func = args(0); 420 octave_value func = args(0);
421 421
422 octave::symbol_table& symtab = interp.get_symbol_table (); 422 symbol_table& symtab = interp.get_symbol_table ();
423 423
424 if (func.is_string ()) 424 if (func.is_string ())
425 { 425 {
426 retval = try_cellfun_internal_ops<boolNDArray,NDArray> (args, nargin); 426 retval = try_cellfun_internal_ops<boolNDArray,NDArray> (args, nargin);
427 427
430 430
431 // See if we can convert the string into a function. 431 // See if we can convert the string into a function.
432 432
433 std::string name = args(0).string_value (); 433 std::string name = args(0).string_value ();
434 434
435 if (! octave::valid_identifier (name)) 435 if (! valid_identifier (name))
436 func = octave::get_function_handle (interp, args(0), "x"); 436 func = get_function_handle (interp, args(0), "x");
437 else 437 else
438 { 438 {
439 func = symtab.find_function (name); 439 func = symtab.find_function (name);
440 440
441 if (func.is_undefined ()) 441 if (func.is_undefined ())
535 } 535 }
536 break; 536 break;
537 } 537 }
538 } 538 }
539 539
540 octave::error_system& es = interp.get_error_system (); 540 error_system& es = interp.get_error_system ();
541 541
542 // Apply functions. 542 // Apply functions.
543 543
544 if (uniform_output) 544 if (uniform_output)
545 { 545 {
1147 octave_value_list retval; 1147 octave_value_list retval;
1148 int nargout1 = (nargout < 1 ? 1 : nargout); 1148 int nargout1 = (nargout < 1 ? 1 : nargout);
1149 bool symbol_table_lookup = false; 1149 bool symbol_table_lookup = false;
1150 octave_value func = args(0); 1150 octave_value func = args(0);
1151 1151
1152 octave::symbol_table& symtab = interp.get_symbol_table (); 1152 symbol_table& symtab = interp.get_symbol_table ();
1153 1153
1154 if (func.is_string ()) 1154 if (func.is_string ())
1155 { 1155 {
1156 // See if we can convert the string into a function. 1156 // See if we can convert the string into a function.
1157 std::string name = args(0).string_value (); 1157 std::string name = args(0).string_value ();
1158 1158
1159 if (! octave::valid_identifier (name)) 1159 if (! valid_identifier (name))
1160 func = octave::get_function_handle (interp, args(0), "x"); 1160 func = get_function_handle (interp, args(0), "x");
1161 else 1161 else
1162 { 1162 {
1163 func = symtab.find_function (name); 1163 func = symtab.find_function (name);
1164 1164
1165 if (func.is_undefined ()) 1165 if (func.is_undefined ())
1241 } 1241 }
1242 break; 1242 break;
1243 } 1243 }
1244 } 1244 }
1245 1245
1246 octave::error_system& es = interp.get_error_system (); 1246 error_system& es = interp.get_error_system ();
1247 1247
1248 // Apply functions. 1248 // Apply functions.
1249 1249
1250 if (uniform_output) 1250 if (uniform_output)
1251 { 1251 {
1921 prepare_idx (container *idx, int idim, int nd, 1921 prepare_idx (container *idx, int idim, int nd,
1922 const Array<octave_idx_type>* d) 1922 const Array<octave_idx_type>* d)
1923 { 1923 {
1924 octave_idx_type nidx = (idim < nd ? d[idim].numel () : 1); 1924 octave_idx_type nidx = (idim < nd ? d[idim].numel () : 1);
1925 if (nidx == 1) 1925 if (nidx == 1)
1926 idx[0] = octave::idx_vector::colon; 1926 idx[0] = idx_vector::colon;
1927 else 1927 else
1928 { 1928 {
1929 octave_idx_type l = 0; 1929 octave_idx_type l = 0;
1930 for (octave_idx_type i = 0; i < nidx; i++) 1930 for (octave_idx_type i = 0; i < nidx; i++)
1931 { 1931 {
1932 octave_idx_type u = l + d[idim](i); 1932 octave_idx_type u = l + d[idim](i);
1933 idx[i] = octave::idx_vector (l, u); 1933 idx[i] = idx_vector (l, u);
1934 l = u; 1934 l = u;
1935 } 1935 }
1936 } 1936 }
1937 } 1937 }
1938 1938
1966 octave_idx_type l = 0; 1966 octave_idx_type l = 0;
1967 octave_idx_type nidx = (ivec == 0 ? nridx : ncidx); 1967 octave_idx_type nidx = (ivec == 0 ? nridx : ncidx);
1968 for (octave_idx_type i = 0; i < nidx; i++) 1968 for (octave_idx_type i = 0; i < nidx; i++)
1969 { 1969 {
1970 octave_idx_type u = l + d[ivec](i); 1970 octave_idx_type u = l + d[ivec](i);
1971 retval.xelem (i) = a.index (octave::idx_vector (l, u)); 1971 retval.xelem (i) = a.index (idx_vector (l, u));
1972 l = u; 1972 l = u;
1973 } 1973 }
1974 } 1974 }
1975 else 1975 else
1976 { 1976 {
1977 // General 2D case. Use 2D indexing. 1977 // General 2D case. Use 2D indexing.
1978 OCTAVE_LOCAL_BUFFER (octave::idx_vector, ridx, nridx); 1978 OCTAVE_LOCAL_BUFFER (idx_vector, ridx, nridx);
1979 prepare_idx (ridx, 0, nd, d); 1979 prepare_idx (ridx, 0, nd, d);
1980 1980
1981 OCTAVE_LOCAL_BUFFER (octave::idx_vector, cidx, ncidx); 1981 OCTAVE_LOCAL_BUFFER (idx_vector, cidx, ncidx);
1982 prepare_idx (cidx, 1, nd, d); 1982 prepare_idx (cidx, 1, nd, d);
1983 1983
1984 for (octave_idx_type j = 0; j < ncidx; j++) 1984 for (octave_idx_type j = 0; j < ncidx; j++)
1985 for (octave_idx_type i = 0; i < nridx; i++) 1985 for (octave_idx_type i = 0; i < nridx; i++)
1986 { 1986 {
2015 idxtot += nidx[i]; 2015 idxtot += nidx[i];
2016 } 2016 }
2017 2017
2018 retval.clear (rdv); 2018 retval.clear (rdv);
2019 2019
2020 OCTAVE_LOCAL_BUFFER (octave::idx_vector, xidx, idxtot); 2020 OCTAVE_LOCAL_BUFFER (idx_vector, xidx, idxtot);
2021 OCTAVE_LOCAL_BUFFER (octave::idx_vector *, idx, nd); 2021 OCTAVE_LOCAL_BUFFER (idx_vector *, idx, nd);
2022 2022
2023 idxtot = 0; 2023 idxtot = 0;
2024 for (int i = 0; i < nd; i++) 2024 for (int i = 0; i < nd; i++)
2025 { 2025 {
2026 idx[i] = xidx + idxtot; 2026 idx[i] = xidx + idxtot;
2027 prepare_idx (idx[i], i, nd, d); 2027 prepare_idx (idx[i], i, nd, d);
2028 idxtot += nidx[i]; 2028 idxtot += nidx[i];
2029 } 2029 }
2030 2030
2031 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0); 2031 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0);
2032 Array<octave::idx_vector> ra_idx 2032 Array<idx_vector> ra_idx
2033 (dim_vector (1, std::max (nd, a.ndims ())), octave::idx_vector::colon); 2033 (dim_vector (1, std::max (nd, a.ndims ())), idx_vector::colon);
2034 2034
2035 for (octave_idx_type j = 0; j < retval.numel (); j++) 2035 for (octave_idx_type j = 0; j < retval.numel (); j++)
2036 { 2036 {
2037 octave_quit (); 2037 octave_quit ();
2038 2038
2301 if (array.isvector () && (dim == -1 2301 if (array.isvector () && (dim == -1
2302 || (dim == 0 && array.columns () == 1) 2302 || (dim == 0 && array.columns () == 1)
2303 || (dim == 1 && array.rows () == 1))) 2303 || (dim == 1 && array.rows () == 1)))
2304 { 2304 {
2305 for (octave_idx_type i = 0; i < n; i++) 2305 for (octave_idx_type i = 0; i < n; i++)
2306 retval.xelem (i) = array.index (octave::idx_vector (lb(i) - 1, ub(i))); 2306 retval.xelem (i) = array.index (idx_vector (lb(i) - 1, ub(i)));
2307 } 2307 }
2308 else 2308 else
2309 { 2309 {
2310 const dim_vector dv = array.dims (); 2310 const dim_vector dv = array.dims ();
2311 int ndims = dv.ndims (); 2311 int ndims = dv.ndims ();
2312 if (dim < 0) 2312 if (dim < 0)
2313 dim = dv.first_non_singleton (); 2313 dim = dv.first_non_singleton ();
2314 ndims = std::max (ndims, dim + 1); 2314 ndims = std::max (ndims, dim + 1);
2315 2315
2316 Array<octave::idx_vector> idx (dim_vector (ndims, 1), octave::idx_vector::colon); 2316 Array<idx_vector> idx (dim_vector (ndims, 1), idx_vector::colon);
2317 2317
2318 for (octave_idx_type i = 0; i < n; i++) 2318 for (octave_idx_type i = 0; i < n; i++)
2319 { 2319 {
2320 idx(dim) = octave::idx_vector (lb(i) - 1, ub(i)); 2320 idx(dim) = idx_vector (lb(i) - 1, ub(i));
2321 retval.xelem (i) = array.index (idx); 2321 retval.xelem (i) = array.index (idx);
2322 } 2322 }
2323 } 2323 }
2324 2324
2325 return retval; 2325 return retval;
2435 dim = dv.first_non_singleton (); 2435 dim = dv.first_non_singleton ();
2436 ndims = std::max (ndims, dim + 1); 2436 ndims = std::max (ndims, dim + 1);
2437 octave_value_list idx (ndims, octave_value::magic_colon_t); 2437 octave_value_list idx (ndims, octave_value::magic_colon_t);
2438 for (octave_idx_type i = 0; i < n; i++) 2438 for (octave_idx_type i = 0; i < n; i++)
2439 { 2439 {
2440 idx(dim) = octave::range<double> (lb(i), ub(i)); 2440 idx(dim) = range<double> (lb(i), ub(i));
2441 retcell.xelem (i) = x.index_op (idx); 2441 retcell.xelem (i) = x.index_op (idx);
2442 } 2442 }
2443 } 2443 }
2444 2444
2445 return ovl (retcell); 2445 return ovl (retcell);