annotate liboctave/SparseCmplxQR.cc @ 11586:12df7854fa7c

strip trailing whitespace from source files
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:24:59 -0500
parents feb90c7cfc16
children 72c96de7a403
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
1 /*
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
2
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11510
diff changeset
3 Copyright (C) 2005-2011 David Bateman
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
4
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6924
diff changeset
5 This file is part of Octave.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6924
diff changeset
6
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6924
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6924
diff changeset
10 option) any later version.
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
11
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
15 for more details.
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
16
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6924
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6924
diff changeset
19 <http://www.gnu.org/licenses/>.
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
20
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
21 */
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
22
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
24 #include <config.h>
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
25 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
26 #include <vector>
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
27
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
28 #include "lo-error.h"
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
29 #include "SparseCmplxQR.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
30 #include "oct-locbuf.h"
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
31
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
32 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER < 2)) || (CS_VER < 2))
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
33 typedef double _Complex cs_complex_t;
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
34
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
35 // Why did g++ 4.x stl_vector.h make
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
36 // OCTAVE_LOCAL_BUFFER (cs_complex_t, buf, n)
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
37 // an error ?
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
38 #define OCTAVE_C99_COMPLEX(buf, n) \
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
39 OCTAVE_LOCAL_BUFFER (double, buf ## tmp, (2 * (n))); \
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
40 cs_complex_t *buf = reinterpret_cast<cs_complex_t *> (buf ## tmp);
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
41
6719
30e1320bb0ee [project @ 2007-06-13 22:22:51 by dbateman]
dbateman
parents: 6685
diff changeset
42 #define OCTAVE_C99_ZERO (0. + 0.iF)
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
43 #define OCTAVE_C99_ONE (1. + 0.iF)
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
44 #else
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
45 #define OCTAVE_C99_COMPLEX(buf, n) \
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
46 OCTAVE_LOCAL_BUFFER (cs_complex_t, buf, (n));
6719
30e1320bb0ee [project @ 2007-06-13 22:22:51 by dbateman]
dbateman
parents: 6685
diff changeset
47 #define OCTAVE_C99_ZERO cs_complex_t(0., 0.);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
48 #define OCTAVE_C99_ONE cs_complex_t(1., 0.);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
49 #endif
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
50
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
51 SparseComplexQR::SparseComplexQR_rep::SparseComplexQR_rep
11498
367bfee35ba0 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 10506
diff changeset
52 (GCC_ATTR_UNUSED const SparseComplexMatrix& a, GCC_ATTR_UNUSED int order)
11528
feb90c7cfc16 Build successfully without HAVE_CXSPARSE
David Grundberg <individ@acc.umu.se>
parents: 11523
diff changeset
53 : count (1), nrows (0)
feb90c7cfc16 Build successfully without HAVE_CXSPARSE
David Grundberg <individ@acc.umu.se>
parents: 11523
diff changeset
54 #ifdef HAVE_CXSPARSE
feb90c7cfc16 Build successfully without HAVE_CXSPARSE
David Grundberg <individ@acc.umu.se>
parents: 11523
diff changeset
55 , S (0), N (0)
feb90c7cfc16 Build successfully without HAVE_CXSPARSE
David Grundberg <individ@acc.umu.se>
parents: 11523
diff changeset
56 #endif
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
57 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
58 #ifdef HAVE_CXSPARSE
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
59 CXSPARSE_ZNAME () A;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
60 A.nzmax = a.nnz ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
61 A.m = a.rows ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
62 A.n = a.cols ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
63 nrows = A.m;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
64 // Cast away const on A, with full knowledge that CSparse won't touch it
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
65 // Prevents the methods below making a copy of the data.
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
66 A.p = const_cast<octave_idx_type *>(a.cidx ());
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
67 A.i = const_cast<octave_idx_type *>(a.ridx ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
68 A.x = const_cast<cs_complex_t *>(reinterpret_cast<const cs_complex_t *>
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
69 (a.data ()));
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
70 A.nz = -1;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
71 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
72 #if defined(CS_VER) && (CS_VER >= 2)
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
73 S = CXSPARSE_ZNAME (_sqr) (order, &A, 1);
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
74 #else
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
75 S = CXSPARSE_ZNAME (_sqr) (&A, order - 1, 1);
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
76 #endif
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
77 N = CXSPARSE_ZNAME (_qr) (&A, S);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
78 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
79 if (!N)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
80 (*current_liboctave_error_handler)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
81 ("SparseComplexQR: sparse matrix QR factorization filled");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
82 count = 1;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
83 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
84 (*current_liboctave_error_handler)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
85 ("SparseComplexQR: sparse matrix QR factorization not implemented");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
86 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
87 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
88
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
89 SparseComplexQR::SparseComplexQR_rep::~SparseComplexQR_rep (void)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
90 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
91 #ifdef HAVE_CXSPARSE
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
92 CXSPARSE_ZNAME (_sfree) (S);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
93 CXSPARSE_ZNAME (_nfree) (N);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
94 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
95 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
96
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
97 SparseComplexMatrix
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
98 SparseComplexQR::SparseComplexQR_rep::V (void) const
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
99 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
100 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
101 // Drop zeros from V and sort
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5681
diff changeset
102 // FIXME Is the double transpose to sort necessary?
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
103 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
104 CXSPARSE_ZNAME (_dropzeros) (N->L);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
105 CXSPARSE_ZNAME () *D = CXSPARSE_ZNAME (_transpose) (N->L, 1);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
106 CXSPARSE_ZNAME (_spfree) (N->L);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
107 N->L = CXSPARSE_ZNAME (_transpose) (D, 1);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
108 CXSPARSE_ZNAME (_spfree) (D);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
109 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
110
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
111 octave_idx_type nc = N->L->n;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
112 octave_idx_type nz = N->L->nzmax;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
113 SparseComplexMatrix ret (N->L->m, nc, nz);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
114 for (octave_idx_type j = 0; j < nc+1; j++)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
115 ret.xcidx (j) = N->L->p[j];
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
116 for (octave_idx_type j = 0; j < nz; j++)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
117 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
118 ret.xridx (j) = N->L->i[j];
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
119 ret.xdata (j) = reinterpret_cast<Complex *>(N->L->x)[j];
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
120 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
121 return ret;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
122 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
123 return SparseComplexMatrix ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
124 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
125 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
126
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
127 ColumnVector
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
128 SparseComplexQR::SparseComplexQR_rep::Pinv (void) const
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
129 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
130 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
131 ColumnVector ret(N->L->m);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
132 for (octave_idx_type i = 0; i < N->L->m; i++)
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
133 #if defined(CS_VER) && (CS_VER >= 2)
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
134 ret.xelem(i) = S->pinv[i];
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
135 #else
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
136 ret.xelem(i) = S->Pinv[i];
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
137 #endif
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
138 return ret;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
139 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
140 return ColumnVector ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
141 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
142 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
143
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
144 ColumnVector
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
145 SparseComplexQR::SparseComplexQR_rep::P (void) const
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
146 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
147 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
148 ColumnVector ret(N->L->m);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
149 for (octave_idx_type i = 0; i < N->L->m; i++)
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
150 #if defined(CS_VER) && (CS_VER >= 2)
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
151 ret.xelem(S->pinv[i]) = i;
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
152 #else
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
153 ret.xelem(S->Pinv[i]) = i;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
154 #endif
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
155 return ret;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
156 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
157 return ColumnVector ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
158 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
159 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
160
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
161 SparseComplexMatrix
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
162 SparseComplexQR::SparseComplexQR_rep::R (const bool econ) const
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
163 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
164 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
165 // Drop zeros from R and sort
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5681
diff changeset
166 // FIXME Is the double transpose to sort necessary?
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
167 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
168 CXSPARSE_ZNAME (_dropzeros) (N->U);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
169 CXSPARSE_ZNAME () *D = CXSPARSE_ZNAME (_transpose) (N->U, 1);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
170 CXSPARSE_ZNAME (_spfree) (N->U);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
171 N->U = CXSPARSE_ZNAME (_transpose) (D, 1);
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
172 CXSPARSE_ZNAME (_spfree) (D);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
173 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
174
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
175 octave_idx_type nc = N->U->n;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
176 octave_idx_type nz = N->U->nzmax;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
177 SparseComplexMatrix ret ((econ ? (nc > nrows ? nrows : nc) : nrows), nc, nz);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
178 for (octave_idx_type j = 0; j < nc+1; j++)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
179 ret.xcidx (j) = N->U->p[j];
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
180 for (octave_idx_type j = 0; j < nz; j++)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
181 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
182 ret.xridx (j) = N->U->i[j];
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
183 ret.xdata (j) = reinterpret_cast<Complex *>(N->U->x)[j];
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
184 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
185 return ret;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
186 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
187 return SparseComplexMatrix ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
188 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
189 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
190
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
191 ComplexMatrix
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
192 SparseComplexQR::SparseComplexQR_rep::C (const ComplexMatrix &b) const
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
193 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
194 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
195 octave_idx_type b_nr = b.rows();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
196 octave_idx_type b_nc = b.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
197 octave_idx_type nc = N->L->n;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
198 octave_idx_type nr = nrows;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
199 const cs_complex_t *bvec =
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
200 reinterpret_cast<const cs_complex_t *>(b.fortran_vec());
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
201 ComplexMatrix ret(b_nr, b_nc);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
202 Complex *vec = ret.fortran_vec();
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
203 if (nr < 0 || nc < 0 || nr != b_nr)
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
204 (*current_liboctave_error_handler) ("matrix dimension mismatch");
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
205 else if (nr == 0 || nc == 0 || b_nc == 0)
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
206 ret = ComplexMatrix (nc, b_nc, Complex (0.0, 0.0));
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
207 else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
208 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
209 OCTAVE_LOCAL_BUFFER (Complex, buf, S->m2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
210 for (volatile octave_idx_type j = 0, idx = 0; j < b_nc; j++, idx+=b_nr)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
211 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
212 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
213 volatile octave_idx_type nm = (nr < nc ? nr : nc);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
214 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
215 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
216 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
217 (S->pinv, bvec + idx, reinterpret_cast<cs_complex_t *>(buf), b_nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
218 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
219 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
220 (b_nr, S->Pinv, bvec + idx, reinterpret_cast<cs_complex_t *>(buf));
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
221 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
222 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
223 for (volatile octave_idx_type i = 0; i < nm; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
224 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
225 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
226 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
227 CXSPARSE_ZNAME (_happly)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
228 (N->L, i, N->B[i], reinterpret_cast<cs_complex_t *>(buf));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
229 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
230 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
231 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
232 vec[i+idx] = buf[i];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
233 }
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
234 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
235 return ret;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
236 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
237 return ComplexMatrix ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
238 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
239 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
240
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
241 ComplexMatrix
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
242 SparseComplexQR::SparseComplexQR_rep::Q (void) const
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
243 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
244 #ifdef HAVE_CXSPARSE
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
245 octave_idx_type nc = N->L->n;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
246 octave_idx_type nr = nrows;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
247 ComplexMatrix ret(nr, nr);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
248 Complex *vec = ret.fortran_vec();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
249 if (nr < 0 || nc < 0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
250 (*current_liboctave_error_handler) ("matrix dimension mismatch");
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
251 else if (nr == 0 || nc == 0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
252 ret = ComplexMatrix (nc, nr, Complex (0.0, 0.0));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
253 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
254 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
255 OCTAVE_C99_COMPLEX (bvec, nr);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
256 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
257 bvec[i] = OCTAVE_C99_ZERO;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
258 OCTAVE_LOCAL_BUFFER (Complex, buf, S->m2);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
259 for (volatile octave_idx_type j = 0, idx = 0; j < nr; j++, idx+=nr)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
260 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
261 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
262 bvec[j] = OCTAVE_C99_ONE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
263 volatile octave_idx_type nm = (nr < nc ? nr : nc);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
264 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
265 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
266 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
267 (S->pinv, bvec, reinterpret_cast<cs_complex_t *>(buf), nr);
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
268 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
269 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
270 (nr, S->Pinv, bvec, reinterpret_cast<cs_complex_t *>(buf));
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
271 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
272 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
273 for (volatile octave_idx_type i = 0; i < nm; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
274 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
275 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
276 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
277 CXSPARSE_ZNAME (_happly)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
278 (N->L, i, N->B[i], reinterpret_cast<cs_complex_t *>(buf));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
279 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
280 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
281 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
282 vec[i+idx] = buf[i];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
283 bvec[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
284 }
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
285 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
286 return ret.hermitian ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
287 #else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
288 return ComplexMatrix ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
289 #endif
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
290 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
291
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
292 ComplexMatrix
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
293 qrsolve(const SparseComplexMatrix&a, const Matrix &b, octave_idx_type &info)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
294 {
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
295 info = -1;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
296 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
297 octave_idx_type nr = a.rows();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
298 octave_idx_type nc = a.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
299 octave_idx_type b_nc = b.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
300 octave_idx_type b_nr = b.rows();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
301 ComplexMatrix x;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
302
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
303 if (nr < 0 || nc < 0 || nr != b_nr)
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
304 (*current_liboctave_error_handler)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
305 ("matrix dimension mismatch in solution of minimum norm problem");
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
306 else if (nr == 0 || nc == 0 || b_nc == 0)
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
307 x = ComplexMatrix (nc, b_nc, Complex (0.0, 0.0));
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
308 else if (nr >= nc)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
309 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
310 SparseComplexQR q (a, 2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
311 if (! q.ok ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
312 return ComplexMatrix();
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
313 x.resize(nc, b_nc);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
314 cs_complex_t *vec = reinterpret_cast<cs_complex_t *>
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
315 (x.fortran_vec());
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
316 OCTAVE_C99_COMPLEX (buf, q.S()->m2);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
317 OCTAVE_LOCAL_BUFFER (Complex, Xx, b_nr);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
318 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
319 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
320 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
321 for (octave_idx_type j = 0; j < b_nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
322 Xx[j] = b.xelem(j,i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
323 for (octave_idx_type j = nr; j < q.S()->m2; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
324 buf[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
325 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
326 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
327 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
328 (q.S()->pinv, reinterpret_cast<cs_complex_t *>(Xx), buf, nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
329 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
330 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
331 (nr, q.S()->Pinv, reinterpret_cast<cs_complex_t *>(Xx), buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
332 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
333 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
334 for (volatile octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
335 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
336 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
337 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
338 CXSPARSE_ZNAME (_happly) (q.N()->L, j, q.N()->B[j], buf);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
339 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
340 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
341 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
342 CXSPARSE_ZNAME (_usolve) (q.N()->U, buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
343 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
344 CXSPARSE_ZNAME (_ipvec) (q.S()->q, buf, vec + idx, nc);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
345 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
346 CXSPARSE_ZNAME (_ipvec) (nc, q.S()->Q, buf, vec + idx);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
347 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
348 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
349 }
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
350 info = 0;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
351 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
352 else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
353 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
354 SparseComplexMatrix at = a.hermitian();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
355 SparseComplexQR q (at, 2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
356 if (! q.ok ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
357 return ComplexMatrix();
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
358 x.resize(nc, b_nc);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
359 cs_complex_t *vec = reinterpret_cast<cs_complex_t *>
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
360 (x.fortran_vec());
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
361 volatile octave_idx_type nbuf = (nc > q.S()->m2 ? nc : q.S()->m2);
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
362 OCTAVE_C99_COMPLEX (buf, nbuf);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
363 OCTAVE_LOCAL_BUFFER (Complex, Xx, b_nr);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
364 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER >= 2)) || (CS_VER > 2))
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
365 OCTAVE_LOCAL_BUFFER (double, B, nr);
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
366 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
367 B[i] = q.N()->B [i];
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
368 #else
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
369 OCTAVE_LOCAL_BUFFER (Complex, B, nr);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
370 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
371 B[i] = conj (reinterpret_cast<Complex *>(q.N()->B) [i]);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
372 #endif
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
373 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
374 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
375 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
376 for (octave_idx_type j = 0; j < b_nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
377 Xx[j] = b.xelem(j,i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
378 for (octave_idx_type j = nr; j < nbuf; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
379 buf[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
380 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
381 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
382 CXSPARSE_ZNAME (_pvec)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
383 (q.S()->q, reinterpret_cast<cs_complex_t *>(Xx), buf, nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
384 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
385 CXSPARSE_ZNAME (_pvec)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
386 (nr, q.S()->Q, reinterpret_cast<cs_complex_t *>(Xx), buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
387 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
388 CXSPARSE_ZNAME (_utsolve) (q.N()->U, buf);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
389 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
390 for (volatile octave_idx_type j = nr-1; j >= 0; j--)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
391 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
392 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
393 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
394
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
395 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER >= 2)) || (CS_VER > 2))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
396 CXSPARSE_ZNAME (_happly) (q.N()->L, j, B[j], buf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
397 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
398 CXSPARSE_ZNAME (_happly)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
399 (q.N()->L, j, reinterpret_cast<cs_complex_t *>(B)[j], buf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
400 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
401 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
402 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
403 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
404 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
405 CXSPARSE_ZNAME (_pvec) (q.S()->pinv, buf, vec + idx, nc);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
406 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
407 CXSPARSE_ZNAME (_pvec) (nc, q.S()->Pinv, buf, vec + idx);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
408 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
409 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
410 }
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
411 info = 0;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
412 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
413
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
414 return x;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
415 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
416 return ComplexMatrix ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
417 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
418 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
419
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
420 SparseComplexMatrix
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
421 qrsolve(const SparseComplexMatrix&a, const SparseMatrix &b, octave_idx_type &info)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
422 {
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
423 info = -1;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
424 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
425 octave_idx_type nr = a.rows();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
426 octave_idx_type nc = a.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
427 octave_idx_type b_nc = b.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
428 octave_idx_type b_nr = b.rows();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
429 SparseComplexMatrix x;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
430 volatile octave_idx_type ii, x_nz;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
431
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
432 if (nr < 0 || nc < 0 || nr != b_nr)
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
433 (*current_liboctave_error_handler)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
434 ("matrix dimension mismatch in solution of minimum norm problem");
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
435 else if (nr == 0 || nc == 0 || b_nc == 0)
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
436 x = SparseComplexMatrix (nc, b_nc);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
437 else if (nr >= nc)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
438 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
439 SparseComplexQR q (a, 2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
440 if (! q.ok ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
441 return SparseComplexMatrix();
10506
bdf5d85cfc5e replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
442 x = SparseComplexMatrix (nc, b_nc, b.nnz());
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
443 x.xcidx(0) = 0;
10506
bdf5d85cfc5e replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
444 x_nz = b.nnz();
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
445 ii = 0;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
446 OCTAVE_LOCAL_BUFFER (Complex, Xx, (b_nr > nc ? b_nr : nc));
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
447 OCTAVE_C99_COMPLEX (buf, q.S()->m2);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
448 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
449 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
450 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
451 for (octave_idx_type j = 0; j < b_nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
452 Xx[j] = b.xelem(j,i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
453 for (octave_idx_type j = nr; j < q.S()->m2; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
454 buf[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
455 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
456 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
457 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
458 (q.S()->pinv, reinterpret_cast<cs_complex_t *>(Xx), buf, nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
459 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
460 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
461 (nr, q.S()->Pinv, reinterpret_cast<cs_complex_t *>(Xx), buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
462 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
463 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
464 for (volatile octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
465 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
466 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
467 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
468 CXSPARSE_ZNAME (_happly) (q.N()->L, j, q.N()->B[j], buf);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
469 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
470 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
471 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
472 CXSPARSE_ZNAME (_usolve) (q.N()->U, buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
473 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
474 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
475 (q.S()->q, buf, reinterpret_cast<cs_complex_t *>(Xx), nc);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
476 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
477 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
478 (nc, q.S()->Q, buf, reinterpret_cast<cs_complex_t *>(Xx));
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
479 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
480 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
481
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
482 for (octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
483 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
484 Complex tmp = Xx[j];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
485 if (tmp != 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
486 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
487 if (ii == x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
488 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
489 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
490 octave_idx_type sz = x_nz * (b_nc - i) / b_nc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
491 sz = (sz > 10 ? sz : 10) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
492 x.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
493 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
494 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
495 x.xdata(ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
496 x.xridx(ii++) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
497 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
498 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
499 x.xcidx(i+1) = ii;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
500 }
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
501 info = 0;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
502 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
503 else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
504 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
505 SparseComplexMatrix at = a.hermitian();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
506 SparseComplexQR q (at, 2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
507 if (! q.ok ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
508 return SparseComplexMatrix();
10506
bdf5d85cfc5e replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
509 x = SparseComplexMatrix (nc, b_nc, b.nnz());
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
510 x.xcidx(0) = 0;
10506
bdf5d85cfc5e replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
511 x_nz = b.nnz();
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
512 ii = 0;
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
513 volatile octave_idx_type nbuf = (nc > q.S()->m2 ? nc : q.S()->m2);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
514 OCTAVE_LOCAL_BUFFER (Complex, Xx, (b_nr > nc ? b_nr : nc));
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
515 OCTAVE_C99_COMPLEX (buf, nbuf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
516
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
517 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER >= 2)) || (CS_VER > 2))
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
518 OCTAVE_LOCAL_BUFFER (double, B, nr);
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
519 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
520 B[i] = q.N()->B [i];
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
521 #else
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
522 OCTAVE_LOCAL_BUFFER (Complex, B, nr);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
523 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
524 B[i] = conj (reinterpret_cast<Complex *>(q.N()->B) [i]);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
525 #endif
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
526 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
527 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
528 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
529 for (octave_idx_type j = 0; j < b_nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
530 Xx[j] = b.xelem(j,i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
531 for (octave_idx_type j = nr; j < nbuf; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
532 buf[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
533 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
534 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
535 CXSPARSE_ZNAME (_pvec)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
536 (q.S()->q, reinterpret_cast<cs_complex_t *>(Xx), buf, nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
537 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
538 CXSPARSE_ZNAME (_pvec)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
539 (nr, q.S()->Q, reinterpret_cast<cs_complex_t *>(Xx), buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
540 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
541 CXSPARSE_ZNAME (_utsolve) (q.N()->U, buf);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
542 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
543 for (volatile octave_idx_type j = nr-1; j >= 0; j--)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
544 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
545 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
546 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
547 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER >= 2)) || (CS_VER > 2))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
548 CXSPARSE_ZNAME (_happly) (q.N()->L, j, B[j], buf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
549 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
550 CXSPARSE_ZNAME (_happly)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
551 (q.N()->L, j, reinterpret_cast<cs_complex_t *>(B)[j], buf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
552 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
553 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
554 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
555 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
556 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
557 CXSPARSE_ZNAME (_pvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
558 (q.S()->pinv, buf, reinterpret_cast<cs_complex_t *>(Xx), nc);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
559 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
560 CXSPARSE_ZNAME (_pvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
561 (nc, q.S()->Pinv, buf, reinterpret_cast<cs_complex_t *>(Xx));
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
562 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
563 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
564
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
565 for (octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
566 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
567 Complex tmp = Xx[j];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
568 if (tmp != 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
569 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
570 if (ii == x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
571 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
572 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
573 octave_idx_type sz = x_nz * (b_nc - i) / b_nc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
574 sz = (sz > 10 ? sz : 10) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
575 x.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
576 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
577 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
578 x.xdata(ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
579 x.xridx(ii++) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
580 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
581 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
582 x.xcidx(i+1) = ii;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
583 }
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
584 info = 0;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
585 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
586
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
587 x.maybe_compress ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
588 return x;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
589 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
590 return SparseComplexMatrix ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
591 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
592 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
593
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
594 ComplexMatrix
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
595 qrsolve(const SparseComplexMatrix&a, const ComplexMatrix &b, octave_idx_type &info)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
596 {
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
597 info = -1;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
598 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
599 octave_idx_type nr = a.rows();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
600 octave_idx_type nc = a.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
601 octave_idx_type b_nc = b.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
602 octave_idx_type b_nr = b.rows();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
603 const cs_complex_t *bvec =
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
604 reinterpret_cast<const cs_complex_t *>(b.fortran_vec());
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
605 ComplexMatrix x;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
606
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
607 if (nr < 0 || nc < 0 || nr != b_nr)
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
608 (*current_liboctave_error_handler)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
609 ("matrix dimension mismatch in solution of minimum norm problem");
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
610 else if (nr == 0 || nc == 0 || b_nc == 0)
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
611 x = ComplexMatrix (nc, b_nc, Complex (0.0, 0.0));
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
612 else if (nr >= nc)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
613 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
614 SparseComplexQR q (a, 2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
615 if (! q.ok ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
616 return ComplexMatrix();
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
617 x.resize(nc, b_nc);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
618 cs_complex_t *vec = reinterpret_cast<cs_complex_t *>
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
619 (x.fortran_vec());
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
620 OCTAVE_C99_COMPLEX (buf, q.S()->m2);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
621 for (volatile octave_idx_type i = 0, idx = 0, bidx = 0; i < b_nc;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
622 i++, idx+=nc, bidx+=b_nr)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
623 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
624 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
625 for (octave_idx_type j = nr; j < q.S()->m2; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
626 buf[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
627 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
628 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
629 CXSPARSE_ZNAME (_ipvec) (q.S()->pinv, bvec + bidx, buf, nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
630 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
631 CXSPARSE_ZNAME (_ipvec) (nr, q.S()->Pinv, bvec + bidx, buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
632 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
633 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
634 for (volatile octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
635 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
636 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
637 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
638 CXSPARSE_ZNAME (_happly) (q.N()->L, j, q.N()->B[j], buf);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
639 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
640 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
641 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
642 CXSPARSE_ZNAME (_usolve) (q.N()->U, buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
643 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
644 CXSPARSE_ZNAME (_ipvec) (q.S()->q, buf, vec + idx, nc);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
645 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
646 CXSPARSE_ZNAME (_ipvec) (nc, q.S()->Q, buf, vec + idx);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
647 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
648 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
649 }
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
650 info = 0;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
651 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
652 else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
653 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
654 SparseComplexMatrix at = a.hermitian();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
655 SparseComplexQR q (at, 2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
656 if (! q.ok ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
657 return ComplexMatrix();
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
658 x.resize(nc, b_nc);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
659 cs_complex_t *vec = reinterpret_cast<cs_complex_t *>
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
660 (x.fortran_vec());
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
661 volatile octave_idx_type nbuf = (nc > q.S()->m2 ? nc : q.S()->m2);
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
662 OCTAVE_C99_COMPLEX (buf, nbuf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
663 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER >= 2)) || (CS_VER > 2))
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
664 OCTAVE_LOCAL_BUFFER (double, B, nr);
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
665 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
666 B[i] = q.N()->B [i];
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
667 #else
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
668 OCTAVE_LOCAL_BUFFER (Complex, B, nr);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
669 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
670 B[i] = conj (reinterpret_cast<Complex *>(q.N()->B) [i]);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
671 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
672 for (volatile octave_idx_type i = 0, idx = 0, bidx = 0; i < b_nc;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
673 i++, idx+=nc, bidx+=b_nr)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
674 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
675 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
676 for (octave_idx_type j = nr; j < nbuf; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
677 buf[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
678 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
679 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
680 CXSPARSE_ZNAME (_pvec) (q.S()->q, bvec + bidx, buf, nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
681 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
682 CXSPARSE_ZNAME (_pvec) (nr, q.S()->Q, bvec + bidx, buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
683 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
684 CXSPARSE_ZNAME (_utsolve) (q.N()->U, buf);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
685 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
686 for (volatile octave_idx_type j = nr-1; j >= 0; j--)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
687 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
688 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
689 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
690 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER >= 2)) || (CS_VER > 2))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
691 CXSPARSE_ZNAME (_happly) (q.N()->L, j, B[j], buf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
692 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
693 CXSPARSE_ZNAME (_happly)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
694 (q.N()->L, j, reinterpret_cast<cs_complex_t *>(B)[j], buf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
695 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
696 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
697 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
698 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
699 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
700 CXSPARSE_ZNAME (_pvec) (q.S()->pinv, buf, vec + idx, nc);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
701 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
702 CXSPARSE_ZNAME (_pvec) (nc, q.S()->Pinv, buf, vec + idx);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
703 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
704 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
705 }
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
706 info = 0;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
707 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
708
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
709 return x;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
710 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
711 return ComplexMatrix ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
712 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
713 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
714
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
715 SparseComplexMatrix
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
716 qrsolve(const SparseComplexMatrix&a, const SparseComplexMatrix &b, octave_idx_type &info)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
717 {
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
718 info = -1;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
719 #ifdef HAVE_CXSPARSE
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
720 octave_idx_type nr = a.rows();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
721 octave_idx_type nc = a.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
722 octave_idx_type b_nc = b.cols();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
723 octave_idx_type b_nr = b.rows();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
724 SparseComplexMatrix x;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
725 volatile octave_idx_type ii, x_nz;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
726
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
727 if (nr < 0 || nc < 0 || nr != b_nr)
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
728 (*current_liboctave_error_handler)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
729 ("matrix dimension mismatch in solution of minimum norm problem");
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
730 else if (nr == 0 || nc == 0 || b_nc == 0)
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6719
diff changeset
731 x = SparseComplexMatrix (nc, b_nc);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
732 else if (nr >= nc)
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
733 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
734 SparseComplexQR q (a, 2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
735 if (! q.ok ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
736 return SparseComplexMatrix();
10506
bdf5d85cfc5e replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
737 x = SparseComplexMatrix (nc, b_nc, b.nnz());
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
738 x.xcidx(0) = 0;
10506
bdf5d85cfc5e replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
739 x_nz = b.nnz();
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
740 ii = 0;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
741 OCTAVE_LOCAL_BUFFER (Complex, Xx, (b_nr > nc ? b_nr : nc));
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5610
diff changeset
742 OCTAVE_C99_COMPLEX (buf, q.S()->m2);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
743 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
744 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
745 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
746 for (octave_idx_type j = 0; j < b_nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
747 Xx[j] = b.xelem(j,i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
748 for (octave_idx_type j = nr; j < q.S()->m2; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
749 buf[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
750 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
751 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
752 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
753 (q.S()->pinv, reinterpret_cast<cs_complex_t *>(Xx), buf, nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
754 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
755 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
756 (nr, q.S()->Pinv, reinterpret_cast<cs_complex_t *>(Xx), buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
757 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
758 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
759 for (volatile octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
760 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
761 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
762 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
763 CXSPARSE_ZNAME (_happly) (q.N()->L, j, q.N()->B[j], buf);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
764 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
765 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
766 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
767 CXSPARSE_ZNAME (_usolve) (q.N()->U, buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
768 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
769 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
770 (q.S()->q, buf, reinterpret_cast<cs_complex_t *>(Xx), nc);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
771 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
772 CXSPARSE_ZNAME (_ipvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
773 (nc, q.S()->Q, buf, reinterpret_cast<cs_complex_t *>(Xx));
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
774 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
775 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
776
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
777 for (octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
778 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
779 Complex tmp = Xx[j];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
780 if (tmp != 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
781 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
782 if (ii == x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
783 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
784 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
785 octave_idx_type sz = x_nz * (b_nc - i) / b_nc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
786 sz = (sz > 10 ? sz : 10) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
787 x.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
788 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
789 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
790 x.xdata(ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
791 x.xridx(ii++) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
792 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
793 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
794 x.xcidx(i+1) = ii;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
795 }
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
796 info = 0;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
797 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
798 else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
799 {
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
800 SparseComplexMatrix at = a.hermitian();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
801 SparseComplexQR q (at, 2);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
802 if (! q.ok ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
803 return SparseComplexMatrix();
10506
bdf5d85cfc5e replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
804 x = SparseComplexMatrix (nc, b_nc, b.nnz());
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
805 x.xcidx(0) = 0;
10506
bdf5d85cfc5e replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
806 x_nz = b.nnz();
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
807 ii = 0;
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
808 volatile octave_idx_type nbuf = (nc > q.S()->m2 ? nc : q.S()->m2);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
809 OCTAVE_LOCAL_BUFFER (Complex, Xx, (b_nr > nc ? b_nr : nc));
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
810 OCTAVE_C99_COMPLEX (buf, nbuf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
811 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER >= 2)) || (CS_VER > 2))
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
812 OCTAVE_LOCAL_BUFFER (double, B, nr);
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
813 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
814 B[i] = q.N()->B [i];
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
815 #else
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
816 OCTAVE_LOCAL_BUFFER (Complex, B, nr);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
817 for (octave_idx_type i = 0; i < nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
818 B[i] = conj (reinterpret_cast<Complex *>(q.N()->B) [i]);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
819 #endif
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
820 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
821 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
822 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
823 for (octave_idx_type j = 0; j < b_nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
824 Xx[j] = b.xelem(j,i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
825 for (octave_idx_type j = nr; j < nbuf; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
826 buf[j] = OCTAVE_C99_ZERO;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
827 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
828 #if defined(CS_VER) && (CS_VER >= 2)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
829 CXSPARSE_ZNAME (_pvec)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
830 (q.S()->q, reinterpret_cast<cs_complex_t *>(Xx), buf, nr);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
831 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
832 CXSPARSE_ZNAME (_pvec)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
833 (nr, q.S()->Q, reinterpret_cast<cs_complex_t *>(Xx), buf);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
834 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
835 CXSPARSE_ZNAME (_utsolve) (q.N()->U, buf);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
836 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
837 for (volatile octave_idx_type j = nr-1; j >= 0; j--)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
838 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
839 octave_quit ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
840 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
841 #if defined(CS_VER) && (((CS_VER == 2) && (CS_SUBVER >= 2)) || (CS_VER > 2))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
842 CXSPARSE_ZNAME (_happly) (q.N()->L, j, B[j], buf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
843 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
844 CXSPARSE_ZNAME (_happly)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
845 (q.N()->L, j, reinterpret_cast<cs_complex_t *>(B)[j], buf);
6685
8c8ef7e4821d [project @ 2007-06-02 11:39:42 by dbateman]
dbateman
parents: 6513
diff changeset
846 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
847 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
848 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
849 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
850 #if defined(CS_VER) && (CS_VER >= 2)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
851 CXSPARSE_ZNAME (_pvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
852 (q.S()->pinv, buf, reinterpret_cast<cs_complex_t *>(Xx), nc);
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
853 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
854 CXSPARSE_ZNAME (_pvec)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
855 (nc, q.S()->Pinv, buf, reinterpret_cast<cs_complex_t *>(Xx));
5792
eb90c83b4f91 [project @ 2006-05-04 20:14:49 by dbateman]
dbateman
parents: 5775
diff changeset
856 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
857 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
858
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
859 for (octave_idx_type j = 0; j < nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
860 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
861 Complex tmp = Xx[j];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
862 if (tmp != 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
863 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
864 if (ii == x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
865 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
866 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
867 octave_idx_type sz = x_nz * (b_nc - i) / b_nc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
868 sz = (sz > 10 ? sz : 10) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
869 x.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
870 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
871 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
872 x.xdata(ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
873 x.xridx(ii++) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
874 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
875 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
876 x.xcidx(i+1) = ii;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
877 }
5797
11fcab4c461d [project @ 2006-05-09 06:15:17 by dbateman]
dbateman
parents: 5792
diff changeset
878 info = 0;
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
879 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
880
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
881 x.maybe_compress ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
882 return x;
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
883 #else
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
884 return SparseComplexMatrix ();
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
885 #endif
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
886 }
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents:
diff changeset
887
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
888 ComplexMatrix
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
889 qrsolve (const SparseComplexMatrix &a, const MArray<double> &b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
890 octave_idx_type &info)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
891 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
892 return qrsolve (a, Matrix (b), info);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
893 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
894
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
895 ComplexMatrix
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11528
diff changeset
896 qrsolve (const SparseComplexMatrix &a, const MArray<Complex> &b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
897 octave_idx_type &info)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
898 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
899 return qrsolve (a, ComplexMatrix (b), info);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
900 }