Mercurial > octave-nkf
annotate liboctave/array/Range.h @ 20603:f61c67865d9f
Don't return A for inv (A) when A is a singular Diagonal matrix (bug #46103).
* dDiagMatrix.cc (inverse), fDiagMatrix.cc (inverse): return octave_Inf for the
inverse of a diagonal element whose value is 0.
* test/diag-perm.tst: Add tests for new behavior.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 07 Oct 2015 07:41:44 -0700 |
parents | 96153b16febe |
children |
rev | line source |
---|---|
3 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19322
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
3 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3 | 20 |
21 */ | |
22 | |
382 | 23 #if !defined (octave_Range_h) |
24 #define octave_Range_h 1 | |
25 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
26 #include <iosfwd> |
7458 | 27 |
4810 | 28 #include "dMatrix.h" |
7458 | 29 #include "oct-sort.h" |
3 | 30 |
1860 | 31 class |
6108 | 32 OCTAVE_API |
1860 | 33 Range |
3 | 34 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
35 public: |
1860 | 36 |
1528 | 37 Range (void) |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
38 : rng_base (0), rng_limit (0), rng_inc (0), rng_numel (0), cache (1, 0) { } |
1528 | 39 |
40 Range (const Range& r) | |
1860 | 41 : rng_base (r.rng_base), rng_limit (r.rng_limit), rng_inc (r.rng_inc), |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
42 rng_numel (r.rng_numel), cache (r.cache) { } |
3 | 43 |
1528 | 44 Range (double b, double l) |
1860 | 45 : rng_base (b), rng_limit (l), rng_inc (1), |
20548 | 46 rng_numel (numel_internal ()), cache () |
47 { | |
48 double tmplimit = rng_limit; | |
49 | |
50 if (rng_inc > 0) | |
51 tmplimit = max (); | |
52 else | |
53 tmplimit = min (); | |
54 | |
55 if (tmplimit != rng_limit) | |
56 rng_limit = tmplimit; | |
57 } | |
1528 | 58 |
59 Range (double b, double l, double i) | |
1860 | 60 : rng_base (b), rng_limit (l), rng_inc (i), |
20548 | 61 rng_numel (numel_internal ()), cache () |
62 { | |
63 double tmplimit = rng_limit; | |
64 | |
65 if (rng_inc > 0) | |
66 tmplimit = max (); | |
67 else | |
68 tmplimit = min (); | |
69 | |
70 if (tmplimit != rng_limit) | |
71 rng_limit = tmplimit; | |
72 } | |
1528 | 73 |
8589
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
74 // For operators' usage (to preserve element count). |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
75 Range (double b, double i, octave_idx_type n) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
76 : rng_base (b), rng_limit (b + (n-1) * i), rng_inc (i), |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
77 rng_numel (n), cache () |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 { |
19322
d60b44acfff7
Change a bitwise OR to a logical OR in Range.h.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
18886
diff
changeset
|
79 if (! xfinite (b) || ! xfinite (i) || ! xfinite (rng_limit)) |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
80 rng_numel = -2; |
20548 | 81 else |
82 { | |
83 // Code below is only needed if the resulting range must be 100% | |
84 // correctly constructed. If the Range object created is only | |
85 // a temporary one used by operators this may be unnecessary. | |
86 double tmplimit = rng_limit; | |
87 | |
88 if (rng_inc > 0) | |
89 tmplimit = max (); | |
90 else | |
91 tmplimit = min (); | |
92 | |
93 if (tmplimit != rng_limit) | |
94 rng_limit = tmplimit; | |
95 } | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
96 } |
8589
0131fa223dbc
make length invariant in range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8553
diff
changeset
|
97 |
4811 | 98 double base (void) const { return rng_base; } |
1528 | 99 double limit (void) const { return rng_limit; } |
4811 | 100 double inc (void) const { return rng_inc; } |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
101 GCC_ATTR_DEPRECATED octave_idx_type nelem (void) const { return numel (); } |
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
102 octave_idx_type numel (void) const { return rng_numel; } |
3 | 103 |
2383 | 104 bool all_elements_are_ints (void) const; |
105 | |
645 | 106 Matrix matrix_value (void) const; |
107 | |
3 | 108 double min (void) const; |
109 double max (void) const; | |
110 | |
7458 | 111 void sort_internal (bool ascending = true); |
112 void sort_internal (Array<octave_idx_type>& sidx, bool ascending = true); | |
113 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
114 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
|
115 |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7458
diff
changeset
|
116 Range sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
7458 | 117 |
118 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
|
119 sortmode mode = ASCENDING) const; |
208 | 120 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8589
diff
changeset
|
121 sortmode is_sorted (sortmode mode = ASCENDING) const; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8589
diff
changeset
|
122 |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
123 // 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
|
124 |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
125 double checkelem (octave_idx_type i) const; |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
126 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
127 double elem (octave_idx_type i) const; |
9986
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
128 |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
129 Array<double> index (const idx_vector& i) const; |
672e1b49e01e
optimize indexing of ranges by single subscripts
Jaroslav Hajek <highegg@gmail.com>
parents:
8971
diff
changeset
|
130 |
20548 | 131 void set_base (double b); |
4811 | 132 |
20548 | 133 void set_limit (double l); |
4811 | 134 |
20548 | 135 void set_inc (double i); |
1528 | 136 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
137 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
|
138 const Range& r); |
6108 | 139 friend OCTAVE_API std::istream& operator >> (std::istream& is, Range& r); |
3 | 140 |
8971 | 141 friend OCTAVE_API Range operator - (const Range& r); |
142 friend OCTAVE_API Range operator + (double x, const Range& r); | |
143 friend OCTAVE_API Range operator + (const Range& r, double x); | |
144 friend OCTAVE_API Range operator - (double x, const Range& r); | |
145 friend OCTAVE_API Range operator - (const Range& r, double x); | |
146 friend OCTAVE_API Range operator * (double x, const Range& r); | |
147 friend OCTAVE_API Range operator * (const Range& r, double x); | |
148 | |
3 | 149 void print_range (void); |
150 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
151 private: |
1860 | 152 |
208 | 153 double rng_base; |
154 double rng_limit; | |
155 double rng_inc; | |
1860 | 156 |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
157 octave_idx_type rng_numel; |
3 | 158 |
4811 | 159 mutable Matrix cache; |
160 | |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
161 octave_idx_type numel_internal (void) const; |
4811 | 162 |
163 void clear_cache (void) const { cache.resize (0, 0); } | |
8971 | 164 |
18886
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
165 protected: |
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
166 |
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
167 // 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
|
168 Range (double b, double l, double i, octave_idx_type n) |
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
169 : rng_base (b), rng_limit (l), rng_inc (i), |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
170 rng_numel (n), cache () |
18886
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
171 { |
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
172 if (! xfinite (b) || ! xfinite (i) || ! xfinite (l)) |
20263
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19731
diff
changeset
|
173 rng_numel = -2; |
18886
47d4b680d0e0
improve accuracy of range/scalar arithmetic (bug #42589)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
174 } |
3 | 175 }; |
176 | |
6108 | 177 extern OCTAVE_API Range operator - (const Range& r); |
2599 | 178 |
8553
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
179 extern OCTAVE_API Range operator + (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
180 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
181 extern OCTAVE_API Range operator + (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
182 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
183 extern OCTAVE_API Range operator - (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
184 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
185 extern OCTAVE_API Range operator - (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
186 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
187 extern OCTAVE_API Range operator * (double x, const Range& r); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
188 |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
189 extern OCTAVE_API Range operator * (const Range& r, double x); |
c7ff200e45f5
optimize range-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
190 |
3 | 191 #endif |