annotate liboctave/array/Range.h @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents fc3bd70cd1be
children dfa5d9c3ae72 aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30489
diff changeset
3 // Copyright (C) 1993-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20513
diff changeset
26 #if ! defined (octave_Range_h)
382
e02d6b664394 [project @ 1994-03-09 21:08:03 by jwe]
jwe
parents: 238
diff changeset
27 #define octave_Range_h 1
e02d6b664394 [project @ 1994-03-09 21:08:03 by jwe]
jwe
parents: 238
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21221
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21221
diff changeset
30
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
31 #include <iosfwd>
30835
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
32 #include <type_traits>
7458
1032e24f199f make sort work for ranges
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
33
30429
e38202d3628d provide header file for forward declaration of Array<T> template
John W. Eaton <jwe@octave.org>
parents: 30420
diff changeset
34 #include "Array-fwd.h"
4810
72a6d410a14a [project @ 2004-03-03 18:49:39 by jwe]
jwe
parents: 4192
diff changeset
35 #include "dMatrix.h"
28004
403df0b32204 update out_of_range error messages
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
36 #include "dim-vector.h"
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
37 #include "lo-error.h"
7458
1032e24f199f make sort work for ranges
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
38 #include "oct-sort.h"
30489
bd67d0045e21 use separate files for MArray, intNDArray, and range template forward decls
John W. Eaton <jwe@octave.org>
parents: 30429
diff changeset
39 #include "range-fwd.h"
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
40
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30853
diff changeset
41 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30853
diff changeset
42
30835
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
43 // For now, only define for floating point types. However, we only
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
44 // need range<float> as a temporary local variable in make_float_range
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
45 // in ov.cc.
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
46
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
47 template <typename T>
30835
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
48 class
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
49 range<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
50 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
51 public:
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
52
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
53 range (void)
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
54 : m_base (0), m_increment (0), m_limit (0), m_final (0), m_numel (0),
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
55 m_reverse (false)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
56 { }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
57
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
58 // LIMIT is an upper limit and may be outside the range of actual
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
59 // values. For floating point ranges, we perform a tolerant check
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
60 // to attempt to capture limit in the set of values if it is "close"
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
61 // to the value of base + a multiple of the increment.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
62
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
63 range (const T& base, const T& increment, const T& limit,
30420
366aa563dd2e style fixes for Range.h and Range.cc
John W. Eaton <jwe@octave.org>
parents: 30416
diff changeset
64 bool reverse = false)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
65 : m_base (base), m_increment (increment), m_limit (limit),
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
66 m_final (), m_numel (), m_reverse (reverse)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
67 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
68 init ();
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
69 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
70
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
71 range (const T& base, const T& limit)
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
72 : m_base (base), m_increment (1), m_limit (limit), m_final (), m_numel (),
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
73 m_reverse (false)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
74 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
75 init ();
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
76 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
77
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
78 // Allow conversion from (presumably) properly constructed Range
30853
fc3bd70cd1be eliminate range<T>::make_constant function
John W. Eaton <jwe@octave.org>
parents: 30852
diff changeset
79 // objects. The values of base, limit, increment, and numel must be
fc3bd70cd1be eliminate range<T>::make_constant function
John W. Eaton <jwe@octave.org>
parents: 30852
diff changeset
80 // consistent.
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
81
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
82 // FIXME: Actually check that base, limit, increment, and numel are
30853
fc3bd70cd1be eliminate range<T>::make_constant function
John W. Eaton <jwe@octave.org>
parents: 30852
diff changeset
83 // consistent?
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
84
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
85 range (const T& base, const T& increment, const T& limit,
30420
366aa563dd2e style fixes for Range.h and Range.cc
John W. Eaton <jwe@octave.org>
parents: 30416
diff changeset
86 octave_idx_type numel, bool reverse = false)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
87 : m_base (base), m_increment (increment), m_limit (limit),
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
88 m_final (limit), m_numel (numel), m_reverse (reverse)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
89 { }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
90
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
91 // We don't use a constructor for this because it will conflict with
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
92 // range<T> (base, limit, increment) when T is octave_idx_type.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
93
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
94 static range<T> make_n_element_range (const T& base, const T& increment,
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
95 octave_idx_type numel,
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
96 bool reverse = false)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
97 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
98 // We could just make this constructor public, but it allows
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
99 // inconsistent ranges to be constructed. And it is probably much
30853
fc3bd70cd1be eliminate range<T>::make_constant function
John W. Eaton <jwe@octave.org>
parents: 30852
diff changeset
100 // clearer to see "make_n_element_range" instead of puzzling over the
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
101 // purpose of this strange constructor form.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
102
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
103 T final_val = (reverse ? base - (numel - 1) * increment
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
104 : base + (numel - 1) * increment);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
105
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
106 return range<T> (base, increment, final_val, numel, reverse);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
107 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
108
30835
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
109 range (const range<T>& r)
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
110 : m_base (r.m_base), m_increment (r.m_increment),
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
111 m_limit (r.m_limit), m_final (r.m_final),
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
112 m_numel (r.m_numel), m_reverse (r.m_reverse)
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
113 { }
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
114
30835
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
115 range<T>& operator = (const range<T>& r)
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
116 {
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
117 if (this != &r)
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
118 {
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
119 m_base = r.m_base;
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
120 m_increment = r.m_increment;
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
121 m_limit = r.m_limit;
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
122 m_final = r.m_final;
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
123 m_numel = r.m_numel;
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
124 m_reverse = r.m_reverse;
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
125 }
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
126
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
127 return *this;
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
128 }
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
129
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
130 ~range (void) = default;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
131
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
132 T base (void) const { return m_base; }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
133 T increment (void) const { return m_increment; }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
134 T limit (void) const { return m_limit; }
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
135 bool reverse (void) const { return m_reverse; }
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
136
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
137 T final_value (void) const { return m_final; }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
138
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
139 T min (void) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
140 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
141 return (m_numel > 0
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
142 ? ((m_reverse ? m_increment > T (0)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
143 : m_increment > T (0)) ? base () : final_value ())
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
144 : T (0));
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
145 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
146
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
147 T max (void) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
148 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
149 return (m_numel > 0
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
150 ? ((m_reverse ? m_increment < T (0)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
151 : m_increment > T (0)) ? final_value () : base ())
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
152 : T (0));
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
153 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
154
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
155 octave_idx_type numel (void) const { return m_numel; }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
156
29353
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
157 // To support things like "for i = 1:Inf; ...; end" that are
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
158 // required for Matlab compatibility, creation of a range object
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
159 // like 1:Inf is allowed with m_numel set to
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
160 // numeric_limits<octave_idx_type>::max(). However, it is not
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
161 // possible to store these ranges. The following function allows
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
162 // us to easily distinguish ranges with an infinite number of
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
163 // elements. There are specializations for double and float.
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
164
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
165 bool is_storable (void) const { return true; }
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
166
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
167 dim_vector dims (void) const { return dim_vector (1, m_numel); }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
168
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
169 octave_idx_type rows (void) const { return 1; }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
170
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
171 octave_idx_type cols (void) const { return numel (); }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
172 octave_idx_type columns (void) const { return numel (); }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
173
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
174 bool isempty (void) const { return numel () == 0; }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
175
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
176 bool all_elements_are_ints (void) const { return true; }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
177
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
178 sortmode issorted (sortmode mode = ASCENDING) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
179 {
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
180 if (m_numel > 1 && (m_reverse ? m_increment < T (0)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
181 : m_increment > T (0)))
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
182 mode = ((mode == DESCENDING) ? UNSORTED : ASCENDING);
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
183 else if (m_numel > 1 && (m_reverse ? m_increment > T (0)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
184 : m_increment < T (0)))
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
185 mode = ((mode == ASCENDING) ? UNSORTED : DESCENDING);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
186 else
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
187 mode = ((mode == UNSORTED) ? ASCENDING : mode);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
188
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
189 return mode;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
190 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
191
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
192 OCTAVE_API octave_idx_type nnz (void) const;
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
193
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
194 // Support for single-index subscripting, without generating matrix cache.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
195
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
196 T checkelem (octave_idx_type i) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
197 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
198 if (i < 0 || i >= m_numel)
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28646
diff changeset
199 err_index_out_of_range (2, 2, i+1, m_numel, dims ());
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
200
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
201 if (i == 0)
29353
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
202 // Required for proper NaN handling.
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
203 return (m_numel == 1 ? final_value () : m_base);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
204 else if (i < m_numel - 1)
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
205 return (m_reverse ? m_base + T (i) * m_increment
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
206 : m_base + T (i) * m_increment);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
207 else
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
208 return final_value ();
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
209 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
210
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
211 T checkelem (octave_idx_type i, octave_idx_type j) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
212 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
213 // Ranges are *always* row vectors.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
214 if (i != 0)
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28646
diff changeset
215 err_index_out_of_range (1, 1, i+1, m_numel, dims ());
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
216
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
217 return checkelem (j);
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
218 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
219
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
220 T elem (octave_idx_type i) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
221 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
222 if (i == 0)
29353
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
223 // Required for proper NaN handling.
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
224 return (m_numel == 1 ? final_value () : m_base);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
225 else if (i < m_numel - 1)
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
226 return (m_reverse ? m_base - T (i) * m_increment
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
227 : m_base + T (i) * m_increment);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
228 else
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
229 return final_value ();
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
230 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
231
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
232 T elem (octave_idx_type /* i */, octave_idx_type j) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
233 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
234 return elem (j);
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
235 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
236
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
237 T operator () (octave_idx_type i) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
238 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
239 return elem (i);
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
240 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
241
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
242 T operator () (octave_idx_type i, octave_idx_type j) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
243 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
244 return elem (i, j);
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
245 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
246
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
247 Array<T> index (const idx_vector& idx) const
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
248 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
249 Array<T> retval;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
250
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
251 octave_idx_type n = m_numel;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
252
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
253 if (idx.is_colon ())
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
254 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
255 retval = array_value ().reshape (dim_vector (m_numel, 1));
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
256 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
257 else
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
258 {
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
259 if (idx.extent (n) != n)
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
260 err_index_out_of_range (1, 1, idx.extent (n), n, dims ());
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
261
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
262 dim_vector idx_dims = idx.orig_dimensions ();
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
263 octave_idx_type idx_len = idx.length (n);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
264
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
265 // taken from Array.cc.
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
266 if (n != 1 && idx_dims.isvector ())
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
267 idx_dims = dim_vector (1, idx_len);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
268
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
269 retval.clear (idx_dims);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
270
30189
41eecdf76372 * Range.h, Range.cc: Fix comments missed in previous change.
John W. Eaton <jwe@octave.org>
parents: 30188
diff changeset
271 // Loop over all values in IDX, executing the lambda
41eecdf76372 * Range.h, Range.cc: Fix comments missed in previous change.
John W. Eaton <jwe@octave.org>
parents: 30188
diff changeset
272 // expression for each index value.
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
273
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
274 T *array = retval.fortran_vec ();
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
275
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30392
diff changeset
276 idx.loop (n, [=, &array] (octave_idx_type i)
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30392
diff changeset
277 {
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
278 if (i == 0)
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
279 // Required for proper NaN handling.
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
280 *array++ = (m_numel == 0 ? m_final : m_base);
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
281 else if (i < m_numel - 1)
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
282 *array++ = (m_reverse ? m_base - T (i) * m_increment
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
283 : m_base + T (i) * m_increment);
30188
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
284 else
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
285 *array++ = m_final;
e424d966dca7 replace rangeidx helper classes with lambda expressions
John W. Eaton <jwe@octave.org>
parents: 29954
diff changeset
286 });
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
287 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
288
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
289 return retval;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
290 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
291
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
292 Array<T> diag (octave_idx_type k) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
293 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
294 return array_value ().diag (k);
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
295 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
296
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
297 Array<T> array_value (void) const
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
298 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
299 octave_idx_type nel = numel ();
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
300
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
301 Array<T> retval (dim_vector (1, nel));
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
302
29353
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
303 if (nel == 1)
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
304 // Required for proper NaN handling.
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
305 retval(0) = final_value ();
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
306 else if (nel > 1)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
307 {
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
308 // The first element must always be *exactly* the base.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
309 // E.g, -0 would otherwise become +0 in the loop (-0 + 0*increment).
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
310 retval(0) = m_base;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
311
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
312 if (m_reverse)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
313 for (octave_idx_type i = 1; i < nel - 1; i++)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
314 retval.xelem (i) = m_base - i * m_increment;
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
315 else
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
316 for (octave_idx_type i = 1; i < nel - 1; i++)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
317 retval.xelem (i) = m_base + i * m_increment;
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
318
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
319 retval.xelem (nel - 1) = final_value ();
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
320 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
321
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
322 return retval;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
323 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
324
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
325 private:
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
326
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
327 T m_base;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
328 T m_increment;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
329 T m_limit;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
330 T m_final;
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
331 octave_idx_type m_numel;
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
332 bool m_reverse;
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
333
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
334 // Setting the number of elements to zero when the increment is zero
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
335 // is intentional and matches the behavior of Matlab's colon
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
336 // operator.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
337
29352
03c283f73b9a specialize range<T>::init instead of defining get_numel and get_final_value
John W. Eaton <jwe@octave.org>
parents: 29351
diff changeset
338 // These calculations are appropriate for integer ranges. There are
03c283f73b9a specialize range<T>::init instead of defining get_numel and get_final_value
John W. Eaton <jwe@octave.org>
parents: 29351
diff changeset
339 // specializations for double and float.
03c283f73b9a specialize range<T>::init instead of defining get_numel and get_final_value
John W. Eaton <jwe@octave.org>
parents: 29351
diff changeset
340
03c283f73b9a specialize range<T>::init instead of defining get_numel and get_final_value
John W. Eaton <jwe@octave.org>
parents: 29351
diff changeset
341 void init (void)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
342 {
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
343 if (m_reverse)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
344 {
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
345 m_numel = ((m_increment == T (0)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
346 || (m_limit > m_base && m_increment > T (0))
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
347 || (m_limit < m_base && m_increment < T (0)))
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
348 ? T (0)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
349 : (m_base - m_limit - m_increment) / m_increment);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
350
30416
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
351 m_final = m_base - (m_numel - 1) * m_increment;
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
352 }
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
353 else
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
354 {
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
355 m_numel = ((m_increment == T (0)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
356 || (m_limit > m_base && m_increment < T (0))
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
357 || (m_limit < m_base && m_increment > T (0)))
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
358 ? T (0)
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
359 : (m_limit - m_base + m_increment) / m_increment);
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
360
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
361 m_final = m_base + (m_numel - 1) * m_increment;
4736bc8e9804 Allow descending ranges of all integer types (bug #61132).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30405
diff changeset
362 }
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
363 }
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
364 };
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
365
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
366 // Specializations defined externally.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
367
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
368 template <> OCTAVE_API bool range<double>::all_elements_are_ints (void) const;
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
369 template <> OCTAVE_API bool range<float>::all_elements_are_ints (void) const;
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
370
29352
03c283f73b9a specialize range<T>::init instead of defining get_numel and get_final_value
John W. Eaton <jwe@octave.org>
parents: 29351
diff changeset
371 template <> OCTAVE_API void range<double>::init (void);
03c283f73b9a specialize range<T>::init instead of defining get_numel and get_final_value
John W. Eaton <jwe@octave.org>
parents: 29351
diff changeset
372 template <> OCTAVE_API void range<float>::init (void);
30835
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
373
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
374 // For now, only define for floating point types. However, we only
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
375 // need range<float> as a temporary local variable in make_float_range
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
376 // in ov.cc.
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
377
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
378 #if 0
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
379
30405
20cefb3b0da6 range: Use specialization of init function for octave_int<T> types (bug #61300).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
380 template <> OCTAVE_API void range<octave_int8>::init (void);
20cefb3b0da6 range: Use specialization of init function for octave_int<T> types (bug #61300).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
381 template <> OCTAVE_API void range<octave_int16>::init (void);
20cefb3b0da6 range: Use specialization of init function for octave_int<T> types (bug #61300).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
382 template <> OCTAVE_API void range<octave_int32>::init (void);
20cefb3b0da6 range: Use specialization of init function for octave_int<T> types (bug #61300).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
383 template <> OCTAVE_API void range<octave_int64>::init (void);
20cefb3b0da6 range: Use specialization of init function for octave_int<T> types (bug #61300).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
384 template <> OCTAVE_API void range<octave_uint8>::init (void);
20cefb3b0da6 range: Use specialization of init function for octave_int<T> types (bug #61300).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
385 template <> OCTAVE_API void range<octave_uint16>::init (void);
20cefb3b0da6 range: Use specialization of init function for octave_int<T> types (bug #61300).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
386 template <> OCTAVE_API void range<octave_uint32>::init (void);
20cefb3b0da6 range: Use specialization of init function for octave_int<T> types (bug #61300).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
387 template <> OCTAVE_API void range<octave_uint64>::init (void);
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
388
30835
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
389 #endif
2989202f92f8 only allow range<FLOAT> to be instantiated
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
390
29353
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
391 template <> OCTAVE_API bool range<double>::is_storable (void) const;
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
392 template <> OCTAVE_API bool range<float>::is_storable (void) const;
715344f405f0 improve handling of nan, infinite value, and empty ranges (bug #59229)
John W. Eaton <jwe@octave.org>
parents: 29352
diff changeset
393
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
394 template <> OCTAVE_API octave_idx_type range<double>::nnz (void) const;
29351
326a7ca62c43 also define range<float>::nnz specialization
John W. Eaton <jwe@octave.org>
parents: 29226
diff changeset
395 template <> OCTAVE_API octave_idx_type range<float>::nnz (void) const;
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30853
diff changeset
396
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30853
diff changeset
397 OCTAVE_END_NAMESPACE(octave)
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
398
1860
821870c30840 [project @ 1996-02-04 10:04:58 by jwe]
jwe
parents: 1528
diff changeset
399 class
821870c30840 [project @ 1996-02-04 10:04:58 by jwe]
jwe
parents: 1528
diff changeset
400 Range
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
401 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
402 public:
1860
821870c30840 [project @ 1996-02-04 10:04:58 by jwe]
jwe
parents: 1528
diff changeset
403
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28637
diff changeset
404 OCTAVE_DEPRECATED (7, "use the 'octave::range<double>' class instead")
1528
dc527156c38c [project @ 1995-10-05 01:44:18 by jwe]
jwe
parents: 1315
diff changeset
405 Range (void)
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
406 : m_base (0), m_limit (0), m_inc (0), m_numel (0)
28402
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
407 { }
1528
dc527156c38c [project @ 1995-10-05 01:44:18 by jwe]
jwe
parents: 1315
diff changeset
408
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
409 // Assume range is already properly constructed, so just copy internal
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
410 // values. However, we set LIMIT to the computed final value because
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
411 // that mimics the behavior of the other Range class constructors that
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
412 // reset limit to the computed final value.
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
413
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28637
diff changeset
414 OCTAVE_DEPRECATED (7, "use the 'octave::range<double>' class instead")
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
415 Range (const octave::range<double>& r)
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
416 : m_base (r.base ()), m_limit (r.final_value ()), m_inc (r.increment ()),
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
417 m_numel (r.numel ())
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
418 { }
1528
dc527156c38c [project @ 1995-10-05 01:44:18 by jwe]
jwe
parents: 1315
diff changeset
419
27023
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
420 Range (const Range& r) = default;
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
421
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
422 Range& operator = (const Range& r) = default;
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
423
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
424 ~Range (void) = default;
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
425
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28637
diff changeset
426 OCTAVE_DEPRECATED (7, "use the 'octave::range<double>' class instead")
1528
dc527156c38c [project @ 1995-10-05 01:44:18 by jwe]
jwe
parents: 1315
diff changeset
427 Range (double b, double l)
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
428 : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ())
20513
96153b16febe Overhaul Range object in liboctave.
Rik <rik@octave.org>
parents: 20228
diff changeset
429 {
28592
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
430 if (! octave::math::isinf (m_limit))
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
431 m_limit = limit_internal ();
20513
96153b16febe Overhaul Range object in liboctave.
Rik <rik@octave.org>
parents: 20228
diff changeset
432 }
1528
dc527156c38c [project @ 1995-10-05 01:44:18 by jwe]
jwe
parents: 1315
diff changeset
433
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28637
diff changeset
434 OCTAVE_DEPRECATED (7, "use the 'octave::range<double>' class instead")
1528
dc527156c38c [project @ 1995-10-05 01:44:18 by jwe]
jwe
parents: 1315
diff changeset
435 Range (double b, double l, double i)
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
436 : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ())
20513
96153b16febe Overhaul Range object in liboctave.
Rik <rik@octave.org>
parents: 20228
diff changeset
437 {
28592
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
438 if (! octave::math::isinf (m_limit))
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
439 m_limit = limit_internal ();
20513
96153b16febe Overhaul Range object in liboctave.
Rik <rik@octave.org>
parents: 20228
diff changeset
440 }
1528
dc527156c38c [project @ 1995-10-05 01:44:18 by jwe]
jwe
parents: 1315
diff changeset
441
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
442 // NOTE: The following constructor may be deprecated and removed after
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
443 // the arithmetic operators are removed.
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
444
28635
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
445 // For operators' usage (to preserve element count) and to create
b6371946f106 new template for range objects
John W. Eaton <jwe@octave.org>
parents: 28592
diff changeset
446 // constant row vectors (obsolete usage).
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
447
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28637
diff changeset
448 OCTAVE_DEPRECATED (7, "use the 'octave::range<double>' class instead")
16169
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15271
diff changeset
449 Range (double b, double i, octave_idx_type n)
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
450 : m_base (b), m_limit (b + (n-1) * i), m_inc (i), m_numel (n)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
451 {
28592
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
452 if (! octave::math::isinf (m_limit))
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
453 m_limit = limit_internal ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
454 }
8589
0131fa223dbc make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 8553
diff changeset
455
28592
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
456 // The range has a finite number of elements.
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
457 bool ok (void) const
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
458 {
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
459 return (octave::math::isfinite (m_limit)
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
460 && (m_numel >= 0 || m_numel == -2));
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
461 }
8589
0131fa223dbc make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 8553
diff changeset
462
28402
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
463 double base (void) const { return m_base; }
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
464 double limit (void) const { return m_limit; }
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
465 double inc (void) const { return m_inc; }
28636
a3db48e66ef8 use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents: 28635
diff changeset
466 double increment (void) const { return m_inc; }
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21040
diff changeset
467
28637
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
468 // We adjust the limit to be the final value, so return that. We
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
469 // could introduce a new variable to store the final value separately,
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
470 // but it seems like that would just add confusion. If we changed
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
471 // the meaning of the limit function, we would change the behavior of
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
472 // programs that expect limit to be the final value instead of the
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
473 // value of the limit when the range was created. This problem will
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
474 // be fixed with the new template range class.
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
475 double final_value (void) const { return m_limit; }
25812
fc74c8d2a584 Clean up liboctave Range implementation.
Rik <rik@octave.org>
parents: 25054
diff changeset
476
28402
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
477 octave_idx_type numel (void) const { return m_numel; }
25812
fc74c8d2a584 Clean up liboctave Range implementation.
Rik <rik@octave.org>
parents: 25054
diff changeset
478
28402
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
479 dim_vector dims (void) const { return dim_vector (1, m_numel); }
28004
403df0b32204 update out_of_range error messages
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
480
24780
0d21e2a1cdfc new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
481 octave_idx_type rows (void) const { return 1; }
0d21e2a1cdfc new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
482
0d21e2a1cdfc new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
483 octave_idx_type cols (void) const { return numel (); }
0d21e2a1cdfc new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
484 octave_idx_type columns (void) const { return numel (); }
0d21e2a1cdfc new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
485
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23564
diff changeset
486 bool isempty (void) const { return numel () == 0; }
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23564
diff changeset
487
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
488 OCTAVE_API bool all_elements_are_ints (void) const;
2383
096529066838 [project @ 1996-10-12 17:50:47 by jwe]
jwe
parents: 1993
diff changeset
489
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
490 OCTAVE_API Matrix matrix_value (void) const;
645
21cb3c7dc9e3 [project @ 1994-08-24 06:19:54 by jwe]
jwe
parents: 461
diff changeset
491
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
492 OCTAVE_API double min (void) const;
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
493 OCTAVE_API double max (void) const;
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
494
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
495 OCTAVE_API void sort_internal (bool ascending = true);
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
496 OCTAVE_API void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true);
7458
1032e24f199f make sort work for ranges
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
497
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
498 OCTAVE_API Matrix diag (octave_idx_type k = 0) const;
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
499
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
500 OCTAVE_API Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
501 OCTAVE_API Range sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
502 sortmode mode = ASCENDING) const;
208
380cb9ccc889 [project @ 1993-11-12 10:35:05 by jwe]
jwe
parents: 3
diff changeset
503
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
504 OCTAVE_API sortmode issorted (sortmode mode = ASCENDING) const;
23588
0549061d35b9 maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents: 23577
diff changeset
505
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
506 OCTAVE_API octave_idx_type nnz (void) const;
24859
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24799
diff changeset
507
9986
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
508 // Support for single-index subscripting, without generating matrix cache.
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
509
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
510 OCTAVE_API double checkelem (octave_idx_type i) const;
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
511 OCTAVE_API double checkelem (octave_idx_type i, octave_idx_type j) const;
9986
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
512
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
513 OCTAVE_API double elem (octave_idx_type i) const;
24799
74a596fd6bab Fix unused variable warning in Range elem(i,j) function introduced in 0d21e2a1cdfc.
Rik <rik@octave.org>
parents: 24780
diff changeset
514 double elem (octave_idx_type /* i */, octave_idx_type j) const
74a596fd6bab Fix unused variable warning in Range elem(i,j) function introduced in 0d21e2a1cdfc.
Rik <rik@octave.org>
parents: 24780
diff changeset
515 { return elem (j); }
9986
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
516
23487
af2f1f3dbe06 eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
517 double operator () (octave_idx_type i) const { return elem (i); }
24780
0d21e2a1cdfc new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
518 double operator () (octave_idx_type i, octave_idx_type j) const
0d21e2a1cdfc new element access operators for Range objects
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
519 { return elem (i, j); }
23487
af2f1f3dbe06 eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
520
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
521 OCTAVE_API Array<double> index (const octave::idx_vector& i) const;
9986
672e1b49e01e optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents: 8971
diff changeset
522
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
523 OCTAVE_API void set_base (double b);
4811
198f3712c692 [project @ 2004-03-03 19:24:33 by jwe]
jwe
parents: 4810
diff changeset
524
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
525 OCTAVE_API void set_limit (double l);
4811
198f3712c692 [project @ 2004-03-03 19:24:33 by jwe]
jwe
parents: 4810
diff changeset
526
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
527 OCTAVE_API void set_inc (double i);
1528
dc527156c38c [project @ 1995-10-05 01:44:18 by jwe]
jwe
parents: 1315
diff changeset
528
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
529 friend OCTAVE_API std::ostream& operator << (std::ostream& os,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
530 const Range& r);
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5347
diff changeset
531 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r);
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
532
8971
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
533 friend OCTAVE_API Range operator - (const Range& r);
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
534 friend OCTAVE_API Range operator + (double x, const Range& r);
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
535 friend OCTAVE_API Range operator + (const Range& r, double x);
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
536 friend OCTAVE_API Range operator - (double x, const Range& r);
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
537 friend OCTAVE_API Range operator - (const Range& r, double x);
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
538 friend OCTAVE_API Range operator * (double x, const Range& r);
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
539 friend OCTAVE_API Range operator * (const Range& r, double x);
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
540
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
541 private:
1860
821870c30840 [project @ 1996-02-04 10:04:58 by jwe]
jwe
parents: 1528
diff changeset
542
28402
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
543 double m_base;
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
544 double m_limit;
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
545 double m_inc;
1860
821870c30840 [project @ 1996-02-04 10:04:58 by jwe]
jwe
parents: 1528
diff changeset
546
28402
09a3c0e91e6e style update for Range class
John W. Eaton <jwe@octave.org>
parents: 28004
diff changeset
547 octave_idx_type m_numel;
4811
198f3712c692 [project @ 2004-03-03 19:24:33 by jwe]
jwe
parents: 4810
diff changeset
548
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
549 OCTAVE_API octave_idx_type numel_internal (void) const;
21321
79a51b7e00b6 eliminate some copy and paste code fragments in the Range class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
550
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
551 OCTAVE_API double limit_internal (void) const;
21321
79a51b7e00b6 eliminate some copy and paste code fragments in the Range class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
552
29226
3ef055ca1d5e Export template class definition instead of template class instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28857
diff changeset
553 OCTAVE_API void init (void);
8971
967a692ddfe2 fix range arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
554
18852
47d4b680d0e0 improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
555 protected:
47d4b680d0e0 improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
556
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
557 // NOTE: The following constructor may be removed when the arithmetic
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
558 // operators are removed.
18852
47d4b680d0e0 improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
559
47d4b680d0e0 improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
560 // For operators' usage (to allow all values to be set directly).
47d4b680d0e0 improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
561 Range (double b, double l, double i, octave_idx_type n)
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
562 : m_base (b), m_limit (l), m_inc (i), m_numel (n)
28592
e70c859c4bff allow infinite limits on for loop ranges (bug #45143)
John W. Eaton <jwe@octave.org>
parents: 28524
diff changeset
563 { }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
564 };
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
565
29954
4c88a452519c rename OCTAVE_USE_DEPRECATED_FUNCTIONS macro and attempt to make it work
John W. Eaton <jwe@octave.org>
parents: 29569
diff changeset
566 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
567 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable")
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5347
diff changeset
568 extern OCTAVE_API Range operator - (const Range& r);
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
569
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
570 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable")
8553
c7ff200e45f5 optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
571 extern OCTAVE_API Range operator + (double x, const Range& r);
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
572
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
573 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable")
8553
c7ff200e45f5 optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
574 extern OCTAVE_API Range operator + (const Range& r, double x);
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
575
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
576 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable")
8553
c7ff200e45f5 optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
577 extern OCTAVE_API Range operator - (double x, const Range& r);
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
578
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
579 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable")
8553
c7ff200e45f5 optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
580 extern OCTAVE_API Range operator - (const Range& r, double x);
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
581
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
582 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable")
8553
c7ff200e45f5 optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
583 extern OCTAVE_API Range operator * (double x, const Range& r);
28524
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
584
455fe4a6f22c deprecate arithmetic operators for ranges; eliminate use in Octave
John W. Eaton <jwe@octave.org>
parents: 28402
diff changeset
585 OCTAVE_DEPRECATED (7, "arithmetic operations on Range objects are unreliable")
8553
c7ff200e45f5 optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
586 extern OCTAVE_API Range operator * (const Range& r, double x);
29954
4c88a452519c rename OCTAVE_USE_DEPRECATED_FUNCTIONS macro and attempt to make it work
John W. Eaton <jwe@octave.org>
parents: 29569
diff changeset
587 #endif
8553
c7ff200e45f5 optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
588
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
589 #endif