Mercurial > octave
annotate libinterp/corefcn/kron.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc,
op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc,
op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc,
op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc,
op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc,
op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc,
op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc,
op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc,
op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc,
op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | 32d2b6604a9f |
children | dfa5d9c3ae72 597f3ee61a48 |
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 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
52 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
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 { | |
30723
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30564
diff
changeset
|
58 error_unless (a.ndims () == 2); |
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30564
diff
changeset
|
59 error_unless (b.ndims () == 2); |
10461 | 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 { | |
30723
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30564
diff
changeset
|
89 error_unless (b.ndims () == 2); |
10461 | 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 -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
248 @deftypefn {} {@var{C} =} kron (@var{A}, @var{B}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
249 @deftypefnx {} {@var{C} =} kron (@var{A1}, @var{A2}, @dots{}) |
21966
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 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30723
diff
changeset
|
255 c = [ a(i,j)*b ] |
21966
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 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
336 OCTAVE_END_NAMESPACE(octave) |