annotate liboctave/array/fMatrix.cc @ 29931:7faff48840eb

prefer data over fortran_vec for read-only access to data See also the discussion here: https://octave.discourse.group/t/rename-uses-of-fortran-vec-to-data-for-clarity/1439 * Array.h (const T * Array<T>::fortran_vec (void) const): Deprecate. Change all uses to call data instead.
author John W. Eaton <jwe@octave.org>
date Fri, 30 Jul 2021 11:46:05 -0400
parents 3cb8519fed0f
children 1e277c6b6626
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 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 // Copyright (C) 1994-2021 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 ////////////////////////////////////////////////////////////////////////
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21273
diff changeset
27 # include "config.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
28 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
29
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
30 #include <algorithm>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25237
diff changeset
31 #include <istream>
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
32 #include <limits>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25237
diff changeset
33 #include <ostream>
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
34
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
35 #include "Array-util.h"
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
36 #include "DET.h"
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
37 #include "PermMatrix.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19065
diff changeset
38 #include "boolMatrix.h"
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
39 #include "byte-swap.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19065
diff changeset
40 #include "chMatrix.h"
21269
3c8a3d35661a better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents: 21266
diff changeset
41 #include "chol.h"
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
42 #include "fCColVector.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19065
diff changeset
43 #include "fCMatrix.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19065
diff changeset
44 #include "fColVector.h"
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
45 #include "fDiagMatrix.h"
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
46 #include "fMatrix.h"
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
47 #include "fMatrix.h"
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
48 #include "fNDArray.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19065
diff changeset
49 #include "fRowVector.h"
22322
93b3cdd36854 move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents: 22317
diff changeset
50 #include "lo-blas-proto.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
51 #include "lo-error.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
52 #include "lo-ieee.h"
22322
93b3cdd36854 move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents: 22317
diff changeset
53 #include "lo-lapack-proto.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
54 #include "lo-mappers.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
55 #include "lo-utils.h"
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9469
diff changeset
56 #include "mx-fdm-fm.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
57 #include "mx-fm-fdm.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
58 #include "mx-inlines.cc"
8774
b756ce0002db split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
59 #include "mx-op-defs.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
60 #include "oct-cmplx.h"
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9469
diff changeset
61 #include "oct-fftw.h"
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9469
diff changeset
62 #include "oct-locbuf.h"
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
63 #include "oct-norm.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
64 #include "quit.h"
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
65 #include "schur.h"
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
66 #include "svd.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
67
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
68 // Matrix class.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
69
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
70 FloatMatrix::FloatMatrix (const FloatRowVector& rv)
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19269
diff changeset
71 : FloatNDArray (rv)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22402
diff changeset
72 { }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
73
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
74 FloatMatrix::FloatMatrix (const FloatColumnVector& cv)
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19269
diff changeset
75 : FloatNDArray (cv)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22402
diff changeset
76 { }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
77
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
78 FloatMatrix::FloatMatrix (const FloatDiagMatrix& a)
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19269
diff changeset
79 : FloatNDArray (a.dims (), 0.0)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
80 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
81 for (octave_idx_type i = 0; i < a.length (); i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
82 elem (i, i) = a.elem (i, i);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
83 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
84
19391
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
85 FloatMatrix::FloatMatrix (const MDiagArray2<float>& a)
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
86 : FloatNDArray (a.dims (), 0.0)
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
87 {
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
88 for (octave_idx_type i = 0; i < a.length (); i++)
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
89 elem (i, i) = a.elem (i, i);
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
90 }
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
91
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
92 FloatMatrix::FloatMatrix (const DiagArray2<float>& a)
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
93 : FloatNDArray (a.dims (), 0.0)
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
94 {
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
95 for (octave_idx_type i = 0; i < a.length (); i++)
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
96 elem (i, i) = a.elem (i, i);
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
97 }
385499581a5e allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents: 19321
diff changeset
98
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8337
diff changeset
99 FloatMatrix::FloatMatrix (const PermMatrix& a)
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19269
diff changeset
100 : FloatNDArray (a.dims (), 0.0)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8337
diff changeset
101 {
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18632
diff changeset
102 const Array<octave_idx_type> ia (a.col_perm_vec ());
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8337
diff changeset
103 octave_idx_type len = a.rows ();
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18632
diff changeset
104 for (octave_idx_type i = 0; i < len; i++)
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18632
diff changeset
105 elem (ia(i), i) = 1.0;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8337
diff changeset
106 }
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8337
diff changeset
107
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
108 // FIXME: could we use a templated mixed-type copy function here?
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
109
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
110 FloatMatrix::FloatMatrix (const boolMatrix& a)
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19269
diff changeset
111 : FloatNDArray (a)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22402
diff changeset
112 { }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
113
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
114 FloatMatrix::FloatMatrix (const charMatrix& a)
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19269
diff changeset
115 : FloatNDArray (a.dims ())
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
116 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
117 for (octave_idx_type i = 0; i < a.rows (); i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
118 for (octave_idx_type j = 0; j < a.cols (); j++)
8956
d91fa4b20bbb ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
119 elem (i, j) = static_cast<unsigned char> (a.elem (i, j));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
120 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
121
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
122 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
123 FloatMatrix::operator == (const FloatMatrix& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
124 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
125 if (rows () != a.rows () || cols () != a.cols ())
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
126 return false;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
127
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
128 return mx_inline_equal (numel (), data (), a.data ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
129 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
130
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
131 bool
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
132 FloatMatrix::operator != (const FloatMatrix& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
133 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
134 return !(*this == a);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
135 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
136
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
137 bool
23596
b63c3a09aee7 maint: Deprecate is_symmetric and replace with issymmetric.
Rik <rik@octave.org>
parents: 23594
diff changeset
138 FloatMatrix::issymmetric (void) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
139 {
23593
a8361bc2361a maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents: 23461
diff changeset
140 if (issquare () && rows () > 0)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
141 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
142 for (octave_idx_type i = 0; i < rows (); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
143 for (octave_idx_type j = i+1; j < cols (); j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
144 if (elem (i, j) != elem (j, i))
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
145 return false;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
146
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
147 return true;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
148 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
149
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
150 return false;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
151 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
152
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
153 FloatMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
154 FloatMatrix::insert (const FloatMatrix& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
155 octave_idx_type r, octave_idx_type c)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
156 {
19321
3746b92739f7 Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents: 19320
diff changeset
157 FloatNDArray::insert (a, r, c);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
158 return *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
159 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
160
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
161 FloatMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
162 FloatMatrix::insert (const FloatRowVector& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
163 octave_idx_type r, octave_idx_type c)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
164 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
165 octave_idx_type a_len = a.numel ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
166
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
167 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
168 (*current_liboctave_error_handler) ("range error for insert");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
169
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
170 if (a_len > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
171 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
172 make_unique ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
173
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
174 for (octave_idx_type i = 0; i < a_len; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
175 xelem (r, c+i) = a.elem (i);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
176 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
177
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
178 return *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
179 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
180
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
181 FloatMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
182 FloatMatrix::insert (const FloatColumnVector& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
183 octave_idx_type r, octave_idx_type c)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
184 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
185 octave_idx_type a_len = a.numel ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
186
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
187 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
188 (*current_liboctave_error_handler) ("range error for insert");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
189
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
190 if (a_len > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
191 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
192 make_unique ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
193
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
194 for (octave_idx_type i = 0; i < a_len; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
195 xelem (r+i, c) = a.elem (i);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
196 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
197
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
198 return *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
199 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
200
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
201 FloatMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
202 FloatMatrix::insert (const FloatDiagMatrix& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
203 octave_idx_type r, octave_idx_type c)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
204 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
205 octave_idx_type a_nr = a.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
206 octave_idx_type a_nc = a.cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
207
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
208 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
209 (*current_liboctave_error_handler) ("range error for insert");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
210
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
211 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
212
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
213 octave_idx_type a_len = a.length ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
214
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
215 if (a_len > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
216 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
217 make_unique ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
218
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
219 for (octave_idx_type i = 0; i < a_len; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
220 xelem (r+i, c+i) = a.elem (i, i);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
221 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
222
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
223 return *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
224 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
225
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
226 FloatMatrix&
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
227 FloatMatrix::fill (float val)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
228 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
229 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
230 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
231
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
232 if (nr > 0 && nc > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
233 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
234 make_unique ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
235
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
236 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
237 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
238 xelem (i, j) = val;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
239 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
240
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
241 return *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
242 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
243
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
244 FloatMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
245 FloatMatrix::fill (float val, octave_idx_type r1, octave_idx_type c1,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
246 octave_idx_type r2, octave_idx_type c2)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
247 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
248 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
249 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
250
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
251 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
252 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
253 (*current_liboctave_error_handler) ("range error for fill");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
254
17663
7975d75f933c Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents: 16300
diff changeset
255 if (r1 > r2) { std::swap (r1, r2); }
7975d75f933c Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents: 16300
diff changeset
256 if (c1 > c2) { std::swap (c1, c2); }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
257
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
258 if (r2 >= r1 && c2 >= c1)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
259 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
260 make_unique ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
261
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
262 for (octave_idx_type j = c1; j <= c2; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
263 for (octave_idx_type i = r1; i <= r2; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
264 xelem (i, j) = val;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
265 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
266
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
267 return *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
268 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
269
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
270 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
271 FloatMatrix::append (const FloatMatrix& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
272 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
273 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
274 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
275 if (nr != a.rows ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
276 (*current_liboctave_error_handler) ("row dimension mismatch for append");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
277
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
278 octave_idx_type nc_insert = nc;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
279 FloatMatrix retval (nr, nc + a.cols ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
280 retval.insert (*this, 0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
281 retval.insert (a, 0, nc_insert);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
282 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
283 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
284
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
285 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
286 FloatMatrix::append (const FloatRowVector& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
287 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
288 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
289 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
290 if (nr != 1)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
291 (*current_liboctave_error_handler) ("row dimension mismatch for append");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
292
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
293 octave_idx_type nc_insert = nc;
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
294 FloatMatrix retval (nr, nc + a.numel ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
295 retval.insert (*this, 0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
296 retval.insert (a, 0, nc_insert);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
297 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
298 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
299
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
300 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
301 FloatMatrix::append (const FloatColumnVector& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
302 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
303 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
304 octave_idx_type nc = cols ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
305 if (nr != a.numel ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
306 (*current_liboctave_error_handler) ("row dimension mismatch for append");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
307
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
308 octave_idx_type nc_insert = nc;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
309 FloatMatrix retval (nr, nc + 1);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
310 retval.insert (*this, 0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
311 retval.insert (a, 0, nc_insert);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
312 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
313 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
314
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
315 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
316 FloatMatrix::append (const FloatDiagMatrix& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
317 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
318 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
319 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
320 if (nr != a.rows ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
321 (*current_liboctave_error_handler) ("row dimension mismatch for append");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
322
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
323 octave_idx_type nc_insert = nc;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
324 FloatMatrix retval (nr, nc + a.cols ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
325 retval.insert (*this, 0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
326 retval.insert (a, 0, nc_insert);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
327 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
328 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
329
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
330 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
331 FloatMatrix::stack (const FloatMatrix& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
332 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
333 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
334 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
335 if (nc != a.cols ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
336 (*current_liboctave_error_handler) ("column dimension mismatch for stack");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
337
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
338 octave_idx_type nr_insert = nr;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
339 FloatMatrix retval (nr + a.rows (), nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
340 retval.insert (*this, 0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
341 retval.insert (a, nr_insert, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
342 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
343 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
344
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
345 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
346 FloatMatrix::stack (const FloatRowVector& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
347 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
348 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
349 octave_idx_type nc = cols ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
350 if (nc != a.numel ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
351 (*current_liboctave_error_handler) ("column dimension mismatch for stack");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
352
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
353 octave_idx_type nr_insert = nr;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
354 FloatMatrix retval (nr + 1, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
355 retval.insert (*this, 0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
356 retval.insert (a, nr_insert, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
357 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
358 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
359
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
360 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
361 FloatMatrix::stack (const FloatColumnVector& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
362 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
363 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
364 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
365 if (nc != 1)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
366 (*current_liboctave_error_handler) ("column dimension mismatch for stack");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
367
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
368 octave_idx_type nr_insert = nr;
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
369 FloatMatrix retval (nr + a.numel (), nc);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
370 retval.insert (*this, 0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
371 retval.insert (a, nr_insert, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
372 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
373 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
374
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
375 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
376 FloatMatrix::stack (const FloatDiagMatrix& a) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
377 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
378 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
379 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
380 if (nc != a.cols ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
381 (*current_liboctave_error_handler) ("column dimension mismatch for stack");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
382
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
383 octave_idx_type nr_insert = nr;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
384 FloatMatrix retval (nr + a.rows (), nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
385 retval.insert (*this, 0, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
386 retval.insert (a, nr_insert, 0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
387 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
388 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
389
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
390 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
391 real (const FloatComplexMatrix& a)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
392 {
10363
a0728e81ed25 improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 10362
diff changeset
393 return do_mx_unary_op<float, FloatComplex> (a, mx_inline_real);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
394 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
395
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
396 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
397 imag (const FloatComplexMatrix& a)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
398 {
10363
a0728e81ed25 improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 10362
diff changeset
399 return do_mx_unary_op<float, FloatComplex> (a, mx_inline_imag);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
400 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
401
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
402 FloatMatrix
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
403 FloatMatrix::extract (octave_idx_type r1, octave_idx_type c1,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
404 octave_idx_type r2, octave_idx_type c2) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
405 {
17663
7975d75f933c Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents: 16300
diff changeset
406 if (r1 > r2) { std::swap (r1, r2); }
7975d75f933c Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents: 16300
diff changeset
407 if (c1 > c2) { std::swap (c1, c2); }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
408
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
409 return index (octave::idx_vector (r1, r2+1), octave::idx_vector (c1, c2+1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
410 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
411
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
412 FloatMatrix
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
413 FloatMatrix::extract_n (octave_idx_type r1, octave_idx_type c1,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
414 octave_idx_type nr, octave_idx_type nc) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
415 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
416 return index (octave::idx_vector (r1, r1 + nr), octave::idx_vector (c1, c1 + nc));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
417 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
418
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
419 // extract row or column i.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
420
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
421 FloatRowVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
422 FloatMatrix::row (octave_idx_type i) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
423 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
424 return index (octave::idx_vector (i), octave::idx_vector::colon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
425 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
426
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
427 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
428 FloatMatrix::column (octave_idx_type i) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
429 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
430 return index (octave::idx_vector::colon, octave::idx_vector (i));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
431 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
432
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
433 // Local function to calculate the 1-norm.
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
434 static
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
435 float
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
436 norm1 (const FloatMatrix& a)
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
437 {
24311
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
438 float anorm = 0.0;
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
439 FloatRowVector colsum = a.abs ().sum ().row (0);
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
440
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
441 for (octave_idx_type i = 0; i < colsum.numel (); i++)
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
442 {
24311
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
443 float sum = colsum.xelem (i);
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
444 if (octave::math::isinf (sum) || octave::math::isnan (sum))
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
445 {
24311
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
446 anorm = sum; // Pass Inf or NaN to output
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
447 break;
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
448 }
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
449 else
24311
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
450 anorm = std::max (anorm, sum);
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
451 }
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
452
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
453 return anorm;
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
454 }
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
455
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
456 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
457 FloatMatrix::inverse (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
458 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
459 octave_idx_type info;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
460 float rcon;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
461 MatrixType mattype (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
462 return inverse (mattype, info, rcon, 0, 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
463 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
464
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
465 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
466 FloatMatrix::inverse (octave_idx_type& info) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
467 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
468 float rcon;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
469 MatrixType mattype (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
470 return inverse (mattype, info, rcon, 0, 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
471 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
472
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
473 FloatMatrix
21719
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
474 FloatMatrix::inverse (octave_idx_type& info, float& rcon, bool force,
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
475 bool calc_cond) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
476 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
477 MatrixType mattype (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
478 return inverse (mattype, info, rcon, force, calc_cond);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
479 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
480
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
481 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
482 FloatMatrix::inverse (MatrixType& mattype) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
483 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
484 octave_idx_type info;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
485 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
486 return inverse (mattype, info, rcon, 0, 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
487 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
488
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
489 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
490 FloatMatrix::inverse (MatrixType& mattype, octave_idx_type& info) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
491 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
492 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
493 return inverse (mattype, info, rcon, 0, 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
494 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
495
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
496 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
497 FloatMatrix::tinverse (MatrixType& mattype, octave_idx_type& info, float& rcon,
21719
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
498 bool force, bool calc_cond) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
499 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
500 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
501
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
502 F77_INT nr = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
503 F77_INT nc = octave::to_f77_int (cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
504
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
505 if (nr != nc || nr == 0 || nc == 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
506 (*current_liboctave_error_handler) ("inverse requires square matrix");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
507
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
508 int typ = mattype.type ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
509 char uplo = (typ == MatrixType::Lower ? 'L' : 'U');
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
510 char udiag = 'N';
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
511 retval = *this;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
512 float *tmp_data = retval.fortran_vec ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
513
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
514 F77_INT tmp_info = 0;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
515
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
516 F77_XFCN (strtri, STRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1),
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
517 F77_CONST_CHAR_ARG2 (&udiag, 1),
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
518 nr, tmp_data, nr, tmp_info
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
519 F77_CHAR_ARG_LEN (1)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
520 F77_CHAR_ARG_LEN (1)));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
521
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
522 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
523
24291
cf33c1b910b7 maint: Correct typo in comment "Throw-away" => "Throw away"
Rik <rik@octave.org>
parents: 24251
diff changeset
524 // Throw away extra info LAPACK gives so as to not change output.
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
525 rcon = 0.0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
526 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
527 info = -1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
528 else if (calc_cond)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
529 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
530 F77_INT dtrcon_info = 0;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
531 char job = '1';
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
532
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
533 OCTAVE_LOCAL_BUFFER (float, work, 3 * nr);
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
534 OCTAVE_LOCAL_BUFFER (F77_INT, iwork, nr);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
535
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
536 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&job, 1),
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
537 F77_CONST_CHAR_ARG2 (&uplo, 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
538 F77_CONST_CHAR_ARG2 (&udiag, 1),
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
539 nr, tmp_data, nr, rcon,
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
540 work, iwork, dtrcon_info
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
541 F77_CHAR_ARG_LEN (1)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
542 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
543 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
544
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
545 if (dtrcon_info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
546 info = -1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
547 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
548
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
549 if (info == -1 && ! force)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
550 retval = *this; // Restore matrix contents.
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
551
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
552 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
553 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
554
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
555 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
556 FloatMatrix::finverse (MatrixType& mattype, octave_idx_type& info, float& rcon,
21719
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
557 bool force, bool calc_cond) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
558 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
559 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
560
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
561 F77_INT nr = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
562 F77_INT nc = octave::to_f77_int (cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
563
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
564 if (nr != nc || nr == 0 || nc == 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
565 (*current_liboctave_error_handler) ("inverse requires square matrix");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
566
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
567 Array<F77_INT> ipvt (dim_vector (nr, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
568 F77_INT *pipvt = ipvt.fortran_vec ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
569
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
570 retval = *this;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
571 float *tmp_data = retval.fortran_vec ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
572
24035
bc0aa7e18c96 fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
573 Array<float> z (dim_vector (1, 1));
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
574 F77_INT lwork = -1;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
575
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
576 F77_INT tmp_info = 0;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
577
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
578 // Query the optimum work array size.
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
579 F77_XFCN (sgetri, SGETRI, (nc, tmp_data, nr, pipvt,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
580 z.fortran_vec (), lwork, tmp_info));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
581
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
582 lwork = static_cast<F77_INT> (z(0));
24035
bc0aa7e18c96 fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
583 lwork = (lwork < 4 * nc ? 4 * nc : lwork);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
584 z.resize (dim_vector (lwork, 1));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
585 float *pz = z.fortran_vec ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
586
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
587 info = 0;
24035
bc0aa7e18c96 fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
588 tmp_info = 0;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
589
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
590 // Calculate the norm of the matrix for later use when determining rcon.
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
591 float anorm;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
592 if (calc_cond)
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
593 anorm = norm1 (retval);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
594
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
595 F77_XFCN (sgetrf, SGETRF, (nc, nc, tmp_data, nr, pipvt, tmp_info));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
596
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
597 info = tmp_info;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
598
24291
cf33c1b910b7 maint: Correct typo in comment "Throw-away" => "Throw away"
Rik <rik@octave.org>
parents: 24251
diff changeset
599 // Throw away extra info LAPACK gives so as to not change output.
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
600 rcon = 0.0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
601 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
602 info = -1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
603 else if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
604 {
24035
bc0aa7e18c96 fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
605 F77_INT sgecon_info = 0;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
606
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
607 // Now calculate the condition number for non-singular matrix.
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
608 char job = '1';
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
609 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
610 F77_INT *piz = iz.fortran_vec ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
611 F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
612 nc, tmp_data, nr, anorm,
24035
bc0aa7e18c96 fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
613 rcon, pz, piz, sgecon_info
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
614 F77_CHAR_ARG_LEN (1)));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
615
24035
bc0aa7e18c96 fix possible array bounds error when calculating inverse (bug #49235)
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
616 if (sgecon_info != 0)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
617 info = -1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
618 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
619
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
620 if (info == -1 && ! force)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
621 retval = *this; // Restore matrix contents.
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
622 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
623 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
624 F77_INT dgetri_info = 0;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
625
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
626 F77_XFCN (sgetri, SGETRI, (nc, tmp_data, nr, pipvt,
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
627 pz, lwork, dgetri_info));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
628
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
629 if (dgetri_info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
630 info = -1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
631 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
632
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
633 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
634 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
635
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
636 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
637 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
638
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
639 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
640 FloatMatrix::inverse (MatrixType& mattype, octave_idx_type& info, float& rcon,
21719
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
641 bool force, bool calc_cond) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
642 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
643 int typ = mattype.type (false);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
644 FloatMatrix ret;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
645
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
646 if (typ == MatrixType::Unknown)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
647 typ = mattype.type (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
648
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
649 if (typ == MatrixType::Upper || typ == MatrixType::Lower)
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
650 ret = tinverse (mattype, info, rcon, force, calc_cond);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
651 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
652 {
23594
af5b813503cb maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents: 23593
diff changeset
653 if (mattype.ishermitian ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
654 {
22317
6ca3acf5fad8 move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
655 octave::math::chol<FloatMatrix> chol (*this, info, true, calc_cond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
656 if (info == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
657 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
658 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
659 rcon = chol.rcond ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
660 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
661 rcon = 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
662 ret = chol.inverse ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
663 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
664 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
665 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
666 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
667
23594
af5b813503cb maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents: 23593
diff changeset
668 if (! mattype.ishermitian ())
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
669 ret = finverse (mattype, info, rcon, force, calc_cond);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
670
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
671 if ((calc_cond || mattype.ishermitian ()) && rcon == 0.0
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
672 && (numel () != 1))
22849
1d242ae72240 Return 0 for special case of scalar Inf input to inverse (bug #49690).
Rik <rik@octave.org>
parents: 22848
diff changeset
673 ret = FloatMatrix (rows (), columns (),
1d242ae72240 Return 0 for special case of scalar Inf input to inverse (bug #49690).
Rik <rik@octave.org>
parents: 22848
diff changeset
674 octave::numeric_limits<float>::Inf ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
675 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
676
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
677 return ret;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
678 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
679
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
680 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
681 FloatMatrix::pseudo_inverse (float tol) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
682 {
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
683 octave::math::svd<FloatMatrix> result (*this,
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
684 octave::math::svd<FloatMatrix>::Type::economy);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
685
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
686 FloatDiagMatrix S = result.singular_values ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
687 FloatMatrix U = result.left_singular_matrix ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
688 FloatMatrix V = result.right_singular_matrix ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
689
15448
0a0912a9ab6e Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15383
diff changeset
690 FloatColumnVector sigma = S.extract_diag ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
691
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
692 octave_idx_type r = sigma.numel () - 1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
693 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
694 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
695
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
696 if (tol <= 0.0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
697 {
24196
2b769c242188 Use std::max to simplify calculating pinv tolerance.
Rik <rik@octave.org>
parents: 24195
diff changeset
698 tol = std::max (nr, nc) * sigma.elem (0)
2b769c242188 Use std::max to simplify calculating pinv tolerance.
Rik <rik@octave.org>
parents: 24195
diff changeset
699 * std::numeric_limits<float>::epsilon ();
24195
d3dc76efb38b Return correct value for pinv of zero vectors and scalars (bug #51246).
Rik <rik@octave.org>
parents: 24035
diff changeset
700
d3dc76efb38b Return correct value for pinv of zero vectors and scalars (bug #51246).
Rik <rik@octave.org>
parents: 24035
diff changeset
701 if (tol == 0)
d3dc76efb38b Return correct value for pinv of zero vectors and scalars (bug #51246).
Rik <rik@octave.org>
parents: 24035
diff changeset
702 tol = std::numeric_limits<float>::min ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
703 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
704
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
705 while (r >= 0 && sigma.elem (r) < tol)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
706 r--;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
707
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
708 if (r < 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
709 return FloatMatrix (nc, nr, 0.0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
710 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
711 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
712 FloatMatrix Ur = U.extract (0, 0, nr-1, r);
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
713 FloatDiagMatrix D = FloatDiagMatrix (sigma.extract (0, r)).inverse ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
714 FloatMatrix Vr = V.extract (0, 0, nc-1, r);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
715 return Vr * D * Ur.transpose ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
716 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
717 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
718
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9469
diff changeset
719 #if defined (HAVE_FFTW)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
720
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
721 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
722 FloatMatrix::fourier (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
723 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
724 std::size_t nr = rows ();
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
725 std::size_t nc = cols ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
726
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
727 FloatComplexMatrix retval (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
728
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
729 std::size_t npts, nsamples;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
730
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
731 if (nr == 1 || nc == 1)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
732 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
733 npts = (nr > nc ? nr : nc);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
734 nsamples = 1;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
735 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
736 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
737 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
738 npts = nr;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
739 nsamples = nc;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
740 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
741
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29902
diff changeset
742 const float *in (data ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
743 FloatComplex *out (retval.fortran_vec ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
744
23058
5839d16828cb move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22988
diff changeset
745 octave::fftw::fft (in, out, npts, nsamples);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
746
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
747 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
748 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
749
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
750 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
751 FloatMatrix::ifourier (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
752 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
753 std::size_t nr = rows ();
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
754 std::size_t nc = cols ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
755
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
756 FloatComplexMatrix retval (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
757
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
758 std::size_t npts, nsamples;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
759
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
760 if (nr == 1 || nc == 1)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
761 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
762 npts = (nr > nc ? nr : nc);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
763 nsamples = 1;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
764 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
765 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
766 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
767 npts = nr;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
768 nsamples = nc;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
769 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
770
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
771 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
772 FloatComplex *in (tmp.fortran_vec ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
773 FloatComplex *out (retval.fortran_vec ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
774
23058
5839d16828cb move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22988
diff changeset
775 octave::fftw::ifft (in, out, npts, nsamples);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
776
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
777 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
778 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
779
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
780 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
781 FloatMatrix::fourier2d (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
782 {
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19864
diff changeset
783 dim_vector dv (rows (), cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
784
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29902
diff changeset
785 const float *in = data ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
786 FloatComplexMatrix retval (rows (), cols ());
23058
5839d16828cb move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22988
diff changeset
787 octave::fftw::fftNd (in, retval.fortran_vec (), 2, dv);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
788
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
789 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
790 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
791
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
792 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
793 FloatMatrix::ifourier2d (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
794 {
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19864
diff changeset
795 dim_vector dv (rows (), cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
796
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
797 FloatComplexMatrix retval (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
798 FloatComplex *out (retval.fortran_vec ());
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
799
23058
5839d16828cb move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22988
diff changeset
800 octave::fftw::ifftNd (out, out, 2, dv);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
801
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
802 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
803 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
804
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
805 #else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
806
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
807 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
808 FloatMatrix::fourier (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
809 {
25586
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
810 (*current_liboctave_error_handler)
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
811 ("support for FFTW was unavailable or disabled when liboctave was built");
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
812
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
813 return FloatComplexMatrix ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
814 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
815
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
816 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
817 FloatMatrix::ifourier (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
818 {
25586
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
819 (*current_liboctave_error_handler)
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
820 ("support for FFTW was unavailable or disabled when liboctave was built");
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
821
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
822 return FloatComplexMatrix ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
823 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
824
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
825 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
826 FloatMatrix::fourier2d (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
827 {
25586
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
828 (*current_liboctave_error_handler)
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
829 ("support for FFTW was unavailable or disabled when liboctave was built");
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
830
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
831 return FloatComplexMatrix ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
832 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
833
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
834 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
835 FloatMatrix::ifourier2d (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
836 {
25586
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
837 (*current_liboctave_error_handler)
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
838 ("support for FFTW was unavailable or disabled when liboctave was built");
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
839
59f4fda5c548 remove fftpack sources
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
840 return FloatComplexMatrix ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
841 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
842
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
843 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
844
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
845 FloatDET
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
846 FloatMatrix::determinant (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
847 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
848 octave_idx_type info;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
849 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
850 return determinant (info, rcon, 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
851 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
852
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
853 FloatDET
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
854 FloatMatrix::determinant (octave_idx_type& info) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
855 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
856 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
857 return determinant (info, rcon, 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
858 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
859
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
860 FloatDET
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
861 FloatMatrix::determinant (octave_idx_type& info, float& rcon,
21719
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
862 bool calc_cond) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
863 {
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
864 MatrixType mattype (*this);
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
865 return determinant (mattype, info, rcon, calc_cond);
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
866 }
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
867
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
868 FloatDET
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
869 FloatMatrix::determinant (MatrixType& mattype,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
870 octave_idx_type& info, float& rcon,
21719
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
871 bool calc_cond) const
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
872 {
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
873 FloatDET retval (1.0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
874
13828
f1b023fd098d always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents: 13756
diff changeset
875 info = 0;
f1b023fd098d always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents: 13756
diff changeset
876 rcon = 0.0;
f1b023fd098d always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents: 13756
diff changeset
877
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
878 F77_INT nr = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
879 F77_INT nc = octave::to_f77_int (cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
880
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
881 if (nr != nc)
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
882 (*current_liboctave_error_handler) ("matrix must be square");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
883
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
884 volatile int typ = mattype.type ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
885
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
886 // Even though the matrix is marked as singular (Rectangular), we may
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
887 // still get a useful number from the LU factorization, because it always
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
888 // completes.
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
889
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
890 if (typ == MatrixType::Unknown)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
891 typ = mattype.type (*this);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
892 else if (typ == MatrixType::Rectangular)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
893 typ = MatrixType::Full;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
894
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
895 if (typ == MatrixType::Lower || typ == MatrixType::Upper)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
896 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
897 for (F77_INT i = 0; i < nc; i++)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
898 retval *= elem (i,i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
899 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
900 else if (typ == MatrixType::Hermitian)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
901 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
902 FloatMatrix atmp = *this;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
903 float *tmp_data = atmp.fortran_vec ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
904
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
905 // Calculate the norm of the matrix for later use when determining rcon.
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
906 float anorm;
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
907 if (calc_cond)
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
908 anorm = norm1 (*this);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
909
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
910 F77_INT tmp_info = 0;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
911
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
912 char job = 'L';
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
913 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
914 tmp_data, nr, tmp_info
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
915 F77_CHAR_ARG_LEN (1)));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
916
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
917 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
918
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
919 if (info != 0)
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
920 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
921 rcon = 0.0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
922 mattype.mark_as_unsymmetric ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
923 typ = MatrixType::Full;
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
924 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
925 else
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
926 {
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
927 if (calc_cond)
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
928 {
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
929 Array<float> z (dim_vector (3 * nc, 1));
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
930 float *pz = z.fortran_vec ();
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
931 Array<F77_INT> iz (dim_vector (nc, 1));
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
932 F77_INT *piz = iz.fortran_vec ();
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
933
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
934 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
935 nr, tmp_data, nr, anorm,
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
936 rcon, pz, piz, tmp_info
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
937 F77_CHAR_ARG_LEN (1)));
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
938
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
939 info = tmp_info;
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
940
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
941 if (info != 0)
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
942 rcon = 0.0;
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
943 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
944
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
945 for (F77_INT i = 0; i < nc; i++)
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
946 retval *= atmp(i,i);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
947
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
948 retval = retval.square ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
949 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
950 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
951 else if (typ != MatrixType::Full)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
952 (*current_liboctave_error_handler) ("det: invalid dense matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
953
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
954 if (typ == MatrixType::Full)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
955 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
956 Array<F77_INT> ipvt (dim_vector (nr, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
957 F77_INT *pipvt = ipvt.fortran_vec ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
958
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
959 FloatMatrix atmp = *this;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
960 float *tmp_data = atmp.fortran_vec ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
961
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
962 info = 0;
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
963 F77_INT tmp_info = 0;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
964
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
965 // Calculate the norm of the matrix for later use when determining rcon.
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
966 float anorm;
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
967 if (calc_cond)
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
968 anorm = norm1 (*this);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
969
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
970 F77_XFCN (sgetrf, SGETRF, (nr, nr, tmp_data, nr, pipvt, tmp_info));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
972 info = tmp_info;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
973
24291
cf33c1b910b7 maint: Correct typo in comment "Throw-away" => "Throw away"
Rik <rik@octave.org>
parents: 24251
diff changeset
974 // Throw away extra info LAPACK gives so as to not change output.
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
975 rcon = 0.0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
976 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
977 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
978 info = -1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
979 retval = FloatDET ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
980 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
981 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
982 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
983 if (calc_cond)
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
984 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
985 // Now calc the condition number for non-singular matrix.
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
986 char job = '1';
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
987 Array<float> z (dim_vector (4 * nc, 1));
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
988 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
989 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
990 F77_INT *piz = iz.fortran_vec ();
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
991
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
992 F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
993 nc, tmp_data, nr, anorm,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
994 rcon, pz, piz, tmp_info
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
995 F77_CHAR_ARG_LEN (1)));
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
996
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
997 info = tmp_info;
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
998 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
999
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1000 if (info != 0)
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
1001 {
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
1002 info = -1;
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
1003 retval = FloatDET ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1004 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1005 else
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
1006 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1007 for (F77_INT i = 0; i < nc; i++)
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
1008 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1009 float c = atmp(i,i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1010 retval *= (ipvt(i) != (i+1)) ? -c : c;
8336
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
1011 }
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
1012 }
9813c07ca946 make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
1013 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1014 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1015
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1016 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1017 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1018
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1019 float
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1020 FloatMatrix::rcond (void) const
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1021 {
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1022 MatrixType mattype (*this);
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1023 return rcond (mattype);
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1024 }
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1025
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1026 float
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1027 FloatMatrix::rcond (MatrixType& mattype) const
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1028 {
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
1029 float rcon = octave::numeric_limits<float>::NaN ();
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1030 F77_INT nr = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1031 F77_INT nc = octave::to_f77_int (cols ());
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1032
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1033 if (nr != nc)
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1034 (*current_liboctave_error_handler) ("matrix must be square");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1035
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1036 if (nr == 0 || nc == 0)
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
1037 rcon = octave::numeric_limits<float>::Inf ();
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1038 else
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1039 {
16300
23c5f90f92cd eliminate some variable might be clobbered by 'longjmp' or 'vfork' warnings
John W. Eaton <jwe@octave.org>
parents: 15448
diff changeset
1040 volatile int typ = mattype.type ();
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1041
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1042 if (typ == MatrixType::Unknown)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1043 typ = mattype.type (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1044
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1045 // Only calculate the condition number for LU/Cholesky
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1046 if (typ == MatrixType::Upper)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1047 {
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29902
diff changeset
1048 const float *tmp_data = data ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1049 F77_INT info = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1050 char norm = '1';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1051 char uplo = 'U';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1052 char dia = 'N';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1053
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1054 Array<float> z (dim_vector (3 * nc, 1));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1055 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1056 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1057 F77_INT *piz = iz.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1058
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1059 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&norm, 1),
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1060 F77_CONST_CHAR_ARG2 (&uplo, 1),
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1061 F77_CONST_CHAR_ARG2 (&dia, 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1062 nr, tmp_data, nr, rcon,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1063 pz, piz, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1064 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1065 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1066 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1067
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1068 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1069 rcon = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1070 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1071 else if (typ == MatrixType::Permuted_Upper)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1072 (*current_liboctave_error_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1073 ("permuted triangular matrix not implemented");
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1074 else if (typ == MatrixType::Lower)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1075 {
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29902
diff changeset
1076 const float *tmp_data = data ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1077 F77_INT info = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1078 char norm = '1';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1079 char uplo = 'L';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1080 char dia = 'N';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1081
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1082 Array<float> z (dim_vector (3 * nc, 1));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1083 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1084 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1085 F77_INT *piz = iz.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1086
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1087 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&norm, 1),
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1088 F77_CONST_CHAR_ARG2 (&uplo, 1),
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1089 F77_CONST_CHAR_ARG2 (&dia, 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1090 nr, tmp_data, nr, rcon,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1091 pz, piz, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1092 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1093 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1094 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1095
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1096 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1097 rcon = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1098 }
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1099 else if (typ == MatrixType::Permuted_Lower)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1100 (*current_liboctave_error_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1101 ("permuted triangular matrix not implemented");
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1102 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1103 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1104 float anorm = -1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1105
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1106 if (typ == MatrixType::Hermitian)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1107 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1108 F77_INT info = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1109 char job = 'L';
15382
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1110
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1111 FloatMatrix atmp = *this;
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1112 float *tmp_data = atmp.fortran_vec ();
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1113
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
1114 anorm = norm1 (atmp);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1115
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1116 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1117 tmp_data, nr, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1118 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1119
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1120 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1121 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1122 rcon = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1123 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1124 typ = MatrixType::Full;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1125 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1126 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1127 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1128 Array<float> z (dim_vector (3 * nc, 1));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1129 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1130 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1131 F77_INT *piz = iz.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1132
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1133 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1134 nr, tmp_data, nr, anorm,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1135 rcon, pz, piz, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1136 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1137
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1138 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1139 rcon = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1140 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1141 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1142
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1143 if (typ == MatrixType::Full)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1144 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1145 F77_INT info = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1146
15382
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1147 FloatMatrix atmp = *this;
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1148 float *tmp_data = atmp.fortran_vec ();
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1149
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1150 Array<F77_INT> ipvt (dim_vector (nr, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1151 F77_INT *pipvt = ipvt.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1152
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1153 if (anorm < 0.0)
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
1154 anorm = norm1 (atmp);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1155
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1156 Array<float> z (dim_vector (4 * nc, 1));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1157 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1158 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1159 F77_INT *piz = iz.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1160
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1161 F77_XFCN (sgetrf, SGETRF, (nr, nr, tmp_data, nr, pipvt, info));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1162
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1163 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1164 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1165 rcon = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1166 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1167 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1168 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1169 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1170 char job = '1';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1171 F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1172 nc, tmp_data, nr, anorm,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1173 rcon, pz, piz, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1174 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1175
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1176 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1177 rcon = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1178 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1179 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1180 }
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1181 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1182 rcon = 0.0;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1183 }
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1184
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1185 return rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1186 }
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1187
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1188 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1189 FloatMatrix::utsolve (MatrixType& mattype, const FloatMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1190 octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1191 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1192 bool calc_cond, blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1193 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1194 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1195
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1196 F77_INT nr = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1197 F77_INT nc = octave::to_f77_int (cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1198
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1199 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1200 F77_INT b_nc = octave::to_f77_int (b.cols ());
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1201
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1202 if (nr != b_nr)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1203 (*current_liboctave_error_handler)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1204 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1205
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1206 if (nr == 0 || nc == 0 || b_nc == 0)
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1207 retval = FloatMatrix (nc, b_nc, 0.0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1208 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1209 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1210 volatile int typ = mattype.type ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1211
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1212 if (typ == MatrixType::Permuted_Upper || typ == MatrixType::Upper)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1213 {
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1214 rcon = 1.0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1215 info = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1216
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1217 if (typ == MatrixType::Permuted_Upper)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1218 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1219 ("permuted triangular matrix not implemented");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1220 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1221 {
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29902
diff changeset
1222 const float *tmp_data = data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1223
19446
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1224 retval = b;
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1225 float *result = retval.fortran_vec ();
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1226
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1227 char uplo = 'U';
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1228 char trans = get_blas_char (transt);
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1229 char dia = 'N';
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1230
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1231 F77_INT tmp_info = 0;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1232
19446
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1233 F77_XFCN (strtrs, STRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1),
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1234 F77_CONST_CHAR_ARG2 (&trans, 1),
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1235 F77_CONST_CHAR_ARG2 (&dia, 1),
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1236 nr, b_nc, tmp_data, nr,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1237 result, nr, tmp_info
19446
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1238 F77_CHAR_ARG_LEN (1)
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1239 F77_CHAR_ARG_LEN (1)
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1240 F77_CHAR_ARG_LEN (1)));
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1241
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1242 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1243
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1244 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1245 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1246 char norm = '1';
19457
cb35d695713c avoid shadowed variable warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19446
diff changeset
1247 uplo = 'U';
cb35d695713c avoid shadowed variable warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19446
diff changeset
1248 dia = 'N';
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1249
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1250 Array<float> z (dim_vector (3 * nc, 1));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1251 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1252 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1253 F77_INT *piz = iz.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1254
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1255 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&norm, 1),
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1256 F77_CONST_CHAR_ARG2 (&uplo, 1),
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1257 F77_CONST_CHAR_ARG2 (&dia, 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1258 nr, tmp_data, nr, rcon,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1259 pz, piz, tmp_info
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1260 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1261 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1262 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1263
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1264 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1265
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1266 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1267 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1268
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1269 volatile float rcond_plus_one = rcon + 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1270
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1271 if (rcond_plus_one == 1.0 || octave::math::isnan (rcon))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1272 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1273 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1274
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1275 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1276 sing_handler (rcon);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1277 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1278 octave::warn_singular_matrix (rcon);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1279 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1280 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1281
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1282 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1283 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1284 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1285 (*current_liboctave_error_handler) ("incorrect matrix type");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1286 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1287
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1288 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1289 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1290
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1291 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1292 FloatMatrix::ltsolve (MatrixType& mattype, const FloatMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1293 octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1294 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1295 bool calc_cond, blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1296 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1297 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1298
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1299 F77_INT nr = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1300 F77_INT nc = octave::to_f77_int (cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1301
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1302 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1303 F77_INT b_nc = octave::to_f77_int (b.cols ());
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1304
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1305 if (nr != b_nr)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1306 (*current_liboctave_error_handler)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1307 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1308
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1309 if (nr == 0 || nc == 0 || b_nc == 0)
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1310 retval = FloatMatrix (nc, b_nc, 0.0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1311 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1312 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1313 volatile int typ = mattype.type ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1314
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
1315 if (typ == MatrixType::Permuted_Lower || typ == MatrixType::Lower)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1316 {
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1317 rcon = 1.0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1318 info = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1319
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1320 if (typ == MatrixType::Permuted_Lower)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1321 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1322 ("permuted triangular matrix not implemented");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1323 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1324 {
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29902
diff changeset
1325 const float *tmp_data = data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1326
19446
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1327 retval = b;
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1328 float *result = retval.fortran_vec ();
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1329
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1330 char uplo = 'L';
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1331 char trans = get_blas_char (transt);
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1332 char dia = 'N';
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1333
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1334 F77_INT tmp_info = 0;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1335
19446
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1336 F77_XFCN (strtrs, STRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1),
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1337 F77_CONST_CHAR_ARG2 (&trans, 1),
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1338 F77_CONST_CHAR_ARG2 (&dia, 1),
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1339 nr, b_nc, tmp_data, nr,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1340 result, nr, tmp_info
19446
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1341 F77_CHAR_ARG_LEN (1)
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1342 F77_CHAR_ARG_LEN (1)
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1343 F77_CHAR_ARG_LEN (1)));
0b4915fcd2eb don't skip solution of singular upper/lower triangular systems
John W. Eaton <jwe@octave.org>
parents: 19434
diff changeset
1344
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1345 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1346
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1347 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1348 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1349 char norm = '1';
19457
cb35d695713c avoid shadowed variable warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19446
diff changeset
1350 uplo = 'L';
cb35d695713c avoid shadowed variable warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19446
diff changeset
1351 dia = 'N';
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1352
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1353 Array<float> z (dim_vector (3 * nc, 1));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1354 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1355 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1356 F77_INT *piz = iz.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1357
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1358 F77_XFCN (strcon, STRCON, (F77_CONST_CHAR_ARG2 (&norm, 1),
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1359 F77_CONST_CHAR_ARG2 (&uplo, 1),
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1360 F77_CONST_CHAR_ARG2 (&dia, 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1361 nr, tmp_data, nr, rcon,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1362 pz, piz, tmp_info
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1363 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1364 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1365 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1366
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1367 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1368
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1369 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1370 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1371
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1372 volatile float rcond_plus_one = rcon + 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1373
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1374 if (rcond_plus_one == 1.0 || octave::math::isnan (rcon))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1375 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1376 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1377
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1378 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1379 sing_handler (rcon);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1380 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1381 octave::warn_singular_matrix (rcon);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1382 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1383 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1384 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1385 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1386 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1387 (*current_liboctave_error_handler) ("incorrect matrix type");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1388 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1389
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1390 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1391 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1392
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1393 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1394 FloatMatrix::fsolve (MatrixType& mattype, const FloatMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1395 octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1396 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1397 bool calc_cond) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1398 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1399 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1400
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1401 F77_INT nr = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1402 F77_INT nc = octave::to_f77_int (cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1403
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1404 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1405 F77_INT b_nc = octave::to_f77_int (b.cols ());
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1406
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1407 if (nr != nc || nr != b_nr)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1408 (*current_liboctave_error_handler)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1409 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1410
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1411 if (nr == 0 || b_nc == 0)
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1412 retval = FloatMatrix (nc, b_nc, 0.0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1413 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1414 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1415 volatile int typ = mattype.type ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1416
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1417 // Calculate the norm of the matrix for later use when determining rcon.
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1418 float anorm = -1.0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1419
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1420 if (typ == MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1421 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1422 info = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1423 char job = 'L';
15382
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1424
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1425 FloatMatrix atmp = *this;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1426 float *tmp_data = atmp.fortran_vec ();
15382
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1427
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1428 // The norm of the matrix for later use when determining rcon.
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1429 if (calc_cond)
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1430 anorm = norm1 (atmp);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1431
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1432 F77_INT tmp_info = 0;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1433
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1434 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1435 tmp_data, nr, tmp_info
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1436 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1437
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1438 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1439
24291
cf33c1b910b7 maint: Correct typo in comment "Throw-away" => "Throw away"
Rik <rik@octave.org>
parents: 24251
diff changeset
1440 // Throw away extra info LAPACK gives so as to not change output.
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1441 rcon = 0.0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1442 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1443 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1444 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1445
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1446 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1447 typ = MatrixType::Full;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1448 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1449 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1450 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1451 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1452 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1453 Array<float> z (dim_vector (3 * nc, 1));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1454 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1455 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1456 F77_INT *piz = iz.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1457
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1458 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (&job, 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1459 nr, tmp_data, nr, anorm,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1460 rcon, pz, piz, tmp_info
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1461 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1462
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1463 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1464
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1465 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1466 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1467
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1468 volatile float rcond_plus_one = rcon + 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1469
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1470 if (rcond_plus_one == 1.0 || octave::math::isnan (rcon))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1471 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1472 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1473
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1474 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1475 sing_handler (rcon);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1476 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1477 octave::warn_singular_matrix (rcon);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1478 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1479 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1480
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1481 if (info == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1482 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1483 retval = b;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1484 float *result = retval.fortran_vec ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1485
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1486 F77_XFCN (spotrs, SPOTRS, (F77_CONST_CHAR_ARG2 (&job, 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1487 nr, b_nc, tmp_data, nr,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1488 result, b_nr, tmp_info
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1489 F77_CHAR_ARG_LEN (1)));
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1490
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1491 info = tmp_info;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1492 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1493 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1494 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1495 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1496 typ = MatrixType::Full;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1497 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1498 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1499 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1500
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1501 if (typ == MatrixType::Full)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1502 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1503 info = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1504
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1505 Array<F77_INT> ipvt (dim_vector (nr, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1506 F77_INT *pipvt = ipvt.fortran_vec ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1507
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1508 FloatMatrix atmp = *this;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1509 float *tmp_data = atmp.fortran_vec ();
15382
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1510
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1511 if (calc_cond && anorm < 0.0)
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
1512 anorm = norm1 (atmp);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1513
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1514 Array<float> z (dim_vector (4 * nc, 1));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1515 float *pz = z.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1516 Array<F77_INT> iz (dim_vector (nc, 1));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1517 F77_INT *piz = iz.fortran_vec ();
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1518
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1519 F77_INT tmp_info = 0;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1520
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1521 F77_XFCN (sgetrf, SGETRF, (nr, nr, tmp_data, nr, pipvt, tmp_info));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1522
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1523 info = tmp_info;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1524
24291
cf33c1b910b7 maint: Correct typo in comment "Throw-away" => "Throw away"
Rik <rik@octave.org>
parents: 24251
diff changeset
1525 // Throw away extra info LAPACK gives so as to not change output.
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1526 rcon = 0.0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1527 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1528 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1529 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1530
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1531 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1532 sing_handler (rcon);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1533 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1534 octave::warn_singular_matrix ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1535
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1536 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1537 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1538 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1539 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1540 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1541 {
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1542 // Calculate the condition number for non-singular matrix.
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1543 char job = '1';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1544 F77_XFCN (sgecon, SGECON, (F77_CONST_CHAR_ARG2 (&job, 1),
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1545 nc, tmp_data, nr, anorm,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1546 rcon, pz, piz, tmp_info
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1547 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1548
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1549 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1550
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1551 if (info != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1552 info = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1553
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1554 volatile float rcond_plus_one = rcon + 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1555
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1556 if (rcond_plus_one == 1.0 || octave::math::isnan (rcon))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1557 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1558 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1559 sing_handler (rcon);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1560 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1561 octave::warn_singular_matrix (rcon);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1562 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1563 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1564
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1565 if (info == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1566 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1567 retval = b;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1568 float *result = retval.fortran_vec ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1569
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1570 char job = 'N';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1571 F77_XFCN (sgetrs, SGETRS, (F77_CONST_CHAR_ARG2 (&job, 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1572 nr, b_nc, tmp_data, nr,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1573 pipvt, result, b_nr, tmp_info
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1574 F77_CHAR_ARG_LEN (1)));
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1575
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1576 info = tmp_info;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1577 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1578 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1579 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1580 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1581 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1582 else if (typ != MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1583 (*current_liboctave_error_handler) ("incorrect matrix type");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1584 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1585
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1586 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1587 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1588
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1589 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1590 FloatMatrix::solve (MatrixType& mattype, const FloatMatrix& b) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1591 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1592 octave_idx_type info;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1593 float rcon;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1594 return solve (mattype, b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1595 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1596
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1597 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1598 FloatMatrix::solve (MatrixType& mattype, const FloatMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1599 octave_idx_type& info) const
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1600 {
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1601 float rcon;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1602 return solve (mattype, b, info, rcon, nullptr);
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1603 }
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1604
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1605 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1606 FloatMatrix::solve (MatrixType& mattype, const FloatMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1607 octave_idx_type& info, float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1608 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1609 return solve (mattype, b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1610 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1611
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1612 FloatMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1613 FloatMatrix::solve (MatrixType& mattype, const FloatMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1614 octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1615 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1616 bool singular_fallback, blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1617 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1618 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1619 int typ = mattype.type ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1620
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1621 if (typ == MatrixType::Unknown)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1622 typ = mattype.type (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1623
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1624 // Only calculate the condition number for LU/Cholesky
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1625 if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper)
19434
aee5fea8a03e compute condition number when solving triangular systems (bug #43875)
John W. Eaton <jwe@octave.org>
parents: 19408
diff changeset
1626 retval = utsolve (mattype, b, info, rcon, sing_handler, true, transt);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1627 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower)
19434
aee5fea8a03e compute condition number when solving triangular systems (bug #43875)
John W. Eaton <jwe@octave.org>
parents: 19408
diff changeset
1628 retval = ltsolve (mattype, b, info, rcon, sing_handler, true, transt);
9661
afcf852256d2 optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
1629 else if (transt == blas_trans || transt == blas_conj_trans)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1630 return transpose ().solve (mattype, b, info, rcon, sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1631 singular_fallback);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1632 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian)
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1633 retval = fsolve (mattype, b, info, rcon, sing_handler, true);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1634 else if (typ != MatrixType::Rectangular)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1635 (*current_liboctave_error_handler) ("unknown matrix type");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1636
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1637 // Rectangular or one of the above solvers flags a singular matrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1638 if (singular_fallback && mattype.type () == MatrixType::Rectangular)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1639 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1640 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1641 retval = lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1642 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1643
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1644 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1645 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1646
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1647 FloatComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1648 FloatMatrix::solve (MatrixType& mattype, const FloatComplexMatrix& b) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1649 {
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1650 octave_idx_type info;
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1651 float rcon;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1652 return solve (mattype, b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1653 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1654
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1655 FloatComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1656 FloatMatrix::solve (MatrixType& mattype, const FloatComplexMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1657 octave_idx_type& info) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1658 {
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1659 float rcon;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1660 return solve (mattype, b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1661 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1662
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1663 FloatComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1664 FloatMatrix::solve (MatrixType& mattype, const FloatComplexMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1665 octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1666 float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1667 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1668 return solve (mattype, b, info, rcon, nullptr);
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1669 }
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1670
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1671 static FloatMatrix
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1672 stack_complex_matrix (const FloatComplexMatrix& cm)
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1673 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
1674 octave_idx_type m = cm.rows ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
1675 octave_idx_type n = cm.cols ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
1676 octave_idx_type nel = m*n;
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1677 FloatMatrix retval (m, 2*n);
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1678 const FloatComplex *cmd = cm.data ();
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1679 float *rd = retval.fortran_vec ();
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1680 for (octave_idx_type i = 0; i < nel; i++)
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1681 {
23708
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23596
diff changeset
1682 rd[i] = std::real (cmd[i]);
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23596
diff changeset
1683 rd[nel+i] = std::imag (cmd[i]);
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1684 }
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1685 return retval;
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1686 }
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1687
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1688 static FloatComplexMatrix
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1689 unstack_complex_matrix (const FloatMatrix& sm)
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1690 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
1691 octave_idx_type m = sm.rows ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
1692 octave_idx_type n = sm.cols () / 2;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
1693 octave_idx_type nel = m*n;
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1694 FloatComplexMatrix retval (m, n);
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1695 const float *smd = sm.data ();
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1696 FloatComplex *rd = retval.fortran_vec ();
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1697 for (octave_idx_type i = 0; i < nel; i++)
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1698 rd[i] = FloatComplex (smd[i], smd[nel+i]);
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1699 return retval;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1700 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1701
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1702 FloatComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1703 FloatMatrix::solve (MatrixType& mattype, const FloatComplexMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1704 octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1705 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1706 bool singular_fallback, blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1707 {
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1708 FloatMatrix tmp = stack_complex_matrix (b);
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1709 tmp = solve (mattype, tmp, info, rcon, sing_handler, singular_fallback,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1710 transt);
9662
0d3b248f4ab6 further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents: 9661
diff changeset
1711 return unstack_complex_matrix (tmp);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1712 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1713
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1714 FloatColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1715 FloatMatrix::solve (MatrixType& mattype, const FloatColumnVector& b) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1716 {
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1717 octave_idx_type info;
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1718 float rcon;
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1719 return solve (mattype, b, info, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1720 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1721
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1722 FloatColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1723 FloatMatrix::solve (MatrixType& mattype, const FloatColumnVector& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1724 octave_idx_type& info) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1725 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1726 float rcon;
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1727 return solve (mattype, b, info, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1728 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1729
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1730 FloatColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1731 FloatMatrix::solve (MatrixType& mattype, const FloatColumnVector& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1732 octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1733 float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1734 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1735 return solve (mattype, b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1736 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1737
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1738 FloatColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1739 FloatMatrix::solve (MatrixType& mattype, const FloatColumnVector& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1740 octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1741 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1742 blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1743 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1744 FloatMatrix tmp (b);
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1745 tmp = solve (mattype, tmp, info, rcon, sing_handler, true, transt);
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1746 return tmp.column (static_cast<octave_idx_type> (0));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1747 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1748
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1749 FloatComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1750 FloatMatrix::solve (MatrixType& mattype,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1751 const FloatComplexColumnVector& b) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1752 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1753 FloatComplexMatrix tmp (*this);
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1754 return tmp.solve (mattype, b);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1755 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1756
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1757 FloatComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1758 FloatMatrix::solve (MatrixType& mattype, const FloatComplexColumnVector& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1759 octave_idx_type& info) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1760 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1761 FloatComplexMatrix tmp (*this);
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1762 return tmp.solve (mattype, b, info);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1763 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1764
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1765 FloatComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1766 FloatMatrix::solve (MatrixType& mattype, const FloatComplexColumnVector& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1767 octave_idx_type& info, float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1768 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1769 FloatComplexMatrix tmp (*this);
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1770 return tmp.solve (mattype, b, info, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1771 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1772
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1773 FloatComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1774 FloatMatrix::solve (MatrixType& mattype, const FloatComplexColumnVector& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1775 octave_idx_type& info, float& rcon,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1776 solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1777 blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1778 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1779 FloatComplexMatrix tmp (*this);
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1780 return tmp.solve (mattype, b, info, rcon, sing_handler, transt);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1781 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1782
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1783 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1784 FloatMatrix::solve (const FloatMatrix& b) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1785 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1786 octave_idx_type info;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1787 float rcon;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1788 return solve (b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1789 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1790
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1791 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1792 FloatMatrix::solve (const FloatMatrix& b, octave_idx_type& info) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1793 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1794 float rcon;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1795 return solve (b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1796 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1797
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1798 FloatMatrix
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1799 FloatMatrix::solve (const FloatMatrix& b, octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1800 float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1801 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1802 return solve (b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1803 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1804
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1805 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1806 FloatMatrix::solve (const FloatMatrix& b, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1807 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1808 blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1809 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1810 MatrixType mattype (*this);
9661
afcf852256d2 optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
1811 return solve (mattype, b, info, rcon, sing_handler, true, transt);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1812 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1813
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1814 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1815 FloatMatrix::solve (const FloatComplexMatrix& b) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1816 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1817 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1818 return tmp.solve (b);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1819 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1820
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1821 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1822 FloatMatrix::solve (const FloatComplexMatrix& b, octave_idx_type& info) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1823 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1824 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1825 return tmp.solve (b, info);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1826 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1827
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1828 FloatComplexMatrix
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1829 FloatMatrix::solve (const FloatComplexMatrix& b, octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1830 float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1831 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1832 FloatComplexMatrix tmp (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1833 return tmp.solve (b, info, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1834 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1835
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1836 FloatComplexMatrix
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1837 FloatMatrix::solve (const FloatComplexMatrix& b, octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1838 float& rcon,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1839 solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1840 blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1841 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1842 FloatComplexMatrix tmp (*this);
9661
afcf852256d2 optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
1843 return tmp.solve (b, info, rcon, sing_handler, transt);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1844 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1845
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1846 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1847 FloatMatrix::solve (const FloatColumnVector& b) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1848 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1849 octave_idx_type info; float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1850 return solve (b, info, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1851 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1852
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1853 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1854 FloatMatrix::solve (const FloatColumnVector& b, octave_idx_type& info) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1855 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1856 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1857 return solve (b, info, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1858 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1859
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1860 FloatColumnVector
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1861 FloatMatrix::solve (const FloatColumnVector& b, octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1862 float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1863 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
1864 return solve (b, info, rcon, nullptr);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1865 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1866
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1867 FloatColumnVector
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1868 FloatMatrix::solve (const FloatColumnVector& b, octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1869 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1870 blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1871 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1872 MatrixType mattype (*this);
9661
afcf852256d2 optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
1873 return solve (mattype, b, info, rcon, sing_handler, transt);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1874 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1875
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1876 FloatComplexColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1877 FloatMatrix::solve (const FloatComplexColumnVector& b) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1878 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1879 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1880 return tmp.solve (b);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1881 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1882
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1883 FloatComplexColumnVector
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1884 FloatMatrix::solve (const FloatComplexColumnVector& b,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1885 octave_idx_type& info) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1886 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1887 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1888 return tmp.solve (b, info);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1889 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1890
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1891 FloatComplexColumnVector
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1892 FloatMatrix::solve (const FloatComplexColumnVector& b, octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1893 float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1894 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1895 FloatComplexMatrix tmp (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1896 return tmp.solve (b, info, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1897 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1898
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1899 FloatComplexColumnVector
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1900 FloatMatrix::solve (const FloatComplexColumnVector& b, octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1901 float& rcon, solve_singularity_handler sing_handler,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1902 blas_trans_type transt) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1903 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1904 FloatComplexMatrix tmp (*this);
9661
afcf852256d2 optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
1905 return tmp.solve (b, info, rcon, sing_handler, transt);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1906 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1907
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1908 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1909 FloatMatrix::lssolve (const FloatMatrix& b) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1910 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1911 octave_idx_type info;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1912 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1913 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1914 return lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1915 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1916
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1917 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1918 FloatMatrix::lssolve (const FloatMatrix& b, octave_idx_type& info) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1919 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1920 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1921 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1922 return lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1923 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1924
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1925 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1926 FloatMatrix::lssolve (const FloatMatrix& b, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1927 octave_idx_type& rank) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1928 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1929 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1930 return lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1931 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1932
24300
117107eed917 Calculate 1-norm of matrices to assess whether NaN or Inf are present (bug #39000).
Rik <rik@octave.org>
parents: 23219
diff changeset
1933
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1934 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1935 FloatMatrix::lssolve (const FloatMatrix& b, octave_idx_type& info,
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
1936 octave_idx_type& rank, float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1937 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1938 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1939
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1940 F77_INT m = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1941 F77_INT n = octave::to_f77_int (cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1942
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1943 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
1944 F77_INT b_nc = octave::to_f77_int (b.cols ());
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
1945 F77_INT nrhs = b_nc; // alias for code readability
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1946
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1947 if (m != b_nr)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1948 (*current_liboctave_error_handler)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1949 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
1950
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1951 if (m == 0 || n == 0 || b_nc == 0)
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1952 retval = FloatMatrix (n, b_nc, 0.0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1953 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1954 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1955 volatile F77_INT minmn = (m < n ? m : n);
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1956 F77_INT maxmn = (m > n ? m : n);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1957 rcon = -1.0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1958 if (m != n)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1959 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1960 retval = FloatMatrix (maxmn, nrhs, 0.0);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1961
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1962 for (F77_INT j = 0; j < nrhs; j++)
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1963 for (F77_INT i = 0; i < m; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1964 retval.elem (i, j) = b.elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1965 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1966 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1967 retval = b;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1968
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1969 FloatMatrix atmp = *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1970 float *tmp_data = atmp.fortran_vec ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1971
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1972 float *pretval = retval.fortran_vec ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1973 Array<float> s (dim_vector (minmn, 1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1974 float *ps = s.fortran_vec ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1975
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1976 // Ask DGELSD what the dimension of WORK should be.
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1977 F77_INT lwork = -1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1978
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1979 Array<float> work (dim_vector (1, 1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1980
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1981 F77_INT smlsiz;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1982 F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("SGELSD", 6),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1983 F77_CONST_CHAR_ARG2 (" ", 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1984 0, 0, 0, 0, smlsiz
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1985 F77_CHAR_ARG_LEN (6)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1986 F77_CHAR_ARG_LEN (1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1987
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
1988 F77_INT mnthr;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1989 F77_FUNC (xilaenv, XILAENV) (6, F77_CONST_CHAR_ARG2 ("SGELSD", 6),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1990 F77_CONST_CHAR_ARG2 (" ", 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1991 m, n, nrhs, -1, mnthr
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1992 F77_CHAR_ARG_LEN (6)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
1993 F77_CHAR_ARG_LEN (1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1994
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1995 // We compute the size of iwork because DGELSD in older versions
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1996 // of LAPACK does not return it on a query call.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1997 float dminmn = static_cast<float> (minmn);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
1998 float dsmlsizp1 = static_cast<float> (smlsiz+1);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1999 float tmp = octave::math::log2 (dminmn / dsmlsizp1);
18847
ff4da3c8ed16 use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
2000
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2001 F77_INT nlvl = static_cast<F77_INT> (tmp) + 1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2002 if (nlvl < 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2003 nlvl = 0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2004
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2005 F77_INT liwork = 3 * minmn * nlvl + 11 * minmn;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2006 if (liwork < 1)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2007 liwork = 1;
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2008 Array<F77_INT> iwork (dim_vector (liwork, 1));
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23443
diff changeset
2009 F77_INT *piwork = iwork.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2010
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2011 F77_INT tmp_info = 0;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2012 F77_INT tmp_rank = 0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2013
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2014 F77_XFCN (sgelsd, SGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2015 ps, rcon, tmp_rank, work.fortran_vec (),
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2016 lwork, piwork, tmp_info));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2017
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2018 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2019 rank = tmp_rank;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2020
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2021 // The workspace query is broken in at least LAPACK 3.0.0
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2022 // through 3.1.1 when n >= mnthr. The obtuse formula below
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2023 // should provide sufficient workspace for DGELSD to operate
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2024 // efficiently.
10813
2c2d4a2f1047 fix workspace bug workaround for xGELSD (since 7486:6a6d2abe51ff)
Jaroslav Hajek <highegg@gmail.com>
parents: 10806
diff changeset
2025 if (n > m && n >= mnthr)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2026 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2027 const F77_INT wlalsd
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2028 = 9*m + 2*m*smlsiz + 8*m*nlvl + m*nrhs + (smlsiz+1)*(smlsiz+1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2029
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2030 F77_INT addend = m;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2031
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2032 if (2*m-4 > addend)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2033 addend = 2*m-4;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2034
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2035 if (nrhs > addend)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2036 addend = nrhs;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2037
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2038 if (n-3*m > addend)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2039 addend = n-3*m;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2040
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2041 if (wlalsd > addend)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2042 addend = wlalsd;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2043
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2044 const F77_INT lworkaround = 4*m + m*m + addend;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2045
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2046 if (work(0) < lworkaround)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2047 work(0) = lworkaround;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2048 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2049 else if (m >= n)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2050 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2051 F77_INT lworkaround
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2052 = 12*n + 2*n*smlsiz + 8*n*nlvl + n*nrhs + (smlsiz+1)*(smlsiz+1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2053
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2054 if (work(0) < lworkaround)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2055 work(0) = lworkaround;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2056 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2057
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2058 lwork = static_cast<F77_INT> (work(0));
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2059 work.resize (dim_vector (lwork, 1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2060
25774
f5ea7511c405 Avoid calculating norm of matrix when not requested in liboctave Matrix classes.
Rik <rik@octave.org>
parents: 25586
diff changeset
2061 float anorm = norm1 (*this);
22598
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2062
24311
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
2063 if (octave::math::isinf (anorm))
22598
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2064 {
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2065 rcon = 0.0;
24311
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
2066 retval = FloatMatrix (n, b_nc, 0.0);
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
2067 }
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
2068 else if (octave::math::isnan (anorm))
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
2069 {
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
2070 rcon = octave::numeric_limits<float>::NaN ();
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
2071 retval = FloatMatrix (n, b_nc,
0643533930e7 Return NaN arrays for left division operator when operands contain NaNs (bug #52516).
Rik <rik@octave.org>
parents: 24301
diff changeset
2072 octave::numeric_limits<float>::NaN ());
22598
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2073 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2074 else
22598
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2075 {
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2076 F77_XFCN (sgelsd, SGELSD, (m, n, nrhs, tmp_data, m, pretval,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2077 maxmn, ps, rcon, tmp_rank,
22598
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2078 work.fortran_vec (), lwork,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2079 piwork, tmp_info));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2080
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2081 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2082 rank = tmp_rank;
22598
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2083
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2084 if (s.elem (0) == 0.0)
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2085 rcon = 0.0;
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2086 else
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2087 rcon = s.elem (minmn - 1) / s.elem (0);
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2088
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2089 retval.resize (n, nrhs);
5aa8f199e328 avoid invalid BLAS calls that then invoke xerbla (bug #39000)
Avinoam Kalma <a.kalma@gmail.com>
parents: 22417
diff changeset
2090 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2091 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2092
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2093 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2094 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2095
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2096 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2097 FloatMatrix::lssolve (const FloatComplexMatrix& b) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2098 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2099 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2100 octave_idx_type info;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2101 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2102 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2103 return tmp.lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2104 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2105
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2106 FloatComplexMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2107 FloatMatrix::lssolve (const FloatComplexMatrix& b, octave_idx_type& info) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2108 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2109 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2110 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2111 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2112 return tmp.lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2113 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2114
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2115 FloatComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2116 FloatMatrix::lssolve (const FloatComplexMatrix& b, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2117 octave_idx_type& rank) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2118 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2119 FloatComplexMatrix tmp (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2120 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2121 return tmp.lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2122 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2123
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2124 FloatComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2125 FloatMatrix::lssolve (const FloatComplexMatrix& b, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2126 octave_idx_type& rank, float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2127 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2128 FloatComplexMatrix tmp (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2129 return tmp.lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2130 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2131
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2132 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2133 FloatMatrix::lssolve (const FloatColumnVector& b) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2134 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2135 octave_idx_type info;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2136 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2137 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2138 return lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2139 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2140
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2141 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2142 FloatMatrix::lssolve (const FloatColumnVector& b, octave_idx_type& info) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2143 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2144 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2145 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2146 return lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2147 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2148
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2149 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2150 FloatMatrix::lssolve (const FloatColumnVector& b, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2151 octave_idx_type& rank) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2152 {
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2153 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2154 return lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2155 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2156
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2157 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2158 FloatMatrix::lssolve (const FloatColumnVector& b, octave_idx_type& info,
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
2159 octave_idx_type& rank, float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2160 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2161 FloatColumnVector retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2162
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2163 F77_INT nrhs = 1;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2164
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2165 F77_INT m = octave::to_f77_int (rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2166 F77_INT n = octave::to_f77_int (cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2167
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
2168 if (m != b.numel ())
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2169 (*current_liboctave_error_handler)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2170 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
2171
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
2172 if (m == 0 || n == 0)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2173 retval = FloatColumnVector (n, 0.0);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2174 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2175 {
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2176 volatile F77_INT minmn = (m < n ? m : n);
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
2177 F77_INT maxmn = (m > n ? m : n);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2178 rcon = -1.0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2179
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2180 if (m != n)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2181 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2182 retval = FloatColumnVector (maxmn, 0.0);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2183
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2184 for (F77_INT i = 0; i < m; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2185 retval.elem (i) = b.elem (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2186 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2187 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2188 retval = b;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2189
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2190 FloatMatrix atmp = *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2191 float *tmp_data = atmp.fortran_vec ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2192
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2193 float *pretval = retval.fortran_vec ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
2194 Array<float> s (dim_vector (minmn, 1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2195 float *ps = s.fortran_vec ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2196
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2197 // Ask DGELSD what the dimension of WORK should be.
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2198 F77_INT lwork = -1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2199
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
2200 Array<float> work (dim_vector (1, 1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2201
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2202 F77_INT smlsiz;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2203 F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("SGELSD", 6),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2204 F77_CONST_CHAR_ARG2 (" ", 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2205 0, 0, 0, 0, smlsiz
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2206 F77_CHAR_ARG_LEN (6)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2207 F77_CHAR_ARG_LEN (1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2208
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2209 // We compute the size of iwork because DGELSD in older versions
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2210 // of LAPACK does not return it on a query call.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2211 float dminmn = static_cast<float> (minmn);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2212 float dsmlsizp1 = static_cast<float> (smlsiz+1);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2213 float tmp = octave::math::log2 (dminmn / dsmlsizp1);
18847
ff4da3c8ed16 use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
2214
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2215 F77_INT nlvl = static_cast<F77_INT> (tmp) + 1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2216 if (nlvl < 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2217 nlvl = 0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2218
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2219 F77_INT liwork = 3 * minmn * nlvl + 11 * minmn;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2220 if (liwork < 1)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2221 liwork = 1;
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2222 Array<F77_INT> iwork (dim_vector (liwork, 1));
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23443
diff changeset
2223 F77_INT *piwork = iwork.fortran_vec ();
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2224
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2225 F77_INT tmp_info = 0;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2226 F77_INT tmp_rank = 0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2227
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2228 F77_XFCN (sgelsd, SGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2229 ps, rcon, tmp_rank, work.fortran_vec (),
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2230 lwork, piwork, tmp_info));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2231
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2232 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2233 rank = tmp_rank;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2234
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2235 lwork = static_cast<F77_INT> (work(0));
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2236 work.resize (dim_vector (lwork, 1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2237
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2238 F77_XFCN (sgelsd, SGELSD, (m, n, nrhs, tmp_data, m, pretval,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2239 maxmn, ps, rcon, tmp_rank,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2240 work.fortran_vec (), lwork,
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2241 piwork, tmp_info));
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2242
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2243 info = tmp_info;
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2244 rank = tmp_rank;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2245
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2246 if (rank < minmn)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2247 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2248 if (s.elem (0) == 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2249 rcon = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2250 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2251 rcon = s.elem (minmn - 1) / s.elem (0);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2252 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2253
22848
a3bd04422a87 don't pass two dimensions to column vector resize method
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
2254 retval.resize (n);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2255 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2256
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2257 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2258 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2259
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2260 FloatComplexColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2261 FloatMatrix::lssolve (const FloatComplexColumnVector& b) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2262 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2263 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2264 octave_idx_type info;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2265 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2266 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2267 return tmp.lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2268 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2269
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2270 FloatComplexColumnVector
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2271 FloatMatrix::lssolve (const FloatComplexColumnVector& b,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2272 octave_idx_type& info) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2273 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2274 FloatComplexMatrix tmp (*this);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2275 octave_idx_type rank;
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2276 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2277 return tmp.lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2278 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2279
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2280 FloatComplexColumnVector
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2281 FloatMatrix::lssolve (const FloatComplexColumnVector& b, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2282 octave_idx_type& rank) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2283 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2284 FloatComplexMatrix tmp (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2285 float rcon;
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2286 return tmp.lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2287 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2288
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2289 FloatComplexColumnVector
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2290 FloatMatrix::lssolve (const FloatComplexColumnVector& b, octave_idx_type& info,
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23220
diff changeset
2291 octave_idx_type& rank, float& rcon) const
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2292 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2293 FloatComplexMatrix tmp (*this);
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
2294 return tmp.lssolve (b, info, rank, rcon);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2295 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2296
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2297 FloatMatrix&
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2298 FloatMatrix::operator += (const FloatDiagMatrix& a)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2299 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2300 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2301 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2302
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2303 octave_idx_type a_nr = a.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2304 octave_idx_type a_nc = a.cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2305
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2306 if (nr != a_nr || nc != a_nc)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2307 octave::err_nonconformant ("operator +=", nr, nc, a_nr, a_nc);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2308
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2309 for (octave_idx_type i = 0; i < a.length (); i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2310 elem (i, i) += a.elem (i, i);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2311
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2312 return *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2313 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2314
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2315 FloatMatrix&
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2316 FloatMatrix::operator -= (const FloatDiagMatrix& a)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2317 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2318 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2319 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2320
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2321 octave_idx_type a_nr = a.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2322 octave_idx_type a_nc = a.cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2323
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2324 if (nr != a_nr || nc != a_nc)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2325 octave::err_nonconformant ("operator -=", nr, nc, a_nr, a_nc);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2326
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2327 for (octave_idx_type i = 0; i < a.length (); i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2328 elem (i, i) -= a.elem (i, i);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2329
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2330 return *this;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2331 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2332
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2333 // column vector by row vector -> matrix operations
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2334
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2335 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2336 operator * (const FloatColumnVector& v, const FloatRowVector& a)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2337 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2338 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2339
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2340 F77_INT len = octave::to_f77_int (v.numel ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2341
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2342 if (len != 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2343 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2344 F77_INT a_len = octave::to_f77_int (a.numel ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2345
9359
be6867ba8104 avoid useless zero initialization when doing matrix multiply
Jaroslav Hajek <highegg@gmail.com>
parents: 9227
diff changeset
2346 retval = FloatMatrix (len, a_len);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2347 float *c = retval.fortran_vec ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2348
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2349 F77_XFCN (sgemm, SGEMM, (F77_CONST_CHAR_ARG2 ("N", 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2350 F77_CONST_CHAR_ARG2 ("N", 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2351 len, a_len, 1, 1.0, v.data (), len,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2352 a.data (), 1, 0.0, c, len
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2353 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2354 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2355 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2356
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2357 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2358 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2359
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2360 // FIXME: Do these really belong here? Maybe they should be in a base class?
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2361
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2362 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2363 FloatMatrix::cumprod (int dim) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2364 {
19321
3746b92739f7 Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents: 19320
diff changeset
2365 return FloatNDArray::cumprod (dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2366 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2367
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2368 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2369 FloatMatrix::cumsum (int dim) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2370 {
19321
3746b92739f7 Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents: 19320
diff changeset
2371 return FloatNDArray::cumsum (dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2372 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2373
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2374 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2375 FloatMatrix::prod (int dim) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2376 {
19321
3746b92739f7 Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents: 19320
diff changeset
2377 return FloatNDArray::prod (dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2378 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2379
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2380 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2381 FloatMatrix::sum (int dim) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2382 {
19321
3746b92739f7 Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents: 19320
diff changeset
2383 return FloatNDArray::sum (dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2384 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2385
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2386 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2387 FloatMatrix::sumsq (int dim) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2388 {
19321
3746b92739f7 Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents: 19320
diff changeset
2389 return FloatNDArray::sumsq (dim);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2390 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2391
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2392 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2393 FloatMatrix::abs (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2394 {
19321
3746b92739f7 Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents: 19320
diff changeset
2395 return FloatNDArray::abs ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2396 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2397
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2398 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2399 FloatMatrix::diag (octave_idx_type k) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2400 {
19321
3746b92739f7 Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents: 19320
diff changeset
2401 return FloatNDArray::diag (k);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2402 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2403
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2404 FloatDiagMatrix
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2405 FloatMatrix::diag (octave_idx_type m, octave_idx_type n) const
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2406 {
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2407 FloatDiagMatrix retval;
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2408
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2409 octave_idx_type nr = rows ();
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2410 octave_idx_type nc = cols ();
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2411
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2412 if (nr == 1 || nc == 1)
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2413 retval = FloatDiagMatrix (*this, m, n);
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2414 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
2415 (*current_liboctave_error_handler) ("diag: expecting vector argument");
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2416
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2417 return retval;
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2418 }
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14427
diff changeset
2419
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2420 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2421 FloatMatrix::row_min (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2422 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2423 Array<octave_idx_type> dummy_idx;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2424 return row_min (dummy_idx);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2425 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2426
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2427 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2428 FloatMatrix::row_min (Array<octave_idx_type>& idx_arg) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2429 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2430 FloatColumnVector result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2431
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2432 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2433 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2434
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2435 if (nr > 0 && nc > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2436 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2437 result.resize (nr);
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2438 idx_arg.resize (dim_vector (nr, 1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2439
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2440 for (octave_idx_type i = 0; i < nr; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2441 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2442 octave_idx_type idx_j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2443
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
2444 float tmp_min = octave::numeric_limits<float>::NaN ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2445
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2446 for (idx_j = 0; idx_j < nc; idx_j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2447 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2448 tmp_min = elem (i, idx_j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2449
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2450 if (! octave::math::isnan (tmp_min))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2451 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2452 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2453
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2454 for (octave_idx_type j = idx_j+1; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2455 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2456 float tmp = elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2457
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2458 if (octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2459 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2460 else if (tmp < tmp_min)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2461 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2462 idx_j = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2463 tmp_min = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2464 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2465 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2466
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2467 result.elem (i) = tmp_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
2468 idx_arg.elem (i) = (octave::math::isnan (tmp_min) ? 0 : idx_j);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2469 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2470 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2471
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2472 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2473 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2474
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2475 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2476 FloatMatrix::row_max (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2477 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2478 Array<octave_idx_type> dummy_idx;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2479 return row_max (dummy_idx);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2480 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2481
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2482 FloatColumnVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2483 FloatMatrix::row_max (Array<octave_idx_type>& idx_arg) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2484 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2485 FloatColumnVector result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2486
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2487 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2488 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2489
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2490 if (nr > 0 && nc > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2491 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2492 result.resize (nr);
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2493 idx_arg.resize (dim_vector (nr, 1));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2494
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2495 for (octave_idx_type i = 0; i < nr; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2496 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2497 octave_idx_type idx_j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2498
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
2499 float tmp_max = octave::numeric_limits<float>::NaN ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2500
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2501 for (idx_j = 0; idx_j < nc; idx_j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2502 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2503 tmp_max = elem (i, idx_j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2504
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2505 if (! octave::math::isnan (tmp_max))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2506 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2507 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2508
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2509 for (octave_idx_type j = idx_j+1; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2510 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2511 float tmp = elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2512
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2513 if (octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2514 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2515 else if (tmp > tmp_max)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2516 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2517 idx_j = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2518 tmp_max = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2519 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2520 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2521
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2522 result.elem (i) = tmp_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
2523 idx_arg.elem (i) = (octave::math::isnan (tmp_max) ? 0 : idx_j);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2524 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2525 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2526
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2527 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2528 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2529
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2530 FloatRowVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2531 FloatMatrix::column_min (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2532 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2533 Array<octave_idx_type> dummy_idx;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2534 return column_min (dummy_idx);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2535 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2536
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2537 FloatRowVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2538 FloatMatrix::column_min (Array<octave_idx_type>& idx_arg) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2539 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2540 FloatRowVector result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2541
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2542 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2543 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2544
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2545 if (nr > 0 && nc > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2546 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2547 result.resize (nc);
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2548 idx_arg.resize (dim_vector (1, nc));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2549
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2550 for (octave_idx_type j = 0; j < nc; j++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2551 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2552 octave_idx_type idx_i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2553
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
2554 float tmp_min = octave::numeric_limits<float>::NaN ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2555
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2556 for (idx_i = 0; idx_i < nr; idx_i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2557 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2558 tmp_min = elem (idx_i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2559
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2560 if (! octave::math::isnan (tmp_min))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2561 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2562 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2563
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2564 for (octave_idx_type i = idx_i+1; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2565 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2566 float tmp = elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2567
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2568 if (octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2569 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2570 else if (tmp < tmp_min)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2571 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2572 idx_i = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2573 tmp_min = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2574 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2575 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2576
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2577 result.elem (j) = tmp_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
2578 idx_arg.elem (j) = (octave::math::isnan (tmp_min) ? 0 : idx_i);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2579 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2580 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2581
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2582 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2583 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2584
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2585 FloatRowVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2586 FloatMatrix::column_max (void) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2587 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2588 Array<octave_idx_type> dummy_idx;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2589 return column_max (dummy_idx);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2590 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2591
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2592 FloatRowVector
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2593 FloatMatrix::column_max (Array<octave_idx_type>& idx_arg) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2594 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2595 FloatRowVector result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2596
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2597 octave_idx_type nr = rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2598 octave_idx_type nc = cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2599
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2600 if (nr > 0 && nc > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2601 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2602 result.resize (nc);
11574
a83bad07f7e3 attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2603 idx_arg.resize (dim_vector (1, nc));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2604
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2605 for (octave_idx_type j = 0; j < nc; j++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2606 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2607 octave_idx_type idx_i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2608
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
2609 float tmp_max = octave::numeric_limits<float>::NaN ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2610
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2611 for (idx_i = 0; idx_i < nr; idx_i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2612 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2613 tmp_max = elem (idx_i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2614
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2615 if (! octave::math::isnan (tmp_max))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2616 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2617 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2618
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2619 for (octave_idx_type i = idx_i+1; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2620 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2621 float tmp = elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2622
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2623 if (octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2624 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2625 else if (tmp > tmp_max)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2626 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2627 idx_i = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2628 tmp_max = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2629 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2630 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2631
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2632 result.elem (j) = tmp_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
2633 idx_arg.elem (j) = (octave::math::isnan (tmp_max) ? 0 : idx_i);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2634 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2635 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2636
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2637 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2638 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2639
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2640 std::ostream&
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2641 operator << (std::ostream& os, const FloatMatrix& a)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2642 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2643 for (octave_idx_type i = 0; i < a.rows (); i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2644 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2645 for (octave_idx_type j = 0; j < a.cols (); j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2646 {
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23795
diff changeset
2647 os << ' ';
28628
83172e1c77f2 refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
2648 octave::write_value<float> (os, a.elem (i, j));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2649 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2650 os << "\n";
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2651 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2652 return os;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2653 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2654
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2655 std::istream&
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2656 operator >> (std::istream& is, FloatMatrix& a)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2657 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2658 octave_idx_type nr = a.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2659 octave_idx_type nc = a.cols ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2660
8999
dc07bc4157b8 allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents: 8956
diff changeset
2661 if (nr > 0 && nc > 0)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2662 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2663 float tmp;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2664 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2665 for (octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2666 {
28628
83172e1c77f2 refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
2667 tmp = octave::read_value<float> (is);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2668 if (is)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2669 a.elem (i, j) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2670 else
21169
40051830f89b maint: Replace more instances of goto in liboctave with other constructs.
Rik <rik@octave.org>
parents: 21136
diff changeset
2671 return is;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2672 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2673 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2674
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2675 return is;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2676 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2677
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2678 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2679 Givens (float x, float y)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2680 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2681 float cc, s, temp_r;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2682
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2683 F77_FUNC (slartg, SLARTG) (x, y, cc, s, temp_r);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2684
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2685 FloatMatrix g (2, 2);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2686
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2687 g.elem (0, 0) = cc;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2688 g.elem (1, 1) = cc;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2689 g.elem (0, 1) = s;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2690 g.elem (1, 0) = -s;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2691
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2692 return g;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2693 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2694
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2695 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2696 Sylvester (const FloatMatrix& a, const FloatMatrix& b, const FloatMatrix& c)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2697 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2698 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2699
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2700 // FIXME: need to check that a, b, and c are all the same size.
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2701
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2702 // Compute Schur decompositions.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2703
22317
6ca3acf5fad8 move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
2704 octave::math::schur<FloatMatrix> as (a, "U");
6ca3acf5fad8 move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
2705 octave::math::schur<FloatMatrix> bs (b, "U");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2706
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2707 // Transform c to new coordinates.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2708
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2709 FloatMatrix ua = as.unitary_matrix ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2710 FloatMatrix sch_a = as.schur_matrix ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2711
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2712 FloatMatrix ub = bs.unitary_matrix ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2713 FloatMatrix sch_b = bs.schur_matrix ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2714
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2715 FloatMatrix cx = ua.transpose () * c * ub;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2716
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2717 // Solve the sylvester equation, back-transform, and return the
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2718 // solution.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2719
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2720 F77_INT a_nr = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2721 F77_INT b_nr = octave::to_f77_int (b.rows ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2722
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2723 float scale;
22971
d244af1d0bc7 use F77_INT instead of octave_idx_type for liboctave Matrix classes
John W. Eaton <jwe@octave.org>
parents: 22849
diff changeset
2724 F77_INT info;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2725
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2726 float *pa = sch_a.fortran_vec ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2727 float *pb = sch_b.fortran_vec ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2728 float *px = cx.fortran_vec ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2729
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2730 F77_XFCN (strsyl, STRSYL, (F77_CONST_CHAR_ARG2 ("N", 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2731 F77_CONST_CHAR_ARG2 ("N", 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2732 1, a_nr, b_nr, pa, a_nr, pb,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2733 b_nr, px, a_nr, scale, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2734 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2735 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2736
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2737 // FIXME: check info?
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2738
19065
d20c81d3cd21 Deprecate syl, add new function sylvester.
Rik <rik@octave.org>
parents: 18850
diff changeset
2739 retval = ua*cx*ub.transpose ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2740
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2741 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2742 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2743
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2744 // matrix by matrix -> matrix operations
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2745
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2746 /*
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2747 ## Simple Dot Product, Matrix-Vector, and Matrix-Matrix Unit tests
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2748 %!assert (single ([1 2 3]) * single ([ 4 ; 5 ; 6]), single (32), 5e-7)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2749 %!assert (single ([1 2 ; 3 4]) * single ([5 ; 6]), single ([17 ; 39]), 5e-7)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2750 %!assert (single ([1 2 ; 3 4]) * single ([5 6 ; 7 8]), single ([19 22; 43 50]), 5e-7)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2751
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2752 ## Test some simple identities
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2753 %!shared M, cv, rv
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2754 %! M = single (randn (10,10));
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2755 %! cv = single (randn (10,1));
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2756 %! rv = single (randn (1,10));
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2757 %!assert ([M*cv,M*cv], M*[cv,cv], 5e-6)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2758 %!assert ([M'*cv,M'*cv], M'*[cv,cv], 5e-6)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2759 %!assert ([rv*M;rv*M], [rv;rv]*M, 5e-6)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2760 %!assert ([rv*M';rv*M'], [rv;rv]*M', 5e-6)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2761 %!assert (2*rv*cv, [rv,rv]*[cv;cv], 5e-6)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2762
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2763 */
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2764
11516
53edbf95fbb6 avoid GCC warnings
John W. Eaton <jwe@octave.org>
parents: 11130
diff changeset
2765 static char
7804
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2766 get_blas_trans_arg (bool trans)
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2767 {
11516
53edbf95fbb6 avoid GCC warnings
John W. Eaton <jwe@octave.org>
parents: 11130
diff changeset
2768 return trans ? 'T' : 'N';
7804
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2769 }
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2770
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2771 // the general GEMM operation
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2772
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2773 FloatMatrix
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2774 xgemm (const FloatMatrix& a, const FloatMatrix& b,
9665
1dba57e9d08d use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents: 9662
diff changeset
2775 blas_trans_type transa, blas_trans_type transb)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2776 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2777 FloatMatrix retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2778
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
2779 bool tra = transa != blas_no_trans;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
2780 bool trb = transb != blas_no_trans;
9665
1dba57e9d08d use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents: 9662
diff changeset
2781
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2782 F77_INT a_nr = octave::to_f77_int (tra ? a.cols () : a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2783 F77_INT a_nc = octave::to_f77_int (tra ? a.rows () : a.cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2784
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2785 F77_INT b_nr = octave::to_f77_int (trb ? b.cols () : b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2786 F77_INT b_nc = octave::to_f77_int (trb ? b.rows () : b.cols ());
7804
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2787
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2788 if (a_nc != b_nr)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2789 octave::err_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc);
21120
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2790
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2791 if (a_nr == 0 || a_nc == 0 || b_nc == 0)
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2792 retval = FloatMatrix (a_nr, b_nc, 0.0);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2793 else if (a.data () == b.data () && a_nr == b_nc && tra != trb)
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2794 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2795 F77_INT lda = octave::to_f77_int (a.rows ());
21120
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2796
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2797 retval = FloatMatrix (a_nr, b_nc);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2798 float *c = retval.fortran_vec ();
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2799
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2800 const char ctra = get_blas_trans_arg (tra);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2801 F77_XFCN (ssyrk, SSYRK, (F77_CONST_CHAR_ARG2 ("U", 1),
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2802 F77_CONST_CHAR_ARG2 (&ctra, 1),
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2803 a_nr, a_nc, 1.0,
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2804 a.data (), lda, 0.0, c, a_nr
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2805 F77_CHAR_ARG_LEN (1)
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2806 F77_CHAR_ARG_LEN (1)));
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2807 for (int j = 0; j < a_nr; j++)
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2808 for (int i = 0; i < j; i++)
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2809 retval.xelem (j,i) = retval.xelem (i,j);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2810
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2811 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2812 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2813 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2814 F77_INT lda = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2815 F77_INT tda = octave::to_f77_int (a.cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2816 F77_INT ldb = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22971
diff changeset
2817 F77_INT tdb = octave::to_f77_int (b.cols ());
21120
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2818
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2819 retval = FloatMatrix (a_nr, b_nc);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2820 float *c = retval.fortran_vec ();
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2821
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2822 if (b_nc == 1)
7804
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2823 {
21120
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2824 if (a_nr == 1)
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2825 F77_FUNC (xsdot, XSDOT) (a_nc, a.data (), 1, b.data (), 1, *c);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2826 else
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2827 {
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2828 const char ctra = get_blas_trans_arg (tra);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2829 F77_XFCN (sgemv, SGEMV, (F77_CONST_CHAR_ARG2 (&ctra, 1),
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2830 lda, tda, 1.0, a.data (), lda,
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2831 b.data (), 1, 0.0, c, 1
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2832 F77_CHAR_ARG_LEN (1)));
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2833 }
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2834 }
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2835 else if (a_nr == 1)
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2836 {
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2837 const char crevtrb = get_blas_trans_arg (! trb);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2838 F77_XFCN (sgemv, SGEMV, (F77_CONST_CHAR_ARG2 (&crevtrb, 1),
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2839 ldb, tdb, 1.0, b.data (), ldb,
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2840 a.data (), 1, 0.0, c, 1
7804
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2841 F77_CHAR_ARG_LEN (1)));
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2842 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2843 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2844 {
21120
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2845 const char ctra = get_blas_trans_arg (tra);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2846 const char ctrb = get_blas_trans_arg (trb);
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2847 F77_XFCN (sgemm, SGEMM, (F77_CONST_CHAR_ARG2 (&ctra, 1),
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2848 F77_CONST_CHAR_ARG2 (&ctrb, 1),
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2849 a_nr, b_nc, a_nc, 1.0, a.data (),
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2850 lda, b.data (), ldb, 0.0, c, a_nr
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2851 F77_CHAR_ARG_LEN (1)
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21112
diff changeset
2852 F77_CHAR_ARG_LEN (1)));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2853 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2854 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2855
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2856 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2857 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2858
7804
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2859 FloatMatrix
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2860 operator * (const FloatMatrix& a, const FloatMatrix& b)
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2861 {
9665
1dba57e9d08d use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents: 9662
diff changeset
2862 return xgemm (a, b);
7804
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2863 }
a0c550b22e61 compound ops for float matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7797
diff changeset
2864
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2865 // FIXME: it would be nice to share code among the min/max functions below.
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2866
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22133
diff changeset
2867 #define EMPTY_RETURN_CHECK(T) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22133
diff changeset
2868 if (nr == 0 || nc == 0) \
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2869 return T (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2870
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2871 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2872 min (float d, const FloatMatrix& m)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2873 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2874 octave_idx_type nr = m.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2875 octave_idx_type nc = m.columns ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2876
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2877 EMPTY_RETURN_CHECK (FloatMatrix);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2878
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2879 FloatMatrix result (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2880
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2881 for (octave_idx_type j = 0; j < nc; j++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2882 for (octave_idx_type i = 0; i < nr; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2883 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2884 octave_quit ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2885 result(i, j) = octave::math::min (d, m(i, j));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2886 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2887
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2888 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2889 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2890
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2891 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2892 min (const FloatMatrix& m, float d)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2893 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2894 octave_idx_type nr = m.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2895 octave_idx_type nc = m.columns ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2896
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2897 EMPTY_RETURN_CHECK (FloatMatrix);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2898
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2899 FloatMatrix result (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2900
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2901 for (octave_idx_type j = 0; j < nc; j++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2902 for (octave_idx_type i = 0; i < nr; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2903 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2904 octave_quit ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2905 result(i, j) = octave::math::min (m(i, j), d);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2906 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2907
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2908 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2909 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2910
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2911 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2912 min (const FloatMatrix& a, const FloatMatrix& b)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2913 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2914 octave_idx_type nr = a.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2915 octave_idx_type nc = a.columns ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2916
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2917 if (nr != b.rows () || nc != b.columns ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
2918 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
2919 ("two-arg min requires same size arguments");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2920
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2921 EMPTY_RETURN_CHECK (FloatMatrix);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2922
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2923 FloatMatrix result (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2924
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2925 for (octave_idx_type j = 0; j < nc; j++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2926 for (octave_idx_type i = 0; i < nr; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2927 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2928 octave_quit ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2929 result(i, j) = octave::math::min (a(i, j), b(i, j));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2930 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2931
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2932 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2933 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2934
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2935 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2936 max (float d, const FloatMatrix& m)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2937 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2938 octave_idx_type nr = m.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2939 octave_idx_type nc = m.columns ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2940
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2941 EMPTY_RETURN_CHECK (FloatMatrix);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2942
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2943 FloatMatrix result (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2944
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2945 for (octave_idx_type j = 0; j < nc; j++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2946 for (octave_idx_type i = 0; i < nr; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2947 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2948 octave_quit ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2949 result(i, j) = octave::math::max (d, m(i, j));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2950 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2951
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2952 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2953 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2954
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2955 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2956 max (const FloatMatrix& m, float d)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2957 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2958 octave_idx_type nr = m.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2959 octave_idx_type nc = m.columns ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2960
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2961 EMPTY_RETURN_CHECK (FloatMatrix);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2962
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2963 FloatMatrix result (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2964
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2965 for (octave_idx_type j = 0; j < nc; j++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2966 for (octave_idx_type i = 0; i < nr; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2967 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2968 octave_quit ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2969 result(i, j) = octave::math::max (m(i, j), d);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2970 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2971
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2972 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2973 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2974
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2975 FloatMatrix
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2976 max (const FloatMatrix& a, const FloatMatrix& b)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2977 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2978 octave_idx_type nr = a.rows ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2979 octave_idx_type nc = a.columns ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2980
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2981 if (nr != b.rows () || nc != b.columns ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
2982 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21129
diff changeset
2983 ("two-arg max requires same size arguments");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2984
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2985 EMPTY_RETURN_CHECK (FloatMatrix);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2986
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2987 FloatMatrix result (nr, nc);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2988
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2989 for (octave_idx_type j = 0; j < nc; j++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2990 for (octave_idx_type i = 0; i < nr; i++)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2991 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10213
diff changeset
2992 octave_quit ();
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2993 result(i, j) = octave::math::max (a(i, j), b(i, j));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2994 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2995
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2996 return result;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2997 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
2998
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2999 FloatMatrix linspace (const FloatColumnVector& x1,
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3000 const FloatColumnVector& x2,
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3001 octave_idx_type n)
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3002
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3003 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
3004 octave_idx_type m = x1.numel ();
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
3005
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
3006 if (x2.numel () != m)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
3007 (*current_liboctave_error_handler)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
3008 ("linspace: vectors must be of equal length");
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3009
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27180
diff changeset
3010 FloatMatrix retval;
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3011
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20462
diff changeset
3012 if (n < 1)
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20462
diff changeset
3013 {
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20462
diff changeset
3014 retval.clear (m, 0);
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20462
diff changeset
3015 return retval;
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20462
diff changeset
3016 }
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20462
diff changeset
3017
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3018 retval.clear (m, n);
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3019 for (octave_idx_type i = 0; i < m; i++)
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27180
diff changeset
3020 retval.xelem (i, 0) = x1(i);
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3021
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20462
diff changeset
3022 // The last column is unused so temporarily store delta there
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27180
diff changeset
3023 float *delta = &retval.xelem (0, n-1);
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3024 for (octave_idx_type i = 0; i < m; i++)
25237
ca022a8c4015 linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents: 25054
diff changeset
3025 delta[i] = (x1(i) == x2(i)) ? 0 : (x2(i) - x1(i)) / (n - 1);
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3026
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3027 for (octave_idx_type j = 1; j < n-1; j++)
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3028 for (octave_idx_type i = 0; i < m; i++)
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27180
diff changeset
3029 retval.xelem (i, j) = x1(i) + j*delta[i];
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3030
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3031 for (octave_idx_type i = 0; i < m; i++)
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27180
diff changeset
3032 retval.xelem (i, n-1) = x2(i);
9653
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3033
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3034 return retval;
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3035 }
e087d7c77ff9 improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9601
diff changeset
3036
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9553
diff changeset
3037 MS_CMP_OPS (FloatMatrix, float)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9528
diff changeset
3038 MS_BOOL_OPS (FloatMatrix, float)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
3039
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9553
diff changeset
3040 SM_CMP_OPS (float, FloatMatrix)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9528
diff changeset
3041 SM_BOOL_OPS (float, FloatMatrix)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
3042
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9553
diff changeset
3043 MM_CMP_OPS (FloatMatrix, FloatMatrix)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9528
diff changeset
3044 MM_BOOL_OPS (FloatMatrix, FloatMatrix)