Mercurial > hg > octave-nkf
annotate liboctave/Range.h @ 8971:967a692ddfe2
fix range arithmetics
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 13 Mar 2009 12:18:50 +0100 |
parents | d865363208d6 |
children | 672e1b49e01e |
rev | line source |
---|---|
3 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, |
8920 | 4 2006, 2007, 2008, 2009 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 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
27 #include <iosfwd> |
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), |
8971 | 43 rng_nelem (r.rng_nelem), cache (r.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). |
8971 | 54 Range (double b, double i, octave_idx_type n); |
8589
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
55 |
4811 | 56 double base (void) const { return rng_base; } |
1528 | 57 double limit (void) const { return rng_limit; } |
4811 | 58 double inc (void) const { return rng_inc; } |
5275 | 59 octave_idx_type nelem (void) const { return rng_nelem; } |
3 | 60 |
2383 | 61 bool all_elements_are_ints (void) const; |
62 | |
645 | 63 Matrix matrix_value (void) const; |
64 | |
3 | 65 double min (void) const; |
66 double max (void) const; | |
67 | |
7458 | 68 void sort_internal (bool ascending = true); |
69 void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true); | |
70 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
71 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
|
72 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7458
diff
changeset
|
73 Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
7458 | 74 |
75 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
|
76 sortmode mode = ASCENDING) const; |
208 | 77 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8589
diff
changeset
|
78 sortmode is_sorted (sortmode mode = ASCENDING) const; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8589
diff
changeset
|
79 |
4811 | 80 void set_base (double b) |
81 { | |
82 if (rng_base != b) | |
83 { | |
84 rng_base = b; | |
85 clear_cache (); | |
86 } | |
87 } | |
88 | |
89 void set_limit (double l) | |
90 { | |
91 if (rng_limit != l) | |
92 { | |
93 rng_limit = l; | |
94 clear_cache (); | |
95 } | |
96 } | |
97 | |
98 void set_inc (double i) | |
99 { | |
100 if (rng_inc != i) | |
101 { | |
102 rng_inc = i; | |
103 clear_cache (); | |
104 } | |
105 } | |
1528 | 106 |
6108 | 107 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Range& r); |
108 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r); | |
3 | 109 |
8971 | 110 friend OCTAVE_API Range operator - (const Range& r); |
111 friend OCTAVE_API Range operator + (double x, const Range& r); | |
112 friend OCTAVE_API Range operator + (const Range& r, double x); | |
113 friend OCTAVE_API Range operator - (double x, const Range& r); | |
114 friend OCTAVE_API Range operator - (const Range& r, double x); | |
115 friend OCTAVE_API Range operator * (double x, const Range& r); | |
116 friend OCTAVE_API Range operator * (const Range& r, double x); | |
117 | |
3 | 118 void print_range (void); |
119 | |
120 private: | |
1860 | 121 |
208 | 122 double rng_base; |
123 double rng_limit; | |
124 double rng_inc; | |
1860 | 125 |
5275 | 126 octave_idx_type rng_nelem; |
3 | 127 |
4811 | 128 mutable Matrix cache; |
129 | |
5275 | 130 octave_idx_type nelem_internal (void) const; |
4811 | 131 |
132 void clear_cache (void) const { cache.resize (0, 0); } | |
8971 | 133 |
3 | 134 }; |
135 | |
6108 | 136 extern OCTAVE_API Range operator - (const Range& r); |
2599 | 137 |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
138 extern OCTAVE_API Range operator + (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
139 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
140 extern OCTAVE_API Range operator + (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
141 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
142 extern OCTAVE_API Range operator - (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
143 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
144 extern OCTAVE_API Range operator - (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
145 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
146 extern OCTAVE_API Range operator * (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
147 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
148 extern OCTAVE_API Range operator * (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
149 |
3 | 150 #endif |
151 | |
152 /* | |
153 ;;; Local Variables: *** | |
154 ;;; mode: C++ *** | |
155 ;;; End: *** | |
156 */ |