Mercurial > hg > octave-lyh
annotate liboctave/Range.h @ 8553:c7ff200e45f5
optimize range-scalar ops
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 21 Jan 2009 15:50:34 +0100 |
parents | 36594d5bbe13 |
children | 0131fa223dbc |
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 |
4811 | 53 double base (void) const { return rng_base; } |
1528 | 54 double limit (void) const { return rng_limit; } |
4811 | 55 double inc (void) const { return rng_inc; } |
5275 | 56 octave_idx_type nelem (void) const { return rng_nelem; } |
3 | 57 |
2383 | 58 bool all_elements_are_ints (void) const; |
59 | |
645 | 60 Matrix matrix_value (void) const; |
61 | |
3 | 62 double min (void) const; |
63 double max (void) const; | |
64 | |
7458 | 65 void sort_internal (bool ascending = true); |
66 void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true); | |
67 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
68 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
|
69 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7458
diff
changeset
|
70 Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
7458 | 71 |
72 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
|
73 sortmode mode = ASCENDING) const; |
208 | 74 |
4811 | 75 void set_base (double b) |
76 { | |
77 if (rng_base != b) | |
78 { | |
79 rng_base = b; | |
80 clear_cache (); | |
81 } | |
82 } | |
83 | |
84 void set_limit (double l) | |
85 { | |
86 if (rng_limit != l) | |
87 { | |
88 rng_limit = l; | |
89 clear_cache (); | |
90 } | |
91 } | |
92 | |
93 void set_inc (double i) | |
94 { | |
95 if (rng_inc != i) | |
96 { | |
97 rng_inc = i; | |
98 clear_cache (); | |
99 } | |
100 } | |
1528 | 101 |
6108 | 102 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const Range& r); |
103 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r); | |
3 | 104 |
105 void print_range (void); | |
106 | |
107 private: | |
1860 | 108 |
208 | 109 double rng_base; |
110 double rng_limit; | |
111 double rng_inc; | |
1860 | 112 |
5275 | 113 octave_idx_type rng_nelem; |
3 | 114 |
4811 | 115 mutable Matrix cache; |
116 | |
5275 | 117 octave_idx_type nelem_internal (void) const; |
4811 | 118 |
119 void clear_cache (void) const { cache.resize (0, 0); } | |
3 | 120 }; |
121 | |
6108 | 122 extern OCTAVE_API Range operator - (const Range& r); |
2599 | 123 |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
124 extern OCTAVE_API Range operator + (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
125 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
126 extern OCTAVE_API Range operator + (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
127 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
128 extern OCTAVE_API Range operator - (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
129 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
130 extern OCTAVE_API Range operator - (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
131 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
132 extern OCTAVE_API Range operator * (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
133 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
134 extern OCTAVE_API Range operator * (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
135 |
3 | 136 #endif |
137 | |
138 /* | |
139 ;;; Local Variables: *** | |
140 ;;; mode: C++ *** | |
141 ;;; End: *** | |
142 */ |