Mercurial > octave
annotate libinterp/corefcn/kron.cc @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 32c3a5805893 |
children | 08b08b7f05b2 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
3 // Copyright (C) 2002-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
3910 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21580
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
3910 | 28 #endif |
29 | |
30 #include "dMatrix.h" | |
10461 | 31 #include "fMatrix.h" |
3910 | 32 #include "CMatrix.h" |
10461 | 33 #include "fCMatrix.h" |
34 | |
35 #include "dSparse.h" | |
36 #include "CSparse.h" | |
37 | |
38 #include "dDiagMatrix.h" | |
39 #include "fDiagMatrix.h" | |
40 #include "CDiagMatrix.h" | |
41 #include "fCDiagMatrix.h" | |
42 | |
43 #include "PermMatrix.h" | |
44 | |
45 #include "mx-inlines.cc" | |
4153 | 46 #include "quit.h" |
3910 | 47 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
48 #include "defun.h" |
3910 | 49 #include "error.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
50 #include "ovl.h" |
3910 | 51 |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
52 OCTAVE_NAMESPACE_BEGIN |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
53 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
54 template <typename R, typename T> |
10461 | 55 static MArray<T> |
56 kron (const MArray<R>& a, const MArray<T>& b) | |
57 { | |
58 assert (a.ndims () == 2); | |
59 assert (b.ndims () == 2); | |
60 | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
61 octave_idx_type nra = a.rows (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
62 octave_idx_type nrb = b.rows (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
63 octave_idx_type nca = a.cols (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
64 octave_idx_type ncb = b.cols (); |
3910 | 65 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
66 MArray<T> c (dim_vector (nra*nrb, nca*ncb)); |
10461 | 67 T *cv = c.fortran_vec (); |
68 | |
69 for (octave_idx_type ja = 0; ja < nca; ja++) | |
25485
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
70 { |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
71 octave_quit (); |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
72 for (octave_idx_type jb = 0; jb < ncb; jb++) |
10461 | 73 { |
25485
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
74 for (octave_idx_type ia = 0; ia < nra; ia++) |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
75 { |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
76 mx_inline_mul (nrb, cv, a(ia, ja), b.data () + nrb*jb); |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
77 cv += nrb; |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
78 } |
10461 | 79 } |
25485
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
80 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7455
diff
changeset
|
81 |
10461 | 82 return c; |
83 } | |
84 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
85 template <typename R, typename T> |
10461 | 86 static MArray<T> |
87 kron (const MDiagArray2<R>& a, const MArray<T>& b) | |
88 { | |
89 assert (b.ndims () == 2); | |
90 | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
91 octave_idx_type nra = a.rows (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
92 octave_idx_type nrb = b.rows (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
93 octave_idx_type dla = a.diag_length (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
94 octave_idx_type nca = a.cols (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
95 octave_idx_type ncb = b.cols (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7455
diff
changeset
|
96 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14556
diff
changeset
|
97 MArray<T> c (dim_vector (nra*nrb, nca*ncb), T ()); |
10461 | 98 |
99 for (octave_idx_type ja = 0; ja < dla; ja++) | |
25485
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
100 { |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
101 octave_quit (); |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
102 for (octave_idx_type jb = 0; jb < ncb; jb++) |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
103 { |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
104 mx_inline_mul (nrb, &c.xelem (ja*nrb, ja*ncb + jb), a.dgelem (ja), |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
105 b.data () + nrb*jb); |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
106 } |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
107 } |
10461 | 108 |
109 return c; | |
110 } | |
3910 | 111 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
112 template <typename T> |
10461 | 113 static MSparse<T> |
114 kron (const MSparse<T>& A, const MSparse<T>& B) | |
7455
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 { |
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
116 octave_idx_type idx = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
117 MSparse<T> C (A.rows () * B.rows (), A.columns () * B.columns (), |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10461
diff
changeset
|
118 A.nnz () * B.nnz ()); |
7455
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
119 |
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
120 C.cidx (0) = 0; |
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
121 |
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
122 for (octave_idx_type Aj = 0; Aj < A.columns (); Aj++) |
25485
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
123 { |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
124 octave_quit (); |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
125 for (octave_idx_type Bj = 0; Bj < B.columns (); Bj++) |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
126 { |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
127 for (octave_idx_type Ai = A.cidx (Aj); Ai < A.cidx (Aj+1); Ai++) |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
128 { |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
129 octave_idx_type Ci = A.ridx (Ai) * B.rows (); |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
130 const T v = A.data (Ai); |
7455
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
131 |
25485
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
132 for (octave_idx_type Bi = B.cidx (Bj); Bi < B.cidx (Bj+1); Bi++) |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
133 { |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
134 C.data (idx) = v * B.data (Bi); |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
135 C.ridx (idx++) = Ci + B.ridx (Bi); |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
136 } |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
137 } |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
138 C.cidx (Aj * B.columns () + Bj + 1) = idx; |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
139 } |
38a07d930ccd
Improve kron performance by 17% by fewer calls to octave_quit() (bug #54005).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
140 } |
10461 | 141 |
142 return C; | |
7455
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
143 } |
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
144 |
10461 | 145 static PermMatrix |
146 kron (const PermMatrix& a, const PermMatrix& b) | |
147 { | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
148 octave_idx_type na = a.rows (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
149 octave_idx_type nb = b.rows (); |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
150 const Array<octave_idx_type>& pa = a.col_perm_vec (); |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
151 const Array<octave_idx_type>& pb = b.col_perm_vec (); |
19341
718aaf1e84f7
kron.cc: Use column vector in undeprecated Array constructor (cset 1f4455ff2329).
Rik <rik@octave.org>
parents:
19330
diff
changeset
|
152 Array<octave_idx_type> res_perm (dim_vector (na * nb, 1)); |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
153 octave_idx_type rescol = 0; |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
154 for (octave_idx_type i = 0; i < na; i++) |
10461 | 155 { |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
156 octave_idx_type a_add = pa(i) * nb; |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
157 for (octave_idx_type j = 0; j < nb; j++) |
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
158 res_perm.xelem (rescol++) = a_add + pb(j); |
10461 | 159 } |
160 | |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18812
diff
changeset
|
161 return PermMatrix (res_perm, true); |
10461 | 162 } |
7455
fe332ce262b5
eliminate spkron.cc; dispatch in kron
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
163 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
164 template <typename MTA, typename MTB> |
10461 | 165 octave_value |
166 do_kron (const octave_value& a, const octave_value& b) | |
167 { | |
168 MTA am = octave_value_extract<MTA> (a); | |
169 MTB bm = octave_value_extract<MTB> (b); | |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
170 |
10461 | 171 return octave_value (kron (am, bm)); |
172 } | |
173 | |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
174 octave_value |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
175 dispatch_kron (const octave_value& a, const octave_value& b) |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
176 { |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
177 octave_value retval; |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
178 if (a.is_perm_matrix () && b.is_perm_matrix ()) |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
179 retval = do_kron<PermMatrix, PermMatrix> (a, b); |
23583
b7747a2c88b2
maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
180 else if (a.issparse () || b.issparse ()) |
15942
75cea615ade4
Check for sparse before diagonal class in kron (bug #38082)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
181 { |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
182 if (a.iscomplex () || b.iscomplex ()) |
15942
75cea615ade4
Check for sparse before diagonal class in kron (bug #38082)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
183 retval = do_kron<SparseComplexMatrix, SparseComplexMatrix> (a, b); |
75cea615ade4
Check for sparse before diagonal class in kron (bug #38082)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
184 else |
75cea615ade4
Check for sparse before diagonal class in kron (bug #38082)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
185 retval = do_kron<SparseMatrix, SparseMatrix> (a, b); |
75cea615ade4
Check for sparse before diagonal class in kron (bug #38082)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
186 } |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
187 else if (a.is_diag_matrix ()) |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
188 { |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
189 if (b.is_diag_matrix () && a.rows () == a.columns () |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
190 && b.rows () == b.columns ()) |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
191 { |
14555
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
192 // We have two diagonal matrices, the product of those will be |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
193 // another diagonal matrix. To do that efficiently, extract |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
194 // the diagonals as vectors and compute the product. That |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
195 // will be another vector, which we then use to construct a |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
196 // diagonal matrix object. Note that this will fail if our |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
197 // digaonal matrix object is modified to allow the nonzero |
14555
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
198 // values to be stored off of the principal diagonal (i.e., if |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
199 // diag ([1,2], 3) is modified to return a diagonal matrix |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
200 // object instead of a full matrix object). |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
201 |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
202 octave_value tmp = dispatch_kron (a.diag (), b.diag ()); |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
203 retval = tmp.diag (); |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
204 } |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
205 else if (a.is_single_type () || b.is_single_type ()) |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
206 { |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
207 if (a.iscomplex ()) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
208 retval = do_kron<FloatComplexDiagMatrix, FloatComplexMatrix> (a, b); |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
209 else if (b.iscomplex ()) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
210 retval = do_kron<FloatDiagMatrix, FloatComplexMatrix> (a, b); |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
211 else |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
212 retval = do_kron<FloatDiagMatrix, FloatMatrix> (a, b); |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
213 } |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
214 else |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
215 { |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
216 if (a.iscomplex ()) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
217 retval = do_kron<ComplexDiagMatrix, ComplexMatrix> (a, b); |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
218 else if (b.iscomplex ()) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
219 retval = do_kron<DiagMatrix, ComplexMatrix> (a, b); |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
220 else |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
221 retval = do_kron<DiagMatrix, Matrix> (a, b); |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
222 } |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
223 } |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
224 else if (a.is_single_type () || b.is_single_type ()) |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
225 { |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
226 if (a.iscomplex ()) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
227 retval = do_kron<FloatComplexMatrix, FloatComplexMatrix> (a, b); |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
228 else if (b.iscomplex ()) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
229 retval = do_kron<FloatMatrix, FloatComplexMatrix> (a, b); |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
230 else |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
231 retval = do_kron<FloatMatrix, FloatMatrix> (a, b); |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
232 } |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
233 else |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
234 { |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
235 if (a.iscomplex ()) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
236 retval = do_kron<ComplexMatrix, ComplexMatrix> (a, b); |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
237 else if (b.iscomplex ()) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
238 retval = do_kron<Matrix, ComplexMatrix> (a, b); |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
239 else |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
240 retval = do_kron<Matrix, Matrix> (a, b); |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
241 } |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
242 return retval; |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
243 } |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
244 |
10461 | 245 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
246 DEFUN (kron, args, , |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
247 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
248 @deftypefn {} {} kron (@var{A}, @var{B}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
249 @deftypefnx {} {} kron (@var{A1}, @var{A2}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
250 Form the Kronecker product of two or more matrices. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
251 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
252 This is defined block by block as |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
253 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
254 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
255 x = [ a(i,j)*b ] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
256 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
257 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
258 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
259 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
260 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
261 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
262 kron (1:4, ones (3, 1)) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
263 @result{} 1 2 3 4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
264 1 2 3 4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
265 1 2 3 4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
266 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
267 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
268 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
269 If there are more than two input arguments @var{A1}, @var{A2}, @dots{}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
270 @var{An} the Kronecker product is computed as |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
271 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
272 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
273 kron (kron (@var{A1}, @var{A2}), @dots{}, @var{An}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
274 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
275 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
276 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
277 Since the Kronecker product is associative, this is well-defined. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
278 @end deftypefn */) |
3910 | 279 { |
280 int nargin = args.length (); | |
281 | |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
282 if (nargin < 2) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
283 print_usage (); |
3910 | 284 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
285 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
286 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
287 octave_value a = args(0); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
288 octave_value b = args(1); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
289 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
290 retval = dispatch_kron (a, b); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
291 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
292 for (octave_idx_type i = 2; i < nargin; i++) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
293 retval = dispatch_kron (retval, args(i)); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20172
diff
changeset
|
294 |
3910 | 295 return retval; |
296 } | |
12790
5ecdb60ddf0f
codesprint: Write two tests for kron.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
297 |
5ecdb60ddf0f
codesprint: Write two tests for kron.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
298 /* |
5ecdb60ddf0f
codesprint: Write two tests for kron.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
299 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
300 %! x = ones (2); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
301 %! assert (kron (x, x), ones (4)); |
12790
5ecdb60ddf0f
codesprint: Write two tests for kron.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
302 |
19134
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
303 %!shared x, y, z, p1, p2, d1, d2 |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
304 %! x = [1, 2]; |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
305 %! y = [-1, -2]; |
12790
5ecdb60ddf0f
codesprint: Write two tests for kron.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
306 %! z = [1, 2, 3, 4; 1, 2, 3, 4; 1, 2, 3, 4]; |
19134
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
307 %! p1 = eye (3)([2, 3, 1], :); ## Permutation matrix |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
308 %! p2 = [0 1 0; 0 0 1; 1 0 0]; ## Non-permutation equivalent |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
309 %! d1 = diag ([1 2 3]); ## Diag type matrix |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
310 %! d2 = [1 0 0; 0 2 0; 0 0 3]; ## Non-diag equivalent |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
311 %!assert (kron (1:4, ones (3, 1)), z) |
19134
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
312 %!assert (kron (single (1:4), ones (3, 1)), single (z)) |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
313 %!assert (kron (sparse (1:4), ones (3, 1)), sparse (z)) |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
314 %!assert (kron (complex (1:4), ones (3, 1)), z) |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
315 %!assert (kron (complex (single (1:4)), ones (3, 1)), single (z)) |
13748
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
316 %!assert (kron (x, y, z), kron (kron (x, y), z)) |
77857d6fe074
Allow more than two input arguments for the kron function, plus some cleanup.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12790
diff
changeset
|
317 %!assert (kron (x, y, z), kron (x, kron (y, z))) |
19134
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
318 %!assert (kron (p1, p1), kron (p2, p2)) |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
319 %!assert (kron (p1, p2), kron (p2, p1)) |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
320 %!assert (kron (d1, d1), kron (d2, d2)) |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
321 %!assert (kron (d1, d2), kron (d2, d1)) |
38c54d45d05f
kron.cc: codesprint: add more kron tests
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18849
diff
changeset
|
322 |
14555
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
323 %!assert (kron (diag ([1, 2]), diag ([3, 4])), diag ([3, 4, 6, 8])) |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
324 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
325 ## Test for two diag matrices. |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
326 ## See the comments above in dispatch_kron for this case. |
14555
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
327 %!test |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
328 %! expected = zeros (16, 16); |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
329 %! expected (1, 11) = 3; |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
330 %! expected (2, 12) = 4; |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
331 %! expected (5, 15) = 6; |
6eabd81604b5
allow kron to work for two diag matrix arguments (bug #35647)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
332 %! expected (6, 16) = 8; |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
333 %! assert (kron (diag ([1, 2], 2), diag ([3, 4], 2)), expected); |
12790
5ecdb60ddf0f
codesprint: Write two tests for kron.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
334 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
335 |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
336 OCTAVE_NAMESPACE_END |