annotate liboctave/numeric/oct-norm.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 51a3d3a69193
children dfa5d9c3ae72 aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30394
diff changeset
3 // Copyright (C) 2008-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 ////////////////////////////////////////////////////////////////////////
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21275
diff changeset
27 # include "config.h"
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28 #endif
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30 #include <cmath>
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31
23475
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23449
diff changeset
32 #include <algorithm>
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23220
diff changeset
33 #include <limits>
8308
5fe0f4dfdbec use std::vector as a simple linear container in oct-norm.cc to avoid problems with instantiating Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 8303
diff changeset
34 #include <vector>
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35
21273
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
36 #include "Array.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
37 #include "CColVector.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
38 #include "CMatrix.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
39 #include "CRowVector.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
40 #include "CSparse.h"
23475
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23449
diff changeset
41 #include "MArray.h"
21273
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
42 #include "dColVector.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
43 #include "dDiagMatrix.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
44 #include "dMatrix.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
45 #include "dRowVector.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
46 #include "dSparse.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
47 #include "fCColVector.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
48 #include "fCMatrix.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
49 #include "fCRowVector.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
50 #include "fColVector.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
51 #include "fDiagMatrix.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
52 #include "fMatrix.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
53 #include "fRowVector.h"
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 #include "lo-error.h"
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 #include "lo-ieee.h"
23475
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23449
diff changeset
56 #include "lo-mappers.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
57 #include "mx-cm-s.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
58 #include "mx-fcm-fs.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18084
diff changeset
59 #include "mx-fs-fcm.h"
21273
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
60 #include "mx-s-cm.h"
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
61 #include "oct-cmplx.h"
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
62 #include "oct-norm.h"
23475
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23449
diff changeset
63 #include "quit.h"
21273
cbced1c09916 better use of templates for svd classes
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
64 #include "svd.h"
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
65
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30898
diff changeset
66 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30898
diff changeset
67
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
68 // Theory: norm accumulator is an object that has an accum method able
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
69 // to handle both real and complex element, and a cast operator
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
70 // returning the intermediate norm. Reference: Higham, N. "Estimating
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
71 // the Matrix p-Norm." Numer. Math. 62, 539-555, 1992.
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
72
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
73 // norm accumulator for the p-norm
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
74 template <typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
75 class norm_accumulator_p
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
76 {
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
77 public:
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
78 norm_accumulator_p () { } // we need this one for Array
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
79 norm_accumulator_p (R pp) : m_p(pp), m_scl(0), m_sum(1) { }
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
80
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
81 template <typename U>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
82 void accum (U val)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
83 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
84 octave_quit ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
85 R t = std::abs (val);
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
86 if (m_scl == t) // we need this to handle Infs properly
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
87 m_sum += 1;
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
88 else if (m_scl < t)
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
89 {
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
90 m_sum *= std::pow (m_scl/t, m_p);
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
91 m_sum += 1;
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
92 m_scl = t;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
93 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
94 else if (t != 0)
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
95 m_sum += std::pow (t/m_scl, m_p);
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
96 }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
97
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
98 operator R () { return m_scl * std::pow (m_sum, 1/m_p); }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
99
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
100 private:
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
101 R m_p, m_scl, m_sum;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
102 };
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
103
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
104 // norm accumulator for the minus p-pseudonorm
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
105 template <typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
106 class norm_accumulator_mp
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
107 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
108 public:
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
109 norm_accumulator_mp () { } // we need this one for Array
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
110 norm_accumulator_mp (R pp) : m_p(pp), m_scl(0), m_sum(1) { }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
111
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
112 template <typename U>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
113 void accum (U val)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
114 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
115 octave_quit ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
116 R t = 1 / std::abs (val);
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
117 if (m_scl == t)
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
118 m_sum += 1;
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
119 else if (m_scl < t)
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
120 {
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
121 m_sum *= std::pow (m_scl/t, m_p);
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
122 m_sum += 1;
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
123 m_scl = t;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
124 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
125 else if (t != 0)
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
126 m_sum += std::pow (t/m_scl, m_p);
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
127 }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
128
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
129 operator R () { return m_scl * std::pow (m_sum, -1/m_p); }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
130
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
131 private:
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
132 R m_p, m_scl, m_sum;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
133 };
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
134
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
135 // norm accumulator for the 2-norm (euclidean)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
136 template <typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
137 class norm_accumulator_2
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
138 {
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
139 public:
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
140 norm_accumulator_2 () : m_scl(0), m_sum(1) { }
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
141
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
142 void accum (R val)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
143 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
144 R t = std::abs (val);
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
145 if (m_scl == t)
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
146 m_sum += 1;
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
147 else if (m_scl < t)
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
148 {
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
149 m_sum *= pow2 (m_scl/t);
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
150 m_sum += 1;
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
151 m_scl = t;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
152 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
153 else if (t != 0)
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
154 m_sum += pow2 (t/m_scl);
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
155 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
156
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
157 void accum (std::complex<R> val)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
158 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
159 accum (val.real ());
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
160 accum (val.imag ());
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
161 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
162
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
163 operator R () { return m_scl * std::sqrt (m_sum); }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
164
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
165 private:
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
166 static inline R pow2 (R x) { return x*x; }
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
167
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
168 //--------
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
169
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
170 R m_scl, m_sum;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
171 };
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
172
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
173 // norm accumulator for the 1-norm (city metric)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
174 template <typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
175 class norm_accumulator_1
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
176 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
177 public:
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
178 norm_accumulator_1 () : m_sum (0) { }
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
179 template <typename U>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
180 void accum (U val)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
181 {
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
182 m_sum += std::abs (val);
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
183 }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
184
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
185 operator R () { return m_sum; }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
186
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
187 private:
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
188 R m_sum;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
189 };
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
190
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
191 // norm accumulator for the inf-norm (max metric)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
192 template <typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
193 class norm_accumulator_inf
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
194 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
195 public:
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
196 norm_accumulator_inf () : m_max (0) { }
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
197 template <typename U>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
198 void accum (U val)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
199 {
29950
6549fa7558ba eliminate some unnecessary octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 29874
diff changeset
200 if (math::isnan (val))
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
201 m_max = numeric_limits<R>::NaN ();
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
202 else
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
203 m_max = std::max (m_max, std::abs (val));
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
204 }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
205
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
206 operator R () { return m_max; }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
207
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
208 private:
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
209 R m_max;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
210 };
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
211
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
212 // norm accumulator for the -inf pseudonorm (min abs value)
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
213 template <typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
214 class norm_accumulator_minf
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
215 {
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
216 public:
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
217 norm_accumulator_minf () : m_min (numeric_limits<R>::Inf ()) { }
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
218 template <typename U>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
219 void accum (U val)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
220 {
29950
6549fa7558ba eliminate some unnecessary octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 29874
diff changeset
221 if (math::isnan (val))
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
222 m_min = numeric_limits<R>::NaN ();
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
223 else
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
224 m_min = std::min (m_min, std::abs (val));
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
225 }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
226
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
227 operator R () { return m_min; }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
228
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
229 private:
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
230 R m_min;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
231 };
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
232
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
233 // norm accumulator for the 0-pseudonorm (hamming distance)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
234 template <typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
235 class norm_accumulator_0
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
236 {
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
237 public:
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
238 norm_accumulator_0 () : m_num (0) { }
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
239 template <typename U>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
240 void accum (U val)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
241 {
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
242 if (val != static_cast<U> (0)) ++m_num;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
243 }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
244
30098
de8ba056e8e2 maint: use "m_" prefix for more member variables in oct-norm.cc (da3659538d16)
Rik <rik@octave.org>
parents: 30097
diff changeset
245 operator R () { return m_num; }
30114
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
246
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
247 private:
b0af792466dc maint: Add "private:" access specifier to classes in oct-norm.cc.
Rik <rik@octave.org>
parents: 30098
diff changeset
248 unsigned int m_num;
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
249 };
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
250
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
251 // OK, we're armed :) Now let's go for the fun
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
252
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
253 template <typename T, typename R, typename ACC>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
254 inline void vector_norm (const Array<T>& v, R& res, ACC acc)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
255 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
256 for (octave_idx_type i = 0; i < v.numel (); i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
257 acc.accum (v(i));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
258
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
259 res = acc;
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
260 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
261
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
262 // dense versions
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
263 template <typename T, typename R, typename ACC>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
264 void column_norms (const MArray<T>& m, MArray<R>& res, ACC acc)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
265 {
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
266 res = MArray<R> (dim_vector (1, m.columns ()));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
267 for (octave_idx_type j = 0; j < m.columns (); j++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
268 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
269 ACC accj = acc;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
270 for (octave_idx_type i = 0; i < m.rows (); i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
271 accj.accum (m(i, j));
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
272
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
273 res.xelem (j) = accj;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
274 }
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
275 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
276
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
277 template <typename T, typename R, typename ACC>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
278 void row_norms (const MArray<T>& m, MArray<R>& res, ACC acc)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
279 {
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
280 res = MArray<R> (dim_vector (m.rows (), 1));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
281 std::vector<ACC> acci (m.rows (), acc);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
282 for (octave_idx_type j = 0; j < m.columns (); j++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
283 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
284 for (octave_idx_type i = 0; i < m.rows (); i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
285 acci[i].accum (m(i, j));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
286 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
287
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
288 for (octave_idx_type i = 0; i < m.rows (); i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
289 res.xelem (i) = acci[i];
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
290 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
291
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
292 // sparse versions
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
293 template <typename T, typename R, typename ACC>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
294 void column_norms (const MSparse<T>& m, MArray<R>& res, ACC acc)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
295 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
296 res = MArray<R> (dim_vector (1, m.columns ()));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
297 for (octave_idx_type j = 0; j < m.columns (); j++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
298 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
299 ACC accj = acc;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
300 for (octave_idx_type k = m.cidx (j); k < m.cidx (j+1); k++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
301 accj.accum (m.data (k));
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
302
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
303 res.xelem (j) = accj;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
304 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
305 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
306
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
307 template <typename T, typename R, typename ACC>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
308 void row_norms (const MSparse<T>& m, MArray<R>& res, ACC acc)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
309 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
310 res = MArray<R> (dim_vector (m.rows (), 1));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
311 std::vector<ACC> acci (m.rows (), acc);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
312 for (octave_idx_type j = 0; j < m.columns (); j++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
313 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
314 for (octave_idx_type k = m.cidx (j); k < m.cidx (j+1); k++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
315 acci[m.ridx (k)].accum (m.data (k));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
316 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
317
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
318 for (octave_idx_type i = 0; i < m.rows (); i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
319 res.xelem (i) = acci[i];
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
320 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
321
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
322 // now the dispatchers
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
323 #define DEFINE_DISPATCHER(FCN_NAME, ARG_TYPE, RES_TYPE) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
324 template <typename T, typename R> \
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
325 RES_TYPE FCN_NAME (const ARG_TYPE& v, R p) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
326 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
327 RES_TYPE res; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
328 if (p == 2) \
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
329 FCN_NAME (v, res, norm_accumulator_2<R> ()); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
330 else if (p == 1) \
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
331 FCN_NAME (v, res, norm_accumulator_1<R> ()); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
332 else if (lo_ieee_isinf (p)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
333 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
334 if (p > 0) \
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
335 FCN_NAME (v, res, norm_accumulator_inf<R> ()); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
336 else \
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
337 FCN_NAME (v, res, norm_accumulator_minf<R> ()); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
338 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
339 else if (p == 0) \
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
340 FCN_NAME (v, res, norm_accumulator_0<R> ()); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
341 else if (p > 0) \
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
342 FCN_NAME (v, res, norm_accumulator_p<R> (p)); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
343 else \
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
344 FCN_NAME (v, res, norm_accumulator_mp<R> (p)); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
345 return res; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
346 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
347
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
348 DEFINE_DISPATCHER (vector_norm, MArray<T>, R)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
349 DEFINE_DISPATCHER (column_norms, MArray<T>, MArray<R>)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
350 DEFINE_DISPATCHER (row_norms, MArray<T>, MArray<R>)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
351 DEFINE_DISPATCHER (column_norms, MSparse<T>, MArray<R>)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
352 DEFINE_DISPATCHER (row_norms, MSparse<T>, MArray<R>)
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
353
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
354 // The approximate subproblem in Higham's method. Find lambda and mu such
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
355 // that norm ([lambda, mu], p) == 1 and norm (y*lambda + col*mu, p) is
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
356 // maximized.
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
357 // Real version. As in Higham's paper.
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
358 template <typename ColVectorT, typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
359 static void
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
360 higham_subp (const ColVectorT& y, const ColVectorT& col,
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
361 octave_idx_type nsamp, R p, R& lambda, R& mu)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
362 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
363 R nrm = 0;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
364 for (octave_idx_type i = 0; i < nsamp; i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
365 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
366 octave_quit ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
367 R fi = i * static_cast<R> (M_PI) / nsamp;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
368 R lambda1 = cos (fi);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
369 R mu1 = sin (fi);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
370 R lmnr = std::pow (std::pow (std::abs (lambda1), p) +
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
371 std::pow (std::abs (mu1), p), 1/p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
372 lambda1 /= lmnr; mu1 /= lmnr;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
373 R nrm1 = vector_norm (lambda1 * y + mu1 * col, p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
374 if (nrm1 > nrm)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
375 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
376 lambda = lambda1;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
377 mu = mu1;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
378 nrm = nrm1;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
379 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
380 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
381 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
382
30097
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
383 // Complex version. Higham's paper does not deal with complex case, so we
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
384 // use a simple extension. First, guess the magnitudes as in real version,
da3659538d16 maint: use "m_" prefix for member variables in oct-norm.cc accumulator classes.
Rik <rik@octave.org>
parents: 29950
diff changeset
385 // then try to rotate lambda to improve further.
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
386 template <typename ColVectorT, typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
387 static void
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
388 higham_subp (const ColVectorT& y, const ColVectorT& col,
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
389 octave_idx_type nsamp, R p,
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
390 std::complex<R>& lambda, std::complex<R>& mu)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
391 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
392 typedef std::complex<R> CR;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
393 R nrm = 0;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
394 lambda = 1.0;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
395 CR lamcu = lambda / std::abs (lambda);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
396 // Probe magnitudes
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
397 for (octave_idx_type i = 0; i < nsamp; i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
398 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
399 octave_quit ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
400 R fi = i * static_cast<R> (M_PI) / nsamp;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
401 R lambda1 = cos (fi);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
402 R mu1 = sin (fi);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
403 R lmnr = std::pow (std::pow (std::abs (lambda1), p) +
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
404 std::pow (std::abs (mu1), p), 1/p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
405 lambda1 /= lmnr; mu1 /= lmnr;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
406 R nrm1 = vector_norm (lambda1 * lamcu * y + mu1 * col, p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
407 if (nrm1 > nrm)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
408 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
409 lambda = lambda1 * lamcu;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
410 mu = mu1;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
411 nrm = nrm1;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
412 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
413 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
414 R lama = std::abs (lambda);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
415 // Probe orientation
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
416 for (octave_idx_type i = 0; i < nsamp; i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
417 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
418 octave_quit ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
419 R fi = i * static_cast<R> (M_PI) / nsamp;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
420 lamcu = CR (cos (fi), sin (fi));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
421 R nrm1 = vector_norm (lama * lamcu * y + mu * col, p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
422 if (nrm1 > nrm)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
423 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
424 lambda = lama * lamcu;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
425 nrm = nrm1;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
426 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
427 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
428 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
429
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
430 // the p-dual element (should work for both real and complex)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
431 template <typename T, typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
432 inline T elem_dual_p (T x, R p)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
433 {
29950
6549fa7558ba eliminate some unnecessary octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 29874
diff changeset
434 return math::signum (x) * std::pow (std::abs (x), p-1);
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
435 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
436
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
437 // the VectorT is used for vectors, but actually it has to be
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
438 // a Matrix type to allow all the operations. For instance SparseMatrix
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
439 // does not support multiplication with column/row vectors.
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
440 // the dual vector
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
441 template <typename VectorT, typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
442 VectorT dual_p (const VectorT& x, R p, R q)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
443 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
444 VectorT res (x.dims ());
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
445 for (octave_idx_type i = 0; i < x.numel (); i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
446 res.xelem (i) = elem_dual_p (x(i), p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
447 return res / vector_norm (res, q);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
448 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
449
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
450 // Higham's hybrid method
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
451 template <typename MatrixT, typename VectorT, typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
452 R higham (const MatrixT& m, R p, R tol, int maxiter,
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
453 VectorT& x)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
454 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
455 x.resize (m.columns (), 1);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
456 // the OSE part
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
457 VectorT y(m.rows (), 1, 0), z(m.rows (), 1);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
458 typedef typename VectorT::element_type RR;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
459 RR lambda = 0;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
460 RR mu = 1;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
461 for (octave_idx_type k = 0; k < m.columns (); k++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
462 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
463 octave_quit ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
464 VectorT col (m.column (k));
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
465 if (k > 0)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
466 higham_subp (y, col, 4*k, p, lambda, mu);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
467 for (octave_idx_type i = 0; i < k; i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
468 x(i) *= lambda;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
469 x(k) = mu;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
470 y = lambda * y + mu * col;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
471 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
472
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
473 // the PM part
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
474 x = x / vector_norm (x, p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
475 R q = p/(p-1);
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
476
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
477 R gamma = 0, gamma1;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
478 int iter = 0;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
479 while (iter < maxiter)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
480 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
481 octave_quit ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
482 y = m*x;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
483 gamma1 = gamma;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
484 gamma = vector_norm (y, p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
485 z = dual_p (y, p, q);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
486 z = z.hermitian ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
487 z = z * m;
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
488
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
489 if (iter > 0 && (vector_norm (z, q) <= gamma
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
490 || (gamma - gamma1) <= tol*gamma))
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
491 break;
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
492
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
493 z = z.hermitian ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
494 x = dual_p (z, q, p);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
495 iter++;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
496 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
497
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
498 return gamma;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
499 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
500
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
501 // derive column vector and SVD types
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
502
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
503 static const char *p_less1_gripe = "xnorm: p must be >= 1";
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
504
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
505 // Static constant to control the maximum number of iterations. 100 seems to
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
506 // be a good value. Eventually, we can provide a means to change this
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
507 // constant from Octave.
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
508 static int max_norm_iter = 100;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
509
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
510 // version with SVD for dense matrices
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
511 template <typename MatrixT, typename VectorT, typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
512 R svd_matrix_norm (const MatrixT& m, R p, VectorT)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
513 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
514 // NOTE: The octave:: namespace tags are needed for the following
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
515 // function calls until the deprecated inline functions are removed
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
516 // from oct-norm.h.
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
517
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
518 R res = 0;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
519 if (p == 2)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
520 {
29950
6549fa7558ba eliminate some unnecessary octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 29874
diff changeset
521 math::svd<MatrixT> fact (m, math::svd<MatrixT>::Type::sigma_only);
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30114
diff changeset
522 res = fact.singular_values () (0, 0);
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
523 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
524 else if (p == 1)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
525 res = octave::xcolnorms (m, static_cast<R> (1)).max ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
526 else if (lo_ieee_isinf (p) && p > 1)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
527 res = octave::xrownorms (m, static_cast<R> (1)).max ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
528 else if (p > 1)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
529 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
530 VectorT x;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
531 const R sqrteps = std::sqrt (std::numeric_limits<R>::epsilon ());
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
532 res = higham (m, p, sqrteps, max_norm_iter, x);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
533 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
534 else
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
535 (*current_liboctave_error_handler) ("%s", p_less1_gripe);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
536
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
537 return res;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
538 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
539
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
540 // SVD-free version for sparse matrices
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
541 template <typename MatrixT, typename VectorT, typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
542 R matrix_norm (const MatrixT& m, R p, VectorT)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
543 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
544 // NOTE: The octave:: namespace tags are needed for the following
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
545 // function calls until the deprecated inline functions are removed
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
546 // from oct-norm.h.
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
547
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
548 R res = 0;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
549 if (p == 1)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
550 res = octave::xcolnorms (m, static_cast<R> (1)).max ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
551 else if (lo_ieee_isinf (p) && p > 1)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
552 res = octave::xrownorms (m, static_cast<R> (1)).max ();
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
553 else if (p > 1)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
554 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
555 VectorT x;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
556 const R sqrteps = std::sqrt (std::numeric_limits<R>::epsilon ());
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
557 res = higham (m, p, sqrteps, max_norm_iter, x);
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
558 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
559 else
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
560 (*current_liboctave_error_handler) ("%s", p_less1_gripe);
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
561
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
562 return res;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
563 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
564
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
565 // and finally, here's what we've promised in the header file
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
566
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
567 #define DEFINE_XNORM_FCNS(PREFIX, RTYPE) \
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
568 RTYPE xnorm (const PREFIX##ColumnVector& x, RTYPE p) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
569 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
570 return vector_norm (x, p); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
571 } \
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
572 RTYPE xnorm (const PREFIX##RowVector& x, RTYPE p) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
573 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
574 return vector_norm (x, p); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
575 } \
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
576 RTYPE xnorm (const PREFIX##Matrix& x, RTYPE p) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
577 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
578 return svd_matrix_norm (x, p, PREFIX##Matrix ()); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
579 } \
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
580 RTYPE xfrobnorm (const PREFIX##Matrix& x) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
581 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
582 return vector_norm (x, static_cast<RTYPE> (2)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
583 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
584
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
585 DEFINE_XNORM_FCNS(, double)
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
586 DEFINE_XNORM_FCNS(Complex, double)
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
587 DEFINE_XNORM_FCNS(Float, float)
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
588 DEFINE_XNORM_FCNS(FloatComplex, float)
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
589
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
590 // this is needed to avoid copying the sparse matrix for xfrobnorm
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
591 template <typename T, typename R>
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
592 inline void array_norm_2 (const T *v, octave_idx_type n, R& res)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
593 {
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
594 norm_accumulator_2<R> acc;
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
595 for (octave_idx_type i = 0; i < n; i++)
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
596 acc.accum (v[i]);
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
597
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
598 res = acc;
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
599 }
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
600
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
601 #define DEFINE_XNORM_SPARSE_FCNS(PREFIX, RTYPE) \
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
602 RTYPE xnorm (const Sparse##PREFIX##Matrix& x, RTYPE p) \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
603 { \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
604 return matrix_norm (x, p, PREFIX##Matrix ()); \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
605 } \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
606 RTYPE xfrobnorm (const Sparse##PREFIX##Matrix& x) \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
607 { \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
608 RTYPE res; \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
609 array_norm_2 (x.data (), x.nnz (), res); \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
610 return res; \
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
611 }
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
612
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
613 DEFINE_XNORM_SPARSE_FCNS(, double)
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
614 DEFINE_XNORM_SPARSE_FCNS(Complex, double)
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
615
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
616 #define DEFINE_COLROW_NORM_FCNS(PREFIX, RPREFIX, RTYPE) \
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
617 RPREFIX##RowVector \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
618 xcolnorms (const PREFIX##Matrix& m, RTYPE p) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
619 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
620 return column_norms (m, p); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
621 } \
29874
92662b17ef7e move liboctave xnorm functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
622 RPREFIX##ColumnVector \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
623 xrownorms (const PREFIX##Matrix& m, RTYPE p) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
624 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
625 return row_norms (m, p); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
626 } \
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
627
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
628 DEFINE_COLROW_NORM_FCNS(, , double)
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
629 DEFINE_COLROW_NORM_FCNS(Complex, , double)
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
630 DEFINE_COLROW_NORM_FCNS(Float, Float, float)
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
631 DEFINE_COLROW_NORM_FCNS(FloatComplex, Float, float)
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
632
30898
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
633 DEFINE_COLROW_NORM_FCNS(Sparse, , double)
51a3d3a69193 maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents: 30564
diff changeset
634 DEFINE_COLROW_NORM_FCNS(SparseComplex, , double)
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30898
diff changeset
635
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30898
diff changeset
636 OCTAVE_END_NAMESPACE(octave)