Mercurial > hg > octave-nkf
annotate liboctave/Range.h @ 8721:e9cb742df9eb
imported patch sort3.diff
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 11 Feb 2009 15:25:53 +0100 |
parents | 0131fa223dbc |
children | eb63fbe60fab |
rev | line source |
---|---|
3 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, |
4 2006, 2007 John W. Eaton | |
3 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
3 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
3 | 21 |
22 */ | |
23 | |
382 | 24 #if !defined (octave_Range_h) |
25 #define octave_Range_h 1 | |
26 | |
3503 | 27 #include <iostream> |
7458 | 28 |
4810 | 29 #include "dMatrix.h" |
7458 | 30 #include "oct-sort.h" |
3 | 31 |
1860 | 32 class |
6108 | 33 OCTAVE_API |
1860 | 34 Range |
3 | 35 { |
36 public: | |
1860 | 37 |
1528 | 38 Range (void) |
5347 | 39 : rng_base (0), rng_limit (0), rng_inc (0), rng_nelem (0), cache (1, 0) { } |
1528 | 40 |
41 Range (const Range& r) | |
1860 | 42 : rng_base (r.rng_base), rng_limit (r.rng_limit), rng_inc (r.rng_inc), |
4811 | 43 rng_nelem (r.rng_nelem), cache () { } |
3 | 44 |
1528 | 45 Range (double b, double l) |
1860 | 46 : rng_base (b), rng_limit (l), rng_inc (1), |
4811 | 47 rng_nelem (nelem_internal ()), cache () { } |
1528 | 48 |
49 Range (double b, double l, double i) | |
1860 | 50 : rng_base (b), rng_limit (l), rng_inc (i), |
4811 | 51 rng_nelem (nelem_internal ()), cache () { } |
1528 | 52 |
8589
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
53 // For operators' usage (to preserve element count). |
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
54 Range (double b, double i, octave_idx_type n) |
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
55 : rng_base (b), rng_limit (b + n * i), rng_inc (i), |
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
56 rng_nelem (n), cache () { } |
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
57 |
4811 | 58 double base (void) const { return rng_base; } |
1528 | 59 double limit (void) const { return rng_limit; } |
4811 | 60 double inc (void) const { return rng_inc; } |
5275 | 61 octave_idx_type nelem (void) const { return rng_nelem; } |
3 | 62 |
2383 | 63 bool all_elements_are_ints (void) const; |
64 | |
645 | 65 Matrix matrix_value (void) const; |
66 | |
3 | 67 double min (void) const; |
68 double max (void) const; | |
69 | |
7458 | 70 void sort_internal (bool ascending = true); |
71 void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true); | |
72 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
73 Matrix diag (octave_idx_type k = 0) const; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
74 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7458
diff
changeset
|
75 Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
7458 | 76 |
77 Range sort (Array<octave_idx_type>& sidx, octave_idx_type dim = 0, | |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7458
diff
changeset
|
78 sortmode mode = ASCENDING) const; |
208 | 79 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8589
diff
changeset
|
80 sortmode is_sorted (sortmode mode = ASCENDING) const; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8589
diff
changeset
|
81 |
4811 | 82 void set_base (double b) |
83 { | |
84 if (rng_base != b) | |
85 { | |
86 rng_base = b; | |
87 clear_cache (); | |
88 } | |
89 } | |
90 | |
91 void set_limit (double l) | |
92 { | |
93 if (rng_limit != l) | |
94 { | |
95 rng_limit = l; | |
96 clear_cache (); | |
97 } | |
98 } | |
99 | |
100 void set_inc (double i) | |
101 { | |
102 if (rng_inc != i) | |
103 { | |
104 rng_inc = i; | |
105 clear_cache (); | |
106 } | |
107 } | |
1528 | 108 |
6108 | 109 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Range& r); |
110 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r); | |
3 | 111 |
112 void print_range (void); | |
113 | |
114 private: | |
1860 | 115 |
208 | 116 double rng_base; |
117 double rng_limit; | |
118 double rng_inc; | |
1860 | 119 |
5275 | 120 octave_idx_type rng_nelem; |
3 | 121 |
4811 | 122 mutable Matrix cache; |
123 | |
5275 | 124 octave_idx_type nelem_internal (void) const; |
4811 | 125 |
126 void clear_cache (void) const { cache.resize (0, 0); } | |
3 | 127 }; |
128 | |
6108 | 129 extern OCTAVE_API Range operator - (const Range& r); |
2599 | 130 |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
131 extern OCTAVE_API Range operator + (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
132 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
133 extern OCTAVE_API Range operator + (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
134 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
135 extern OCTAVE_API Range operator - (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
136 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
137 extern OCTAVE_API Range operator - (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
138 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
139 extern OCTAVE_API Range operator * (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
140 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
141 extern OCTAVE_API Range operator * (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
142 |
3 | 143 #endif |
144 | |
145 /* | |
146 ;;; Local Variables: *** | |
147 ;;; mode: C++ *** | |
148 ;;; End: *** | |
149 */ |