annotate libinterp/corefcn/data.cc @ 17787:175b392e91fe

Use GNU style coding conventions for code in libinterp/ * libinterp/corefcn/Cell.h, libinterp/corefcn/__contourc__.cc, libinterp/corefcn/__dispatch__.cc, libinterp/corefcn/__lin_interpn__.cc, libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc, libinterp/corefcn/balance.cc, libinterp/corefcn/besselj.cc, libinterp/corefcn/betainc.cc, libinterp/corefcn/bitfcns.cc, libinterp/corefcn/bsxfun.cc, libinterp/corefcn/c-file-ptr-stream.cc, libinterp/corefcn/c-file-ptr-stream.h, libinterp/corefcn/cellfun.cc, libinterp/corefcn/colloc.cc, libinterp/corefcn/comment-list.h, libinterp/corefcn/conv2.cc, libinterp/corefcn/daspk.cc, libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc, libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc, libinterp/corefcn/defaults.in.h, libinterp/corefcn/defun-int.h, libinterp/corefcn/defun.cc, libinterp/corefcn/det.cc, libinterp/corefcn/dirfns.cc, libinterp/corefcn/display.cc, libinterp/corefcn/dlmread.cc, libinterp/corefcn/dot.cc, libinterp/corefcn/dynamic-ld.cc, libinterp/corefcn/dynamic-ld.h, libinterp/corefcn/eig.cc, libinterp/corefcn/ellipj.cc, libinterp/corefcn/error.cc, libinterp/corefcn/error.h, libinterp/corefcn/event-queue.h, libinterp/corefcn/fft.cc, libinterp/corefcn/fft2.cc, libinterp/corefcn/fftn.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/filter.cc, libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc, libinterp/corefcn/gcd.cc, libinterp/corefcn/getgrent.cc, libinterp/corefcn/getpwent.cc, libinterp/corefcn/getrusage.cc, libinterp/corefcn/givens.cc, libinterp/corefcn/gl-render.cc, libinterp/corefcn/gl2ps-renderer.cc, libinterp/corefcn/gl2ps-renderer.h, libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h, libinterp/corefcn/gripes.cc, libinterp/corefcn/gripes.h, libinterp/corefcn/help.cc, libinterp/corefcn/hess.cc, libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc, libinterp/corefcn/input.h, libinterp/corefcn/inv.cc, libinterp/corefcn/jit-ir.h, libinterp/corefcn/jit-typeinfo.cc, libinterp/corefcn/jit-typeinfo.h, libinterp/corefcn/jit-util.h, libinterp/corefcn/kron.cc, libinterp/corefcn/load-path.cc, libinterp/corefcn/load-path.h, libinterp/corefcn/load-save.cc, libinterp/corefcn/load-save.h, libinterp/corefcn/lookup.cc, libinterp/corefcn/ls-ascii-helper.cc, libinterp/corefcn/ls-hdf5.cc, libinterp/corefcn/ls-hdf5.h, libinterp/corefcn/ls-mat-ascii.cc, libinterp/corefcn/ls-mat-ascii.h, libinterp/corefcn/ls-mat4.cc, libinterp/corefcn/ls-mat5.cc, libinterp/corefcn/ls-mat5.h, libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lsode.cc, libinterp/corefcn/lu.cc, libinterp/corefcn/luinc.cc, libinterp/corefcn/mappers.cc, libinterp/corefcn/matrix_type.cc, libinterp/corefcn/max.cc, libinterp/corefcn/md5sum.cc, libinterp/corefcn/mex.cc, libinterp/corefcn/mexproto.h, libinterp/corefcn/mgorth.cc, libinterp/corefcn/mxarray.in.h, libinterp/corefcn/nproc.cc, libinterp/corefcn/oct-hist.cc, libinterp/corefcn/oct-lvalue.h, libinterp/corefcn/oct-map.cc, libinterp/corefcn/oct-map.h, libinterp/corefcn/oct-obj.h, libinterp/corefcn/oct-prcstrm.h, libinterp/corefcn/oct-stdstrm.h, libinterp/corefcn/oct-stream.cc, libinterp/corefcn/oct-stream.h, libinterp/corefcn/octave-link.cc, libinterp/corefcn/octave-link.h, libinterp/corefcn/pager.cc, libinterp/corefcn/pinv.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/procstream.h, libinterp/corefcn/profiler.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/pt-jit.h, libinterp/corefcn/quad.cc, libinterp/corefcn/quadcc.cc, libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/rcond.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc, libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sighandlers.h, libinterp/corefcn/sparse-xdiv.cc, libinterp/corefcn/sparse-xdiv.h, libinterp/corefcn/sparse-xpow.cc, libinterp/corefcn/sparse.cc, libinterp/corefcn/spparms.cc, libinterp/corefcn/sqrtm.cc, libinterp/corefcn/str2double.cc, libinterp/corefcn/strfind.cc, libinterp/corefcn/strfns.cc, libinterp/corefcn/sub2ind.cc, libinterp/corefcn/svd.cc, libinterp/corefcn/syl.cc, libinterp/corefcn/symtab.cc, libinterp/corefcn/symtab.h, libinterp/corefcn/syscalls.cc, libinterp/corefcn/sysdep.cc, libinterp/corefcn/sysdep.h, libinterp/corefcn/time.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h, libinterp/corefcn/tril.cc, libinterp/corefcn/txt-eng-ft.cc, libinterp/corefcn/txt-eng-ft.h, libinterp/corefcn/txt-eng.h, libinterp/corefcn/typecast.cc, libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc, libinterp/corefcn/variables.h, libinterp/corefcn/xdiv.cc, libinterp/corefcn/xdiv.h, libinterp/corefcn/xnorm.h, libinterp/corefcn/xpow.cc, libinterp/corefcn/xpow.h, libinterp/corefcn/zfstream.cc, libinterp/corefcn/zfstream.h, libinterp/dldfcn/__delaunayn__.cc, libinterp/dldfcn/__dsearchn__.cc, libinterp/dldfcn/__eigs__.cc, libinterp/dldfcn/__fltk_uigetfile__.cc, libinterp/dldfcn/__glpk__.cc, libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__init_gnuplot__.cc, libinterp/dldfcn/__magick_read__.cc, libinterp/dldfcn/__voronoi__.cc, libinterp/dldfcn/amd.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/chol.cc, libinterp/dldfcn/colamd.cc, libinterp/dldfcn/convhulln.cc, libinterp/dldfcn/dmperm.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc, libinterp/dldfcn/symbfact.cc, libinterp/dldfcn/symrcm.cc, libinterp/dldfcn/tsearch.cc, libinterp/octave-value/ov-base-diag.cc, libinterp/octave-value/ov-base-diag.h, libinterp/octave-value/ov-base-int.cc, libinterp/octave-value/ov-base-int.h, libinterp/octave-value/ov-base-mat.h, libinterp/octave-value/ov-base-scalar.cc, libinterp/octave-value/ov-base-scalar.h, libinterp/octave-value/ov-base-sparse.cc, libinterp/octave-value/ov-base-sparse.h, libinterp/octave-value/ov-base.cc, libinterp/octave-value/ov-base.h, libinterp/octave-value/ov-bool-mat.cc, libinterp/octave-value/ov-bool-mat.h, libinterp/octave-value/ov-bool-sparse.cc, libinterp/octave-value/ov-bool-sparse.h, libinterp/octave-value/ov-bool.cc, libinterp/octave-value/ov-bool.h, libinterp/octave-value/ov-builtin.cc, libinterp/octave-value/ov-builtin.h, libinterp/octave-value/ov-cell.cc, libinterp/octave-value/ov-cell.h, libinterp/octave-value/ov-ch-mat.cc, libinterp/octave-value/ov-ch-mat.h, libinterp/octave-value/ov-class.cc, libinterp/octave-value/ov-class.h, libinterp/octave-value/ov-colon.h, libinterp/octave-value/ov-complex.cc, libinterp/octave-value/ov-complex.h, libinterp/octave-value/ov-cx-diag.cc, libinterp/octave-value/ov-cx-diag.h, libinterp/octave-value/ov-cx-mat.cc, libinterp/octave-value/ov-cx-mat.h, libinterp/octave-value/ov-cx-sparse.cc, libinterp/octave-value/ov-cx-sparse.h, libinterp/octave-value/ov-dld-fcn.h, libinterp/octave-value/ov-fcn-handle.cc, libinterp/octave-value/ov-fcn-handle.h, libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-fcn-inline.h, libinterp/octave-value/ov-fcn.h, libinterp/octave-value/ov-float.cc, libinterp/octave-value/ov-float.h, libinterp/octave-value/ov-flt-complex.cc, libinterp/octave-value/ov-flt-complex.h, libinterp/octave-value/ov-flt-cx-diag.cc, libinterp/octave-value/ov-flt-cx-diag.h, libinterp/octave-value/ov-flt-cx-mat.cc, libinterp/octave-value/ov-flt-cx-mat.h, libinterp/octave-value/ov-flt-re-diag.cc, libinterp/octave-value/ov-flt-re-diag.h, libinterp/octave-value/ov-flt-re-mat.cc, libinterp/octave-value/ov-flt-re-mat.h, libinterp/octave-value/ov-int16.cc, libinterp/octave-value/ov-int32.cc, libinterp/octave-value/ov-int64.cc, libinterp/octave-value/ov-int8.cc, libinterp/octave-value/ov-intx.h, libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-lazy-idx.h, libinterp/octave-value/ov-mex-fcn.cc, libinterp/octave-value/ov-mex-fcn.h, libinterp/octave-value/ov-null-mat.cc, libinterp/octave-value/ov-null-mat.h, libinterp/octave-value/ov-oncleanup.cc, libinterp/octave-value/ov-perm.cc, libinterp/octave-value/ov-perm.h, libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-range.h, libinterp/octave-value/ov-re-diag.cc, libinterp/octave-value/ov-re-diag.h, libinterp/octave-value/ov-re-mat.cc, libinterp/octave-value/ov-re-mat.h, libinterp/octave-value/ov-re-sparse.cc, libinterp/octave-value/ov-re-sparse.h, libinterp/octave-value/ov-scalar.cc, libinterp/octave-value/ov-scalar.h, libinterp/octave-value/ov-str-mat.cc, libinterp/octave-value/ov-str-mat.h, libinterp/octave-value/ov-struct.cc, libinterp/octave-value/ov-struct.h, libinterp/octave-value/ov-type-conv.h, libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov-typeinfo.h, libinterp/octave-value/ov-uint16.cc, libinterp/octave-value/ov-uint32.cc, libinterp/octave-value/ov-uint64.cc, libinterp/octave-value/ov-uint8.cc, libinterp/octave-value/ov-usr-fcn.cc, libinterp/octave-value/ov-usr-fcn.h, libinterp/octave-value/ov.cc, libinterp/octave-value/ov.h, libinterp/octave.cc, libinterp/operators/op-b-bm.cc, libinterp/operators/op-b-sbm.cc, libinterp/operators/op-bm-b.cc, libinterp/operators/op-bm-bm.cc, libinterp/operators/op-cdm-cdm.cc, libinterp/operators/op-chm.cc, libinterp/operators/op-class.cc, libinterp/operators/op-cm-cm.cc, libinterp/operators/op-cm-cs.cc, libinterp/operators/op-cm-s.cc, libinterp/operators/op-cm-scm.cc, libinterp/operators/op-cm-sm.cc, libinterp/operators/op-cs-cm.cc, libinterp/operators/op-cs-cs.cc, libinterp/operators/op-cs-scm.cc, libinterp/operators/op-cs-sm.cc, libinterp/operators/op-dm-dm.cc, libinterp/operators/op-dm-scm.cc, libinterp/operators/op-double-conv.cc, libinterp/operators/op-fcdm-fcdm.cc, libinterp/operators/op-fcm-fcm.cc, libinterp/operators/op-fcm-fcs.cc, libinterp/operators/op-fcm-fm.cc, libinterp/operators/op-fcm-fs.cc, libinterp/operators/op-fcs-fcm.cc, libinterp/operators/op-fcs-fcs.cc, libinterp/operators/op-fcs-fm.cc, libinterp/operators/op-fcs-fs.cc, libinterp/operators/op-fdm-fdm.cc, libinterp/operators/op-float-conv.cc, libinterp/operators/op-fm-fcm.cc, libinterp/operators/op-fm-fcs.cc, libinterp/operators/op-fm-fm.cc, libinterp/operators/op-fm-fs.cc, libinterp/operators/op-fs-fcm.cc, libinterp/operators/op-fs-fcs.cc, libinterp/operators/op-fs-fm.cc, libinterp/operators/op-fs-fs.cc, libinterp/operators/op-m-cm.cc, libinterp/operators/op-m-cs.cc, libinterp/operators/op-m-m.cc, libinterp/operators/op-m-s.cc, libinterp/operators/op-m-scm.cc, libinterp/operators/op-m-sm.cc, libinterp/operators/op-pm-scm.cc, libinterp/operators/op-range.cc, libinterp/operators/op-s-cm.cc, libinterp/operators/op-s-cs.cc, libinterp/operators/op-s-scm.cc, libinterp/operators/op-sbm-b.cc, libinterp/operators/op-sbm-bm.cc, libinterp/operators/op-sbm-sbm.cc, libinterp/operators/op-scm-cm.cc, libinterp/operators/op-scm-cs.cc, libinterp/operators/op-scm-m.cc, libinterp/operators/op-scm-s.cc, libinterp/operators/op-scm-scm.cc, libinterp/operators/op-scm-sm.cc, libinterp/operators/op-sm-cm.cc, libinterp/operators/op-sm-m.cc, libinterp/operators/op-sm-s.cc, libinterp/operators/op-sm-scm.cc, libinterp/operators/op-sm-sm.cc, libinterp/operators/op-str-m.cc, libinterp/operators/op-str-s.cc, libinterp/operators/op-str-str.cc, libinterp/operators/ops.h, libinterp/parse-tree/lex.h, libinterp/parse-tree/parse.h, libinterp/parse-tree/pt-arg-list.cc, libinterp/parse-tree/pt-arg-list.h, libinterp/parse-tree/pt-assign.cc, libinterp/parse-tree/pt-assign.h, libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-binop.h, libinterp/parse-tree/pt-bp.h, libinterp/parse-tree/pt-cbinop.cc, libinterp/parse-tree/pt-check.cc, libinterp/parse-tree/pt-colon.cc, libinterp/parse-tree/pt-colon.h, libinterp/parse-tree/pt-const.cc, libinterp/parse-tree/pt-decl.cc, libinterp/parse-tree/pt-decl.h, libinterp/parse-tree/pt-eval.cc, libinterp/parse-tree/pt-except.h, libinterp/parse-tree/pt-exp.h, libinterp/parse-tree/pt-fcn-handle.cc, libinterp/parse-tree/pt-id.cc, libinterp/parse-tree/pt-id.h, libinterp/parse-tree/pt-idx.cc, libinterp/parse-tree/pt-idx.h, libinterp/parse-tree/pt-loop.h, libinterp/parse-tree/pt-mat.cc, libinterp/parse-tree/pt-misc.cc, libinterp/parse-tree/pt-misc.h, libinterp/parse-tree/pt-pr-code.cc, libinterp/parse-tree/pt-select.h, libinterp/parse-tree/pt-stmt.h, libinterp/parse-tree/token.h, libinterp/version.cc: Use GNU style coding conventions for code in libinterp/
author Rik <rik@octave.org>
date Mon, 28 Oct 2013 19:51:46 -0700
parents d63878346099
children 573f865aa8c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1 /*
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17621
diff changeset
3 Copyright (C) 1994-2013 John W. Eaton
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
4 Copyright (C) 2009 Jaroslav Hajek
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11435
diff changeset
5 Copyright (C) 2009-2010 VZLU Prague
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
6 Copyright (C) 2012 Carlo de Falco
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
7
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
8 This file is part of Octave.
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
9
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
10 Octave is free software; you can redistribute it and/or modify it
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
11 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
12 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
13 option) any later version.
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
14
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
15 Octave is distributed in the hope that it will be useful, but WITHOUT
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
18 for more details.
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
19
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
21 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
22 <http://www.gnu.org/licenses/>.
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
23
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
24 */
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
25
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1129
diff changeset
27 #include <config.h>
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
28 #endif
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
29
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
30 #include <sys/types.h>
10302
5669a0b893db data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
31 #include <sys/times.h>
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
32
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
33 #ifdef HAVE_SYS_RESOURCE_H
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
34 #include <sys/resource.h>
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
35 #endif
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
36
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
37 #include <cfloat>
10303
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
38 #include <ctime>
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
39
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1572
diff changeset
40 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1572
diff changeset
41
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
42 #include "lo-ieee.h"
7231
2eb392d058bb [project @ 2007-11-30 18:53:29 by jwe]
jwe
parents: 7189
diff changeset
43 #include "lo-math.h"
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
44 #include "oct-base64.h"
10240
fa7b5751730c use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents: 10185
diff changeset
45 #include "oct-time.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
46 #include "str-vec.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4114
diff changeset
47 #include "quit.h"
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
48 #include "mx-base.h"
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
49 #include "oct-binmap.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
50
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
51 #include "Cell.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
52 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
53 #include "error.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
54 #include "gripes.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
55 #include "oct-map.h"
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
56 #include "oct-obj.h"
2366
c90105b99479 [project @ 1996-10-11 23:22:27 by jwe]
jwe
parents: 2305
diff changeset
57 #include "ov.h"
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
58 #include "ov-class.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
59 #include "ov-float.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
60 #include "ov-complex.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
61 #include "ov-flt-complex.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
62 #include "ov-cx-mat.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
63 #include "ov-flt-cx-mat.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
64 #include "ov-cx-sparse.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
65 #include "parse.h"
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
66 #include "pt-mat.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
67 #include "utils.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
68 #include "variables.h"
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
69 #include "pager.h"
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
70 #include "xnorm.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
71
10303
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
72 #if ! defined (CLOCKS_PER_SEC)
10302
5669a0b893db data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
73 #if defined (CLK_TCK)
10303
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
74 #define CLOCKS_PER_SEC CLK_TCK
10302
5669a0b893db data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
75 #else
10303
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
76 #error "no definition for CLOCKS_PER_SEC!"
10302
5669a0b893db data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
77 #endif
5669a0b893db data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
78 #endif
5669a0b893db data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents: 10293
diff changeset
79
7914
e998e81224b5 Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents: 7815
diff changeset
80 #if ! defined (HAVE_HYPOTF) && defined (HAVE__HYPOTF)
e998e81224b5 Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents: 7815
diff changeset
81 #define hypotf _hypotf
e998e81224b5 Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents: 7815
diff changeset
82 #define HAVE_HYPOTF 1
e998e81224b5 Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents: 7815
diff changeset
83 #endif
e998e81224b5 Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents: 7815
diff changeset
84
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
85 #define ANY_ALL(FCN) \
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
86 \
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
87 octave_value retval; \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
88 \
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
89 int nargin = args.length (); \
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
90 \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
91 if (nargin == 1 || nargin == 2) \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
92 { \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
93 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
94 \
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
95 if (! error_state) \
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
96 { \
4556
773a21e4fce8 [project @ 2003-10-28 05:02:10 by jwe]
jwe
parents: 4554
diff changeset
97 if (dim >= -1) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
98 retval = args(0).FCN (dim); \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
99 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
100 error (#FCN ": invalid dimension argument = %d", dim + 1); \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
101 } \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
102 else \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
103 error (#FCN ": expecting dimension argument to be an integer"); \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
104 } \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
105 else \
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
106 print_usage (); \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
107 \
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
108 return retval
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
109
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
110 DEFUN (all, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
111 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
112 @deftypefn {Built-in Function} {} all (@var{x})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
113 @deftypefnx {Built-in Function} {} all (@var{x}, @var{dim})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
114 For a vector argument, return true (logical 1) if all elements of the vector\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
115 are nonzero.\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
116 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
117 For a matrix argument, return a row vector of logical ones and\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
118 zeros with each element indicating whether all of the elements of the\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
119 corresponding column of the matrix are nonzero. For example:\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
120 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
121 @example\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
122 @group\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
123 all ([2, 3; 1, 0]))\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
124 @result{} [ 1, 0 ]\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
125 @end group\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
126 @end example\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
127 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
128 If the optional argument @var{dim} is supplied, work along dimension\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
129 @var{dim}.\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
130 @seealso{any}\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
131 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
132 {
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
133 ANY_ALL (all);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
134 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
135
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
136 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
137 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
138 %! x = ones (3);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
139 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
140 %! assert (all (all (rand (3) + 1) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
141 %! assert (all (all (x) == [0, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
142 %! assert (all (x, 1) == [0, 1, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
143 %! assert (all (x, 2) == [0; 1; 1]);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
144
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
145 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
146 %! x = ones (3, "single");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
147 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
148 %! assert (all (all (single (rand (3) + 1)) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
149 %! assert (all (all (x) == [0, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
150 %! assert (all (x, 1) == [0, 1, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
151 %! assert (all (x, 2) == [0; 1; 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
152
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
153 %!error all ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
154 %!error all (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
155 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
156
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
157 DEFUN (any, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
158 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
159 @deftypefn {Built-in Function} {} any (@var{x})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
160 @deftypefnx {Built-in Function} {} any (@var{x}, @var{dim})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
161 For a vector argument, return true (logical 1) if any element of the vector\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
162 is nonzero.\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
163 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
164 For a matrix argument, return a row vector of logical ones and\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
165 zeros with each element indicating whether any of the elements of the\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
166 corresponding column of the matrix are nonzero. For example:\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
167 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
168 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
169 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
170 any (eye (2, 4))\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
171 @result{} [ 1, 1, 0, 0 ]\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
172 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
173 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
174 \n\
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
175 If the optional argument @var{dim} is supplied, work along dimension\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
176 @var{dim}. For example:\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
177 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
178 @example\n\
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
179 @group\n\
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
180 any (eye (2, 4), 2)\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
181 @result{} [ 1; 1 ]\n\
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
182 @end group\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
183 @end example\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
184 @seealso{all}\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
185 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
186 {
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
187 ANY_ALL (any);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
188 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
189
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
190 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
191 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
192 %! x = zeros (3);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
193 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
194 %! assert (all (any (x) == [0, 0, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
195 %! assert (all (any (ones (3)) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
196 %! assert (any (x, 1) == [0, 0, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
197 %! assert (any (x, 2) == [0; 0; 1]);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
198
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
199 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
200 %! x = zeros (3, "single");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
201 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
202 %! assert (all (any (x) == [0, 0, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
203 %! assert (all (any (ones (3, "single")) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
204 %! assert (any (x, 1) == [0, 0, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
205 %! assert (any (x, 2) == [0; 0; 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
206
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
207 %!error any ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
208 %!error any (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
209 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
210
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
211 // These mapping functions may also be useful in other places, eh?
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
212
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
213 DEFUN (atan2, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
214 "-*- texinfo -*-\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
215 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
216 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\
9155
ad20b967e1c9 Update section 17.3 (Trigonometry) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9142
diff changeset
217 and @var{x}. Signal an error if @var{y} and @var{x} do not match in size\n\
ad20b967e1c9 Update section 17.3 (Trigonometry) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9142
diff changeset
218 and orientation.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
219 @seealso{tan, tand, tanh, atanh}\n\
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3428
diff changeset
220 @end deftypefn")
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
221 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
222 octave_value retval;
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
223
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
224 int nargin = args.length ();
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
225
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
226 if (nargin == 2)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
227 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
228 if (! args(0).is_numeric_type ())
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
229 gripe_wrong_type_arg ("atan2", args(0));
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
230 else if (! args(1).is_numeric_type ())
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
231 gripe_wrong_type_arg ("atan2", args(1));
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
232 else if (args(0).is_complex_type () || args(1).is_complex_type ())
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
233 error ("atan2: not defined for complex numbers");
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
234 else if (args(0).is_single_type () || args(1).is_single_type ())
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
235 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
236 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
237 retval = atan2f (args(0).float_value (), args(1).float_value ());
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
238 else
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
239 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
240 FloatNDArray a0 = args(0).float_array_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
241 FloatNDArray a1 = args(1).float_array_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
242 retval = binmap<float> (a0, a1, ::atan2f, "atan2");
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
243 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
244 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
245 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
246 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
247 bool a0_scalar = args(0).is_scalar_type ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
248 bool a1_scalar = args(1).is_scalar_type ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
249 if (a0_scalar && a1_scalar)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
250 retval = atan2 (args(0).scalar_value (), args(1).scalar_value ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
251 else if ((a0_scalar || args(0).is_sparse_type ())
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
252 && (a1_scalar || args(1).is_sparse_type ()))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
253 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
254 SparseMatrix m0 = args(0).sparse_matrix_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
255 SparseMatrix m1 = args(1).sparse_matrix_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
256 retval = binmap<double> (m0, m1, ::atan2, "atan2");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
257 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
258 else
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
259 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
260 NDArray a0 = args(0).array_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
261 NDArray a1 = args(1).array_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
262 retval = binmap<double> (a0, a1, ::atan2, "atan2");
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
263 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
264 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
265 }
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
266 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
267 print_usage ();
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
268
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
269 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
270 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
271
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
272 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
273 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
274 %!assert (size (atan2 (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
275 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
276 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
277 %!assert (size (atan2 (1, 2)), [1, 1])
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
278
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
279 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
280 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
281 %! rt3 = sqrt (3);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
282 %! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
283 %! y = [0, rt3, 1, rt3, -rt3, -1, -rt3, 0];
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
284 %! x = [1, 3, 1, 1, 1, 1, 3, 1];
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
285 %! assert (atan2 (y, x), v, sqrt (eps));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
286
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
287 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
288 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
289 %! rt3 = sqrt (3);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
290 %! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
291 %! y = single ([0, rt3, 1, rt3, -rt3, -1, -rt3, 0]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
292 %! x = single ([1, 3, 1, 1, 1, 1, 3, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
293 %! assert (atan2 (y, x), v, sqrt (eps ("single")));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
294
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
295 %!error atan2 ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
296 %!error atan2 (1, 2, 3)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
297 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
298
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
299
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
300 static octave_value
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
301 do_hypot (const octave_value& x, const octave_value& y)
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
302 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
303 octave_value retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
304
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
305 octave_value arg0 = x, arg1 = y;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
306 if (! arg0.is_numeric_type ())
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
307 gripe_wrong_type_arg ("hypot", arg0);
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
308 else if (! arg1.is_numeric_type ())
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
309 gripe_wrong_type_arg ("hypot", arg1);
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
310 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
311 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
312 if (arg0.is_complex_type ())
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
313 arg0 = arg0.abs ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
314 if (arg1.is_complex_type ())
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
315 arg1 = arg1.abs ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
316
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
317 if (arg0.is_single_type () || arg1.is_single_type ())
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
318 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
319 if (arg0.is_scalar_type () && arg1.is_scalar_type ())
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
320 retval = hypotf (arg0.float_value (), arg1.float_value ());
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
321 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
322 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
323 FloatNDArray a0 = arg0.float_array_value ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
324 FloatNDArray a1 = arg1.float_array_value ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
325 retval = binmap<float> (a0, a1, ::hypotf, "hypot");
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
326 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
327 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
328 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
329 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
330 bool a0_scalar = arg0.is_scalar_type ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
331 bool a1_scalar = arg1.is_scalar_type ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
332 if (a0_scalar && a1_scalar)
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
333 retval = hypot (arg0.scalar_value (), arg1.scalar_value ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
334 else if ((a0_scalar || arg0.is_sparse_type ())
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
335 && (a1_scalar || arg1.is_sparse_type ()))
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
336 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
337 SparseMatrix m0 = arg0.sparse_matrix_value ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
338 SparseMatrix m1 = arg1.sparse_matrix_value ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
339 retval = binmap<double> (m0, m1, ::hypot, "hypot");
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
340 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
341 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
342 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
343 NDArray a0 = arg0.array_value ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
344 NDArray a1 = arg1.array_value ();
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
345 retval = binmap<double> (a0, a1, ::hypot, "hypot");
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
346 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
347 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
348 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
349
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
350 return retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
351 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
352
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
353 DEFUN (hypot, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
354 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
355 @deftypefn {Built-in Function} {} hypot (@var{x}, @var{y})\n\
10711
fbd7843974fa Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents: 10707
diff changeset
356 @deftypefnx {Built-in Function} {} hypot (@var{x}, @var{y}, @var{z}, @dots{})\n\
9165
8c71a86c4bf4 Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9163
diff changeset
357 Compute the element-by-element square root of the sum of the squares of\n\
8c71a86c4bf4 Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9163
diff changeset
358 @var{x} and @var{y}. This is equivalent to\n\
8c71a86c4bf4 Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9163
diff changeset
359 @code{sqrt (@var{x}.^2 + @var{y}.^2)}, but calculated in a manner that\n\
8c71a86c4bf4 Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9163
diff changeset
360 avoids overflows for large values of @var{x} or @var{y}.\n\
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
361 @code{hypot} can also be called with more than 2 arguments; in this case,\n\
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
362 the arguments are accumulated from left to right:\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
363 \n\
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
364 @example\n\
10711
fbd7843974fa Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents: 10707
diff changeset
365 @group\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
366 hypot (hypot (@var{x}, @var{y}), @var{z})\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
367 hypot (hypot (hypot (@var{x}, @var{y}), @var{z}), @var{w}), etc.\n\
10711
fbd7843974fa Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents: 10707
diff changeset
368 @end group\n\
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
369 @end example\n\
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
370 @end deftypefn")
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
371 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
372 octave_value retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
373
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
374 int nargin = args.length ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
375
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
376 if (nargin == 2)
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
377 {
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
378 retval = do_hypot (args(0), args(1));
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
379 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
380 else if (nargin >= 3)
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
381 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
382 retval = args(0);
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
383 for (int i = 1; i < nargin && ! error_state; i++)
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
384 retval = do_hypot (retval, args(i));
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
385 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
386 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
387 print_usage ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
388
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
389 return retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
390 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
391
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
392 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
393 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
394 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
395 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
396 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
397 %!assert (size (hypot (1, 2)), [1, 1])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
398 %!assert (hypot (1:10, 1:10), sqrt (2) * [1:10], 16*eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
399 %!assert (hypot (single (1:10), single (1:10)), single (sqrt (2) * [1:10]))
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
400 */
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
401
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
402 template<typename T, typename ET>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
403 void
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
404 map_2_xlog2 (const Array<T>& x, Array<T>& f, Array<ET>& e)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
405 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
406 f = Array<T>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
407 e = Array<ET>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
408 for (octave_idx_type i = 0; i < x.numel (); i++)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
409 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
410 int exp;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
411 f.xelem (i) = xlog2 (x(i), exp);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
412 e.xelem (i) = exp;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
413 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
414 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
415
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
416 DEFUN (log2, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
417 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
418 @deftypefn {Mapping Function} {} log2 (@var{x})\n\
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
419 @deftypefnx {Mapping Function} {[@var{f}, @var{e}] =} log2 (@var{x})\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
420 Compute the base-2 logarithm of each element of @var{x}.\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
421 \n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
422 If called with two output arguments, split @var{x} into\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
423 binary mantissa and exponent so that\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
424 @tex\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
425 ${1 \\over 2} \\le \\left| f \\right| < 1$\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
426 @end tex\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
427 @ifnottex\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
428 @code{1/2 <= abs(f) < 1}\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
429 @end ifnottex\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
430 and @var{e} is an integer. If\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
431 @tex\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
432 $x = 0$, $f = e = 0$.\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
433 @end tex\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
434 @ifnottex\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
435 @code{x = 0}, @code{f = e = 0}.\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
436 @end ifnottex\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
437 @seealso{pow2, log, log10, exp}\n\
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
438 @end deftypefn")
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
439 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
440 octave_value_list retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
441
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
442 if (args.length () == 1)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
443 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
444 if (nargout < 2)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
445 retval(0) = args(0).log2 ();
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
446 else if (args(0).is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
447 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
448 if (args(0).is_real_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
449 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
450 FloatNDArray f;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
451 FloatNDArray x = args(0).float_array_value ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
452 // FIXME: should E be an int value?
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
453 FloatMatrix e;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
454 map_2_xlog2 (x, f, e);
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
455 retval(1) = e;
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
456 retval(0) = f;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
457 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
458 else if (args(0).is_complex_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
459 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
460 FloatComplexNDArray f;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
461 FloatComplexNDArray x = args(0).float_complex_array_value ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
462 // FIXME: should E be an int value?
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
463 FloatNDArray e;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
464 map_2_xlog2 (x, f, e);
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
465 retval(1) = e;
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
466 retval(0) = f;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
467 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
468 }
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
469 else if (args(0).is_real_type ())
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
470 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
471 NDArray f;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
472 NDArray x = args(0).array_value ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
473 // FIXME: should E be an int value?
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
474 Matrix e;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
475 map_2_xlog2 (x, f, e);
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
476 retval(1) = e;
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
477 retval(0) = f;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
478 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
479 else if (args(0).is_complex_type ())
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
480 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
481 ComplexNDArray f;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
482 ComplexNDArray x = args(0).complex_array_value ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
483 // FIXME: should E be an int value?
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
484 NDArray e;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
485 map_2_xlog2 (x, f, e);
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
486 retval(1) = e;
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
487 retval(0) = f;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
488 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
489 else
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
490 gripe_wrong_type_arg ("log2", args(0));
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
491 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
492 else
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
493 print_usage ();
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
494
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
495 return retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
496 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
497
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
498 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
499 %!assert (log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
500 %!assert (log2 (Inf), Inf)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
501 %!assert (isnan (log2 (NaN)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
502 %!assert (log2 (4*i), 2 + log2 (1*i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
503 %!assert (log2 (complex (0,Inf)), Inf + log2 (i))
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
504
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
505 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
506 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
507 %! assert (f, [0,-0.5; 0.5,-0.5; Inf,-Inf]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
508 %! assert (e(1:2,:), [0,1;2,3]);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
509
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
510 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
511 %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf]));
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
512 %! assert (f, complex (zeros (3, 2), [0,-0.5; 0.5,-0.5; Inf,-Inf]));
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
513 %! assert (e(1:2,:), [0,1; 2,3]);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
514 */
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
515
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
516 DEFUN (rem, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
517 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
518 @deftypefn {Mapping Function} {} rem (@var{x}, @var{y})\n\
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
519 @deftypefnx {Mapping Function} {} fmod (@var{x}, @var{y})\n\
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12639
diff changeset
520 Return the remainder of the division @code{@var{x} / @var{y}}, computed\n\
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
521 using the expression\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
522 \n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
523 @example\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
524 x - y .* fix (x ./ y)\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
525 @end example\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
526 \n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
527 An error message is printed if the dimensions of the arguments do not\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
528 agree, or if either of the arguments is complex.\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
529 @seealso{mod}\n\
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
530 @end deftypefn")
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
531 {
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
532 octave_value retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
533
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
534 int nargin = args.length ();
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
535
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
536 if (nargin == 2)
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
537 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
538 if (! args(0).is_numeric_type ())
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
539 gripe_wrong_type_arg ("rem", args(0));
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
540 else if (! args(1).is_numeric_type ())
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
541 gripe_wrong_type_arg ("rem", args(1));
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
542 else if (args(0).is_complex_type () || args(1).is_complex_type ())
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
543 error ("rem: not defined for complex numbers");
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
544 else if (args(0).is_integer_type () || args(1).is_integer_type ())
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
545 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
546 builtin_type_t btyp0 = args(0).builtin_type ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
547 builtin_type_t btyp1 = args(1).builtin_type ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
548 if (btyp0 == btyp_double || btyp0 == btyp_float)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
549 btyp0 = btyp1;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
550 if (btyp1 == btyp_double || btyp1 == btyp_float)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
551 btyp1 = btyp0;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
552
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
553 if (btyp0 == btyp1)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
554 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
555 switch (btyp0)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
556 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
557 #define MAKE_INT_BRANCH(X) \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
558 case btyp_ ## X: \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
559 { \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
560 X##NDArray a0 = args(0).X##_array_value (); \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
561 X##NDArray a1 = args(1).X##_array_value (); \
10682
7b4ffe27bbb4 Specify template arguments explicitely [MSVC].
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10538
diff changeset
562 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, rem, "rem"); \
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
563 } \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
564 break
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
565 MAKE_INT_BRANCH (int8);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
566 MAKE_INT_BRANCH (int16);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
567 MAKE_INT_BRANCH (int32);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
568 MAKE_INT_BRANCH (int64);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
569 MAKE_INT_BRANCH (uint8);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
570 MAKE_INT_BRANCH (uint16);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
571 MAKE_INT_BRANCH (uint32);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
572 MAKE_INT_BRANCH (uint64);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
573 #undef MAKE_INT_BRANCH
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
574 default:
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
575 panic_impossible ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
576 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
577 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
578 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
579 error ("rem: cannot combine %s and %d",
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
580 args(0).class_name ().c_str (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
581 args(1).class_name ().c_str ());
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
582 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
583 else if (args(0).is_single_type () || args(1).is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
584 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
585 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
11209
94d9d412a2a0 improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents: 10983
diff changeset
586 retval = xrem (args(0).float_value (), args(1).float_value ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
587 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
588 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
589 FloatNDArray a0 = args(0).float_array_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
590 FloatNDArray a1 = args(1).float_array_value ();
13731
3b52038e6e6c Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13294
diff changeset
591 retval = binmap<float> (a0, a1, xrem<float>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
592 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
593 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
594 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
595 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
596 bool a0_scalar = args(0).is_scalar_type ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
597 bool a1_scalar = args(1).is_scalar_type ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
598 if (a0_scalar && a1_scalar)
11209
94d9d412a2a0 improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents: 10983
diff changeset
599 retval = xrem (args(0).scalar_value (), args(1).scalar_value ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
600 else if ((a0_scalar || args(0).is_sparse_type ())
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
601 && (a1_scalar || args(1).is_sparse_type ()))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
602 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
603 SparseMatrix m0 = args(0).sparse_matrix_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
604 SparseMatrix m1 = args(1).sparse_matrix_value ();
13731
3b52038e6e6c Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13294
diff changeset
605 retval = binmap<double> (m0, m1, xrem<double>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
606 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
607 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
608 {
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
609 NDArray a0 = args(0).array_value ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
610 NDArray a1 = args(1).array_value ();
13731
3b52038e6e6c Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13294
diff changeset
611 retval = binmap<double> (a0, a1, xrem<double>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
612 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
613 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
614 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
615 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
616 print_usage ();
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
617
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
618 return retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
619 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
620
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
621 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
622 %!assert (rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
623 %!assert (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
624 %!assert (rem (uint8 ([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8 ([1, 0, 1; -1, 0, -1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
625 %!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8 ([1, 0, 1; -1, 0, -1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
626
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
627 %!error rem (uint (8), int8 (5))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
628 %!error rem (uint8 ([1, 2]), uint8 ([3, 4, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
629 %!error rem ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
630 %!error rem (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
631 %!error rem ([1, 2], [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
632 %!error rem (i, 1)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
633 */
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
634
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
635 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
636
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
637 %!assert (size (fmod (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
638 %!assert (size (fmod (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
7743
fbe27e477578 more tests fixed
John W. Eaton <jwe@octave.org>
parents: 7741
diff changeset
639 %!assert (size (fmod (rand (2, 3, 4), 1)), [2, 3, 4])
fbe27e477578 more tests fixed
John W. Eaton <jwe@octave.org>
parents: 7741
diff changeset
640 %!assert (size (fmod (1, rand (2, 3, 4))), [2, 3, 4])
fbe27e477578 more tests fixed
John W. Eaton <jwe@octave.org>
parents: 7741
diff changeset
641 %!assert (size (fmod (1, 2)), [1, 1])
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
642 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
643
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
644 DEFALIAS (fmod, rem)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
645
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
646 DEFUN (mod, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
647 "-*- texinfo -*-\n\
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
648 @deftypefn {Mapping Function} {} mod (@var{x}, @var{y})\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
649 Compute the modulo of @var{x} and @var{y}. Conceptually this is given by\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
650 \n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
651 @example\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
652 x - y .* floor (x ./ y)\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
653 @end example\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
654 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
655 @noindent\n\
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
656 and is written such that the correct modulus is returned for\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
657 integer types. This function handles negative values correctly. That\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
658 is, @code{mod (-1, 3)} is 2, not -1, as @code{rem (-1, 3)} returns.\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
659 @code{mod (@var{x}, 0)} returns @var{x}.\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
660 \n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
661 An error results if the dimensions of the arguments do not agree, or if\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
662 either of the arguments is complex.\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
663 @seealso{rem}\n\
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
664 @end deftypefn")
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
665 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
666 octave_value retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
667
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
668 int nargin = args.length ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
669
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
670 if (nargin == 2)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
671 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
672 if (! args(0).is_numeric_type ())
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
673 gripe_wrong_type_arg ("mod", args(0));
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
674 else if (! args(1).is_numeric_type ())
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
675 gripe_wrong_type_arg ("mod", args(1));
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
676 else if (args(0).is_complex_type () || args(1).is_complex_type ())
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
677 error ("mod: not defined for complex numbers");
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
678 else if (args(0).is_integer_type () || args(1).is_integer_type ())
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
679 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
680 builtin_type_t btyp0 = args(0).builtin_type ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
681 builtin_type_t btyp1 = args(1).builtin_type ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
682 if (btyp0 == btyp_double || btyp0 == btyp_float)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
683 btyp0 = btyp1;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
684 if (btyp1 == btyp_double || btyp1 == btyp_float)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
685 btyp1 = btyp0;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
686
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
687 if (btyp0 == btyp1)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
688 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
689 switch (btyp0)
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
690 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
691 #define MAKE_INT_BRANCH(X) \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
692 case btyp_ ## X: \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
693 { \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
694 X##NDArray a0 = args(0).X##_array_value (); \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
695 X##NDArray a1 = args(1).X##_array_value (); \
10682
7b4ffe27bbb4 Specify template arguments explicitely [MSVC].
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10538
diff changeset
696 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, mod, "mod"); \
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
697 } \
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
698 break
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
699 MAKE_INT_BRANCH (int8);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
700 MAKE_INT_BRANCH (int16);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
701 MAKE_INT_BRANCH (int32);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
702 MAKE_INT_BRANCH (int64);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
703 MAKE_INT_BRANCH (uint8);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
704 MAKE_INT_BRANCH (uint16);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
705 MAKE_INT_BRANCH (uint32);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
706 MAKE_INT_BRANCH (uint64);
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
707 #undef MAKE_INT_BRANCH
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
708 default:
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
709 panic_impossible ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
710 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
711 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
712 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
713 error ("mod: cannot combine %s and %d",
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
714 args(0).class_name ().c_str (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
715 args(1).class_name ().c_str ());
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
716 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
717 else if (args(0).is_single_type () || args(1).is_single_type ())
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
718 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
719 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
11209
94d9d412a2a0 improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents: 10983
diff changeset
720 retval = xmod (args(0).float_value (), args(1).float_value ());
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
721 else
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
722 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
723 FloatNDArray a0 = args(0).float_array_value ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
724 FloatNDArray a1 = args(1).float_array_value ();
13731
3b52038e6e6c Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13294
diff changeset
725 retval = binmap<float> (a0, a1, xmod<float>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
726 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
727 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
728 else
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
729 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
730 bool a0_scalar = args(0).is_scalar_type ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
731 bool a1_scalar = args(1).is_scalar_type ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
732 if (a0_scalar && a1_scalar)
11209
94d9d412a2a0 improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents: 10983
diff changeset
733 retval = xmod (args(0).scalar_value (), args(1).scalar_value ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
734 else if ((a0_scalar || args(0).is_sparse_type ())
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
735 && (a1_scalar || args(1).is_sparse_type ()))
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
736 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
737 SparseMatrix m0 = args(0).sparse_matrix_value ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
738 SparseMatrix m1 = args(1).sparse_matrix_value ();
13731
3b52038e6e6c Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13294
diff changeset
739 retval = binmap<double> (m0, m1, xmod<double>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
740 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
741 else
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
742 {
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
743 NDArray a0 = args(0).array_value ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
744 NDArray a1 = args(1).array_value ();
13731
3b52038e6e6c Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13294
diff changeset
745 retval = binmap<double> (a0, a1, xmod<double>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
746 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
747 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
748 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
749 else
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
750 print_usage ();
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
751
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
752 return retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
753 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
754
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
755 /*
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
756 ## empty input test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
757 %!assert (isempty (mod ([], [])))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
758
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
759 ## x mod y, y != 0 tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
760 %!assert (mod (5, 3), 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
761 %!assert (mod (-5, 3), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
762 %!assert (mod (0, 3), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
763 %!assert (mod ([-5, 5, 0], [3, 3, 3]), [1, 2, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
764 %!assert (mod ([-5; 5; 0], [3; 3; 3]), [1; 2; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
765 %!assert (mod ([-5, 5; 0, 3], [3, 3 ; 3, 1]), [1, 2 ; 0, 0])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
766
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
767 ## x mod 0 tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
768 %!assert (mod (5, 0), 5)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
769 %!assert (mod (-5, 0), -5)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
770 %!assert (mod ([-5, 5, 0], [3, 0, 3]), [1, 5, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
771 %!assert (mod ([-5; 5; 0], [3; 0; 3]), [1; 5; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
772 %!assert (mod ([-5, 5; 0, 3], [3, 0 ; 3, 1]), [1, 5 ; 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
773 %!assert (mod ([-5, 5; 0, 3], [0, 0 ; 0, 0]), [-5, 5; 0, 3])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
774
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
775 ## mixed scalar/matrix tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
776 %!assert (mod ([-5, 5; 0, 3], 0), [-5, 5; 0, 3])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
777 %!assert (mod ([-5, 5; 0, 3], 3), [1, 2; 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
778 %!assert (mod (-5, [0,0; 0,0]), [-5, -5; -5, -5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
779 %!assert (mod (-5, [3,0; 3,1]), [1, -5; 1, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
780 %!assert (mod (-5, [3,2; 3,1]), [1, 1; 1, 0])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
781
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
782 ## integer types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
783 %!assert (mod (uint8 (5), uint8 (4)), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
784 %!assert (mod (uint8 ([1:5]), uint8 (4)), uint8 ([1,2,3,0,1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
785 %!assert (mod (uint8 ([1:5]), uint8 (0)), uint8 ([1:5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
786 %!error (mod (uint8 (5), int8 (4)))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
787
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
788 ## mixed integer/real types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
789 %!assert (mod (uint8 (5), 4), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
790 %!assert (mod (5, uint8 (4)), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
791 %!assert (mod (uint8 ([1:5]), 4), uint8 ([1,2,3,0,1]))
11357
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
792
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
793 ## non-integer real numbers
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
794 %!assert (mod (2.1, 0.1), 0)
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
795 %!assert (mod (2.1, 0.2), 0.1, eps)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
796 */
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
797
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
798 // FIXME: Need to convert reduction functions of this file for single precision
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
799
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
800 #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
801 (arg.is_ ## TYPE ## _type ()) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
802 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
803 TYPE ## NDArray tmp = arg. TYPE ##_array_value (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
804 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
805 if (! error_state) \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
806 { \
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
807 retval = tmp.FCN (DIM); \
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
808 } \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
809 }
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
810
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
811 #define NATIVE_REDUCTION(FCN, BOOL_FCN) \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
812 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
813 octave_value retval; \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
814 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
815 int nargin = args.length (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
816 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
817 bool isnative = false; \
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
818 bool isdouble = false; \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
819 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
820 if (nargin > 1 && args(nargin - 1).is_string ()) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
821 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
822 std::string str = args(nargin - 1).string_value (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
823 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
824 if (! error_state) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
825 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
826 if (str == "native") \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
827 isnative = true; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
828 else if (str == "double") \
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
829 isdouble = true; \
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
830 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
831 error ("sum: unrecognized string argument"); \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
832 nargin --; \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
833 } \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
834 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
835 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
836 if (nargin == 1 || nargin == 2) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
837 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
838 octave_value arg = args(0); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
839 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
840 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
841 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
842 if (! error_state) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
843 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
844 if (dim >= -1) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
845 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
846 if (arg.is_sparse_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
847 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
848 if (arg.is_real_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
849 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
850 SparseMatrix tmp = arg.sparse_matrix_value (); \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
851 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
852 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
853 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
854 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
855 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
856 { \
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
857 SparseComplexMatrix tmp \
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
858 = arg.sparse_complex_matrix_value (); \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
859 \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
860 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
861 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
862 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
863 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
864 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
865 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
866 if (isnative) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
867 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
868 if NATIVE_REDUCTION_1 (FCN, uint8, dim) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
869 else if NATIVE_REDUCTION_1 (FCN, uint16, dim) \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
870 else if NATIVE_REDUCTION_1 (FCN, uint32, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
871 else if NATIVE_REDUCTION_1 (FCN, uint64, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
872 else if NATIVE_REDUCTION_1 (FCN, int8, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
873 else if NATIVE_REDUCTION_1 (FCN, int16, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
874 else if NATIVE_REDUCTION_1 (FCN, int32, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
875 else if NATIVE_REDUCTION_1 (FCN, int64, dim) \
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
876 else if (arg.is_bool_type ()) \
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
877 { \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
878 boolNDArray tmp = arg.bool_array_value (); \
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
879 if (! error_state) \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
880 retval = boolNDArray (tmp.BOOL_FCN (dim)); \
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
881 } \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
882 else if (arg.is_char_matrix ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
883 { \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
884 error (#FCN, ": invalid char type"); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
885 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
886 else if (!isdouble && arg.is_single_type ()) \
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
887 { \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
888 if (arg.is_complex_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
889 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
890 FloatComplexNDArray tmp = \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
891 arg.float_complex_array_value (); \
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
892 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
893 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
894 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
895 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
896 else if (arg.is_real_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
897 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
898 FloatNDArray tmp = arg.float_array_value (); \
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
899 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
900 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
901 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
902 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
903 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
904 else if (arg.is_complex_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
905 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
906 ComplexNDArray tmp = arg.complex_array_value (); \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
907 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
908 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
909 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
910 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
911 else if (arg.is_real_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
912 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
913 NDArray tmp = arg.array_value (); \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
914 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
915 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
916 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
917 } \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
918 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
919 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
920 gripe_wrong_type_arg (#FCN, arg); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
921 return retval; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
922 } \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
923 } \
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
924 else if (arg.is_bool_type ()) \
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
925 { \
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
926 boolNDArray tmp = arg.bool_array_value (); \
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
927 if (! error_state) \
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
928 retval = tmp.FCN (dim); \
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8734
diff changeset
929 } \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
930 else if (!isdouble && arg.is_single_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
931 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
932 if (arg.is_real_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
933 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
934 FloatNDArray tmp = arg.float_array_value (); \
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
935 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
936 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
937 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
938 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
939 else if (arg.is_complex_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
940 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
941 FloatComplexNDArray tmp = \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
942 arg.float_complex_array_value (); \
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
943 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
944 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
945 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
946 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
947 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
948 else if (arg.is_real_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
949 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
950 NDArray tmp = arg.array_value (); \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
951 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
952 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
953 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
954 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
955 else if (arg.is_complex_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
956 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
957 ComplexNDArray tmp = arg.complex_array_value (); \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
958 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
959 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
960 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
961 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
962 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
963 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
964 gripe_wrong_type_arg (#FCN, arg); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
965 return retval; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
966 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
967 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
968 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
969 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
970 error (#FCN ": invalid dimension argument = %d", dim + 1); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
971 } \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
972 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
973 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
974 else \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
975 print_usage (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
976 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
977 return retval
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
978
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
979 #define DATA_REDUCTION(FCN) \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
980 \
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
981 octave_value retval; \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
982 \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
983 int nargin = args.length (); \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
984 \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
985 if (nargin == 1 || nargin == 2) \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
986 { \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
987 octave_value arg = args(0); \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
988 \
3864
e78705239df5 [project @ 2001-11-16 12:56:20 by jwe]
jwe
parents: 3797
diff changeset
989 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
990 \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
991 if (! error_state) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
992 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
993 if (dim >= -1) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
994 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
995 if (arg.is_real_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
996 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
997 if (arg.is_sparse_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
998 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
999 SparseMatrix tmp = arg.sparse_matrix_value (); \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1000 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1001 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1002 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1003 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1004 else if (arg.is_single_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1005 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1006 FloatNDArray tmp = arg.float_array_value (); \
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
1007 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1008 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1009 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1010 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1011 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1012 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1013 NDArray tmp = arg.array_value (); \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1014 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1015 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1016 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1017 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1018 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1019 else if (arg.is_complex_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1020 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1021 if (arg.is_sparse_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1022 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1023 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1024 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1025 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1026 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1027 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1028 else if (arg.is_single_type ()) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1029 { \
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1030 FloatComplexNDArray tmp \
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1031 = arg.float_complex_array_value (); \
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
1032 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1033 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1034 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1035 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1036 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1037 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1038 ComplexNDArray tmp = arg.complex_array_value (); \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1039 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1040 if (! error_state) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1041 retval = tmp.FCN (dim); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1042 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1043 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1044 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1045 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1046 gripe_wrong_type_arg (#FCN, arg); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1047 return retval; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1048 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1049 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1050 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1051 error (#FCN ": invalid dimension argument = %d", dim + 1); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1052 } \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1053 } \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1054 else \
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1055 print_usage (); \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1056 \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1057 return retval
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1058
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1059 DEFUN (cumprod, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1060 "-*- texinfo -*-\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1061 @deftypefn {Built-in Function} {} cumprod (@var{x})\n\
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1062 @deftypefnx {Built-in Function} {} cumprod (@var{x}, @var{dim})\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1063 Cumulative product of elements along dimension @var{dim}. If\n\
9723
f426899f4b9c fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
1064 @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\
5061
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1065 \n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1066 @seealso{prod, cumsum}\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1067 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1068 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1069 DATA_REDUCTION (cumprod);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1070 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1071
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1072 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1073 %!assert (cumprod ([1, 2, 3]), [1, 2, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1074 %!assert (cumprod ([-1; -2; -3]), [-1; 2; -6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1075 %!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1076 %!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1077
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1078 %!assert (cumprod (single ([1, 2, 3])), single ([1, 2, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1079 %!assert (cumprod (single ([-1; -2; -3])), single ([-1; 2; -6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1080 %!assert (cumprod (single ([i, 2+i, -3+2i, 4])), single ([i, -1+2i, -1-8i, -4-32i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1081 %!assert (cumprod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1082
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1083 %!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1084 %!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1085
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1086 %!assert (cumprod (single ([2, 3; 4, 5]), 1), single ([2, 3; 8, 15]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1087 %!assert (cumprod (single ([2, 3; 4, 5]), 2), single ([2, 6; 4, 20]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1088
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1089 %!error cumprod ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1090 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1091
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1092 DEFUN (cumsum, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1093 "-*- texinfo -*-\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1094 @deftypefn {Built-in Function} {} cumsum (@var{x})\n\
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1095 @deftypefnx {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\
14361
8de863b7126b doc: Use Octave preference for double quote in docstrings in all .cc files
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1096 @deftypefnx {Built-in Function} {} cumsum (@dots{}, \"native\")\n\
8de863b7126b doc: Use Octave preference for double quote in docstrings in all .cc files
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1097 @deftypefnx {Built-in Function} {} cumsum (@dots{}, \"double\")\n\
8de863b7126b doc: Use Octave preference for double quote in docstrings in all .cc files
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
1098 @deftypefnx {Built-in Function} {} cumsum (@dots{}, \"extra\")\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1099 Cumulative sum of elements along dimension @var{dim}. If @var{dim}\n\
9723
f426899f4b9c fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
1100 is omitted, it defaults to the first non-singleton dimension.\n\
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
1101 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
1102 See @code{sum} for an explanation of the optional parameters\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
1103 @qcode{\"native\"}, @qcode{\"double\"}, and @qcode{\"extra\"}.\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1104 @seealso{sum, cumprod}\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1105 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1106 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1107 octave_value retval;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1108
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1109 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1110
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1111 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1112 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1113
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1114 if (nargin > 1 && args(nargin - 1).is_string ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1115 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1116 std::string str = args(nargin - 1).string_value ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1117
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1118 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1119 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1120 if (str == "native")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1121 isnative = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1122 else if (str == "double")
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1123 isdouble = true;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1124 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1125 error ("sum: unrecognized string argument");
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1126 nargin --;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1127 }
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1128 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1129
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1130 if (error_state)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1131 return retval;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1132
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1133 if (nargin == 1 || nargin == 2)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1134 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1135 octave_value arg = args(0);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1136
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1137 int dim = -1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1138 if (nargin == 2)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1139 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1140 dim = args(1).int_value () - 1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1141 if (dim < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1142 error ("cumsum: invalid dimension argument = %d", dim + 1);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1143 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1144
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1145 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1146 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1147 switch (arg.builtin_type ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1148 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1149 case btyp_double:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1150 if (arg.is_sparse_type ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1151 retval = arg.sparse_matrix_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1152 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1153 retval = arg.array_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1154 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1155 case btyp_complex:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1156 if (arg.is_sparse_type ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1157 retval = arg.sparse_complex_matrix_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1158 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1159 retval = arg.complex_array_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1160 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1161 case btyp_float:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1162 if (isdouble)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1163 retval = arg.array_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1164 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1165 retval = arg.float_array_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1166 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1167 case btyp_float_complex:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1168 if (isdouble)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1169 retval = arg.complex_array_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1170 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1171 retval = arg.float_complex_array_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1172 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1173
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1174 #define MAKE_INT_BRANCH(X) \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1175 case btyp_ ## X: \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1176 if (isnative) \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1177 retval = arg.X ## _array_value ().cumsum (dim); \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1178 else \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1179 retval = arg.array_value ().cumsum (dim); \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1180 break
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1181 MAKE_INT_BRANCH (int8);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1182 MAKE_INT_BRANCH (int16);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1183 MAKE_INT_BRANCH (int32);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1184 MAKE_INT_BRANCH (int64);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1185 MAKE_INT_BRANCH (uint8);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1186 MAKE_INT_BRANCH (uint16);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1187 MAKE_INT_BRANCH (uint32);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1188 MAKE_INT_BRANCH (uint64);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1189 #undef MAKE_INT_BRANCH
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1190
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1191 case btyp_bool:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1192 if (arg.is_sparse_type ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1193 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1194 SparseMatrix cs = arg.sparse_matrix_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1195 if (isnative)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1196 retval = cs != 0.0;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1197 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1198 retval = cs;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1199 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1200 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1201 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1202 NDArray cs = arg.bool_array_value ().cumsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1203 if (isnative)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1204 retval = cs != 0.0;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1205 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1206 retval = cs;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1207 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1208 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1209
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1210 default:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1211 gripe_wrong_type_arg ("cumsum", arg);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1212 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1213 }
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1214 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1215 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1216 print_usage ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1217
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1218 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1219 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1220
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1221 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1222 %!assert (cumsum ([1, 2, 3]), [1, 3, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1223 %!assert (cumsum ([-1; -2; -3]), [-1; -3; -6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1224 %!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1225 %!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1226
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1227 %!assert (cumsum (single ([1, 2, 3])), single ([1, 3, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1228 %!assert (cumsum (single ([-1; -2; -3])), single ([-1; -3; -6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1229 %!assert (cumsum (single ([i, 2+i, -3+2i, 4])), single ([i, 2+2i, -1+4i, 3+4i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1230 %!assert (cumsum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1231
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1232 %!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1233 %!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1234
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1235 %!assert (cumsum (single ([1, 2; 3, 4]), 1), single ([1, 2; 4, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1236 %!assert (cumsum (single ([1, 2; 3, 4]), 2), single ([1, 3; 3, 7]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1237
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1238 %!error cumsum ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1239 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1240
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1241 DEFUN (diag, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1242 "-*- texinfo -*-\n\
12567
cc8ccdfec424 Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents: 12546
diff changeset
1243 @deftypefn {Built-in Function} {@var{M} =} diag (@var{v})\n\
cc8ccdfec424 Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents: 12546
diff changeset
1244 @deftypefnx {Built-in Function} {@var{M} =} diag (@var{v}, @var{k})\n\
12571
bed932910eb9 Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents: 12570
diff changeset
1245 @deftypefnx {Built-in Function} {@var{M} =} diag (@var{v}, @var{m}, @var{n})\n\
12567
cc8ccdfec424 Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents: 12546
diff changeset
1246 @deftypefnx {Built-in Function} {@var{v} =} diag (@var{M})\n\
cc8ccdfec424 Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents: 12546
diff changeset
1247 @deftypefnx {Built-in Function} {@var{v} =} diag (@var{M}, @var{k})\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1248 Return a diagonal matrix with vector @var{v} on diagonal @var{k}. The\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1249 second argument is optional. If it is positive, the vector is placed on\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1250 the @var{k}-th super-diagonal. If it is negative, it is placed on the\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1251 @var{-k}-th sub-diagonal. The default value of @var{k} is 0, and the\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
1252 vector is placed on the main diagonal. For example:\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1253 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1254 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1255 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1256 diag ([1, 2, 3], 1)\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
1257 @result{} 0 1 0 0\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
1258 0 0 2 0\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
1259 0 0 0 3\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
1260 0 0 0 0\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1261 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1262 @end example\n\
6772
315bc7c8f9b5 [project @ 2007-07-10 09:51:39 by dbateman]
dbateman
parents: 6688
diff changeset
1263 \n\
315bc7c8f9b5 [project @ 2007-07-10 09:51:39 by dbateman]
dbateman
parents: 6688
diff changeset
1264 @noindent\n\
12571
bed932910eb9 Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents: 12570
diff changeset
1265 The 3-input form returns a diagonal matrix with vector @var{v} on the main\n\
bed932910eb9 Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents: 12570
diff changeset
1266 diagonal and the resulting matrix being of size @var{m} rows x @var{n}\n\
bed932910eb9 Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents: 12570
diff changeset
1267 columns.\n\
bed932910eb9 Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents: 12570
diff changeset
1268 \n\
6772
315bc7c8f9b5 [project @ 2007-07-10 09:51:39 by dbateman]
dbateman
parents: 6688
diff changeset
1269 Given a matrix argument, instead of a vector, @code{diag} extracts the\n\
6774
3b09c87d5165 [project @ 2007-07-13 13:27:36 by dbateman]
dbateman
parents: 6772
diff changeset
1270 @var{k}-th diagonal of the matrix.\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1271 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1272 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1273 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1274
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1275 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1276
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
1277 if (nargin == 1 && args(0).is_defined ())
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1278 retval = args(0).diag ();
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
1279 else if (nargin == 2 && args(0).is_defined () && args(1).is_defined ())
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1280 {
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1281 octave_idx_type k = args(1).int_value ();
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1282
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1283 if (error_state)
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
1284 error ("diag: invalid argument K");
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1285 else
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1286 retval = args(0).diag (k);
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1287 }
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1288 else if (nargin == 3)
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1289 {
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1290 octave_value arg0 = args(0);
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1291
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1292 if (arg0.ndims () == 2 && (arg0.rows () == 1 || arg0.columns () == 1))
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1293 {
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1294 octave_idx_type m = args(1).int_value ();
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1295 octave_idx_type n = args(2).int_value ();
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1296
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1297 if (! error_state)
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1298 retval = arg0.diag (m, n);
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1299 else
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1300 error ("diag: invalid dimensions");
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1301 }
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1302 else
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1303 error ("diag: V must be a vector");
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1304 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1305 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1306 print_usage ();
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1307
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1308 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1309 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1310
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1311 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1312
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1313 %!assert (full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1314 %!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1315 %!assert (diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1316 %!assert (diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1317 %!assert (diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1318
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1319 %!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1320 %!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1321 %!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1322 %!assert (diag (ones (1, 0), 2), zeros (2))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1323 %!assert (diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1324
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1325 %!assert (full (diag (single ([1; 2; 3]))), single ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1326 %!assert (diag (single ([1; 2; 3]), 1), single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1327 %!assert (diag (single ([1; 2; 3]), 2), single ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1328 %!assert (diag (single ([1; 2; 3]),-1), single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1329 %!assert (diag (single ([1; 2; 3]),-2), single ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1330
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1331 %!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1332 %!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1333 %!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1334
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1335 %!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1336 %!assert (diag (int8 ([1; 2; 3]), 1), int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1337 %!assert (diag (int8 ([1; 2; 3]), 2), int8 ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1338 %!assert (diag (int8 ([1; 2; 3]),-1), int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1339 %!assert (diag (int8 ([1; 2; 3]),-2), int8 ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1340
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1341 %!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1342 %!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8 ([1; 2; 3]))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1343 %!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8 ([1; 2; 3]))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1344
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14567
diff changeset
1345 ## bug #37411
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14567
diff changeset
1346 %!assert (diag (diag ([5, 2, 3])(:,1)), diag([5 0 0 ]))
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14567
diff changeset
1347 %!assert (diag (diag ([5, 2, 3])(:,1), 2), [0 0 5 0 0; zeros(4, 5)])
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14567
diff changeset
1348 %!assert (diag (diag ([5, 2, 3])(:,1), -2), [[0 0 5 0 0]', zeros(5, 4)])
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14567
diff changeset
1349
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1350 ## Test non-square size
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1351 %!assert (diag ([1,2,3], 6, 3), [1 0 0; 0 2 0; 0 0 3; 0 0 0; 0 0 0; 0 0 0])
14567
5bb5fcffa29d correctly fill cell arrays for three-arg diag function calls
John W. Eaton <jwe@octave.org>
parents: 14490
diff changeset
1352 %!assert (diag (1, 2, 3), [1,0,0; 0,0,0]);
5bb5fcffa29d correctly fill cell arrays for three-arg diag function calls
John W. Eaton <jwe@octave.org>
parents: 14490
diff changeset
1353 %!assert (diag ({1}, 2, 3), {1,[],[]; [],[],[]});
5bb5fcffa29d correctly fill cell arrays for three-arg diag function calls
John W. Eaton <jwe@octave.org>
parents: 14490
diff changeset
1354 %!assert (diag ({1,2}, 3, 4), {1,[],[],[]; [],2,[],[]; [],[],[],[]});
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1355
12571
bed932910eb9 Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents: 12570
diff changeset
1356 %% Test input validation
14491
5bd9e47e9277 maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14429 14490
diff changeset
1357 %!error <Invalid call to diag> diag ()
5bd9e47e9277 maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14429 14490
diff changeset
1358 %!error <Invalid call to diag> diag (1,2,3,4)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1359 %!error diag (ones (2), 3, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1360 %!error diag (1:3, -4, 3)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1361
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1362 %!assert (diag (1, 3, 3), diag ([1, 0, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1363 %!assert (diag (i, 3, 3), diag ([i, 0, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1364 %!assert (diag (single (1), 3, 3), diag ([single(1), 0, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1365 %!assert (diag (single (i), 3, 3), diag ([single(i), 0, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1366 %!assert (diag ([1, 2], 3, 3), diag ([1, 2, 0]))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1367 %!assert (diag ([1, 2]*i, 3, 3), diag ([1, 2, 0]*i))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1368 %!assert (diag (single ([1, 2]), 3, 3), diag (single ([1, 2, 0])))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1369 %!assert (diag (single ([1, 2]*i), 3, 3), diag (single ([1, 2, 0]*i)))
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1370 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1371
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1372 DEFUN (prod, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1373 "-*- texinfo -*-\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1374 @deftypefn {Built-in Function} {} prod (@var{x})\n\
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1375 @deftypefnx {Built-in Function} {} prod (@var{x}, @var{dim})\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1376 Product of elements along dimension @var{dim}. If @var{dim} is\n\
9723
f426899f4b9c fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
1377 omitted, it defaults to the first non-singleton dimension.\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
1378 @seealso{cumprod, sum}\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1379 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1380 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1381 DATA_REDUCTION (prod);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1382 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1383
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1384 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1385 %!assert (prod ([1, 2, 3]), 6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1386 %!assert (prod ([-1; -2; -3]), -6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1387 %!assert (prod ([i, 2+i, -3+2i, 4]), -4 - 32i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1388 %!assert (prod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [-1+i, -8+8i, -27+27i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1389
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1390 %!assert (prod (single ([1, 2, 3])), single (6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1391 %!assert (prod (single ([-1; -2; -3])), single (-6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1392 %!assert (prod (single ([i, 2+i, -3+2i, 4])), single (-4 - 32i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1393 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([-1+i, -8+8i, -27+27i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1394
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1395 %!assert (prod ([1, 2; 3, 4], 1), [3, 8])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1396 %!assert (prod ([1, 2; 3, 4], 2), [2; 12])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1397 %!assert (prod (zeros (1, 0)), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1398 %!assert (prod (zeros (1, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1399 %!assert (prod (zeros (1, 0), 2), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1400 %!assert (prod (zeros (0, 1)), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1401 %!assert (prod (zeros (0, 1), 1), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1402 %!assert (prod (zeros (0, 1), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1403 %!assert (prod (zeros (2, 0)), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1404 %!assert (prod (zeros (2, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1405 %!assert (prod (zeros (2, 0), 2), [1; 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1406 %!assert (prod (zeros (0, 2)), [1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1407 %!assert (prod (zeros (0, 2), 1), [1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1408 %!assert (prod (zeros (0, 2), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1409
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1410 %!assert (prod (single ([1, 2; 3, 4]), 1), single ([3, 8]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1411 %!assert (prod (single ([1, 2; 3, 4]), 2), single ([2; 12]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1412 %!assert (prod (zeros (1, 0, "single")), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1413 %!assert (prod (zeros (1, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1414 %!assert (prod (zeros (1, 0, "single"), 2), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1415 %!assert (prod (zeros (0, 1, "single")), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1416 %!assert (prod (zeros (0, 1, "single"), 1), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1417 %!assert (prod (zeros (0, 1, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1418 %!assert (prod (zeros (2, 0, "single")), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1419 %!assert (prod (zeros (2, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1420 %!assert (prod (zeros (2, 0, "single"), 2), single ([1; 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1421 %!assert (prod (zeros (0, 2, "single")), single ([1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1422 %!assert (prod (zeros (0, 2, "single"), 1), single ([1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1423 %!assert (prod (zeros (0, 2, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1424
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1425 %!error prod ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1426 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1427
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1428 static bool
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1429 all_scalar_1x1 (const octave_value_list& args)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1430 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1431 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1432 for (int i = 0; i < n_args; i++)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1433 if (args(i).numel () != 1)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1434 return false;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1435
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1436 return true;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1437 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1438
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1439 template <class TYPE, class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1440 static void
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1441 single_type_concat (Array<T>& result,
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1442 const octave_value_list& args,
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1443 int dim)
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1444 {
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1445 int n_args = args.length ();
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1446 if (! (equal_types<T, char>::value
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1447 || equal_types<T, octave_value>::value)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1448 && all_scalar_1x1 (args))
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1449 {
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1450 // Optimize all scalars case.
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1451 dim_vector dv (1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1452 if (dim == -1 || dim == -2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1453 dim = -dim - 1;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1454 else if (dim >= 2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1455 dv.resize (dim+1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1456 dv(dim) = n_args;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1457
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1458 result.clear (dv);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1459
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1460 for (int j = 0; j < n_args && ! error_state; j++)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1461 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1462 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1463
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1464 result(j) = octave_value_extract<T> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1465 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1466 }
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1467 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1468 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1469 OCTAVE_LOCAL_BUFFER (Array<T>, array_list, n_args);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1470
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1471 for (int j = 0; j < n_args && ! error_state; j++)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1472 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1473 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1474
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1475 array_list[j] = octave_value_extract<TYPE> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1476 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1477
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1478 if (! error_state)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1479 result = Array<T>::cat (dim, n_args, array_list);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1480 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1481 }
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1482
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1483 template <class TYPE, class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1484 static void
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1485 single_type_concat (Sparse<T>& result,
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1486 const octave_value_list& args,
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1487 int dim)
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1488 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1489 int n_args = args.length ();
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1490 OCTAVE_LOCAL_BUFFER (Sparse<T>, sparse_list, n_args);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1491
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1492 for (int j = 0; j < n_args && ! error_state; j++)
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1493 {
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1494 octave_quit ();
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1495
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1496 sparse_list[j] = octave_value_extract<TYPE> (args(j));
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1497 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1498
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1499 if (! error_state)
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1500 result = Sparse<T>::cat (dim, n_args, sparse_list);
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1501 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1502
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1503 // Dispatcher.
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1504 template<class TYPE>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1505 static TYPE
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1506 do_single_type_concat (const octave_value_list& args, int dim)
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1507 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1508 TYPE result;
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1509
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1510 single_type_concat<TYPE, typename TYPE::element_type> (result, args, dim);
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1511
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1512 return result;
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1513 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1514
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1515 template<class MAP>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1516 static void
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1517 single_type_concat_map (octave_map& result,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1518 const octave_value_list& args,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1519 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1520 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1521 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1522 OCTAVE_LOCAL_BUFFER (MAP, map_list, n_args);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1523
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1524 for (int j = 0; j < n_args && ! error_state; j++)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1525 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1526 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1527
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1528 map_list[j] = octave_value_extract<MAP> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1529 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1530
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1531 if (! error_state)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1532 result = octave_map::cat (dim, n_args, map_list);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1533 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1534
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1535 static octave_map
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1536 do_single_type_concat_map (const octave_value_list& args,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1537 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1538 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1539 octave_map result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1540 if (all_scalar_1x1 (args)) // optimize all scalars case.
10763
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10758
diff changeset
1541 single_type_concat_map<octave_scalar_map> (result, args, dim);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1542 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1543 single_type_concat_map<octave_map> (result, args, dim);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1544
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1545 return result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1546 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1547
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1548 static octave_value
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1549 attempt_type_conversion (const octave_value& ov, std::string dtype)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1550 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1551 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1552
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1553 // First try to find function in the class of OV that can convert to
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1554 // the dispatch type dtype. It will have the name of the dispatch
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1555 // type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1556
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1557 std::string cname = ov.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1558
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1559 octave_value fcn = symbol_table::find_method (dtype, cname);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1560
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1561 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1562 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1563 octave_value_list result
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1564 = fcn.do_multi_index_op (1, octave_value_list (1, ov));
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1565
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1566 if (! error_state && result.length () > 0)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1567 retval = result(0);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1568 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1569 error ("conversion from %s to %s failed", dtype.c_str (),
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1570 cname.c_str ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1571 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1572 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1573 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1574 // No conversion function available. Try the constructor for the
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1575 // dispatch type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1576
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1577 fcn = symbol_table::find_method (dtype, dtype);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1578
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1579 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1580 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1581 octave_value_list result
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1582 = fcn.do_multi_index_op (1, octave_value_list (1, ov));
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1583
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1584 if (! error_state && result.length () > 0)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1585 retval = result(0);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1586 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1587 error ("%s constructor failed for %s argument", dtype.c_str (),
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1588 cname.c_str ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1589 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1590 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1591 error ("no constructor for %s!", dtype.c_str ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1592 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1593
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1594 return retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1595 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1596
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1597 octave_value
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1598 do_class_concat (const octave_value_list& ovl, std::string cattype, int dim)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1599 {
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1600 octave_value retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1601
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1602 // Get dominant type for list
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1603
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1604 std::string dtype = get_dispatch_type (ovl);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1605
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1606 octave_value fcn = symbol_table::find_method (cattype, dtype);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1607
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1608 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1609 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1610 // Have method for dominant type, so call it and let it handle
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1611 // conversions.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1612
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1613 octave_value_list tmp2 = fcn.do_multi_index_op (1, ovl);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1614
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1615 if (! error_state)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1616 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1617 if (tmp2.length () > 0)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1618 retval = tmp2(0);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1619 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1620 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1621 error ("%s/%s method did not return a value",
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1622 dtype.c_str (), cattype.c_str ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1623 goto done;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1624 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1625 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1626 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1627 goto done;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1628 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1629 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1630 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1631 // No method for dominant type, so attempt type conversions for
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1632 // all elements that are not of the dominant type, then do the
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1633 // default operation for octave_class values.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1634
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1635 octave_idx_type j = 0;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1636 octave_idx_type len = ovl.length ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1637 octave_value_list tmp (len, octave_value ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1638 for (octave_idx_type k = 0; k < len; k++)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1639 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1640 octave_value elt = ovl(k);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1641
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1642 std::string t1_type = elt.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1643
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1644 if (t1_type == dtype)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1645 tmp(j++) = elt;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1646 else if (elt.is_object () || ! elt.is_empty ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1647 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1648 tmp(j++) = attempt_type_conversion (elt, dtype);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1649
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1650 if (error_state)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1651 goto done;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1652 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1653 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1654
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1655 tmp.resize (j);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1656
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1657 octave_map m = do_single_type_concat_map (tmp, dim);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1658
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1659 std::string cname = tmp(0).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1660 std::list<std::string> parents = tmp(0).parent_class_name_list ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1661
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1662 retval = octave_value (new octave_class (m, cname, parents));
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1663 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1664
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1665 done:
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1666 return retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1667 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1668
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1669 static octave_value
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1670 do_cat (const octave_value_list& xargs, int dim, std::string fname)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1671 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1672 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1673
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1674 // We may need to convert elements of the list to cells, so make a
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1675 // copy. This should be efficient, it is done mostly by incrementing
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1676 // reference counts.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1677 octave_value_list args = xargs;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1678
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1679 int n_args = args.length ();
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1680
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1681 if (n_args == 0)
5714
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1682 retval = Matrix ();
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1683 else if (n_args == 1)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1684 retval = args(0);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1685 else if (n_args > 1)
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1686 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1687 std::string result_type;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1688
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1689 bool all_sq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1690 bool all_dq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1691 bool all_real_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1692 bool all_cmplx_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1693 bool any_sparse_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1694 bool any_cell_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1695 bool any_class_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1696
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1697 bool first_elem_is_struct = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1698
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1699 for (int i = 0; i < n_args; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1700 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1701 if (i == 0)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1702 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1703 result_type = args(i).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1704
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1705 first_elem_is_struct = args(i).is_map ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1706 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1707 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1708 result_type = get_concat_class (result_type, args(i).class_name ());
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1709
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1710 if (all_sq_strings_p && ! args(i).is_sq_string ())
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1711 all_sq_strings_p = false;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1712 if (all_dq_strings_p && ! args(i).is_dq_string ())
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1713 all_dq_strings_p = false;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1714 if (all_real_p && ! args(i).is_real_type ())
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1715 all_real_p = false;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1716 if (all_cmplx_p && ! (args(i).is_complex_type ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1717 || args(i).is_real_type ()))
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1718 all_cmplx_p = false;
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1719 if (!any_sparse_p && args(i).is_sparse_type ())
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1720 any_sparse_p = true;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1721 if (!any_cell_p && args(i).is_cell ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1722 any_cell_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1723 if (!any_class_p && args(i).is_object ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1724 any_class_p = true;
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1725 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1726
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1727 if (any_cell_p && ! any_class_p && ! first_elem_is_struct)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1728 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1729 for (int i = 0; i < n_args; i++)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1730 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1731 if (! args(i).is_cell ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1732 args(i) = Cell (args(i));
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1733 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1734 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1735
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1736 if (any_class_p)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1737 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1738 retval = do_class_concat (args, fname, dim);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1739 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1740 else if (result_type == "double")
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1741 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1742 if (any_sparse_p)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1743 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1744 if (all_real_p)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1745 retval = do_single_type_concat<SparseMatrix> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1746 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1747 retval = do_single_type_concat<SparseComplexMatrix> (args, dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1748 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1749 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1750 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1751 if (all_real_p)
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1752 retval = do_single_type_concat<NDArray> (args, dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1753 else
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1754 retval = do_single_type_concat<ComplexNDArray> (args, dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1755 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1756 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1757 else if (result_type == "single")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1758 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1759 if (all_real_p)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1760 retval = do_single_type_concat<FloatNDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1761 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1762 retval = do_single_type_concat<FloatComplexNDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1763 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1764 else if (result_type == "char")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1765 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1766 char type = all_dq_strings_p ? '"' : '\'';
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1767
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1768 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1769
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1770 charNDArray result = do_single_type_concat<charNDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1771
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1772 retval = octave_value (result, type);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1773 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1774 else if (result_type == "logical")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1775 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1776 if (any_sparse_p)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1777 retval = do_single_type_concat<SparseBoolMatrix> (args, dim);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1778 else
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1779 retval = do_single_type_concat<boolNDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1780 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1781 else if (result_type == "int8")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1782 retval = do_single_type_concat<int8NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1783 else if (result_type == "int16")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1784 retval = do_single_type_concat<int16NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1785 else if (result_type == "int32")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1786 retval = do_single_type_concat<int32NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1787 else if (result_type == "int64")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1788 retval = do_single_type_concat<int64NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1789 else if (result_type == "uint8")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1790 retval = do_single_type_concat<uint8NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1791 else if (result_type == "uint16")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1792 retval = do_single_type_concat<uint16NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1793 else if (result_type == "uint32")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1794 retval = do_single_type_concat<uint32NDArray> (args, dim);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1795 else if (result_type == "uint64")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1796 retval = do_single_type_concat<uint64NDArray> (args, dim);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1797 else if (result_type == "cell")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1798 retval = do_single_type_concat<Cell> (args, dim);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1799 else if (result_type == "struct")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1800 retval = do_single_type_concat_map (args, dim);
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1801 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1802 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1803 dim_vector dv = args(0).dims ();
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1804
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1805 // Default concatenation.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1806 bool (dim_vector::*concat_rule) (const dim_vector&, int)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1807 = &dim_vector::concat;
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1808
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1809 if (dim == -1 || dim == -2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1810 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1811 concat_rule = &dim_vector::hvcat;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1812 dim = -dim - 1;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1813 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1814
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1815 for (int i = 1; i < args.length (); i++)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1816 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1817 if (! (dv.*concat_rule) (args(i).dims (), dim))
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1818 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1819 // Dimensions do not match.
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1820 error ("cat: dimension mismatch");
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1821 return retval;
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1822 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1823 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1824
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1825 // The lines below might seem crazy, since we take a copy
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1826 // of the first argument, resize it to be empty and then resize
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1827 // it to be full. This is done since it means that there is no
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1828 // recopying of data, as would happen if we used a single resize.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1829 // It should be noted that resize operation is also significantly
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1830 // slower than the do_cat_op function, so it makes sense to have
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1831 // an empty matrix and copy all data.
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1832 //
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1833 // We might also start with a empty octave_value using
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1834 // tmp = octave_value_typeinfo::lookup_type
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1835 // (args(1).type_name());
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1836 // and then directly resize. However, for some types there might
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1837 // be some additional setup needed, and so this should be avoided.
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1838
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1839 octave_value tmp = args (0);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1840 tmp = tmp.resize (dim_vector (0,0)).resize (dv);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1841
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1842 if (error_state)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1843 return retval;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1844
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1845 int dv_len = dv.length ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1846 Array<octave_idx_type> ra_idx (dim_vector (dv_len, 1), 0);
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1847
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1848 for (int j = 0; j < n_args; j++)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1849 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1850 // Can't fast return here to skip empty matrices as something
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
1851 // like cat (1,[],single ([])) must return an empty matrix of
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1852 // the right type.
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1853 tmp = do_cat_op (tmp, args (j), ra_idx);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1854
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1855 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1856 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1857
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1858 dim_vector dv_tmp = args (j).dims ();
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1859
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1860 if (dim >= dv_len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1861 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1862 if (j > 1)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1863 error ("%s: indexing error", fname.c_str ());
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1864 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1865 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1866 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1867 ra_idx (dim) += (dim < dv_tmp.length () ?
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1868 dv_tmp (dim) : 1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1869 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1870 retval = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1871 }
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1872 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1873 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1874 print_usage ();
8113
38a797766a2a Special case single type conacation in Fcat. Rework cell2mat to take advantage
David Bateman <dbateman@free.fr>
parents: 8111
diff changeset
1875
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1876 return retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1877 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1878
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1879 DEFUN (horzcat, args, ,
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1880 "-*- texinfo -*-\n\
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1881 @deftypefn {Built-in Function} {} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
1882 Return the horizontal concatenation of N-D array objects, @var{array1},\n\
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1883 @var{array2}, @dots{}, @var{arrayN} along dimension 2.\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
1884 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
1885 Arrays may also be concatenated horizontally using the syntax for creating\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
1886 new matrices. For example:\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
1887 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
1888 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
1889 @var{hcat} = [ @var{array1}, @var{array2}, @dots{} ]\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
1890 @end example\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1891 @seealso{cat, vertcat}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1892 @end deftypefn")
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1893 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1894 return do_cat (args, -2, "horzcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1895 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1896
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1897 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1898 ## Test concatenation with all zero matrices
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1899 %!assert (horzcat ("", 65*ones (1,10)), "AAAAAAAAAA");
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1900 %!assert (horzcat (65*ones (1,10), ""), "AAAAAAAAAA");
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1901
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1902 %!assert (class (horzcat (int64 (1), int64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1903 %!assert (class (horzcat (int64 (1), int32 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1904 %!assert (class (horzcat (int64 (1), int16 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1905 %!assert (class (horzcat (int64 (1), int8 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1906 %!assert (class (horzcat (int64 (1), uint64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1907 %!assert (class (horzcat (int64 (1), uint32 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1908 %!assert (class (horzcat (int64 (1), uint16 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1909 %!assert (class (horzcat (int64 (1), uint8 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1910 %!assert (class (horzcat (int64 (1), single (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1911 %!assert (class (horzcat (int64 (1), double (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1912 %!assert (class (horzcat (int64 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1913 %!assert (class (horzcat (int64 (1), true)), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1914 %!assert (class (horzcat (int64 (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1915
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1916 %!assert (class (horzcat (int32 (1), int64 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1917 %!assert (class (horzcat (int32 (1), int32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1918 %!assert (class (horzcat (int32 (1), int16 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1919 %!assert (class (horzcat (int32 (1), int8 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1920 %!assert (class (horzcat (int32 (1), uint64 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1921 %!assert (class (horzcat (int32 (1), uint32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1922 %!assert (class (horzcat (int32 (1), uint16 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1923 %!assert (class (horzcat (int32 (1), uint8 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1924 %!assert (class (horzcat (int32 (1), single (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1925 %!assert (class (horzcat (int32 (1), double (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1926 %!assert (class (horzcat (int32 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1927 %!assert (class (horzcat (int32 (1), true)), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1928 %!assert (class (horzcat (int32 (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1929
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1930 %!assert (class (horzcat (int16 (1), int64 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1931 %!assert (class (horzcat (int16 (1), int32 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1932 %!assert (class (horzcat (int16 (1), int16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1933 %!assert (class (horzcat (int16 (1), int8 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1934 %!assert (class (horzcat (int16 (1), uint64 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1935 %!assert (class (horzcat (int16 (1), uint32 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1936 %!assert (class (horzcat (int16 (1), uint16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1937 %!assert (class (horzcat (int16 (1), uint8 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1938 %!assert (class (horzcat (int16 (1), single (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1939 %!assert (class (horzcat (int16 (1), double (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1940 %!assert (class (horzcat (int16 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1941 %!assert (class (horzcat (int16 (1), true)), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1942 %!assert (class (horzcat (int16 (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1943
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1944 %!assert (class (horzcat (int8 (1), int64 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1945 %!assert (class (horzcat (int8 (1), int32 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1946 %!assert (class (horzcat (int8 (1), int16 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1947 %!assert (class (horzcat (int8 (1), int8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1948 %!assert (class (horzcat (int8 (1), uint64 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1949 %!assert (class (horzcat (int8 (1), uint32 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1950 %!assert (class (horzcat (int8 (1), uint16 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1951 %!assert (class (horzcat (int8 (1), uint8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1952 %!assert (class (horzcat (int8 (1), single (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1953 %!assert (class (horzcat (int8 (1), double (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1954 %!assert (class (horzcat (int8 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1955 %!assert (class (horzcat (int8 (1), true)), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1956 %!assert (class (horzcat (int8 (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1957
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1958 %!assert (class (horzcat (uint64 (1), int64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1959 %!assert (class (horzcat (uint64 (1), int32 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1960 %!assert (class (horzcat (uint64 (1), int16 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1961 %!assert (class (horzcat (uint64 (1), int8 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1962 %!assert (class (horzcat (uint64 (1), uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1963 %!assert (class (horzcat (uint64 (1), uint32 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1964 %!assert (class (horzcat (uint64 (1), uint16 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1965 %!assert (class (horzcat (uint64 (1), uint8 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1966 %!assert (class (horzcat (uint64 (1), single (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1967 %!assert (class (horzcat (uint64 (1), double (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1968 %!assert (class (horzcat (uint64 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1969 %!assert (class (horzcat (uint64 (1), true)), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1970 %!assert (class (horzcat (uint64 (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1971
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1972 %!assert (class (horzcat (uint32 (1), int64 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1973 %!assert (class (horzcat (uint32 (1), int32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1974 %!assert (class (horzcat (uint32 (1), int16 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1975 %!assert (class (horzcat (uint32 (1), int8 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1976 %!assert (class (horzcat (uint32 (1), uint64 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1977 %!assert (class (horzcat (uint32 (1), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1978 %!assert (class (horzcat (uint32 (1), uint16 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1979 %!assert (class (horzcat (uint32 (1), uint8 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1980 %!assert (class (horzcat (uint32 (1), single (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1981 %!assert (class (horzcat (uint32 (1), double (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1982 %!assert (class (horzcat (uint32 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1983 %!assert (class (horzcat (uint32 (1), true)), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1984 %!assert (class (horzcat (uint32 (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1985
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1986 %!assert (class (horzcat (uint16 (1), int64 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1987 %!assert (class (horzcat (uint16 (1), int32 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1988 %!assert (class (horzcat (uint16 (1), int16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1989 %!assert (class (horzcat (uint16 (1), int8 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1990 %!assert (class (horzcat (uint16 (1), uint64 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1991 %!assert (class (horzcat (uint16 (1), uint32 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1992 %!assert (class (horzcat (uint16 (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1993 %!assert (class (horzcat (uint16 (1), uint8 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1994 %!assert (class (horzcat (uint16 (1), single (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1995 %!assert (class (horzcat (uint16 (1), double (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1996 %!assert (class (horzcat (uint16 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1997 %!assert (class (horzcat (uint16 (1), true)), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1998 %!assert (class (horzcat (uint16 (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1999
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2000 %!assert (class (horzcat (uint8 (1), int64 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2001 %!assert (class (horzcat (uint8 (1), int32 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2002 %!assert (class (horzcat (uint8 (1), int16 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2003 %!assert (class (horzcat (uint8 (1), int8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2004 %!assert (class (horzcat (uint8 (1), uint64 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2005 %!assert (class (horzcat (uint8 (1), uint32 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2006 %!assert (class (horzcat (uint8 (1), uint16 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2007 %!assert (class (horzcat (uint8 (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2008 %!assert (class (horzcat (uint8 (1), single (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2009 %!assert (class (horzcat (uint8 (1), double (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2010 %!assert (class (horzcat (uint8 (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2011 %!assert (class (horzcat (uint8 (1), true)), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2012 %!assert (class (horzcat (uint8 (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2013
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2014 %!assert (class (horzcat (single (1), int64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2015 %!assert (class (horzcat (single (1), int32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2016 %!assert (class (horzcat (single (1), int16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2017 %!assert (class (horzcat (single (1), int8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2018 %!assert (class (horzcat (single (1), uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2019 %!assert (class (horzcat (single (1), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2020 %!assert (class (horzcat (single (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2021 %!assert (class (horzcat (single (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2022 %!assert (class (horzcat (single (1), single (1))), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2023 %!assert (class (horzcat (single (1), double (1))), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2024 %!assert (class (horzcat (single (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2025 %!assert (class (horzcat (single (1), true)), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2026 %!assert (class (horzcat (single (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2027
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2028 %!assert (class (horzcat (double (1), int64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2029 %!assert (class (horzcat (double (1), int32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2030 %!assert (class (horzcat (double (1), int16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2031 %!assert (class (horzcat (double (1), int8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2032 %!assert (class (horzcat (double (1), uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2033 %!assert (class (horzcat (double (1), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2034 %!assert (class (horzcat (double (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2035 %!assert (class (horzcat (double (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2036 %!assert (class (horzcat (double (1), single (1))), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2037 %!assert (class (horzcat (double (1), double (1))), "double")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2038 %!assert (class (horzcat (double (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2039 %!assert (class (horzcat (double (1), true)), "double")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2040 %!assert (class (horzcat (double (1), "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2041
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2042 %!assert (class (horzcat (cell (1), int64 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2043 %!assert (class (horzcat (cell (1), int32 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2044 %!assert (class (horzcat (cell (1), int16 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2045 %!assert (class (horzcat (cell (1), int8 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2046 %!assert (class (horzcat (cell (1), uint64 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2047 %!assert (class (horzcat (cell (1), uint32 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2048 %!assert (class (horzcat (cell (1), uint16 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2049 %!assert (class (horzcat (cell (1), uint8 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2050 %!assert (class (horzcat (cell (1), single (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2051 %!assert (class (horzcat (cell (1), double (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2052 %!assert (class (horzcat (cell (1), cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2053 %!assert (class (horzcat (cell (1), true)), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2054 %!assert (class (horzcat (cell (1), "a")), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2055
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2056 %!assert (class (horzcat (true, int64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2057 %!assert (class (horzcat (true, int32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2058 %!assert (class (horzcat (true, int16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2059 %!assert (class (horzcat (true, int8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2060 %!assert (class (horzcat (true, uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2061 %!assert (class (horzcat (true, uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2062 %!assert (class (horzcat (true, uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2063 %!assert (class (horzcat (true, uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2064 %!assert (class (horzcat (true, single (1))), "single")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2065 %!assert (class (horzcat (true, double (1))), "double")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2066 %!assert (class (horzcat (true, cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2067 %!assert (class (horzcat (true, true)), "logical")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2068 %!assert (class (horzcat (true, "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2069
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2070 %!assert (class (horzcat ("a", int64 (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2071 %!assert (class (horzcat ("a", int32 (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2072 %!assert (class (horzcat ("a", int16 (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2073 %!assert (class (horzcat ("a", int8 (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2074 %!assert (class (horzcat ("a", int64 (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2075 %!assert (class (horzcat ("a", int32 (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2076 %!assert (class (horzcat ("a", int16 (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2077 %!assert (class (horzcat ("a", int8 (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2078 %!assert (class (horzcat ("a", single (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2079 %!assert (class (horzcat ("a", double (1))), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2080 %!assert (class (horzcat ("a", cell (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2081 %!assert (class (horzcat ("a", true)), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2082 %!assert (class (horzcat ("a", "a")), "char")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2083
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2084 %!assert (class (horzcat (cell (1), struct ("foo", "bar"))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2085
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2086 %!error horzcat (struct ("foo", "bar"), cell (1))
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2087 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2088
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2089 DEFUN (vertcat, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2090 "-*- texinfo -*-\n\
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2091 @deftypefn {Built-in Function} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2092 Return the vertical concatenation of N-D array objects, @var{array1},\n\
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2093 @var{array2}, @dots{}, @var{arrayN} along dimension 1.\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2094 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2095 Arrays may also be concatenated vertically using the syntax for creating\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2096 new matrices. For example:\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2097 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2098 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2099 @var{vcat} = [ @var{array1}; @var{array2}; @dots{} ]\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2100 @end example\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
2101 @seealso{cat, horzcat}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
2102 @end deftypefn")
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2103 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2104 return do_cat (args, -1, "vertcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2105 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2106
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2107 /*
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2108 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2109 %! c = {"foo"; "bar"; "bazoloa"};
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2110 %! assert (vertcat (c, "a", "bc", "def"), {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"});
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2111 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2112
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2113 DEFUN (cat, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2114 "-*- texinfo -*-\n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2115 @deftypefn {Built-in Function} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2116 Return the concatenation of N-D array objects, @var{array1},\n\
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2117 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.\n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2118 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2119 @example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2120 @group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2121 A = ones (2, 2);\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2122 B = zeros (2, 2);\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2123 cat (2, A, B)\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2124 @result{} 1 1 0 0\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2125 1 1 0 0\n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2126 @end group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2127 @end example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2128 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2129 Alternatively, we can concatenate @var{A} and @var{B} along the\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2130 second dimension in the following way:\n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2131 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2132 @example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2133 @group\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2134 [A, B]\n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2135 @end group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2136 @end example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2137 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2138 @var{dim} can be larger than the dimensions of the N-D array objects\n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2139 and the result will thus have @var{dim} dimensions as the\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2140 following example shows:\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2141 \n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2142 @example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2143 @group\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2144 cat (4, ones (2, 2), zeros (2, 2))\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2145 @result{} ans(:,:,1,1) =\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2146 \n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2147 1 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2148 1 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2149 \n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2150 ans(:,:,1,2) =\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2151 \n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2152 0 0\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2153 0 0\n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2154 @end group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2155 @end example\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
2156 @seealso{horzcat, vertcat}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
2157 @end deftypefn")
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2158 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2159 octave_value retval;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2160
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2161 if (args.length () > 0)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2162 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2163 int dim = args(0).int_value () - 1;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2164
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2165 if (! error_state)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2166 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2167 if (dim >= 0)
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2168 retval = do_cat (args.slice (1, args.length () - 1), dim, "cat");
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2169 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
2170 error ("cat: DIM must be a valid dimension");
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2171 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2172 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
2173 error ("cat: DIM must be an integer");
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2174 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2175 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2176 print_usage ();
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2177
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2178 return retval;
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2179 }
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2180
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2181 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2182 %!function ret = __testcat (t1, t2, tr, cmplx)
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
2183 %! assert (cat (1, cast ([], t1), cast ([], t2)), cast ([], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2184 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2185 %! assert (cat (1, cast (1, t1), cast (2, t2)), cast ([1; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2186 %! assert (cat (1, cast (1, t1), cast ([2; 3], t2)), cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2187 %! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2188 %! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)), cast ([1; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2189 %! assert (cat (2, cast (1, t1), cast (2, t2)), cast ([1, 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2190 %! assert (cat (2, cast (1, t1), cast ([2, 3], t2)), cast ([1, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2191 %! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2192 %! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)), cast ([1, 2, 3, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2193 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2194 %! assert ([cast(1, t1); cast(2, t2)], cast ([1; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2195 %! assert ([cast(1, t1); cast([2; 3], t2)], cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2196 %! assert ([cast([1; 2], t1); cast(3, t2)], cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2197 %! assert ([cast([1; 2], t1); cast([3; 4], t2)], cast ([1; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2198 %! assert ([cast(1, t1), cast(2, t2)], cast ([1, 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2199 %! assert ([cast(1, t1), cast([2, 3], t2)], cast ([1, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2200 %! assert ([cast([1, 2], t1), cast(3, t2)], cast ([1, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2201 %! assert ([cast([1, 2], t1), cast([3, 4], t2)], cast ([1, 2, 3, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2202 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2203 %! if (nargin == 3 || cmplx)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2204 %! assert (cat (1, cast (1i, t1), cast (2, t2)), cast ([1i; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2205 %! assert (cat (1, cast (1i, t1), cast ([2; 3], t2)), cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2206 %! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2207 %! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)), cast ([1i; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2208 %! assert (cat (2, cast (1i, t1), cast (2, t2)), cast ([1i, 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2209 %! assert (cat (2, cast (1i, t1), cast ([2, 3], t2)), cast ([1i, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2210 %! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2211 %! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)), cast ([1i, 2, 3, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2212 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2213 %! assert ([cast(1i, t1); cast(2, t2)], cast ([1i; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2214 %! assert ([cast(1i, t1); cast([2; 3], t2)], cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2215 %! assert ([cast([1i; 2], t1); cast(3, t2)], cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2216 %! assert ([cast([1i; 2], t1); cast([3; 4], t2)], cast ([1i; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2217 %! assert ([cast(1i, t1), cast(2, t2)], cast ([1i, 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2218 %! assert ([cast(1i, t1), cast([2, 3], t2)], cast ([1i, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2219 %! assert ([cast([1i, 2], t1), cast(3, t2)], cast ([1i, 2, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2220 %! assert ([cast([1i, 2], t1), cast([3, 4], t2)], cast ([1i, 2, 3, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2221 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2222 %! assert (cat (1, cast (1, t1), cast (2i, t2)), cast ([1; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2223 %! assert (cat (1, cast (1, t1), cast ([2i; 3], t2)), cast ([1; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2224 %! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2225 %! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)), cast ([1; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2226 %! assert (cat (2, cast (1, t1), cast (2i, t2)), cast ([1, 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2227 %! assert (cat (2, cast (1, t1), cast ([2i, 3], t2)), cast ([1, 2i, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2228 %! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2229 %! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)), cast ([1, 2, 3i, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2230 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2231 %! assert ([cast(1, t1); cast(2i, t2)], cast ([1; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2232 %! assert ([cast(1, t1); cast([2i; 3], t2)], cast ([1; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2233 %! assert ([cast([1; 2], t1); cast(3i, t2)], cast ([1; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2234 %! assert ([cast([1; 2], t1); cast([3i; 4], t2)], cast ([1; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2235 %! assert ([cast(1, t1), cast(2i, t2)], cast ([1, 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2236 %! assert ([cast(1, t1), cast([2i, 3], t2)], cast ([1, 2i, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2237 %! assert ([cast([1, 2], t1), cast(3i, t2)], cast ([1, 2, 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2238 %! assert ([cast([1, 2], t1), cast([3i, 4], t2)], cast ([1, 2, 3i, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2239 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2240 %! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2241 %! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)), cast ([1i; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2242 %! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)), cast ([1i; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2243 %! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)), cast ([1i; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2244 %! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2245 %! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)), cast ([1i, 2i, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2246 %! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)), cast ([1i, 2, 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2247 %! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)), cast ([1i, 2, 3i, 4], tr));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2248 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2249 %! assert ([cast(1i, t1); cast(2i, t2)], cast ([1i; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2250 %! assert ([cast(1i, t1); cast([2i; 3], t2)], cast ([1i; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2251 %! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2252 %! assert ([cast([1i; 2], t1); cast([3i; 4], t2)], cast ([1i; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2253 %! assert ([cast(1i, t1), cast(2i, t2)], cast ([1i, 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2254 %! assert ([cast(1i, t1), cast([2i, 3], t2)], cast ([1i, 2i, 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2255 %! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2256 %! assert ([cast([1i, 2], t1), cast([3i, 4], t2)], cast ([1i, 2, 3i, 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2257 %! endif
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2258 %! ret = true;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2259 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2260
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2261 %!assert (__testcat ("double", "double", "double"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2262 %!assert (__testcat ("single", "double", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2263 %!assert (__testcat ("double", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2264 %!assert (__testcat ("single", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2265
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2266 %!assert (__testcat ("double", "int8", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2267 %!assert (__testcat ("int8", "double", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2268 %!assert (__testcat ("single", "int8", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2269 %!assert (__testcat ("int8", "single", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2270 %!assert (__testcat ("int8", "int8", "int8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2271 %!assert (__testcat ("double", "int16", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2272 %!assert (__testcat ("int16", "double", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2273 %!assert (__testcat ("single", "int16", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2274 %!assert (__testcat ("int16", "single", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2275 %!assert (__testcat ("int16", "int16", "int16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2276 %!assert (__testcat ("double", "int32", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2277 %!assert (__testcat ("int32", "double", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2278 %!assert (__testcat ("single", "int32", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2279 %!assert (__testcat ("int32", "single", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2280 %!assert (__testcat ("int32", "int32", "int32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2281 %!assert (__testcat ("double", "int64", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2282 %!assert (__testcat ("int64", "double", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2283 %!assert (__testcat ("single", "int64", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2284 %!assert (__testcat ("int64", "single", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2285 %!assert (__testcat ("int64", "int64", "int64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2286
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2287 %!assert (__testcat ("double", "uint8", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2288 %!assert (__testcat ("uint8", "double", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2289 %!assert (__testcat ("single", "uint8", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2290 %!assert (__testcat ("uint8", "single", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2291 %!assert (__testcat ("uint8", "uint8", "uint8", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2292 %!assert (__testcat ("double", "uint16", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2293 %!assert (__testcat ("uint16", "double", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2294 %!assert (__testcat ("single", "uint16", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2295 %!assert (__testcat ("uint16", "single", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2296 %!assert (__testcat ("uint16", "uint16", "uint16", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2297 %!assert (__testcat ("double", "uint32", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2298 %!assert (__testcat ("uint32", "double", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2299 %!assert (__testcat ("single", "uint32", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2300 %!assert (__testcat ("uint32", "single", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2301 %!assert (__testcat ("uint32", "uint32", "uint32", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2302 %!assert (__testcat ("double", "uint64", "uint64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2303 %!assert (__testcat ("uint64", "double", "uint64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2304 %!assert (__testcat ("single", "uint64", "uint64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2305 %!assert (__testcat ("uint64", "single", "uint64", false))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2306 %!assert (__testcat ("uint64", "uint64", "uint64", false))
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2307
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2308 %!assert (cat (3, [], [1,2;3,4]), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2309 %!assert (cat (3, [1,2;3,4], []), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2310 %!assert (cat (3, [], [1,2;3,4], []), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2311 %!assert (cat (3, [], [], []), zeros (0, 0, 3))
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2312
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2313 %!assert (cat (3, [], [], 1, 2), cat (3, 1, 2))
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2314 %!assert (cat (3, [], [], [1,2;3,4]), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2315 %!assert (cat (4, [], [], [1,2;3,4]), [1,2;3,4])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2316
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2317 %!assert ([zeros(3,2,2); ones(1,2,2)], repmat ([0;0;0;1],[1,2,2]) )
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2318 %!assert ([zeros(3,2,2); ones(1,2,2)], vertcat (zeros (3,2,2), ones (1,2,2)) )
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2319
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2320 %!error <dimension mismatch> cat (3, cat (3, [], []), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2321 %!error <dimension mismatch> cat (3, zeros (0, 0, 2), [1,2;3,4])
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2322 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2323
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2324 static octave_value
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2325 do_permute (const octave_value_list& args, bool inv)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2326 {
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2327 octave_value retval;
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2328
5148
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
2329 if (args.length () == 2 && args(1).length () >= args(1).ndims ())
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2330 {
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2331 Array<int> vec = args(1).int_vector_value ();
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2332
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2333 // FIXME: maybe we should create an idx_vector object
5148
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
2334 // here and pass that to permute?
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
2335
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
2336 int n = vec.length ();
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
2337
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
2338 for (int i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2339 vec(i)--;
5148
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
2340
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2341 octave_value ret = args(0).permute (vec, inv);
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2342
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2343 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2344 retval = ret;
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2345 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2346 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2347 print_usage ();
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2348
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2349 return retval;
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2350 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2351
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2352 DEFUN (permute, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2353 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2354 @deftypefn {Built-in Function} {} permute (@var{A}, @var{perm})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2355 Return the generalized transpose for an N-D array object @var{A}.\n\
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2356 The permutation vector @var{perm} must contain the elements\n\
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
2357 @code{1:ndims (A)} (in any order, but each element must appear only once).\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
2358 @seealso{ipermute}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
2359 @end deftypefn")
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2360 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2361 return do_permute (args, false);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2362 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2363
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2364 DEFUN (ipermute, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2365 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2366 @deftypefn {Built-in Function} {} ipermute (@var{A}, @var{iperm})\n\
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2367 The inverse of the @code{permute} function. The expression\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2368 \n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2369 @example\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2370 ipermute (permute (A, perm), perm)\n\
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2371 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2372 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
2373 @noindent\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
2374 returns the original array @var{A}.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
2375 @seealso{permute}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
2376 @end deftypefn")
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2377 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2378 return do_permute (args, true);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2379 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2380
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2381 DEFUN (length, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2382 "-*- texinfo -*-\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2383 @deftypefn {Built-in Function} {} length (@var{a})\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2384 Return the length of the object @var{a}.\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2385 \n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2386 The length is 0 for empty objects, 1 for scalars, and the number of elements\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2387 for vectors. For matrix objects, the length is the number of rows or\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2388 columns, whichever is greater (this odd definition is used for compatibility\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2389 with @sc{matlab}).\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2390 @seealso{numel, size}\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2391 @end deftypefn")
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2392 {
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2393 octave_value retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2394
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2395 if (args.length () == 1)
9706
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2396 retval = args(0).length ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2397 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2398 print_usage ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2399
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2400 return retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2401 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2402
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2403 DEFUN (ndims, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2404 "-*- texinfo -*-\n\
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2405 @deftypefn {Built-in Function} {} ndims (@var{a})\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2406 Return the number of dimensions of @var{a}.\n\
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2407 For any array, the result will always be larger than or equal to 2.\n\
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2408 Trailing singleton dimensions are not counted.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2409 \n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2410 @example\n\
10711
fbd7843974fa Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents: 10707
diff changeset
2411 @group\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2412 ndims (ones (4, 1, 2, 1))\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2413 @result{} 3\n\
10711
fbd7843974fa Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents: 10707
diff changeset
2414 @end group\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2415 @end example\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
2416 @seealso{size}\n\
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2417 @end deftypefn")
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2418 {
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2419 octave_value retval;
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2420
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2421 if (args.length () == 1)
9706
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2422 retval = args(0).ndims ();
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2423 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2424 print_usage ();
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2425
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2426 return retval;
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2427 }
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2428
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2429 DEFUN (numel, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2430 "-*- texinfo -*-\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2431 @deftypefn {Built-in Function} {} numel (@var{a})\n\
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2432 @deftypefnx {Built-in Function} {} numel (@var{a}, @var{idx1}, @var{idx2}, @dots{})\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2433 Return the number of elements in the object @var{a}.\n\
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2434 Optionally, if indices @var{idx1}, @var{idx2}, @dots{} are supplied,\n\
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2435 return the number of elements that would result from the indexing\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2436 \n\
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2437 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2438 @var{a}(@var{idx1}, @var{idx2}, @dots{})\n\
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2439 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2440 \n\
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
2441 Note that the indices do not have to be numerical. For example,\n\
12924
67a5acac8e1b Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12681
diff changeset
2442 \n\
67a5acac8e1b Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12681
diff changeset
2443 @example\n\
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
2444 @group\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2445 @var{a} = 1;\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2446 @var{b} = ones (2, 3);\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2447 numel (@var{a}, @var{b})\n\
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
2448 @end group\n\
12924
67a5acac8e1b Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12681
diff changeset
2449 @end example\n\
67a5acac8e1b Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12681
diff changeset
2450 \n\
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13915
diff changeset
2451 @noindent\n\
12924
67a5acac8e1b Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12681
diff changeset
2452 will return 6, as this is the number of ways to index with @var{b}.\n\
67a5acac8e1b Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12681
diff changeset
2453 \n\
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2454 This method is also called when an object appears as lvalue with cs-list\n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9736
diff changeset
2455 indexing, i.e., @code{object@{@dots{}@}} or @code{object(@dots{}).field}.\n\
5724
82247c2a7520 [project @ 2006-03-30 21:34:52 by jwe]
jwe
parents: 5714
diff changeset
2456 @seealso{size}\n\
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2457 @end deftypefn")
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2458 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2459 octave_value retval;
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
2460 octave_idx_type nargin = args.length ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
2461
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2462 if (nargin == 1)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2463 retval = args(0).numel ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2464 else if (nargin > 1)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2465 {
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2466 // Don't use numel (const octave_value_list&) here as that corresponds to
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2467 // an overloaded call, not to builtin!
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2468 retval = dims_to_numel (args(0).dims (), args.slice (1, nargin-1));
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2469 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2470 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2471 print_usage ();
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2472
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2473 return retval;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2474 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2475
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2476 DEFUN (size, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2477 "-*- texinfo -*-\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2478 @deftypefn {Built-in Function} {} size (@var{a})\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2479 @deftypefnx {Built-in Function} {} size (@var{a}, @var{dim})\n\
12546
39ca02387a32 Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
2480 Return the number of rows and columns of @var{a}.\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2481 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2482 With one input argument and one output argument, the result is returned\n\
4741
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
2483 in a row vector. If there are multiple output arguments, the number of\n\
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
2484 rows is assigned to the first, and the number of columns to the second,\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2485 etc. For example:\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2486 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2487 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2488 @group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2489 size ([1, 2; 3, 4; 5, 6])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2490 @result{} [ 3, 2 ]\n\
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2491 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2492 [nr, nc] = size ([1, 2; 3, 4; 5, 6])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2493 @result{} nr = 3\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2494 @result{} nc = 2\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2495 @end group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2496 @end example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2497 \n\
4741
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
2498 If given a second argument, @code{size} will return the size of the\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2499 corresponding dimension. For example,\n\
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2500 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2501 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
2502 @group\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2503 size ([1, 2; 3, 4; 5, 6], 2)\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2504 @result{} 2\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
2505 @end group\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2506 @end example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2507 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2508 @noindent\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2509 returns the number of columns in the given matrix.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
2510 @seealso{numel, ndims, length, rows, columns}\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
2511 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2512 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
2513 octave_value_list retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2514
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2515 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2516
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2517 if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2518 {
9706
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2519 const dim_vector dimensions = args(0).dims ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2520
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2521 if (nargout > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2522 {
9706
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2523 const dim_vector rdims = dimensions.redim (nargout);
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2524 retval.resize (nargout);
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2525 for (int i = 0; i < nargout; i++)
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2526 retval(i) = rdims(i);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2527 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2528 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2529 {
9706
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2530 int ndims = dimensions.length ();
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2531
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2532 NoAlias<Matrix> m (1, ndims);
71160b139b07 simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents: 9705
diff changeset
2533
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2534 for (int i = 0; i < ndims; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2535 m(i) = dimensions(i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2536
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2537 retval(0) = m;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2538 }
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2539 }
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2540 else if (nargin == 2 && nargout < 2)
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2541 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
2542 octave_idx_type nd = args(1).int_value (true);
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2543
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2544 if (error_state)
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
2545 error ("size: DIM must be a scalar");
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
2546 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2547 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2548 const dim_vector dv = args(0).dims ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2549
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2550 if (nd > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2551 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2552 if (nd <= dv.length ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2553 retval(0) = dv(nd-1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
2554 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2555 retval(0) = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2556 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2557 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
2558 error ("size: requested dimension DIM (= %d) out of range", nd);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2559 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2560 }
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
2561 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2562 print_usage ();
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2563
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2564 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2565 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2566
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2567 DEFUN (size_equal, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2568 "-*- texinfo -*-\n\
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2569 @deftypefn {Built-in Function} {} size_equal (@var{a}, @var{b}, @dots{})\n\
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2570 Return true if the dimensions of all arguments agree.\n\
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2571 Trailing singleton dimensions are ignored.\n\
10002
e93c9bfff8b8 allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 9866
diff changeset
2572 Called with a single or no argument, size_equal returns true.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
2573 @seealso{size, numel, ndims}\n\
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2574 @end deftypefn")
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2575 {
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2576 octave_value retval;
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2577
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2578 int nargin = args.length ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2579
10002
e93c9bfff8b8 allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 9866
diff changeset
2580 retval = true;
e93c9bfff8b8 allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 9866
diff changeset
2581
8947
1e4b3149365a allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents: 8934
diff changeset
2582 if (nargin >= 1)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2583 {
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2584 dim_vector a_dims = args(0).dims ();
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2585
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2586 for (int i = 1; i < nargin; ++i)
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2587 {
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2588 dim_vector b_dims = args(i).dims ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2589
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2590 if (a_dims != b_dims)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2591 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2592 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2593 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2594 }
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2595 }
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2596 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2597
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2598 return retval;
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2599 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2600
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2601 DEFUN (nnz, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2602 "-*- texinfo -*-\n\
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2603 @deftypefn {Built-in Function} {@var{scalar} =} nnz (@var{a})\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11570
diff changeset
2604 Return the number of non zero elements in @var{a}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
2605 @seealso{sparse, nzmax}\n\
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2606 @end deftypefn")
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2607 {
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2608 octave_value retval;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2609
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2610 if (args.length () == 1)
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2611 retval = args(0).nnz ();
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2612 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2613 print_usage ();
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2614
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2615 return retval;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2616 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2617
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2618 DEFUN (nzmax, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2619 "-*- texinfo -*-\n\
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2620 @deftypefn {Built-in Function} {@var{scalar} =} nzmax (@var{SM})\n\
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2621 Return the amount of storage allocated to the sparse matrix @var{SM}.\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6999
diff changeset
2622 Note that Octave tends to crop unused memory at the first opportunity\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
2623 for sparse objects. There are some cases of user created sparse objects\n\
9066
be150a172010 Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
2624 where the value returned by @dfn{nzmax} will not be the same as @dfn{nnz},\n\
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2625 but in general they will give the same result.\n\
15034
1116864ee270 doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents: 15031
diff changeset
2626 @seealso{nnz, spalloc, sparse}\n\
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2627 @end deftypefn")
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2628 {
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2629 octave_value retval;
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2630
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
2631 if (args.length () == 1)
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2632 retval = args(0).nzmax ();
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2633 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2634 print_usage ();
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2635
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2636 return retval;
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2637 }
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2638
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2639 DEFUN (rows, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2640 "-*- texinfo -*-\n\
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2641 @deftypefn {Built-in Function} {} rows (@var{a})\n\
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2642 Return the number of rows of @var{a}.\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2643 @seealso{columns, size, length, numel, isscalar, isvector, ismatrix}\n\
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2644 @end deftypefn")
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2645 {
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2646 octave_value retval;
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2647
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2648 if (args.length () == 1)
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2649 retval = args(0).rows ();
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2650 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2651 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2652
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2653 return retval;
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2654 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2655
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2656 DEFUN (columns, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2657 "-*- texinfo -*-\n\
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2658 @deftypefn {Built-in Function} {} columns (@var{a})\n\
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2659 Return the number of columns of @var{a}.\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
2660 @seealso{rows, size, length, numel, isscalar, isvector, ismatrix}\n\
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2661 @end deftypefn")
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2662 {
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2663 octave_value retval;
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2664
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2665 if (args.length () == 1)
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2666 retval = args(0).columns ();
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2667 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2668 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2669
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2670 return retval;
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2671 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2672
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2673 DEFUN (sum, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2674 "-*- texinfo -*-\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
2675 @deftypefn {Built-in Function} {} sum (@var{x})\n\
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
2676 @deftypefnx {Built-in Function} {} sum (@var{x}, @var{dim})\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2677 @deftypefnx {Built-in Function} {} sum (@dots{}, \"native\")\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2678 @deftypefnx {Built-in Function} {} sum (@dots{}, \"double\")\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2679 @deftypefnx {Built-in Function} {} sum (@dots{}, \"extra\")\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
2680 Sum of elements along dimension @var{dim}. If @var{dim} is\n\
9723
f426899f4b9c fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
2681 omitted, it defaults to the first non-singleton dimension.\n\
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2682 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2683 If the optional argument @qcode{\"native\"} is given, then the sum is\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2684 performed in the same type as the original argument, rather than in the\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2685 default double type. For example:\n\
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2686 \n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2687 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
2688 @group\n\
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2689 sum ([true, true])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2690 @result{} 2\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2691 sum ([true, true], \"native\")\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2692 @result{} true\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
2693 @end group\n\
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2694 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2695 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2696 On the contrary, if @qcode{\"double\"} is given, the sum is performed in\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2697 double precision even for single precision inputs.\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2698 \n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2699 For double precision inputs, @qcode{\"extra\"} indicates that a more accurate\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
2700 algorithm than straightforward summation is to be used. For single precision\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2701 inputs, @qcode{\"extra\"} is the same as @qcode{\"double\"}. Otherwise,\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
2702 @qcode{\"extra\"} has no effect.\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
2703 @seealso{cumsum, sumsq, prod}\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
2704 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2705 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2706 octave_value retval;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2707
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2708 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2709
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2710 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2711 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2712 bool isextra = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2713
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2714 if (nargin > 1 && args(nargin - 1).is_string ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2715 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2716 std::string str = args(nargin - 1).string_value ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2717
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2718 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2719 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2720 if (str == "native")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2721 isnative = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2722 else if (str == "double")
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2723 isdouble = true;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2724 else if (str == "extra")
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2725 isextra = true;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2726 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2727 error ("sum: unrecognized string argument");
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2728 nargin --;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2729 }
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2730 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2731
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2732 if (error_state)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2733 return retval;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2734
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2735 if (nargin == 1 || nargin == 2)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2736 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2737 octave_value arg = args(0);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2738
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2739 int dim = -1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2740 if (nargin == 2)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2741 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2742 dim = args(1).int_value () - 1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2743 if (dim < 0)
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
2744 error ("sum: invalid dimension DIM = %d", dim + 1);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2745 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2746
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2747 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2748 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2749 switch (arg.builtin_type ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2750 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2751 case btyp_double:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2752 if (arg.is_sparse_type ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2753 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2754 if (isextra)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2755 warning ("sum: 'extra' not yet implemented for sparse matrices");
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2756 retval = arg.sparse_matrix_value ().sum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2757 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2758 else if (isextra)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2759 retval = arg.array_value ().xsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2760 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2761 retval = arg.array_value ().sum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2762 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2763 case btyp_complex:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2764 if (arg.is_sparse_type ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2765 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2766 if (isextra)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2767 warning ("sum: 'extra' not yet implemented for sparse matrices");
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2768 retval = arg.sparse_complex_matrix_value ().sum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2769 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2770 else if (isextra)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2771 retval = arg.complex_array_value ().xsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2772 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2773 retval = arg.complex_array_value ().sum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2774 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2775 case btyp_float:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2776 if (isdouble || isextra)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2777 retval = arg.float_array_value ().dsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2778 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2779 retval = arg.float_array_value ().sum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2780 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2781 case btyp_float_complex:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2782 if (isdouble || isextra)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2783 retval = arg.float_complex_array_value ().dsum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2784 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2785 retval = arg.float_complex_array_value ().sum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2786 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2787
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2788 #define MAKE_INT_BRANCH(X) \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2789 case btyp_ ## X: \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2790 if (isnative) \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2791 retval = arg.X ## _array_value ().sum (dim); \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2792 else \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2793 retval = arg.X ## _array_value ().dsum (dim); \
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2794 break
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2795 MAKE_INT_BRANCH (int8);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2796 MAKE_INT_BRANCH (int16);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2797 MAKE_INT_BRANCH (int32);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2798 MAKE_INT_BRANCH (int64);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2799 MAKE_INT_BRANCH (uint8);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2800 MAKE_INT_BRANCH (uint16);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2801 MAKE_INT_BRANCH (uint32);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2802 MAKE_INT_BRANCH (uint64);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2803 #undef MAKE_INT_BRANCH
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2804 // GAGME: Accursed Matlab compatibility...
15621
e9d842dcfc91 *data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15509
diff changeset
2805 case btyp_char:
e9d842dcfc91 *data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15509
diff changeset
2806 if (isextra)
e9d842dcfc91 *data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15509
diff changeset
2807 retval = arg.array_value (true).xsum (dim);
e9d842dcfc91 *data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15509
diff changeset
2808 else
e9d842dcfc91 *data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15509
diff changeset
2809 retval = arg.array_value (true).sum (dim);
e9d842dcfc91 *data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15509
diff changeset
2810 break;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2811 case btyp_bool:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2812 if (arg.is_sparse_type ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2813 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2814 if (isnative)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2815 retval = arg.sparse_bool_matrix_value ().any (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2816 else
10983
4b51c0a20a98 optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10880
diff changeset
2817 retval = arg.sparse_bool_matrix_value ().sum (dim);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2818 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2819 else if (isnative)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2820 retval = arg.bool_array_value ().any (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2821 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2822 retval = arg.bool_array_value ().sum (dim);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2823 break;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2824
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2825 default:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2826 gripe_wrong_type_arg ("sum", arg);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2827 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2828 }
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2829 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2830 else
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2831 print_usage ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2832
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
2833 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2834 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2835
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2836 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2837 %!assert (sum ([true,true]), 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2838 %!assert (sum ([true,true],"native"), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2839 %!assert (sum (int8 ([127,10,-20])), 117)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2840 %!assert (sum (int8 ([127,10,-20]),'native'), int8 (107))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2841
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2842 %!assert (sum ([1, 2, 3]), 6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2843 %!assert (sum ([-1; -2; -3]), -6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2844 %!assert (sum ([i, 2+i, -3+2i, 4]), 3+4i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2845 %!assert (sum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [2+2i, 4+4i, 6+6i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2846
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2847 %!assert (sum (single ([1, 2, 3])), single (6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2848 %!assert (sum (single ([-1; -2; -3])), single (-6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2849 %!assert (sum (single ([i, 2+i, -3+2i, 4])), single (3+4i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2850 %!assert (sum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([2+2i, 4+4i, 6+6i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2851
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2852 %!assert (sum ([1, 2; 3, 4], 1), [4, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2853 %!assert (sum ([1, 2; 3, 4], 2), [3; 7])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2854 %!assert (sum (zeros (1, 0)), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2855 %!assert (sum (zeros (1, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2856 %!assert (sum (zeros (1, 0), 2), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2857 %!assert (sum (zeros (0, 1)), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2858 %!assert (sum (zeros (0, 1), 1), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2859 %!assert (sum (zeros (0, 1), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2860 %!assert (sum (zeros (2, 0)), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2861 %!assert (sum (zeros (2, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2862 %!assert (sum (zeros (2, 0), 2), [0; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2863 %!assert (sum (zeros (0, 2)), [0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2864 %!assert (sum (zeros (0, 2), 1), [0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2865 %!assert (sum (zeros (0, 2), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2866 %!assert (sum (zeros (2, 2, 0, 3)), zeros (1, 2, 0, 3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2867 %!assert (sum (zeros (2, 2, 0, 3), 2), zeros (2, 1, 0, 3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2868 %!assert (sum (zeros (2, 2, 0, 3), 3), zeros (2, 2, 1, 3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2869 %!assert (sum (zeros (2, 2, 0, 3), 4), zeros (2, 2, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2870 %!assert (sum (zeros (2, 2, 0, 3), 7), zeros (2, 2, 0, 3))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2871
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2872 %!assert (sum (single ([1, 2; 3, 4]), 1), single ([4, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2873 %!assert (sum (single ([1, 2; 3, 4]), 2), single ([3; 7]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2874 %!assert (sum (zeros (1, 0, "single")), single (0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2875 %!assert (sum (zeros (1, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2876 %!assert (sum (zeros (1, 0, "single"), 2), single (0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2877 %!assert (sum (zeros (0, 1, "single")), single (0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2878 %!assert (sum (zeros (0, 1, "single"), 1), single (0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2879 %!assert (sum (zeros (0, 1, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2880 %!assert (sum (zeros (2, 0, "single")), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2881 %!assert (sum (zeros (2, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2882 %!assert (sum (zeros (2, 0, "single"), 2), single ([0; 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2883 %!assert (sum (zeros (0, 2, "single")), single ([0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2884 %!assert (sum (zeros (0, 2, "single"), 1), single ([0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2885 %!assert (sum (zeros (0, 2, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2886 %!assert (sum (zeros (2, 2, 0, 3, "single")), zeros (1, 2, 0, 3, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2887 %!assert (sum (zeros (2, 2, 0, 3, "single"), 2), zeros (2, 1, 0, 3, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2888 %!assert (sum (zeros (2, 2, 0, 3, "single"), 3), zeros (2, 2, 1, 3, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2889 %!assert (sum (zeros (2, 2, 0, 3, "single"), 4), zeros (2, 2, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2890 %!assert (sum (zeros (2, 2, 0, 3, "single"), 7), zeros (2, 2, 0, 3, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2891
15623
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
2892 ;-)
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
2893 %!assert (sum ("Octave") + "8", sumsq (primes (17)))
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
2894
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2895 %!error sum ()
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2896 */
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
2897
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2898 DEFUN (sumsq, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2899 "-*- texinfo -*-\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
2900 @deftypefn {Built-in Function} {} sumsq (@var{x})\n\
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
2901 @deftypefnx {Built-in Function} {} sumsq (@var{x}, @var{dim})\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
2902 Sum of squares of elements along dimension @var{dim}. If @var{dim}\n\
9723
f426899f4b9c fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
2903 is omitted, it defaults to the first non-singleton dimension.\n\
5061
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
2904 \n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
2905 This function is conceptually equivalent to computing\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2906 \n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
2907 @example\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
2908 sum (x .* conj (x), dim)\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
2909 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
2910 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
2911 @noindent\n\
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9155
diff changeset
2912 but it uses less memory and avoids calling @code{conj} if @var{x} is real.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
2913 @seealso{sum, prod}\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
2914 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2915 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
2916 DATA_REDUCTION (sumsq);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2917 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2918
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
2919 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2920 %!assert (sumsq ([1, 2, 3]), 14)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2921 %!assert (sumsq ([-1; -2; 4i]), 21)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2922 %!assert (sumsq ([1, 2, 3; 2, 3, 4; 4i, 6i, 2]), [21, 49, 29])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2923
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2924 %!assert (sumsq (single ([1, 2, 3])), single (14))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2925 %!assert (sumsq (single ([-1; -2; 4i])), single (21))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2926 %!assert (sumsq (single ([1, 2, 3; 2, 3, 4; 4i, 6i, 2])), single ([21, 49, 29]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2927
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2928 %!assert (sumsq ([1, 2; 3, 4], 1), [10, 20])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2929 %!assert (sumsq ([1, 2; 3, 4], 2), [5; 25])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2930
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2931 %!assert (sumsq (single ([1, 2; 3, 4]), 1), single ([10, 20]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2932 %!assert (sumsq (single ([1, 2; 3, 4]), 2), single ([5; 25]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2933
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2934 %!error sumsq ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2935 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
2936
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
2937 DEFUN (islogical, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2938 "-*- texinfo -*-\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
2939 @deftypefn {Built-in Function} {} islogical (@var{x})\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
2940 @deftypefnx {Built-in Function} {} isbool (@var{x})\n\
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
2941 Return true if @var{x} is a logical object.\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
2942 @seealso{isfloat, isinteger, ischar, isnumeric, isa}\n\
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3428
diff changeset
2943 @end deftypefn")
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2944 {
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2945 octave_value retval;
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2946
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2947 if (args.length () == 1)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
2948 retval = args(0).is_bool_type ();
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2949 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2950 print_usage ();
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2951
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2952 return retval;
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2953 }
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2954
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
2955 DEFALIAS (isbool, islogical);
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
2956
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
2957 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2958 %!assert (islogical (true), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2959 %!assert (islogical (false), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2960 %!assert (islogical ([true, false]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2961 %!assert (islogical (1), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2962 %!assert (islogical (1i), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2963 %!assert (islogical ([1,1]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2964 %!assert (islogical (single (1)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2965 %!assert (islogical (single (1i)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2966 %!assert (islogical (single ([1,1])), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2967 %!assert (islogical (sparse ([true, false])), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2968 %!assert (islogical (sparse ([1, 0])), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2969 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
2970
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2971 DEFUN (isinteger, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2972 "-*- texinfo -*-\n\
6230
06bee64edc08 [project @ 2007-01-08 16:59:35 by jwe]
jwe
parents: 6223
diff changeset
2973 @deftypefn {Built-in Function} {} isinteger (@var{x})\n\
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2974 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
2975 Note that @w{@code{isinteger (14)}} is false because numeric constants in\n\
8429
f34ab2b433e8 One word missing from int8 help string.
Francesco Potortì <pot@gnu.org>
parents: 8366
diff changeset
2976 Octave are double precision floating point values.\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
2977 @seealso{isfloat, ischar, islogical, isnumeric, isa}\n\
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2978 @end deftypefn")
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2979 {
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2980 octave_value retval;
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2981
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2982 if (args.length () == 1)
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2983 retval = args(0).is_integer_type ();
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2984 else
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2985 print_usage ();
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2986
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2987 return retval;
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2988 }
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
2989
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
2990 DEFUN (iscomplex, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2991 "-*- texinfo -*-\n\
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
2992 @deftypefn {Built-in Function} {} iscomplex (@var{x})\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
2993 Return true if @var{x} is a complex-valued numeric object.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
2994 @seealso{isreal, isnumeric, islogical, ischar, isfloat, isa}\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
2995 @end deftypefn")
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
2996 {
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
2997 octave_value retval;
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
2998
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
2999 if (args.length () == 1)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3000 retval = args(0).is_complex_type ();
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3001 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3002 print_usage ();
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3003
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3004 return retval;
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3005 }
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3006
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3007 DEFUN (isfloat, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3008 "-*- texinfo -*-\n\
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3009 @deftypefn {Built-in Function} {} isfloat (@var{x})\n\
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3010 Return true if @var{x} is a floating-point numeric object.\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
3011 Objects of class double or single are floating-point objects.\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
3012 @seealso{isinteger, ischar, islogical, isnumeric, isa}\n\
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3013 @end deftypefn")
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3014 {
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3015 octave_value retval;
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3016
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3017 if (args.length () == 1)
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3018 retval = args(0).is_float_type ();
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3019 else
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3020 print_usage ();
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3021
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3022 return retval;
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3023 }
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3024
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3025 // FIXME: perhaps this should be implemented with an
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3026 // octave_value member function?
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3027
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3028 DEFUN (complex, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3029 "-*- texinfo -*-\n\
9309
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3030 @deftypefn {Built-in Function} {} complex (@var{x})\n\
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3031 @deftypefnx {Built-in Function} {} complex (@var{re}, @var{im})\n\
9309
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3032 Return a complex result from real arguments. With 1 real argument @var{x},\n\
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3033 return the complex result @code{@var{x} + 0i}. With 2 real arguments,\n\
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3034 return the complex result @code{@var{re} + @var{im}}. @code{complex} can\n\
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3035 often be more convenient than expressions such as @code{a + i*b}.\n\
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3036 For example:\n\
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3037 \n\
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3038 @example\n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9736
diff changeset
3039 @group\n\
9309
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3040 complex ([1, 2], [3, 4])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
3041 @result{} [ 1 + 3i 2 + 4i ]\n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9736
diff changeset
3042 @end group\n\
9309
fb8b8589dd46 Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents: 9308
diff changeset
3043 @end example\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
3044 @seealso{real, imag, iscomplex, abs, arg}\n\
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3045 @end deftypefn")
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3046 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3047 octave_value retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3048
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3049 int nargin = args.length ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3050
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3051 if (nargin == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3052 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3053 octave_value arg = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3054
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3055 if (arg.is_complex_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3056 retval = arg;
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3057 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3058 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3059 if (arg.is_sparse_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3060 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3061 SparseComplexMatrix val = arg.sparse_complex_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3062
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3063 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3064 retval = octave_value (new octave_sparse_complex_matrix (val));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3065 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3066 else if (arg.is_single_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3067 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3068 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3069 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3070 FloatComplex val = arg.float_complex_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3071
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3072 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3073 retval = octave_value (new octave_float_complex (val));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3074 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3075 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3076 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3077 FloatComplexNDArray val = arg.float_complex_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3078
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3079 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3080 retval = octave_value (new octave_float_complex_matrix (val));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3081 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3082 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3083 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3084 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3085 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3086 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3087 Complex val = arg.complex_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3088
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3089 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3090 retval = octave_value (new octave_complex (val));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3091 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3092 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3093 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3094 ComplexNDArray val = arg.complex_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3095
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3096 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3097 retval = octave_value (new octave_complex_matrix (val));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3098 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3099 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3100
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3101 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3102 error ("complex: invalid conversion");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3103 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3104 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3105 else if (nargin == 2)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3106 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3107 octave_value re = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3108 octave_value im = args(1);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3109
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3110 if (re.is_sparse_type () && im.is_sparse_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3111 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3112 const SparseMatrix re_val = re.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3113 const SparseMatrix im_val = im.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3114
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3115 if (!error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3116 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3117 if (re.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3118 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3119 SparseComplexMatrix result;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3120 if (re_val.nnz () == 0)
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
3121 result = Complex (0, 1) * SparseComplexMatrix (im_val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3122 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3123 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3124 result = SparseComplexMatrix (im_val.dims (), re_val (0));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3125 octave_idx_type nr = im_val.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3126 octave_idx_type nc = im_val.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3127
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3128 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3129 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3130 octave_idx_type off = j * nr;
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
3131 for (octave_idx_type i = im_val.cidx (j);
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
3132 i < im_val.cidx (j + 1); i++)
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
3133 result.data (im_val.ridx (i) + off) =
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
3134 result.data (im_val.ridx (i) + off) +
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3135 Complex (0, im_val.data (i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3136 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3137 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3138 retval = octave_value (new octave_sparse_complex_matrix (result));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3139 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3140 else if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3141 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3142 SparseComplexMatrix result;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3143 if (im_val.nnz () == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3144 result = SparseComplexMatrix (re_val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3145 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3146 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3147 result = SparseComplexMatrix (re_val.rows (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3148 re_val.cols (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3149 Complex (0, im_val (0)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3150 octave_idx_type nr = re_val.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3151 octave_idx_type nc = re_val.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3152
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3153 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3154 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3155 octave_idx_type off = j * nr;
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
3156 for (octave_idx_type i = re_val.cidx (j);
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
3157 i < re_val.cidx (j + 1); i++)
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
3158 result.data (re_val.ridx (i) + off) =
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14853
diff changeset
3159 result.data (re_val.ridx (i) + off) +
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3160 re_val.data (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3161 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3162 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3163 retval = octave_value (new octave_sparse_complex_matrix (result));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3164 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3165 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3166 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3167 if (re_val.dims () == im_val.dims ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3168 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3169 SparseComplexMatrix result;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3170 result = SparseComplexMatrix (re_val)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3171 + Complex (0, 1) * SparseComplexMatrix (im_val);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3172 retval = octave_value (
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3173 new octave_sparse_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3174 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3175 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3176 error ("complex: dimension mismatch");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3177 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3178 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3179 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3180 else if (re.is_single_type () || im.is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3181 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3182 if (re.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3183 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3184 float re_val = re.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3185
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3186 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3187 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3188 float im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3189
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3190 if (! error_state)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3191 retval = octave_value (
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3192 new octave_float_complex (FloatComplex (re_val,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3193 im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3194 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3195 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3196 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3197 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3198
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3199 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3200 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3201 FloatComplexNDArray result (im_val.dims (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3202 FloatComplex ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3203
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3204 for (octave_idx_type i = 0; i < im_val.numel (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3205 result.xelem (i) = FloatComplex (re_val, im_val(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3206
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3207 retval = octave_value (
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3208 new octave_float_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3209 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3210 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3211 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3212 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3213 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3214 const FloatNDArray re_val = re.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3215
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3216 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3217 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3218 float im_val = im.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3219
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3220 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3221 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3222 FloatComplexNDArray result (re_val.dims (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3223 FloatComplex ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3224
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3225 for (octave_idx_type i = 0; i < re_val.numel (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3226 result.xelem (i) = FloatComplex (re_val(i), im_val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3227
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3228 retval = octave_value (
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3229 new octave_float_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3230 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3231 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3232 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3233 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3234 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3235
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3236 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3237 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3238 if (re_val.dims () == im_val.dims ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3239 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3240 FloatComplexNDArray result (re_val.dims (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3241 FloatComplex ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3242
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3243 for (octave_idx_type i = 0; i < re_val.numel (); i++)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3244 result.xelem (i) = FloatComplex (re_val(i),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3245 im_val(i));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3246
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3247 retval = octave_value (
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3248 new octave_float_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3249 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3250 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3251 error ("complex: dimension mismatch");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3252 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3253 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3254 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3255 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3256 else if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3257 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3258 double re_val = re.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3259
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3260 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3261 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3262 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3263
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3264 if (! error_state)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3265 retval = octave_value (new octave_complex (Complex (re_val,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3266 im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3267 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3268 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3269 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3270 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3271
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3272 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3273 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3274 ComplexNDArray result (im_val.dims (), Complex ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3275
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3276 for (octave_idx_type i = 0; i < im_val.numel (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3277 result.xelem (i) = Complex (re_val, im_val(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3278
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3279 retval = octave_value (new octave_complex_matrix (result));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3280 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3281 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3282 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3283 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3284 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3285 const NDArray re_val = re.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3286
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3287 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3288 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3289 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3290
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3291 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3292 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3293 ComplexNDArray result (re_val.dims (), Complex ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3294
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3295 for (octave_idx_type i = 0; i < re_val.numel (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3296 result.xelem (i) = Complex (re_val(i), im_val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3297
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3298 retval = octave_value (new octave_complex_matrix (result));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3299 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3300 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3301 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3302 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3303 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3304
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3305 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3306 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3307 if (re_val.dims () == im_val.dims ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3308 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3309 ComplexNDArray result (re_val.dims (), Complex ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3310
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3311 for (octave_idx_type i = 0; i < re_val.numel (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3312 result.xelem (i) = Complex (re_val(i), im_val(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3313
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3314 retval = octave_value (
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3315 new octave_complex_matrix (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3316 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3317 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3318 error ("complex: dimension mismatch");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3319 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3320 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3321 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3322
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3323 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3324 error ("complex: invalid conversion");
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3325 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3326 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3327 print_usage ();
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3328
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3329 return retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3330 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3331
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3332 DEFUN (isreal, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3333 "-*- texinfo -*-\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
3334 @deftypefn {Built-in Function} {} isreal (@var{x})\n\
10291
fc879f361bda make isreal matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10290
diff changeset
3335 Return true if @var{x} is a non-complex matrix or scalar.\n\
10711
fbd7843974fa Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents: 10707
diff changeset
3336 For compatibility with @sc{matlab}, this includes logical and character\n\
10291
fc879f361bda make isreal matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10290
diff changeset
3337 matrices.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
3338 @seealso{iscomplex, isnumeric, isa}\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
3339 @end deftypefn")
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3340 {
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3341 octave_value retval;
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3342
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3343 if (args.length () == 1)
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3344 retval = args(0).is_real_type ();
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3345 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3346 print_usage ();
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3347
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3348 return retval;
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3349 }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3350
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3351 DEFUN (isempty, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3352 "-*- texinfo -*-\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
3353 @deftypefn {Built-in Function} {} isempty (@var{a})\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
3354 Return true if @var{a} is an empty matrix (any one of its dimensions is\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
3355 zero). Otherwise, return false.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
3356 @seealso{isnull, isa}\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
3357 @end deftypefn")
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3358 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
3359 octave_value retval = false;
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3360
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3361 if (args.length () == 1)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
3362 retval = args(0).is_empty ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3363 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3364 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3365
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3366 return retval;
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3367 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3368
16779
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3369 /*
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3370 %% Debian bug #706376
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3371 %!assert (isempty (speye(2^16)), false)
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3372 */
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3373
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3374 DEFUN (isnumeric, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3375 "-*- texinfo -*-\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
3376 @deftypefn {Built-in Function} {} isnumeric (@var{x})\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
3377 Return true if @var{x} is a numeric object, i.e., an integer, real, or\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
3378 complex array. Logical and character arrays are not considered to be\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
3379 numeric.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
3380 @seealso{isinteger, isfloat, isreal, iscomplex, islogical, ischar, iscell, isstruct, isa}\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
3381 @end deftypefn")
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3382 {
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3383 octave_value retval;
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3384
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3385 if (args.length () == 1)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3386 retval = args(0).is_numeric_type ();
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3387 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3388 print_usage ();
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3389
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3390 return retval;
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3391 }
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3392
11435
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3393 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3394 %!assert (isnumeric (1), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3395 %!assert (isnumeric (1i), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3396 %!assert (isnumeric ([1,1]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3397 %!assert (isnumeric (single (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3398 %!assert (isnumeric (single (1i)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3399 %!assert (isnumeric (single ([1,1])), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3400 %!assert (isnumeric (int8 (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3401 %!assert (isnumeric (uint8 ([1,1])), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3402 %!assert (isnumeric ("Hello World"), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3403 %!assert (isnumeric (true), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3404 %!assert (isnumeric (false), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3405 %!assert (isnumeric ([true, false]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3406 %!assert (isnumeric (sparse ([true, false])), false)
11435
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3407 */
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3408
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
3409 DEFUN (ismatrix, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3410 "-*- texinfo -*-\n\
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
3411 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
3412 Return true if @var{a} is a numeric, logical, or character matrix.\n\
11591
1d13679b587e Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
3413 Scalars (1x1 matrices) and vectors (@nospell{1xN} or @nospell{Nx1} matrices)\n\
1d13679b587e Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
3414 are subsets of the more general N-dimensional matrix and @code{ismatrix}\n\
1d13679b587e Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
3415 will return true for these objects as well.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
3416 @seealso{isscalar, isvector, iscell, isstruct, issparse, isa}\n\
3333
15cddaacbc2d [project @ 1999-11-03 19:53:59 by jwe]
jwe
parents: 3322
diff changeset
3417 @end deftypefn")
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3418 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
3419 octave_value retval = false;
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3420
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3421 if (args.length () == 1)
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3422 {
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3423 octave_value arg = args(0);
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3424
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3425 retval = arg.is_matrix_type ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3426 || arg.is_scalar_type ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3427 || arg.is_range ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3428 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3429 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3430 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3431
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3432 return retval;
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3433 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3434
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3435 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3436 %!assert (ismatrix ([]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3437 %!assert (ismatrix (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3438 %!assert (ismatrix ([1, 2, 3]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3439 %!assert (ismatrix ([1, 2; 3, 4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3440 %!assert (ismatrix (zeros (3, 2, 4)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3441
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3442 %!assert (ismatrix (single ([])))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3443 %!assert (ismatrix (single (1)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3444 %!assert (ismatrix (single ([1, 2, 3])))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3445 %!assert (ismatrix (single ([1, 2; 3, 4])))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3446
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3447 %!assert (ismatrix ("t"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3448 %!assert (ismatrix ("test"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3449 %!assert (ismatrix (["test"; "ing"]))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3450
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3451 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3452 %! s.a = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3453 %! assert (ismatrix (s), false);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3454
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3455 %!error ismatrix ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3456 %!error ismatrix ([1, 2; 3, 4], 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3457 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3458
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
3459 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3460 fill_matrix (const octave_value_list& args, int val, const char *fcn)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3461 {
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
3462 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3463
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3464 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3465
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3466 oct_data_conv::data_type dt = oct_data_conv::dt_double;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3467
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3468 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3469
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3470 if (nargin > 0 && args(nargin-1).is_string ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3471 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3472 std::string nm = args(nargin-1).string_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3473 nargin--;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3474
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3475 dt = oct_data_conv::string_to_data_type (nm);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3476
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3477 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3478 return retval;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3479 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3480
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3481 switch (nargin)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3482 {
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
3483 case 0:
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
3484 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
3485
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
3486 case 1:
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3487 get_dimensions (args(0), fcn, dims);
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
3488 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
3489
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
3490 default:
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
3491 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3492 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3493
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3494 for (int i = 0; i < nargin; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3495 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3496 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3497
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3498 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3499 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3500 error ("%s: expecting scalar integer arguments", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3501 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3502 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3503 }
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
3504 }
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
3505 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3506 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3507
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3508 if (! error_state)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3509 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3510 dims.chop_trailing_singletons ();
4565
1db951a4fcd5 [project @ 2003-10-29 13:49:30 by jwe]
jwe
parents: 4563
diff changeset
3511
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3512 check_dimensions (dims, fcn);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
3513
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3514 // FIXME: perhaps this should be made extensible by
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3515 // using the class name to lookup a function to call to create
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3516 // the new value.
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3517
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3518 // Note that automatic narrowing will handle conversion from
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3519 // NDArray to scalar.
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
3520
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3521 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3522 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3523 switch (dt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3524 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3525 case oct_data_conv::dt_int8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3526 retval = int8NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3527 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3528
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3529 case oct_data_conv::dt_uint8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3530 retval = uint8NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3531 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3532
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3533 case oct_data_conv::dt_int16:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3534 retval = int16NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3535 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3536
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3537 case oct_data_conv::dt_uint16:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3538 retval = uint16NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3539 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3540
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3541 case oct_data_conv::dt_int32:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3542 retval = int32NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3543 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3544
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3545 case oct_data_conv::dt_uint32:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3546 retval = uint32NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3547 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3548
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3549 case oct_data_conv::dt_int64:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3550 retval = int64NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3551 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3552
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3553 case oct_data_conv::dt_uint64:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3554 retval = uint64NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3555 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3556
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3557 case oct_data_conv::dt_single:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3558 retval = FloatNDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3559 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3560
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3561 case oct_data_conv::dt_double:
8972
5fa53d1b6247 more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8947
diff changeset
3562 {
5fa53d1b6247 more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8947
diff changeset
3563 if (val == 1 && dims.length () == 2 && dims (0) == 1)
5fa53d1b6247 more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8947
diff changeset
3564 retval = Range (1.0, 0.0, dims (1)); // packed form
5fa53d1b6247 more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8947
diff changeset
3565 else
5fa53d1b6247 more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8947
diff changeset
3566 retval = NDArray (dims, val);
5fa53d1b6247 more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8947
diff changeset
3567 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3568 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3569
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3570 case oct_data_conv::dt_logical:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3571 retval = boolNDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3572 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3573
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3574 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3575 error ("%s: invalid class name", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3576 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3577 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3578 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3579 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3580
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3581 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3582 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3583
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3584 static octave_value
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3585 fill_matrix (const octave_value_list& args, double val, float fval,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3586 const char *fcn)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3587 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3588 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3589
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3590 int nargin = args.length ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3591
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3592 oct_data_conv::data_type dt = oct_data_conv::dt_double;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3593
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3594 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3595
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3596 if (nargin > 0 && args(nargin-1).is_string ())
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3597 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3598 std::string nm = args(nargin-1).string_value ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3599 nargin--;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3600
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3601 dt = oct_data_conv::string_to_data_type (nm);
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3602
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3603 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3604 return retval;
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3605 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3606
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3607 switch (nargin)
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3608 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3609 case 0:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3610 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3611
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3612 case 1:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3613 get_dimensions (args(0), fcn, dims);
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3614 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3615
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3616 default:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3617 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3618 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3619
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3620 for (int i = 0; i < nargin; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3621 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3622 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3623
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3624 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3625 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3626 error ("%s: expecting scalar integer arguments", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3627 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3628 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3629 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3630 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3631 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3632 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3633
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3634 if (! error_state)
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3635 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3636 dims.chop_trailing_singletons ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3637
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3638 check_dimensions (dims, fcn);
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3639
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3640 // Note that automatic narrowing will handle conversion from
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3641 // NDArray to scalar.
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3642
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3643 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3644 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3645 switch (dt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3646 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3647 case oct_data_conv::dt_single:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3648 retval = FloatNDArray (dims, fval);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3649 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3650
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3651 case oct_data_conv::dt_double:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3652 retval = NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3653 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3654
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3655 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3656 error ("%s: invalid class name", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3657 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3658 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3659 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3660 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3661
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3662 return retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3663 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3664
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3665 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3666 fill_matrix (const octave_value_list& args, double val, const char *fcn)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3667 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3668 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3669
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3670 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3671
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3672 oct_data_conv::data_type dt = oct_data_conv::dt_double;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3673
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3674 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3675
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3676 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3677 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3678 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3679 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3680
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3681 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3682
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3683 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3684 return retval;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3685 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3686
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3687 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3688 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3689 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3690 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3691
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3692 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3693 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3694 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3695
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3696 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3697 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3698 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3699
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3700 for (int i = 0; i < nargin; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3701 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3702 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3703
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3704 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3705 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3706 error ("%s: expecting scalar integer arguments", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3707 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3708 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3709 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3710 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3711 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3712 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3713
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3714 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3715 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3716 dims.chop_trailing_singletons ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3717
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3718 check_dimensions (dims, fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3719
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3720 // Note that automatic narrowing will handle conversion from
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3721 // NDArray to scalar.
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3722
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3723 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3724 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3725 switch (dt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3726 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3727 case oct_data_conv::dt_single:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3728 retval = FloatNDArray (dims, static_cast <float> (val));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3729 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3730
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3731 case oct_data_conv::dt_double:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3732 retval = NDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3733 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3734
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3735 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3736 error ("%s: invalid class name", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3737 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3738 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3739 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3740 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3741
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3742 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3743 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3744
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3745 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3746 fill_matrix (const octave_value_list& args, const Complex& val,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3747 const char *fcn)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3748 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3749 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3750
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3751 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3752
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3753 oct_data_conv::data_type dt = oct_data_conv::dt_double;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3754
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3755 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3756
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3757 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3758 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3759 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3760 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3761
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3762 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3763
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3764 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3765 return retval;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3766 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3767
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3768 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3769 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3770 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3771 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3772
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3773 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3774 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3775 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3776
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3777 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3778 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3779 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3780
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3781 for (int i = 0; i < nargin; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3782 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3783 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3784
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3785 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3786 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3787 error ("%s: expecting scalar integer arguments", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3788 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3789 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3790 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3791 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3792 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3793 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3794
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3795 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3796 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3797 dims.chop_trailing_singletons ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3798
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3799 check_dimensions (dims, fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3800
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3801 // Note that automatic narrowing will handle conversion from
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3802 // NDArray to scalar.
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3803
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3804 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3805 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3806 switch (dt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3807 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3808 case oct_data_conv::dt_single:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3809 retval = FloatComplexNDArray (dims,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3810 static_cast<FloatComplex> (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3811 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3812
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3813 case oct_data_conv::dt_double:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3814 retval = ComplexNDArray (dims, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3815 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3816
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3817 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3818 error ("%s: invalid class name", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3819 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3820 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3821 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3822 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3823
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3824 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3825 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3826
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3827 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3828 fill_matrix (const octave_value_list& args, bool val, const char *fcn)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3829 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3830 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3831
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3832 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3833
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3834 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
3835
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3836 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3837 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3838 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3839 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3840
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3841 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3842 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3843 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3844
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3845 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3846 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3847 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3848
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3849 for (int i = 0; i < nargin; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3850 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3851 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3852
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3853 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3854 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3855 error ("%s: expecting scalar integer arguments", fcn);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3856 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3857 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3858 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3859 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3860 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3861 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3862
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3863 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3864 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3865 dims.chop_trailing_singletons ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3866
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3867 check_dimensions (dims, fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3868
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3869 // Note that automatic narrowing will handle conversion from
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3870 // NDArray to scalar.
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3871
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3872 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3873 retval = boolNDArray (dims, val);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3874 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3875
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3876 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3877 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3878
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
3879 DEFUN (ones, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3880 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3881 @deftypefn {Built-in Function} {} ones (@var{n})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3882 @deftypefnx {Built-in Function} {} ones (@var{m}, @var{n})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3883 @deftypefnx {Built-in Function} {} ones (@var{m}, @var{n}, @var{k}, @dots{})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3884 @deftypefnx {Built-in Function} {} ones ([@var{m} @var{n} @dots{}])\n\
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
3885 @deftypefnx {Built-in Function} {} ones (@dots{}, @var{class})\n\
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3886 Return a matrix or N-dimensional array whose elements are all 1.\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3887 If invoked with a single scalar integer argument @var{n}, return a square\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3888 @nospell{NxN} matrix. If invoked with two or more scalar\n\
9428
b317debeb828 data.cc (Fones, Fzeros, Ftrue, Ffalse): update docstring
John W. Eaton <jwe@octave.org>
parents: 9351
diff changeset
3889 integer arguments, or a vector of integer values, return an array with\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3890 the given dimensions.\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
3891 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
3892 If you need to create a matrix whose values are all the same, you should\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
3893 use an expression like\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
3894 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
3895 @example\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3896 val_matrix = val * ones (m, n)\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
3897 @end example\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
3898 \n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
3899 The optional argument @var{class} specifies the class of the return array\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
3900 and defaults to double. For example:\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
3901 \n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
3902 @example\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3903 val = ones (m,n, \"uint8\")\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
3904 @end example\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
3905 @seealso{zeros}\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
3906 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3907 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3908 return fill_matrix (args, 1, "ones");
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3909 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3910
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3911 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3912 %!assert (ones (3), [1, 1, 1; 1, 1, 1; 1, 1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3913 %!assert (ones (2, 3), [1, 1, 1; 1, 1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3914 %!assert (ones (3, 2), [1, 1; 1, 1; 1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3915 %!assert (size (ones (3, 4, 5)), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3916
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3917 %!assert (ones (3, "single"), single ([1, 1, 1; 1, 1, 1; 1, 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3918 %!assert (ones (2, 3, "single"), single ([1, 1, 1; 1, 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3919 %!assert (ones (3, 2, "single"), single ([1, 1; 1, 1; 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3920 %!assert (size (ones (3, 4, 5, "single")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3921
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3922 %!assert (ones (3, "int8"), int8 ([1, 1, 1; 1, 1, 1; 1, 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3923 %!assert (ones (2, 3, "int8"), int8 ([1, 1, 1; 1, 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3924 %!assert (ones (3, 2, "int8"), int8 ([1, 1; 1, 1; 1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3925 %!assert (size (ones (3, 4, 5, "int8")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3926 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3927
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
3928 DEFUN (zeros, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3929 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3930 @deftypefn {Built-in Function} {} zeros (@var{n})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3931 @deftypefnx {Built-in Function} {} zeros (@var{m}, @var{n})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3932 @deftypefnx {Built-in Function} {} zeros (@var{m}, @var{n}, @var{k}, @dots{})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3933 @deftypefnx {Built-in Function} {} zeros ([@var{m} @var{n} @dots{}])\n\
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
3934 @deftypefnx {Built-in Function} {} zeros (@dots{}, @var{class})\n\
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
3935 Return a matrix or N-dimensional array whose elements are all 0.\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
3936 If invoked with a single scalar integer argument, return a square\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3937 @nospell{NxN} matrix. If invoked with two or more scalar\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
3938 integer arguments, or a vector of integer values, return an array with\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3939 the given dimensions.\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
3940 \n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
3941 The optional argument @var{class} specifies the class of the return array\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
3942 and defaults to double. For example:\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
3943 \n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
3944 @example\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
3945 val = zeros (m,n, \"uint8\")\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
3946 @end example\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
3947 @seealso{ones}\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
3948 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3949 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3950 return fill_matrix (args, 0, "zeros");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3951 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3952
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3953 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3954 %!assert (zeros (3), [0, 0, 0; 0, 0, 0; 0, 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3955 %!assert (zeros (2, 3), [0, 0, 0; 0, 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3956 %!assert (zeros (3, 2), [0, 0; 0, 0; 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3957 %!assert (size (zeros (3, 4, 5)), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3958
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3959 %!assert (zeros (3, "single"), single ([0, 0, 0; 0, 0, 0; 0, 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3960 %!assert (zeros (2, 3, "single"), single ([0, 0, 0; 0, 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3961 %!assert (zeros (3, 2, "single"), single ([0, 0; 0, 0; 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3962 %!assert (size (zeros (3, 4, 5, "single")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3963
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3964 %!assert (zeros (3, "int8"), int8 ([0, 0, 0; 0, 0, 0; 0, 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3965 %!assert (zeros (2, 3, "int8"), int8 ([0, 0, 0; 0, 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3966 %!assert (zeros (3, 2, "int8"), int8 ([0, 0; 0, 0; 0, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3967 %!assert (size (zeros (3, 4, 5, "int8")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3968 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
3969
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3970 DEFUN (Inf, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3971 "-*- texinfo -*-\n\
14171
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14169
diff changeset
3972 @c List other form of function in documentation index\n\
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14169
diff changeset
3973 @findex inf\n\
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14169
diff changeset
3974 \n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3975 @deftypefn {Built-in Function} {} Inf\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3976 @deftypefnx {Built-in Function} {} Inf (@var{n})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3977 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3978 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
3979 @deftypefnx {Built-in Function} {} Inf (@dots{}, @var{class})\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3980 Return a scalar, matrix or N-dimensional array whose elements are all equal\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3981 to the IEEE representation for positive infinity.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3982 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3983 Infinity is produced when results are too large to be represented using the\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3984 the IEEE floating point format for numbers. Two common examples which\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3985 produce infinity are division by zero and overflow.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
3986 \n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3987 @example\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3988 @group\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
3989 [ 1/0 e^800 ]\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
3990 @result{} Inf Inf\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3991 @end group\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3992 @end example\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3993 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3994 When called with no arguments, return a scalar with the value @samp{Inf}.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3995 When called with a single argument, return a square matrix with the dimension\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3996 specified. When called with more than one scalar argument the first two\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3997 arguments are taken as the number of rows and columns and any further\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3998 arguments specify additional matrix dimensions.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
3999 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4000 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
15034
1116864ee270 doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents: 15031
diff changeset
4001 @seealso{isinf, NaN}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4002 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4003 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4004 return fill_matrix (args, lo_ieee_inf_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4005 lo_ieee_float_inf_value (), "Inf");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4006 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4007
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4008 DEFALIAS (inf, Inf);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4009
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4010 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4011 %!assert (inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4012 %!assert (inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4013 %!assert (inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4014 %!assert (size (inf (3, 4, 5)), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4015
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4016 %!assert (inf (3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4017 %!assert (inf (2, 3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4018 %!assert (inf (3, 2, "single"), single ([Inf, Inf; Inf, Inf; Inf, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4019 %!assert (size (inf (3, 4, 5, "single")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4020
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4021 %!error (inf (3, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4022 %!error (inf (2, 3, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4023 %!error (inf (3, 2, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4024 %!error (inf (3, 4, 5, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4025 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4026
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4027 DEFUN (NaN, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4028 "-*- texinfo -*-\n\
14171
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14169
diff changeset
4029 @c List other form of function in documentation index\n\
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14169
diff changeset
4030 @findex nan\n\
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14169
diff changeset
4031 \n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4032 @deftypefn {Built-in Function} {} NaN\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4033 @deftypefnx {Built-in Function} {} NaN (@var{n})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4034 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4035 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4036 @deftypefnx {Built-in Function} {} NaN (@dots{}, @var{class})\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4037 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4038 to the IEEE symbol NaN (Not a Number).\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4039 NaN is the result of operations which do not produce a well defined numerical\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4040 result. Common operations which produce a NaN are arithmetic with infinity\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4041 @tex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4042 ($\\infty - \\infty$), zero divided by zero ($0/0$),\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4043 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4044 @ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4045 (Inf - Inf), zero divided by zero (0/0),\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4046 @end ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4047 and any operation involving another NaN value (5 + NaN).\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4048 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4049 Note that NaN always compares not equal to NaN (NaN != NaN). This behavior\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4050 is specified by the IEEE standard for floating point arithmetic. To\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4051 find NaN values, use the @code{isnan} function.\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4052 \n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4053 When called with no arguments, return a scalar with the value @samp{NaN}.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4054 When called with a single argument, return a square matrix with the dimension\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4055 specified. When called with more than one scalar argument the first two\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4056 arguments are taken as the number of rows and columns and any further\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4057 arguments specify additional matrix dimensions.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4058 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4059 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
15034
1116864ee270 doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents: 15031
diff changeset
4060 @seealso{isnan, Inf}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4061 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4062 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4063 return fill_matrix (args, lo_ieee_nan_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4064 lo_ieee_float_nan_value (), "NaN");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4065 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4066
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4067 DEFALIAS (nan, NaN);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4068
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4069 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4070 %!assert (NaN (3), [NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4071 %!assert (NaN (2, 3), [NaN, NaN, NaN; NaN, NaN, NaN])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4072 %!assert (NaN (3, 2), [NaN, NaN; NaN, NaN; NaN, NaN])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4073 %!assert (size (NaN (3, 4, 5)), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4074
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4075 %!assert (NaN (3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4076 %!assert (NaN (2, 3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4077 %!assert (NaN (3, 2, "single"), single ([NaN, NaN; NaN, NaN; NaN, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4078 %!assert (size (NaN (3, 4, 5, "single")), [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4079
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4080 %!error (NaN (3, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4081 %!error (NaN (2, 3, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4082 %!error (NaN (3, 2, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4083 %!error (NaN (3, 4, 5, "int8"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4084 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4085
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4086 DEFUN (e, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4087 "-*- texinfo -*-\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4088 @deftypefn {Built-in Function} {} e\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4089 @deftypefnx {Built-in Function} {} e (@var{n})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4090 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4091 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4092 @deftypefnx {Built-in Function} {} e (@dots{}, @var{class})\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4093 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4094 to the base of natural logarithms. The constant\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4095 @tex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4096 $e$ satisfies the equation $\\log (e) = 1$.\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4097 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4098 @ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4099 @samp{e} satisfies the equation @code{log} (e) = 1.\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4100 @end ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4101 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4102 When called with no arguments, return a scalar with the value @math{e}. When\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4103 called with a single argument, return a square matrix with the dimension\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4104 specified. When called with more than one scalar argument the first two\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4105 arguments are taken as the number of rows and columns and any further\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4106 arguments specify additional matrix dimensions.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4107 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4108 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
15175
5984aa619cd9 doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents: 15111
diff changeset
4109 @seealso{log, exp, pi, I}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4110 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4111 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4112 #if defined (M_E)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4113 double e_val = M_E;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4114 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4115 double e_val = exp (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4116 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4117
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4118 return fill_matrix (args, e_val, "e");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4119 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4120
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4121 DEFUN (eps, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4122 "-*- texinfo -*-\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4123 @deftypefn {Built-in Function} {} eps\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4124 @deftypefnx {Built-in Function} {} eps (@var{x})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4125 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4126 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4127 @deftypefnx {Built-in Function} {} eps (@dots{}, @var{class})\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4128 Return a scalar, matrix or N-dimensional array whose elements are all eps,\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4129 the machine precision. More precisely, @code{eps} is the relative spacing\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4130 between any two adjacent numbers in the machine's floating point system.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4131 This number is obviously system dependent. On machines that support IEEE\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4132 floating point arithmetic, @code{eps} is approximately\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4133 @tex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4134 $2.2204\\times10^{-16}$ for double precision and $1.1921\\times10^{-7}$\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4135 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4136 @ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4137 2.2204e-16 for double precision and 1.1921e-07\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4138 @end ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4139 for single precision.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4140 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4141 When called with no arguments, return a scalar with the value\n\
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
4142 @code{eps (1.0)}.\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4143 Given a single argument @var{x}, return the distance between @var{x} and\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4144 the next largest value.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4145 When called with more than one argument the first two arguments are taken as\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4146 the number of rows and columns and any further\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4147 arguments specify additional matrix dimensions.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4148 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4149 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
4150 @seealso{realmax, realmin, intmax, bitmax}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4151 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4152 {
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4153 int nargin = args.length ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4154 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4155
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4156 if (nargin == 1 && ! args(0).is_string ())
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4157 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4158 if (args(0).is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4159 {
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4160 Array<float> x = args(0).float_array_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4161
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4162 if (! error_state)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4163 {
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4164 Array<float> epsval (x.dims ());
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4165
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4166 for (octave_idx_type i = 0; i < x.numel (); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4167 {
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4168 float val = ::fabsf (x(i));
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4169 if (xisnan (val) || xisinf (val))
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4170 epsval(i) = lo_ieee_nan_value ();
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4171 else if (val < std::numeric_limits<float>::min ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4172 epsval(i) = powf (2.0, -149e0);
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4173 else
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4174 {
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4175 int expon;
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4176 frexpf (val, &expon);
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4177 epsval(i) = std::pow (static_cast <float> (2.0),
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4178 static_cast <float> (expon - 24));
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4179 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4180 }
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4181 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4182 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4183 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4184 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4185 {
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4186 Array<double> x = args(0).array_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4187
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4188 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4189 {
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4190 Array<double> epsval (x.dims ());
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4191
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4192 for (octave_idx_type i = 0; i < x.numel (); i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4193 {
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4194 double val = ::fabs (x(i));
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4195 if (xisnan (val) || xisinf (val))
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4196 epsval(i) = lo_ieee_nan_value ();
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4197 else if (val < std::numeric_limits<double>::min ())
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4198 epsval(i) = pow (2.0, -1074e0);
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4199 else
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4200 {
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4201 int expon;
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4202 frexp (val, &expon);
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4203 epsval(i) = std::pow (static_cast <double> (2.0),
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4204 static_cast <double> (expon - 53));
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4205 }
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4206 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4207 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4208 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4209 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4210 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4211 else
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4212 retval = fill_matrix (args, std::numeric_limits<double>::epsilon (),
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4213 std::numeric_limits<float>::epsilon (), "eps");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4214
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4215 return retval;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4216 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4217
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4218 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4219 %!assert (eps (1/2), 2^(-53))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4220 %!assert (eps (1), 2^(-52))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4221 %!assert (eps (2), 2^(-51))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4222 %!assert (eps (realmax), 2^971)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4223 %!assert (eps (0), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4224 %!assert (eps (realmin/2), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4225 %!assert (eps (realmin/16), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4226 %!assert (eps (Inf), NaN)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4227 %!assert (eps (NaN), NaN)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4228 %!assert (eps ([1/2 1 2 realmax 0 realmin/2 realmin/16 Inf NaN]),
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4229 %! [2^(-53) 2^(-52) 2^(-51) 2^971 2^(-1074) 2^(-1074) 2^(-1074) NaN NaN])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4230 %!assert (eps (single (1/2)), single (2^(-24)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4231 %!assert (eps (single (1)), single (2^(-23)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4232 %!assert (eps (single (2)), single (2^(-22)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4233 %!assert (eps (realmax ("single")), single (2^104))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4234 %!assert (eps (single (0)), single (2^(-149)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4235 %!assert (eps (realmin ("single")/2), single (2^(-149)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4236 %!assert (eps (realmin ("single")/16), single (2^(-149)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4237 %!assert (eps (single (Inf)), single (NaN))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4238 %!assert (eps (single (NaN)), single (NaN))
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4239 %!assert (eps (single ([1/2 1 2 realmax("single") 0 realmin("single")/2 realmin("single")/16 Inf NaN])),
15509
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4240 %! single ([2^(-24) 2^(-23) 2^(-22) 2^104 2^(-149) 2^(-149) 2^(-149) NaN NaN]))
f0dfdc7faa71 Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15467
diff changeset
4241
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4242 */
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4243
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4244 DEFUN (pi, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4245 "-*- texinfo -*-\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4246 @deftypefn {Built-in Function} {} pi\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4247 @deftypefnx {Built-in Function} {} pi (@var{n})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4248 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4249 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4250 @deftypefnx {Built-in Function} {} pi (@dots{}, @var{class})\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4251 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4252 to the ratio of the circumference of a circle to its\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4253 @tex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4254 diameter($\\pi$).\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4255 @end tex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4256 @ifnottex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4257 diameter.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4258 @end ifnottex\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4259 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4260 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4261 When called with no arguments, return a scalar with the value of\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4262 @tex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4263 $\\pi$.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4264 @end tex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4265 @ifnottex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4266 pi.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4267 @end ifnottex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4268 When called with a single argument, return a square matrix with the dimension\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4269 specified. When called with more than one scalar argument the first two\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4270 arguments are taken as the number of rows and columns and any further\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4271 arguments specify additional matrix dimensions.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4272 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4273 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
15175
5984aa619cd9 doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents: 15111
diff changeset
4274 @seealso{e, I}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4275 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4276 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4277 #if defined (M_PI)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4278 double pi_val = M_PI;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4279 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4280 double pi_val = 4.0 * atan (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4281 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4282
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4283 return fill_matrix (args, pi_val, "pi");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4284 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4285
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4286 DEFUN (realmax, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4287 "-*- texinfo -*-\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4288 @deftypefn {Built-in Function} {} realmax\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4289 @deftypefnx {Built-in Function} {} realmax (@var{n})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4290 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4291 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4292 @deftypefnx {Built-in Function} {} realmax (@dots{}, @var{class})\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4293 Return a scalar, matrix or N-dimensional array whose elements are all equal\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4294 to the largest floating point number that is representable. The actual\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4295 value is system dependent. On machines that support IEEE\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4296 floating point arithmetic, @code{realmax} is approximately\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4297 @tex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4298 $1.7977\\times10^{308}$ for double precision and $3.4028\\times10^{38}$\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4299 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4300 @ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4301 1.7977e+308 for double precision and 3.4028e+38\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4302 @end ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4303 for single precision.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4304 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4305 When called with no arguments, return a scalar with the value\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4306 @code{realmax (@qcode{\"double\"})}.\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4307 When called with a single argument, return a square matrix with the dimension\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4308 specified. When called with more than one scalar argument the first two\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4309 arguments are taken as the number of rows and columns and any further\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4310 arguments specify additional matrix dimensions.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4311 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4312 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
4313 @seealso{realmin, intmax, bitmax, eps}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4314 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4315 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4316 return fill_matrix (args, std::numeric_limits<double>::max (),
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4317 std::numeric_limits<float>::max (), "realmax");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4318 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4319
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4320 DEFUN (realmin, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4321 "-*- texinfo -*-\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4322 @deftypefn {Built-in Function} {} realmin\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4323 @deftypefnx {Built-in Function} {} realmin (@var{n})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4324 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4325 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4326 @deftypefnx {Built-in Function} {} realmin (@dots{}, @var{class})\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4327 Return a scalar, matrix or N-dimensional array whose elements are all equal\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4328 to the smallest normalized floating point number that is representable.\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4329 The actual value is system dependent. On machines that support\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4330 IEEE floating point arithmetic, @code{realmin} is approximately\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4331 @tex\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4332 $2.2251\\times10^{-308}$ for double precision and $1.1755\\times10^{-38}$\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4333 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4334 @ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4335 2.2251e-308 for double precision and 1.1755e-38\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4336 @end ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4337 for single precision.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4338 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4339 When called with no arguments, return a scalar with the value\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4340 @code{realmin (@qcode{\"double\"})}.\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4341 When called with a single argument, return a square matrix with the dimension\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4342 specified. When called with more than one scalar argument the first two\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4343 arguments are taken as the number of rows and columns and any further\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4344 arguments specify additional matrix dimensions.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4345 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4346 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
4347 @seealso{realmax, intmin, eps}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4348 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4349 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4350 return fill_matrix (args, std::numeric_limits<double>::min (),
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4351 std::numeric_limits<float>::min (), "realmin");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4352 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4353
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4354 DEFUN (I, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4355 "-*- texinfo -*-\n\
14100
8a2dc08886ea Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents: 14085
diff changeset
4356 @c List other forms of function in documentation index\n\
8a2dc08886ea Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents: 14085
diff changeset
4357 @findex i\n\
8a2dc08886ea Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents: 14085
diff changeset
4358 @findex j\n\
8a2dc08886ea Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents: 14085
diff changeset
4359 @findex J\n\
8a2dc08886ea Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents: 14085
diff changeset
4360 \n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4361 @deftypefn {Built-in Function} {} I\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4362 @deftypefnx {Built-in Function} {} I (@var{n})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4363 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4364 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4365 @deftypefnx {Built-in Function} {} I (@dots{}, @var{class})\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4366 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4367 to the pure imaginary unit, defined as\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4368 @tex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4369 $\\sqrt{-1}$.\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4370 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4371 @ifnottex\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4372 @code{sqrt (-1)}.\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8487
diff changeset
4373 @end ifnottex\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
4374 \n\
15034
1116864ee270 doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents: 15031
diff changeset
4375 I, and its equivalents i, j, and J, are functions so any of the names may\n\
9197
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4376 be reused for other purposes (such as i for a counter variable).\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4377 \n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4378 When called with no arguments, return a scalar with the value @math{i}. When\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4379 called with a single argument, return a square matrix with the dimension\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4380 specified. When called with more than one scalar argument the first two\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4381 arguments are taken as the number of rows and columns and any further\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4382 arguments specify additional matrix dimensions.\n\
3c27a0340a64 Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents: 9194
diff changeset
4383 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4384 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
15175
5984aa619cd9 doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents: 15111
diff changeset
4385 @seealso{e, pi, log, exp}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4386 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4387 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4388 return fill_matrix (args, Complex (0.0, 1.0), "I");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4389 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4390
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4391 DEFALIAS (i, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4392 DEFALIAS (J, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4393 DEFALIAS (j, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4394
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4395 DEFUN (NA, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4396 "-*- texinfo -*-\n\
9308
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4397 @deftypefn {Built-in Function} {} NA\n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4398 @deftypefnx {Built-in Function} {} NA (@var{n})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4399 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4400 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4401 @deftypefnx {Built-in Function} {} NA (@dots{}, @var{class})\n\
9308
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4402 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4403 to the special constant used to designate missing values.\n\
9308
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4404 \n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4405 Note that NA always compares not equal to NA (NA != NA).\n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4406 To find NA values, use the @code{isna} function.\n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4407 \n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4408 When called with no arguments, return a scalar with the value @samp{NA}.\n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4409 When called with a single argument, return a square matrix with the dimension\n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4410 specified. When called with more than one scalar argument the first two\n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4411 arguments are taken as the number of rows and columns and any further\n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4412 arguments specify additional matrix dimensions.\n\
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4413 The optional argument @var{class} specifies the return type and may be\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
4414 either @qcode{\"double\"} or @qcode{\"single\"}.\n\
9308
f2bf62f62286 Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents: 9198
diff changeset
4415 @seealso{isna}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4416 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4417 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4418 return fill_matrix (args, lo_ieee_na_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4419 lo_ieee_float_na_value (), "NA");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4420 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4421
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
4422 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4423 %!assert (single (NA ("double")), NA ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4424 %!assert (double (NA ("single")), NA ("double"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4425 */
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
4426
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4427 DEFUN (false, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4428 "-*- texinfo -*-\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4429 @deftypefn {Built-in Function} {} false (@var{x})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4430 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4431 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4432 Return a matrix or N-dimensional array whose elements are all logical 0.\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4433 If invoked with a single scalar integer argument, return a square\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4434 matrix of the specified size. If invoked with two or more scalar\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4435 integer arguments, or a vector of integer values, return an array with\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4436 given dimensions.\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4437 @seealso{true}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4438 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4439 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4440 return fill_matrix (args, false, "false");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4441 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4442
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4443 DEFUN (true, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4444 "-*- texinfo -*-\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4445 @deftypefn {Built-in Function} {} true (@var{x})\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4446 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4447 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4448 Return a matrix or N-dimensional array whose elements are all logical 1.\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4449 If invoked with a single scalar integer argument, return a square\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4450 matrix of the specified size. If invoked with two or more scalar\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4451 integer arguments, or a vector of integer values, return an array with\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4452 given dimensions.\n\
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
4453 @seealso{false}\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4454 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4455 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4456 return fill_matrix (args, true, "true");
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4457 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4458
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4459 template <class MT>
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4460 octave_value
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4461 identity_matrix (int nr, int nc)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4462 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4463 octave_value retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4464
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
4465 typename MT::element_type one (1);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4466
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4467 if (nr == 1 && nc == 1)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4468 retval = one;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4469 else
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4470 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4471 dim_vector dims (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4472
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
4473 typename MT::element_type zero (0);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4474
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4475 MT m (dims, zero);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4476
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4477 if (nr > 0 && nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4478 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4479 int n = std::min (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4480
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4481 for (int i = 0; i < n; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4482 m(i,i) = one;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4483 }
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4484
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4485 retval = m;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4486 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4487
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4488 return retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4489 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4490
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4491 #define INSTANTIATE_EYE(T) \
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4492 template octave_value identity_matrix<T> (int, int)
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4493
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4494 INSTANTIATE_EYE (int8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4495 INSTANTIATE_EYE (uint8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4496 INSTANTIATE_EYE (int16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4497 INSTANTIATE_EYE (uint16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4498 INSTANTIATE_EYE (int32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4499 INSTANTIATE_EYE (uint32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4500 INSTANTIATE_EYE (int64NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4501 INSTANTIATE_EYE (uint64NDArray);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
4502 INSTANTIATE_EYE (FloatNDArray);
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4503 INSTANTIATE_EYE (NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4504 INSTANTIATE_EYE (boolNDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
4505
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4506 static octave_value
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4507 identity_matrix (int nr, int nc, oct_data_conv::data_type dt)
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4508 {
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4509 octave_value retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4510
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4511 // FIXME: perhaps this should be made extensible by using
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4512 // the class name to lookup a function to call to create the new
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4513 // value.
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4514
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4515 if (! error_state)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4516 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4517 switch (dt)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4518 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4519 case oct_data_conv::dt_int8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4520 retval = identity_matrix<int8NDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4521 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4522
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4523 case oct_data_conv::dt_uint8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4524 retval = identity_matrix<uint8NDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4525 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4526
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4527 case oct_data_conv::dt_int16:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4528 retval = identity_matrix<int16NDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4529 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4530
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4531 case oct_data_conv::dt_uint16:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4532 retval = identity_matrix<uint16NDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4533 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4534
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4535 case oct_data_conv::dt_int32:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4536 retval = identity_matrix<int32NDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4537 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4538
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4539 case oct_data_conv::dt_uint32:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4540 retval = identity_matrix<uint32NDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4541 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4542
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4543 case oct_data_conv::dt_int64:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4544 retval = identity_matrix<int64NDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4545 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4546
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4547 case oct_data_conv::dt_uint64:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4548 retval = identity_matrix<uint64NDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4549 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4550
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4551 case oct_data_conv::dt_single:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4552 retval = FloatDiagMatrix (nr, nc, 1.0f);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4553 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4554
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4555 case oct_data_conv::dt_double:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4556 retval = DiagMatrix (nr, nc, 1.0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4557 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4558
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4559 case oct_data_conv::dt_logical:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4560 retval = identity_matrix<boolNDArray> (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4561 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4562
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4563 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4564 error ("eye: invalid class name");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4565 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4566 }
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4567 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4568
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4569 return retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4570 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4571
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4572 #undef INT_EYE_MATRIX
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4573
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
4574 DEFUN (eye, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4575 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4576 @deftypefn {Built-in Function} {} eye (@var{n})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4577 @deftypefnx {Built-in Function} {} eye (@var{m}, @var{n})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4578 @deftypefnx {Built-in Function} {} eye ([@var{m} @var{n}])\n\
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4579 @deftypefnx {Built-in Function} {} eye (@dots{}, @var{class})\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4580 Return an identity matrix. If invoked with a single scalar argument @var{n},\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4581 return a square @nospell{NxN} identity matrix. If\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4582 supplied two scalar arguments (@var{m}, @var{n}), @code{eye} takes them to be\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4583 the number of rows and columns. If given a vector with two elements,\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4584 @code{eye} uses the values of the elements as the number of rows and columns,\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
4585 respectively. For example:\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4586 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4587 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4588 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4589 eye (3)\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4590 @result{} 1 0 0\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4591 0 1 0\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4592 0 0 1\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4593 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4594 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4595 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4596 The following expressions all produce the same result:\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4597 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4598 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4599 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4600 eye (2)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4601 @equiv{}\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4602 eye (2, 2)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4603 @equiv{}\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4604 eye (size ([1, 2; 3, 4])\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4605 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4606 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4607 \n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4608 The optional argument @var{class}, allows @code{eye} to return an array of\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4609 the specified type, like\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4610 \n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4611 @example\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4612 val = zeros (n,m, \"uint8\")\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4613 @end example\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4614 \n\
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6518
diff changeset
4615 Calling @code{eye} with no arguments is equivalent to calling it\n\
12905
f7a8d1dafda3 Let rand accept negative dimensions (bug #33301)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12886
diff changeset
4616 with an argument of 1. Any negative dimensions are treated as zero. \n\
f7a8d1dafda3 Let rand accept negative dimensions (bug #33301)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12886
diff changeset
4617 These odd definitions are for compatibility with @sc{matlab}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
4618 @seealso{speye, ones, zeros}\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4619 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4620 {
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4621 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4622
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4623 int nargin = args.length ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4624
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4625 oct_data_conv::data_type dt = oct_data_conv::dt_double;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4626
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4627 // Check for type information.
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4628
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4629 if (nargin > 0 && args(nargin-1).is_string ())
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4630 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4631 std::string nm = args(nargin-1).string_value ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4632 nargin--;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4633
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4634 dt = oct_data_conv::string_to_data_type (nm);
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4635
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4636 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4637 return retval;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4638 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
4639
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4640 switch (nargin)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4641 {
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
4642 case 0:
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
4643 retval = identity_matrix (1, 1, dt);
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
4644 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4645
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
4646 case 1:
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4647 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4648 octave_idx_type nr, nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4649 get_dimensions (args(0), "eye", nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4650
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4651 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4652 retval = identity_matrix (nr, nc, dt);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4653 }
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
4654 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4655
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4656 case 2:
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4657 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4658 octave_idx_type nr, nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4659 get_dimensions (args(0), args(1), "eye", nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4660
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4661 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4662 retval = identity_matrix (nr, nc, dt);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4663 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4664 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4665
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4666 default:
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
4667 print_usage ();
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4668 break;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4669 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4670
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4671 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4672 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4673
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4674 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4675 %!assert (full (eye (3)), [1, 0, 0; 0, 1, 0; 0, 0, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4676 %!assert (full (eye (2, 3)), [1, 0, 0; 0, 1, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4677
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4678 %!assert (full (eye (3,"single")), single ([1, 0, 0; 0, 1, 0; 0, 0, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4679 %!assert (full (eye (2, 3,"single")), single ([1, 0, 0; 0, 1, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4680
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4681 %!assert (eye (3, "int8"), int8 ([1, 0, 0; 0, 1, 0; 0, 0, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4682 %!assert (eye (2, 3, "int8"), int8 ([1, 0, 0; 0, 1, 0]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4683
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4684 %!error eye (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4685 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4686
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4687 template <class MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4688 static octave_value
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4689 do_linspace (const octave_value& base, const octave_value& limit,
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4690 octave_idx_type n)
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4691 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4692 typedef typename MT::column_vector_type CVT;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4693 typedef typename MT::element_type T;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4694
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4695 octave_value retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4696
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4697 if (base.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4698 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4699 T bs = octave_value_extract<T> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4700 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4701 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4702 T ls = octave_value_extract<T> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4703 retval = linspace (bs, ls, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4704 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4705 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4706 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4707 CVT lv = octave_value_extract<CVT> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4708 CVT bv (lv.length (), bs);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4709 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4710 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4711 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4712 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4713 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4714 CVT bv = octave_value_extract<CVT> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4715 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4716 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4717 T ls = octave_value_extract<T> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4718 CVT lv (bv.length (), ls);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4719 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4720 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4721 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4722 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4723 CVT lv = octave_value_extract<CVT> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4724 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4725 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4726 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4727
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4728 return retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4729 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4730
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
4731 DEFUN (linspace, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4732 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4733 @deftypefn {Built-in Function} {} linspace (@var{base}, @var{limit})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4734 @deftypefnx {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4735 Return a row vector with @var{n} linearly spaced elements between\n\
6630
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6561
diff changeset
4736 @var{base} and @var{limit}. If the number of elements is greater than one,\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4737 then the endpoints @var{base} and @var{limit} are always included in\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4738 the range. If @var{base} is greater than @var{limit}, the elements are\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4739 stored in decreasing order. If the number of points is not specified, a\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4740 value of 100 is used.\n\
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4741 \n\
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4742 The @code{linspace} function always returns a row vector if both\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4743 @var{base} and @var{limit} are scalars. If one, or both, of them are column\n\
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4744 vectors, @code{linspace} returns a matrix.\n\
6630
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6561
diff changeset
4745 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4746 For compatibility with @sc{matlab}, return the second argument (@var{limit})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4747 if fewer than two values are requested.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
4748 @seealso{logspace}\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
4749 @end deftypefn")
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4750 {
3418
ca92c9d3f882 [project @ 2000-01-12 03:07:47 by jwe]
jwe
parents: 3373
diff changeset
4751 octave_value retval;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4752
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4753 int nargin = args.length ();
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4754
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
4755 octave_idx_type npoints = 100;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4756
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
4757 if (nargin != 2 && nargin != 3)
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
4758 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
4759 print_usage ();
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
4760 return retval;
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
4761 }
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
4762
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4763 if (nargin == 3)
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4764 {
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4765 // Apparently undocumented Matlab. If the third arg is an empty
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4766 // numeric value, the number of points defaults to 1.
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4767
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4768 octave_value arg_3 = args(2);
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4769
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4770 if (arg_3.is_numeric_type () && arg_3.is_empty ())
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4771 npoints = 1;
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4772 else
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4773 npoints = arg_3.idx_type_value ();
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4774 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4775
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4776 if (! error_state)
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4777 {
3322
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
4778 octave_value arg_1 = args(0);
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
4779 octave_value arg_2 = args(1);
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4780
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
4781 if (arg_1.is_single_type () || arg_2.is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4782 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4783 if (arg_1.is_complex_type () || arg_2.is_complex_type ())
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4784 retval = do_linspace<FloatComplexMatrix> (arg_1, arg_2, npoints);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4785 else
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4786 retval = do_linspace<FloatMatrix> (arg_1, arg_2, npoints);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4787
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4788 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4789 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4790 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4791 if (arg_1.is_complex_type () || arg_2.is_complex_type ())
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4792 retval = do_linspace<ComplexMatrix> (arg_1, arg_2, npoints);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4793 else
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
4794 retval = do_linspace<Matrix> (arg_1, arg_2, npoints);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4795 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4796 }
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4685
diff changeset
4797 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
4798 error ("linspace: N must be an integer");
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4799
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4800 return retval;
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4801 }
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
4802
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4803
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4804 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4805 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4806 %! x1 = linspace (1, 2);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4807 %! x2 = linspace (1, 2, 10);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4808 %! x3 = linspace (1, -2, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4809 %! assert (size (x1) == [1, 100] && x1(1) == 1 && x1(100) == 2);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4810 %! assert (size (x2) == [1, 10] && x2(1) == 1 && x2(10) == 2);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4811 %! assert (size (x3) == [1, 10] && x3(1) == 1 && x3(10) == -2);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4812
17206
ea5830dc6b19 test: Correct typo '%assert' -> '%!assert' to have test blocks run.
Rik <rik@octave.org>
parents: 17115
diff changeset
4813 %! ##assert (linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6))
ea5830dc6b19 test: Correct typo '%assert' -> '%!assert' to have test blocks run.
Rik <rik@octave.org>
parents: 17115
diff changeset
4814
ea5830dc6b19 test: Correct typo '%assert' -> '%!assert' to have test blocks run.
Rik <rik@octave.org>
parents: 17115
diff changeset
4815 %!assert (linspace (0, 1, []), 1)
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
4816
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4817 %!error linspace ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4818 %!error linspace (1, 2, 3, 4)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4819 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4820
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4821 // FIXME: should accept dimensions as separate args for N-d
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
4822 // arrays as well as 1-d and 2-d arrays.
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
4823
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4824 DEFUN (resize, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4825 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
4826 @deftypefn {Built-in Function} {} resize (@var{x}, @var{m})\n\
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4827 @deftypefnx {Built-in Function} {} resize (@var{x}, @var{m}, @var{n}, @dots{})\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4828 @deftypefnx {Built-in Function} {} resize (@var{x}, [@var{m} @var{n} @dots{}])\n\
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4829 Resize @var{x} cutting off elements as necessary.\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4830 \n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4831 In the result, element with certain indices is equal to the corresponding\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4832 element of @var{x} if the indices are within the bounds of @var{x};\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4833 otherwise, the element is set to zero.\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4834 \n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4835 In other words, the statement\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4836 \n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4837 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4838 y = resize (x, dv)\n\
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4839 @end example\n\
6174
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
4840 \n\
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4841 @noindent\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4842 is equivalent to the following code:\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4843 \n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4844 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
4845 @group\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4846 y = zeros (dv, class (x));\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4847 sz = min (dv, size (x));\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4848 for i = 1:length (sz)\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4849 idx@{i@} = 1:sz(i);\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4850 endfor\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4851 y(idx@{:@}) = x(idx@{:@});\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
4852 @end group\n\
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4853 @end example\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4854 \n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4855 @noindent\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4856 but is performed more efficiently.\n\
6174
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
4857 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4858 If only @var{m} is supplied, and it is a scalar, the dimension of the\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4859 result is @var{m}-by-@var{m}.\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4860 If @var{m}, @var{n}, @dots{} are all scalars, then the dimensions of\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4861 the result are @var{m}-by-@var{n}-by-@dots{}.\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4862 If given a vector as input, then the\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4863 dimensions of the result are given by the elements of that vector.\n\
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4864 \n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4865 An object can be resized to more dimensions than it has;\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4866 in such case the missing dimensions are assumed to be 1.\n\
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4867 Resizing an object to fewer dimensions is not possible.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
4868 @seealso{reshape, postpad, prepad, cat}\n\
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4869 @end deftypefn")
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4870 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4871 octave_value retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4872 int nargin = args.length ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4873
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4874 if (nargin == 2)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4875 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4876 Array<double> vec = args(1).vector_value ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4877 int ndim = vec.length ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4878 if (ndim == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4879 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4880 octave_idx_type m = static_cast<octave_idx_type> (vec(0));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4881 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4882 retval = retval.resize (dim_vector (m, m), true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4883 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4884 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4885 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4886 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4887 dv.resize (ndim);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4888 for (int i = 0; i < ndim; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4889 dv(i) = static_cast<octave_idx_type> (vec(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4890 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4891 retval = retval.resize (dv, true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4892 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4893 }
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4894 else if (nargin > 2)
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4895 {
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4896 dim_vector dv;
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4897 dv.resize (nargin - 1);
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4898 for (octave_idx_type i = 1; i < nargin; i++)
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4899 dv(i-1) = static_cast<octave_idx_type> (args(i).scalar_value ());
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4900 if (!error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4901 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4902 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4903 retval = retval.resize (dv, true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4904 }
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
4905
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4906 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4907 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
4908 print_usage ();
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4909 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4910 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
4911
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4912 // FIXME: should use octave_idx_type for dimensions.
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
4913
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4914 DEFUN (reshape, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
4915 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4916 @deftypefn {Built-in Function} {} reshape (@var{A}, @var{m}, @var{n}, @dots{})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4917 @deftypefnx {Built-in Function} {} reshape (@var{A}, [@var{m} @var{n} @dots{}])\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4918 @deftypefnx {Built-in Function} {} reshape (@var{A}, @dots{}, [], @dots{})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4919 @deftypefnx {Built-in Function} {} reshape (@var{A}, @var{size})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4920 Return a matrix with the specified dimensions (@var{m}, @var{n}, @dots{})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4921 whose elements are taken from the matrix @var{A}. The elements of the\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4922 matrix are accessed in column-major order (like Fortran arrays are stored).\n\
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4923 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4924 The following code demonstrates reshaping a 1x4 row vector into a 2x2 square\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4925 matrix.\n\
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4926 \n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4927 @example\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4928 @group\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4929 reshape ([1, 2, 3, 4], 2, 2)\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4930 @result{} 1 3\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
4931 2 4\n\
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4932 @end group\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4933 @end example\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4934 \n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4935 @noindent\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4936 Note that the total number of elements in the original\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4937 matrix (@code{prod (size (@var{A}))}) must match the total number of elements\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4938 in the new matrix (@code{prod ([@var{m} @var{n} @dots{}])}).\n\
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
4939 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4940 A single dimension of the return matrix may be left unspecified and Octave\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4941 will determine its size automatically. An empty matrix ([]) is used to flag\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
4942 the unspecified dimension.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
4943 @seealso{resize, vec, postpad, cat, squeeze}\n\
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4944 @end deftypefn")
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4945 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4946 octave_value retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4947
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4948 int nargin = args.length ();
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4949
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4950 dim_vector new_dims;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4951
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4952 if (nargin == 2)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4953 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4954 Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value ();
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4955
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4956 new_dims = dim_vector::alloc (new_size.length ());
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4957
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4958 for (octave_idx_type i = 0; i < new_size.length (); i++)
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4959 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4960 if (new_size(i) < 0)
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4961 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
4962 error ("reshape: SIZE must be non-negative");
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4963 break;
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4964 }
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4965 else
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4966 new_dims(i) = new_size(i);
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4967 }
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4968 }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4969 else if (nargin > 2)
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4970 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4971 new_dims = dim_vector::alloc (nargin-1);
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
4972 int empty_dim = -1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4973
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
4974 for (int i = 1; i < nargin; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4975 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4976 if (args(i).is_empty ())
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4977 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4978 if (empty_dim > 0)
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4979 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4980 error ("reshape: only a single dimension can be unknown");
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4981 break;
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4982 }
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4983 else
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4984 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4985 empty_dim = i;
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4986 new_dims(i-1) = 1;
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4987 }
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4988 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4989 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4990 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4991 new_dims(i-1) = args(i).idx_type_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4992
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4993 if (error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4994 break;
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4995 else if (new_dims(i-1) < 0)
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4996 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
4997 error ("reshape: SIZE must be non-negative");
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4998 break;
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
4999 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5000 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5001 }
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5002
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5003 if (! error_state && (empty_dim > 0))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5004 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5005 octave_idx_type nel = new_dims.numel ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5006
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5007 if (nel == 0)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5008 new_dims(empty_dim-1) = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5009 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5010 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5011 octave_idx_type a_nel = args(0).numel ();
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5012 octave_idx_type size_empty_dim = a_nel / nel;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5013
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5014 if (a_nel != size_empty_dim * nel)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5015 error ("reshape: SIZE is not divisible by the product of known dimensions (= %d)",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5016 nel);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5017 else
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5018 new_dims(empty_dim-1) = size_empty_dim;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5019 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5020 }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5021 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5022 else
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5023 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
5024 print_usage ();
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5025 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5026 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5027
10352
a3635bc1ea19 remove Array2
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
5028 if (! error_state)
a3635bc1ea19 remove Array2
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
5029 retval = args(0).reshape (new_dims);
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5030
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5031 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5032 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5033
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5034 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5035 %!assert (size (reshape (ones (4, 4), 2, 8)), [2, 8])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5036 %!assert (size (reshape (ones (4, 4), 8, 2)), [8, 2])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5037 %!assert (size (reshape (ones (15, 4), 1, 60)), [1, 60])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5038 %!assert (size (reshape (ones (15, 4), 60, 1)), [60, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5039
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5040 %!assert (size (reshape (ones (4, 4, "single"), 2, 8)), [2, 8])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5041 %!assert (size (reshape (ones (4, 4, "single"), 8, 2)), [8, 2])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5042 %!assert (size (reshape (ones (15, 4, "single"), 1, 60)), [1, 60])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5043 %!assert (size (reshape (ones (15, 4, "single"), 60, 1)), [60, 1])
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5044
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5045 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5046 %! s.a = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5047 %! fail ("reshape (s, 2, 3)");
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5048
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5049 %!error reshape ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5050 %!error reshape (1, 2, 3, 4)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5051 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5052
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5053 DEFUN (vec, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5054 "-*- texinfo -*-\n\
12578
f5a780d675a1 Clean up operator and function indices in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
5055 @deftypefn {Built-in Function} {@var{v} =} vec (@var{x})\n\
f5a780d675a1 Clean up operator and function indices in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
5056 @deftypefnx {Built-in Function} {@var{v} =} vec (@var{x}, @var{dim})\n\
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5057 Return the vector obtained by stacking the columns of the matrix @var{x}\n\
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5058 one above the other. Without @var{dim} this is equivalent to\n\
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5059 @code{@var{x}(:)}. If @var{dim} is supplied, the dimensions of @var{v}\n\
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5060 are set to @var{dim} with all elements along the last dimension.\n\
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5061 This is equivalent to @code{shiftdim (@var{x}(:), 1-@var{dim})}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5062 @seealso{vech, resize, cat}\n\
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5063 @end deftypefn")
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5064 {
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5065 octave_value retval;
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5066 int dim = 1;
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5067
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5068 int nargin = args.length ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5069
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5070 if (nargin < 1 || nargin > 2)
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5071 print_usage () ;
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5072
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5073 if (! error_state && nargin == 2)
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5074 {
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5075 dim = args(1).idx_type_value ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5076
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5077 if (dim < 1)
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
5078 error ("vec: DIM must be greater than zero");
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5079 }
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5080
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5081 if (! error_state)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5082 {
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5083 octave_value colon (octave_value::magic_colon_t);
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5084 octave_value arg = args(0);
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5085 retval = arg.single_subsref ("(", colon);
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5086
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5087
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5088 if (! error_state && dim > 1)
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5089 {
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5090 dim_vector new_dims = dim_vector::alloc (dim);
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5091
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5092 for (int i = 0; i < dim-1; i++)
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5093 new_dims(i) = 1;
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5094
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5095 new_dims(dim-1) = retval.numel ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5096
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5097 retval = retval.reshape (new_dims);
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5098 }
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5099 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5100
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5101 return retval;
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5102 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5103
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5104 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5105 %!assert (vec ([1, 2; 3, 4]), [1; 3; 2; 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5106 %!assert (vec ([1, 3, 2, 4]), [1; 3; 2; 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5107 %!assert (vec ([1, 2, 3, 4], 2), [1, 2, 3, 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5108 %!assert (vec ([1, 2; 3, 4]), vec ([1, 2; 3, 4], 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5109 %!assert (vec ([1, 2; 3, 4], 1), [1; 3; 2; 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5110 %!assert (vec ([1, 2; 3, 4], 2), [1, 3, 2, 4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5111 %!assert (vec ([1, 3; 2, 4], 3), reshape ([1, 2, 3, 4], 1, 1, 4))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5112 %!assert (vec ([1, 3; 2, 4], 3), shiftdim (vec ([1, 3; 2, 4]), -2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5113
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5114 %!error vec ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5115 %!error vec (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5116 %!error vec ([1, 2; 3, 4], 0)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5117 */
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5118
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5119 DEFUN (squeeze, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5120 "-*- texinfo -*-\n\
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5121 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5122 Remove singleton dimensions from @var{x} and return the result.\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
5123 Note that for compatibility with @sc{matlab}, all objects have\n\
7007
6304d9ea0a30 [project @ 2007-10-11 16:26:36 by jwe]
jwe
parents: 7001
diff changeset
5124 a minimum of two dimensions and row vectors are left unchanged.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5125 @seealso{reshape}\n\
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5126 @end deftypefn")
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5127 {
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5128 octave_value retval;
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5129
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5130 if (args.length () == 1)
4545
c16f153836a0 [project @ 2003-10-24 04:45:45 by jwe]
jwe
parents: 4532
diff changeset
5131 retval = args(0).squeeze ();
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5132 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5133 print_usage ();
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5134
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5135 return retval;
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5136 }
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
5137
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5138 DEFUN (full, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5139 "-*- texinfo -*-\n\
15038
ab18578c2ade doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents: 15034
diff changeset
5140 @deftypefn {Built-in Function} {@var{FM} =} full (@var{SM})\n\
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 12571
diff changeset
5141 Return a full storage matrix from a sparse, diagonal, permutation matrix\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
5142 or a range.\n\
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5143 @seealso{sparse}\n\
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5144 @end deftypefn")
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5145 {
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5146 octave_value retval;
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5147
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5148 if (args.length () == 1)
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5149 retval = args(0).full_value ();
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5150 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5151 print_usage ();
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5152
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5153 return retval;
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5154 }
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
5155
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
5156 // Compute various norms of the vector X.
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
5157
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5158 DEFUN (norm, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5159 "-*- texinfo -*-\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5160 @deftypefn {Built-in Function} {} norm (@var{A})\n\
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5161 @deftypefnx {Built-in Function} {} norm (@var{A}, @var{p})\n\
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5162 @deftypefnx {Built-in Function} {} norm (@var{A}, @var{p}, @var{opt})\n\
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5163 Compute the p-norm of the matrix @var{A}. If the second argument is\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5164 missing, @code{p = 2} is assumed.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5165 \n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5166 If @var{A} is a matrix (or sparse matrix):\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5167 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5168 @table @asis\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5169 @item @var{p} = @code{1}\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5170 1-norm, the largest column sum of the absolute values of @var{A}.\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5171 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5172 @item @var{p} = @code{2}\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5173 Largest singular value of @var{A}.\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5174 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
5175 @item @var{p} = @code{Inf} or @qcode{\"inf\"}\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5176 @cindex infinity norm\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5177 Infinity norm, the largest row sum of the absolute values of @var{A}.\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5178 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
5179 @item @var{p} = @qcode{\"fro\"}\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5180 @cindex Frobenius norm\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5181 Frobenius norm of @var{A}, @code{sqrt (sum (diag (@var{A}' * @var{A})))}.\n\
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5182 \n\
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5183 @item other @var{p}, @code{@var{p} > 1}\n\
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12639
diff changeset
5184 @cindex general p-norm\n\
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5185 maximum @code{norm (A*x, p)} such that @code{norm (x, p) == 1}\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5186 @end table\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5187 \n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5188 If @var{A} is a vector or a scalar:\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5189 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5190 @table @asis\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
5191 @item @var{p} = @code{Inf} or @qcode{\"inf\"}\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5192 @code{max (abs (@var{A}))}.\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5193 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5194 @item @var{p} = @code{-Inf}\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5195 @code{min (abs (@var{A}))}.\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5196 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
5197 @item @var{p} = @qcode{\"fro\"}\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5198 Frobenius norm of @var{A}, @code{sqrt (sumsq (abs (A)))}.\n\
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7145
diff changeset
5199 \n\
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5200 @item @var{p} = 0\n\
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5201 Hamming norm - the number of nonzero elements.\n\
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5202 \n\
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5203 @item other @var{p}, @code{@var{p} > 1}\n\
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 12578
diff changeset
5204 p-norm of @var{A}, @code{(sum (abs (@var{A}) .^ @var{p})) ^ (1/@var{p})}.\n\
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5205 \n\
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5206 @item other @var{p} @code{@var{p} < 1}\n\
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5207 the p-pseudonorm defined as above.\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5208 @end table\n\
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5209 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
5210 If @var{opt} is the value @qcode{\"rows\"}, treat each row as a vector and\n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10682
diff changeset
5211 compute its norm. The result is returned as a column vector.\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
5212 Similarly, if @var{opt} is @qcode{\"columns\"} or @qcode{\"cols\"} then\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
5213 compute the norms of each column and return a row vector.\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5214 @seealso{cond, svd}\n\
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5215 @end deftypefn")
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5216 {
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5217 octave_value_list retval;
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5218
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5219 int nargin = args.length ();
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5220
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5221 if (nargin >= 1 && nargin <= 3)
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5222 {
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5223 octave_value x_arg = args(0);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
5224
10185
455759a5fcbe fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 10182
diff changeset
5225 if (x_arg.ndims () == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5226 {
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5227 enum { sfmatrix, sfcols, sfrows, sffrob, sfinf } strflag = sfmatrix;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5228 if (nargin > 1 && args(nargin-1).is_string ())
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5229 {
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5230 std::string str = args(nargin-1).string_value ();
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5231 if (str == "cols" || str == "columns")
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5232 strflag = sfcols;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5233 else if (str == "rows")
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5234 strflag = sfrows;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5235 else if (str == "fro")
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5236 strflag = sffrob;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5237 else if (str == "inf")
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5238 strflag = sfinf;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5239 else
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5240 error ("norm: unrecognized option: %s", str.c_str ());
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5241 // we've handled the last parameter, so act as if it was removed
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5242 nargin --;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5243 }
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5244
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5245 if (! error_state)
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5246 {
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5247 octave_value p_arg = (nargin > 1) ? args(1) : octave_value (2);
17115
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5248
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5249 if (p_arg.is_empty ())
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5250 p_arg = octave_value (2);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5251 else if (p_arg.is_string ())
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5252 {
17115
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5253 std::string str = p_arg.string_value ();
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5254 if ((strflag == sfcols || strflag == sfrows))
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5255 {
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5256 if (str == "cols" || str == "columns" || str == "rows")
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5257 error ("norm: invalid combination of options");
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5258 else if (str == "fro")
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5259 p_arg = octave_value (2);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5260 else if (str == "inf")
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5261 p_arg = octave_Inf;
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5262 else
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5263 error ("norm: unrecognized option: %s", str.c_str ());
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5264 }
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5265 else
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5266 error ("norm: invalid combination of options");
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5267 }
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5268 else if (! p_arg.is_scalar_type ())
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5269 gripe_wrong_type_arg ("norm", p_arg, true);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5270
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5271 if (! error_state)
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5272 {
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5273 switch (strflag)
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5274 {
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5275 case sfmatrix:
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5276 retval(0) = xnorm (x_arg, p_arg);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5277 break;
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5278 case sfcols:
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5279 retval(0) = xcolnorms (x_arg, p_arg);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5280 break;
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5281 case sfrows:
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5282 retval(0) = xrownorms (x_arg, p_arg);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5283 break;
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5284 case sffrob:
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5285 retval(0) = xfrobnorm (x_arg);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5286 break;
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5287 case sfinf:
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5288 retval(0) = xnorm (x_arg, octave_Inf);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5289 break;
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5290 }
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5291 }
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
5292 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5293 }
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5294 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5295 error ("norm: only valid for 2-D objects");
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5296 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5297 else
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5298 print_usage ();
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5299
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5300 return retval;
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5301 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
5302
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5303 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5304 %!shared x
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5305 %! x = [1, -3, 4, 5, -7];
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5306 %!assert (norm (x,1), 20)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5307 %!assert (norm (x,2), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5308 %!assert (norm (x,3), 8.24257059961711, -4*eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5309 %!assert (norm (x,Inf), 7)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5310 %!assert (norm (x,-Inf), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5311 %!assert (norm (x,"inf"), 7)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5312 %!assert (norm (x,"fro"), 10, -eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5313 %!assert (norm (x), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5314 %!assert (norm ([1e200, 1]), 1e200)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5315 %!assert (norm ([3+4i, 3-4i, sqrt(31)]), 9, -4*eps)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5316 %!shared m
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5317 %! m = magic (4);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5318 %!assert (norm (m,1), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5319 %!assert (norm (m,2), 34, -eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5320 %!assert (norm (m,Inf), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5321 %!assert (norm (m,"inf"), 34)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5322 %!shared m2, flo, fhi
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5323 %! m2 = [1,2;3,4];
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5324 %! flo = 1e-300;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5325 %! fhi = 1e+300;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5326 %!assert (norm (flo*m2,"fro"), sqrt (30)*flo, -eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5327 %!assert (norm (fhi*m2,"fro"), sqrt (30)*fhi, -eps)
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5328
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5329 %!shared x
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5330 %! x = single ([1, -3, 4, 5, -7]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5331 %!assert (norm (x,1), single (20))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5332 %!assert (norm (x,2), single (10))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5333 %!assert (norm (x,3), single (8.24257059961711), -4*eps ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5334 %!assert (norm (x,Inf), single (7))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5335 %!assert (norm (x,-Inf), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5336 %!assert (norm (x,"inf"), single (7))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5337 %!assert (norm (x,"fro"), single (10), -eps ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5338 %!assert (norm (x), single (10))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5339 %!assert (norm (single ([1e200, 1])), single (1e200))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5340 %!assert (norm (single ([3+4i, 3-4i, sqrt(31)])), single (9), -4*eps ("single"))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5341 %!shared m
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5342 %! m = single (magic (4));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5343 %!assert (norm (m,1), single (34))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5344 %!assert (norm (m,2), single (34), -eps ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5345 %!assert (norm (m,Inf), single (34))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5346 %!assert (norm (m,"inf"), single (34))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5347 %!shared m2, flo, fhi
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5348 %! m2 = single ([1,2;3,4]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5349 %! flo = single (1e-300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5350 %! fhi = single (1e+300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5351 %!assert (norm (flo*m2,"fro"), single (sqrt (30)*flo), -eps ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5352 %!assert (norm (fhi*m2,"fro"), single (sqrt (30)*fhi), -eps ("single"))
14520
c4ed0fdf2b62 Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents: 14491
diff changeset
5353
17115
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5354 %!shared q
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5355 %! q = rand (1e3, 3);
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5356 %!assert (norm (q, 3, "rows"), sum (q.^3, 2).^(1/3), sqrt (eps));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5357 %!assert (norm (q, "fro", "rows"), sum (q.^2, 2).^(1/2), sqrt (eps));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5358 %!assert (norm (q, "fro", "rows"), sqrt (sumsq (q, 2)), sqrt (eps));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5359 %!assert (norm (q, "fro", "cols"), sqrt (sumsq (q, 1)), sqrt (eps));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5360 %!assert (norm (q, 3, "cols"), sum (q.^3, 1).^(1/3), sqrt (eps));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5361 %!assert (norm (q, "inf", "rows"), norm (q, Inf, "rows"));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5362 %!assert (norm (q, "inf", "cols"), norm (q, Inf, "cols"));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5363 %!assert (norm (q, [], "rows"), norm (q, 2, "rows"));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5364 %!assert (norm (q, [], "cols"), norm (q, 2, "cols"));
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
5365
14520
c4ed0fdf2b62 Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents: 14491
diff changeset
5366 %!test
c4ed0fdf2b62 Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents: 14491
diff changeset
5367 %! ## Test for norm returning NaN on sparse matrix (bug #30631)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5368 %! A = sparse (2,2);
14520
c4ed0fdf2b62 Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents: 14491
diff changeset
5369 %! A(2,1) = 1;
c4ed0fdf2b62 Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents: 14491
diff changeset
5370 %! assert (norm (A), 1);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5371 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5372
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5373 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5374 unary_op_defun_body (octave_value::unary_op op,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5375 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5376 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5377 octave_value retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5378 if (args.length () == 1)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5379 retval = do_unary_op (op, args(0));
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5380 else
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5381 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5382
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5383 return retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5384 }
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5385
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5386 DEFUN (not, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5387 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5388 @deftypefn {Built-in Function} {} not (@var{x})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5389 Return the logical NOT of @var{x}. This function is equivalent to\n\
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5390 @code{! x}.\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
5391 @seealso{and, or, xor}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5392 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5393 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5394 return unary_op_defun_body (octave_value::op_not, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5395 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5396
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5397 DEFUN (uplus, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5398 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5399 @deftypefn {Built-in Function} {} uplus (@var{x})\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5400 This function and @w{@tcode{+ x}} are equivalent.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5401 @seealso{uminus, plus, minus}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5402 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5403 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5404 return unary_op_defun_body (octave_value::op_uplus, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5405 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5406
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5407 DEFUN (uminus, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5408 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5409 @deftypefn {Built-in Function} {} uminus (@var{x})\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5410 This function and @w{@tcode{- x}} are equivalent.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5411 @seealso{uplus, minus}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5412 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5413 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5414 return unary_op_defun_body (octave_value::op_uminus, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5415 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5416
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5417 DEFUN (transpose, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5418 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5419 @deftypefn {Built-in Function} {} transpose (@var{x})\n\
13780
990762e784fe Fix confusing interaction between @code macro and transpose operator (') in documentation (Bug #34661).
Rik <octave@nomad.inbox5.com>
parents: 13760
diff changeset
5420 Return the transpose of @var{x}.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5421 This function and @tcode{x.'} are equivalent.\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5422 @seealso{ctranspose}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5423 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5424 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5425 return unary_op_defun_body (octave_value::op_transpose, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5426 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5427
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5428 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5429 %!assert (2.', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5430 %!assert (2i.', 2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5431 %!assert ([1:4].', [1;2;3;4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5432 %!assert ([1;2;3;4].', [1:4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5433 %!assert ([1,2;3,4].', [1,3;2,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5434 %!assert ([1,2i;3,4].', [1,3;2i,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5435
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5436 %!assert (transpose ([1,2;3,4]), [1,3;2,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5437
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5438 %!assert (single (2).', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5439 %!assert (single (2i).', single (2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5440 %!assert (single ([1:4]).', single ([1;2;3;4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5441 %!assert (single ([1;2;3;4]).', single ([1:4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5442 %!assert (single ([1,2;3,4]).', single ([1,3;2,4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5443 %!assert (single ([1,2i;3,4]).', single ([1,3;2i,4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5444
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5445 %!assert (transpose (single ([1,2;3,4])), single ([1,3;2,4]))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5446 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5447
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5448 DEFUN (ctranspose, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5449 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5450 @deftypefn {Built-in Function} {} ctranspose (@var{x})\n\
13780
990762e784fe Fix confusing interaction between @code macro and transpose operator (') in documentation (Bug #34661).
Rik <octave@nomad.inbox5.com>
parents: 13760
diff changeset
5451 Return the complex conjugate transpose of @var{x}.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5452 This function and @tcode{x'} are equivalent.\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5453 @seealso{transpose}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5454 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5455 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5456 return unary_op_defun_body (octave_value::op_hermitian, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5457 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5458
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5459 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5460 %!assert (2', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5461 %!assert (2i', -2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5462 %!assert ([1:4]', [1;2;3;4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5463 %!assert ([1;2;3;4]', [1:4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5464 %!assert ([1,2;3,4]', [1,3;2,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5465 %!assert ([1,2i;3,4]', [1,3;-2i,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5466
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5467 %!assert (ctranspose ([1,2i;3,4]), [1,3;-2i,4])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5468
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5469 %!assert (single (2)', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5470 %!assert (single (2i)', single (-2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5471 %!assert (single ([1:4])', single ([1;2;3;4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5472 %!assert (single ([1;2;3;4])', single ([1:4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5473 %!assert (single ([1,2;3,4])', single ([1,3;2,4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5474 %!assert (single ([1,2i;3,4])', single ([1,3;-2i,4]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5475
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5476 %!assert (ctranspose (single ([1,2i;3,4])), single ([1,3;-2i,4]))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5477 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5478
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5479 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5480 binary_op_defun_body (octave_value::binary_op op,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5481 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5482 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5483 octave_value retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5484
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5485 if (args.length () == 2)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5486 retval = do_binary_op (op, args(0), args(1));
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5487 else
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5488 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5489
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5490 return retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5491 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5492
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5493 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5494 binary_assoc_op_defun_body (octave_value::binary_op op,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5495 octave_value::assign_op aop,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5496 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5497 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5498 octave_value retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5499 int nargin = args.length ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5500
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5501 switch (nargin)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5502 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5503 case 0:
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5504 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5505 break;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5506 case 1:
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5507 retval = args(0);
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5508 break;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5509 case 2:
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5510 retval = do_binary_op (op, args(0), args(1));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5511 break;
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5512 default:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5513 retval = do_binary_op (op, args(0), args(1));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5514 for (int i = 2; i < nargin; i++)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5515 retval.assign (aop, args(i));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5516 break;
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5517 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5518
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5519 return retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5520 }
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5521
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5522 DEFUN (plus, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5523 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
5524 @deftypefn {Built-in Function} {} plus (@var{x}, @var{y})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5525 @deftypefnx {Built-in Function} {} plus (@var{x1}, @var{x2}, @dots{})\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5526 This function and @w{@tcode{x + y}} are equivalent.\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5527 If more arguments are given, the summation is applied\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5528 cumulatively from left to right:\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5529 \n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5530 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
5531 (@dots{}((x1 + x2) + x3) + @dots{})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5532 @end example\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5533 \n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5534 At least one argument is required.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5535 @seealso{minus, uplus}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5536 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5537 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5538 return binary_assoc_op_defun_body (octave_value::op_add,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5539 octave_value::op_add_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5540 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5541
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5542 DEFUN (minus, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5543 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5544 @deftypefn {Built-in Function} {} minus (@var{x}, @var{y})\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5545 This function and @w{@tcode{x - y}} are equivalent.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5546 @seealso{plus, uminus}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5547 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5548 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5549 return binary_op_defun_body (octave_value::op_sub, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5550 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5551
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5552 DEFUN (mtimes, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5553 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
5554 @deftypefn {Built-in Function} {} mtimes (@var{x}, @var{y})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5555 @deftypefnx {Built-in Function} {} mtimes (@var{x1}, @var{x2}, @dots{})\n\
11575
d6619410e79c Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11572
diff changeset
5556 Return the matrix multiplication product of inputs.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5557 This function and @w{@tcode{x * y}} are equivalent.\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5558 If more arguments are given, the multiplication is applied\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5559 cumulatively from left to right:\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5560 \n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5561 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
5562 (@dots{}((x1 * x2) * x3) * @dots{})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5563 @end example\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5564 \n\
11575
d6619410e79c Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11572
diff changeset
5565 At least one argument is required.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5566 @seealso{times, plus, minus, rdivide, mrdivide, mldivide, mpower}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5567 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5568 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5569 return binary_assoc_op_defun_body (octave_value::op_mul,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5570 octave_value::op_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5571 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5572
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5573 DEFUN (mrdivide, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5574 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5575 @deftypefn {Built-in Function} {} mrdivide (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5576 Return the matrix right division of @var{x} and @var{y}.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5577 This function and @w{@tcode{x / y}} are equivalent.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5578 @seealso{mldivide, rdivide, plus, minus}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5579 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5580 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5581 return binary_op_defun_body (octave_value::op_div, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5582 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5583
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5584 DEFUN (mpower, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5585 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5586 @deftypefn {Built-in Function} {} mpower (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5587 Return the matrix power operation of @var{x} raised to the @var{y} power.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5588 This function and @w{@tcode{x ^ y}} are equivalent.\n\
15034
1116864ee270 doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents: 15031
diff changeset
5589 @seealso{power, mtimes, plus, minus}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5590 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5591 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5592 return binary_op_defun_body (octave_value::op_pow, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5593 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5594
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5595 DEFUN (mldivide, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5596 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5597 @deftypefn {Built-in Function} {} mldivide (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5598 Return the matrix left division of @var{x} and @var{y}.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5599 This function and @w{@tcode{x @xbackslashchar{} y}} are equivalent.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5600 @seealso{mrdivide, ldivide, rdivide}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5601 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5602 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5603 return binary_op_defun_body (octave_value::op_ldiv, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5604 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5605
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5606 DEFUN (lt, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5607 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5608 @deftypefn {Built-in Function} {} lt (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5609 This function is equivalent to @w{@code{x < y}}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5610 @seealso{le, eq, ge, gt, ne}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5611 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5612 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5613 return binary_op_defun_body (octave_value::op_lt, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5614 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5615
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5616 DEFUN (le, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5617 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5618 @deftypefn {Built-in Function} {} le (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5619 This function is equivalent to @w{@code{x <= y}}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5620 @seealso{eq, ge, gt, ne, lt}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5621 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5622 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5623 return binary_op_defun_body (octave_value::op_le, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5624 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5625
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5626 DEFUN (eq, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5627 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5628 @deftypefn {Built-in Function} {} eq (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5629 Return true if the two inputs are equal.\n\
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5630 This function is equivalent to @w{@code{x == y}}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5631 @seealso{ne, isequal, le, ge, gt, ne, lt}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5632 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5633 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5634 return binary_op_defun_body (octave_value::op_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5635 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5636
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5637 DEFUN (ge, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5638 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5639 @deftypefn {Built-in Function} {} ge (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5640 This function is equivalent to @w{@code{x >= y}}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5641 @seealso{le, eq, gt, ne, lt}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5642 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5643 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5644 return binary_op_defun_body (octave_value::op_ge, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5645 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5646
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5647 DEFUN (gt, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5648 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5649 @deftypefn {Built-in Function} {} gt (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5650 This function is equivalent to @w{@code{x > y}}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5651 @seealso{le, eq, ge, ne, lt}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5652 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5653 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5654 return binary_op_defun_body (octave_value::op_gt, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5655 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5656
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5657 DEFUN (ne, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5658 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5659 @deftypefn {Built-in Function} {} ne (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5660 Return true if the two inputs are not equal.\n\
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5661 This function is equivalent to @w{@code{x != y}}.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5662 @seealso{eq, isequal, le, ge, lt}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5663 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5664 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5665 return binary_op_defun_body (octave_value::op_ne, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5666 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5667
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5668 DEFUN (times, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5669 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
5670 @deftypefn {Built-in Function} {} times (@var{x}, @var{y})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5671 @deftypefnx {Built-in Function} {} times (@var{x1}, @var{x2}, @dots{})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5672 Return the element-by-element multiplication product of inputs.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5673 This function and @w{@tcode{x .* y}} are equivalent.\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5674 If more arguments are given, the multiplication is applied\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5675 cumulatively from left to right:\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5676 \n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5677 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
5678 (@dots{}((x1 .* x2) .* x3) .* @dots{})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5679 @end example\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5680 \n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5681 At least one argument is required.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5682 @seealso{mtimes, rdivide}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5683 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5684 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5685 return binary_assoc_op_defun_body (octave_value::op_el_mul,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5686 octave_value::op_el_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5687 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5688
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5689 DEFUN (rdivide, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5690 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5691 @deftypefn {Built-in Function} {} rdivide (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5692 Return the element-by-element right division of @var{x} and @var{y}.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5693 This function and @w{@tcode{x ./ y}} are equivalent.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5694 @seealso{ldivide, mrdivide, times, plus}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5695 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5696 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5697 return binary_op_defun_body (octave_value::op_el_div, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5698 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5699
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5700 DEFUN (power, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5701 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5702 @deftypefn {Built-in Function} {} power (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5703 Return the element-by-element operation of @var{x} raised to the\n\
14171
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14169
diff changeset
5704 @var{y} power. If several complex results are possible,\n\
2ced2f59f523 doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents: 14169
diff changeset
5705 returns the one with smallest non-negative argument (angle). Use\n\
14169
c0ca47ab7641 doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
5706 @code{realpow}, @code{realsqrt}, @code{cbrt}, or @code{nthroot} if a\n\
c0ca47ab7641 doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
5707 real result is preferred.\n\
c0ca47ab7641 doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
5708 \n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5709 This function and @w{@tcode{x .^ y}} are equivalent.\n\
14169
c0ca47ab7641 doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
5710 @seealso{mpower, realpow, realsqrt, cbrt, nthroot}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5711 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5712 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5713 return binary_op_defun_body (octave_value::op_el_pow, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5714 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5715
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5716 DEFUN (ldivide, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5717 "-*- texinfo -*-\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5718 @deftypefn {Built-in Function} {} ldivide (@var{x}, @var{y})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5719 Return the element-by-element left division of @var{x} and @var{y}.\n\
17268
1c21f264d26f doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents: 17206
diff changeset
5720 This function and @w{@tcode{x .@xbackslashchar{} y}} are equivalent.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5721 @seealso{rdivide, mldivide, times, plus}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5722 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5723 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5724 return binary_op_defun_body (octave_value::op_el_ldiv, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5725 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5726
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5727 DEFUN (and, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5728 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
5729 @deftypefn {Built-in Function} {} and (@var{x}, @var{y})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5730 @deftypefnx {Built-in Function} {} and (@var{x1}, @var{x2}, @dots{})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5731 Return the logical AND of @var{x} and @var{y}.\n\
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5732 This function is equivalent to @w{@code{x & y}}.\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5733 If more arguments are given, the logical and is applied\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5734 cumulatively from left to right:\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5735 \n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5736 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
5737 (@dots{}((x1 & x2) & x3) & @dots{})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5738 @end example\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5739 \n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5740 At least one argument is required.\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
5741 @seealso{or, not, xor}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5742 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5743 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5744 return binary_assoc_op_defun_body (octave_value::op_el_and,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5745 octave_value::op_el_and_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5746 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5747
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5748 DEFUN (or, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5749 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
5750 @deftypefn {Built-in Function} {} or (@var{x}, @var{y})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5751 @deftypefnx {Built-in Function} {} or (@var{x1}, @var{x2}, @dots{})\n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5752 Return the logical OR of @var{x} and @var{y}.\n\
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5753 This function is equivalent to @w{@code{x | y}}.\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5754 If more arguments are given, the logical or is applied\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5755 cumulatively from left to right:\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5756 \n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5757 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
5758 (@dots{}((x1 | x2) | x3) | @dots{})\n\
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5759 @end example\n\
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
5760 \n\
11422
3cae59b4c0f7 Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents: 11402
diff changeset
5761 At least one argument is required.\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
5762 @seealso{and, not, xor}\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5763 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5764 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5765 return binary_assoc_op_defun_body (octave_value::op_el_or,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
5766 octave_value::op_el_or_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5767 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
5768
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5769 static double tic_toc_timestamp = -1.0;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5770
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5771 DEFUN (tic, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5772 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
5773 @deftypefn {Built-in Function} {} tic ()\n\
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14849
diff changeset
5774 @deftypefnx {Built-in Function} {@var{id} =} tic ()\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5775 @deftypefnx {Built-in Function} {} toc ()\n\
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5776 @deftypefnx {Built-in Function} {} toc (@var{id})\n\
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5777 @deftypefnx {Built-in Function} {@var{val} =} toc (@dots{})\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5778 Set or check a wall-clock timer. Calling @code{tic} without an\n\
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5779 output argument sets the internal timer state. Subsequent calls\n\
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5780 to @code{toc} return the number of seconds since the timer was set.\n\
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5781 For example,\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5782 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5783 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
5784 @group\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5785 tic ();\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
5786 # many computations later@dots{}\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5787 elapsed_time = toc ();\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9041
diff changeset
5788 @end group\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5789 @end example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5790 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5791 @noindent\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5792 will set the variable @code{elapsed_time} to the number of seconds since\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5793 the most recent call to the function @code{tic}.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5794 \n\
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5795 If called with one output argument, @code{tic} returns a scalar\n\
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5796 of type @code{uint64} that may be later passed to @code{toc}.\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5797 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5798 @example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5799 @group\n\
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5800 id = tic; sleep (5); toc (id)\n\
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5801 @result{} 5.0010\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5802 @end group\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5803 @end example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5804 \n\
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5805 Calling @code{tic} and @code{toc} this way allows nested timing calls.\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5806 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5807 If you are more interested in the CPU time that your process used, you\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5808 should use the @code{cputime} function instead. The @code{tic} and\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5809 @code{toc} functions report the actual wall clock time that elapsed\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5810 between the calls. This may include time spent processing other jobs or\n\
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5811 doing nothing at all.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5812 @seealso{toc, cputime}\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5813 @end deftypefn")
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5814 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5815 octave_value retval;
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5816
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5817 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5818
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5819 if (nargin != 0)
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5820 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5821
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5822 octave_time now;
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5823
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5824 double tmp = now.double_value ();
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5825
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5826 if (nargout > 0)
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5827 {
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5828 double ip = 0.0;
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5829 double frac = modf (tmp, &ip);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5830 uint64_t microsecs = static_cast<uint64_t> (CLOCKS_PER_SEC * frac);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5831 microsecs += CLOCKS_PER_SEC * static_cast<uint64_t> (ip);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5832 retval = octave_uint64 (microsecs);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5833 }
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5834 else
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5835 tic_toc_timestamp = tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5836
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5837 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5838 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5839
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5840 DEFUN (toc, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5841 "-*- texinfo -*-\n\
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14849
diff changeset
5842 @deftypefn {Built-in Function} {} toc ()\n\
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5843 @deftypefnx {Built-in Function} {} toc (@var{id})\n\
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14849
diff changeset
5844 @deftypefnx {Built-in Function} {@var{val} =} toc (@dots{})\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5845 @seealso{tic, cputime}\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5846 @end deftypefn")
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5847 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5848 octave_value retval;
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5849
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5850 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5851
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5852 double start_time = tic_toc_timestamp;
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5853
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5854 if (nargin > 1)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5855 print_usage ();
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5856 else
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5857 {
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5858 if (nargin == 1)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5859 {
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5860 octave_uint64 id = args(0).uint64_scalar_value ();
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5861
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5862 if (! error_state)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5863 {
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5864 uint64_t val = id.value ();
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5865
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5866 start_time
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5867 = (static_cast<double> (val / CLOCKS_PER_SEC)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5868 + static_cast<double> (val % CLOCKS_PER_SEC)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5869 / CLOCKS_PER_SEC);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5870
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5871 // FIXME: should we also check to see whether the start
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5872 // time is after the beginning of this Octave session?
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5873 }
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5874 else
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5875 error ("toc: invalid ID");
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5876 }
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5877
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5878 if (! error_state)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5879 {
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5880 if (start_time < 0)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5881 error ("toc called before timer set");
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5882 else
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5883 {
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5884 octave_time now;
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5885
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5886 double tmp = now.double_value () - start_time;
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5887
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5888 if (nargout > 0)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5889 retval = tmp;
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5890 else
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5891 octave_stdout << "Elapsed time is " << tmp << " seconds.\n";
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5892 }
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5893 }
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
5894 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5895
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5896 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5897 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5898
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5899 /*
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5900 %!shared id
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5901 %! id = tic ();
14849
f6d3d5b0bd42 test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
5902 %!assert (isa (id, "uint64"))
f6d3d5b0bd42 test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
5903 %!assert (isa (toc (id), "double"))
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5904 */
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
5905
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5906 DEFUN (cputime, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5907 "-*- texinfo -*-\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5908 @deftypefn {Built-in Function} {[@var{total}, @var{user}, @var{system}] =} cputime ();\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5909 Return the CPU time used by your Octave session. The first output is\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5910 the total time spent executing your process and is equal to the sum of\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5911 second and third outputs, which are the number of CPU seconds spent\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5912 executing in user mode and the number of CPU seconds spent executing in\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5913 system mode, respectively. If your system does not have a way to report\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5914 CPU time usage, @code{cputime} returns 0 for each of its output values.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5915 Note that because Octave used some CPU time to start, it is reasonable\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5916 to check to see if @code{cputime} works by checking to see if the total\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5917 CPU time used is nonzero.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
5918 @seealso{tic, toc}\n\
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5919 @end deftypefn")
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5920 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5921 octave_value_list retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5922 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5923 double usr = 0.0;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5924 double sys = 0.0;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5925
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5926 if (nargin != 0)
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5927 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5928
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5929 #if defined (HAVE_GETRUSAGE)
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5930
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5931 struct rusage ru;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5932
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5933 getrusage (RUSAGE_SELF, &ru);
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5934
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5935 usr = static_cast<double> (ru.ru_utime.tv_sec) +
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5936 static_cast<double> (ru.ru_utime.tv_usec) * 1e-6;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5937
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5938 sys = static_cast<double> (ru.ru_stime.tv_sec) +
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5939 static_cast<double> (ru.ru_stime.tv_usec) * 1e-6;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5940
10240
fa7b5751730c use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents: 10185
diff changeset
5941 #else
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5942
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5943 struct tms t;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5944
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5945 times (&t);
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5946
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5947 unsigned long ticks;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5948 unsigned long seconds;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5949 unsigned long fraction;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5950
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5951 ticks = t.tms_utime + t.tms_cutime;
10303
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
5952 fraction = ticks % CLOCKS_PER_SEC;
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
5953 seconds = ticks / CLOCKS_PER_SEC;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5954
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5955 usr = static_cast<double> (seconds) + static_cast<double>(fraction) /
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5956 static_cast<double>(CLOCKS_PER_SEC);
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5957
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5958 ticks = t.tms_stime + t.tms_cstime;
10303
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
5959 fraction = ticks % CLOCKS_PER_SEC;
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
5960 seconds = ticks / CLOCKS_PER_SEC;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5961
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5962 sys = static_cast<double> (seconds) + static_cast<double>(fraction) /
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5963 static_cast<double>(CLOCKS_PER_SEC);
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5964
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5965 #endif
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5966
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
5967 retval(2) = sys;
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
5968 retval(1) = usr;
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
5969 retval(0) = sys + usr;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5970
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5971 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5972 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
5973
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5974 DEFUN (sort, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5975 "-*- texinfo -*-\n\
15038
ab18578c2ade doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents: 15034
diff changeset
5976 @deftypefn {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x})\n\
ab18578c2ade doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents: 15034
diff changeset
5977 @deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})\n\
ab18578c2ade doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents: 15034
diff changeset
5978 @deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})\n\
ab18578c2ade doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents: 15034
diff changeset
5979 @deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5980 Return a copy of @var{x} with the elements arranged in increasing\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
5981 order. For matrices, @code{sort} orders the elements within columns\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5982 \n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
5983 For example:\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5984 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5985 @example\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5986 @group\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5987 sort ([1, 2; 2, 3; 3, 1])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
5988 @result{} 1 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
5989 2 2\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
5990 3 3\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5991 @end group\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5992 @end example\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5993 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
5994 If the optional argument @var{dim} is given, then the matrix is sorted\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
5995 along the dimension defined by @var{dim}. The optional argument @code{mode}\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
5996 defines the order in which the values will be sorted. Valid values of\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
5997 @code{mode} are @qcode{\"ascend\"} or @qcode{\"descend\"}.\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
5998 \n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
5999 The @code{sort} function may also be used to produce a matrix\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6000 containing the original row indices of the elements in the sorted\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
6001 matrix. For example:\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6002 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6003 @example\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6004 @group\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6005 [s, i] = sort ([1, 2; 2, 3; 3, 1])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6006 @result{} s = 1 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6007 2 2\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6008 3 3\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6009 @result{} i = 1 3\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6010 2 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6011 3 2\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6012 @end group\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6013 @end example\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6014 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6015 For equal elements, the indices are such that equal elements are listed\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6016 in the order in which they appeared in the original list.\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6017 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6018 Sorting of complex entries is done first by magnitude (@code{abs (@var{z})})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6019 and for any ties by phase angle (@code{angle (z)}). For example:\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6020 \n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6021 @example\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6022 @group\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6023 sort ([1+i; 1; 1-i])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6024 @result{} 1 + 0i\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6025 1 - 1i\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14171
diff changeset
6026 1 + 1i\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6027 @end group\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6028 @end example\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6029 \n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6030 NaN values are treated as being greater than any other value and are sorted\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6031 to the end of the list.\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6032 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6033 The @code{sort} function may also be used to sort strings and cell arrays\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6034 of strings, in which case ASCII dictionary order (uppercase 'A' precedes\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6035 lowercase 'a') of the strings is used.\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6036 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6037 The algorithm used in @code{sort} is optimized for the sorting of partially\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6038 ordered lists.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
6039 @seealso{sortrows, issorted}\n\
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6040 @end deftypefn")
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6041 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6042 octave_value_list retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6043
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6044 int nargin = args.length ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6045 sortmode smode = ASCENDING;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6046
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6047 if (nargin < 1 || nargin > 3)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6048 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6049 print_usage ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6050 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6051 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6052
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6053 bool return_idx = nargout > 1;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6054
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6055 octave_value arg = args(0);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6056
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6057 int dim = 0;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6058 if (nargin > 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6059 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6060 if (args(1).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6061 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
6062 std::string mode = args(1).string_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6063 if (mode == "ascend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6064 smode = ASCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6065 else if (mode == "descend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6066 smode = DESCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6067 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6068 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6069 error ("sort: MODE must be either \"ascend\" or \"descend\"");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6070 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6071 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6072 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6073 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6074 dim = args(1).nint_value () - 1;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6075 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6076
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6077 if (nargin > 2)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6078 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6079 if (args(1).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6080 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6081 print_usage ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6082 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6083 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6084
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6085 if (! args(2).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6086 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6087 error ("sort: MODE must be a string");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6088 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6089 }
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
6090 std::string mode = args(2).string_value ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6091 if (mode == "ascend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6092 smode = ASCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6093 else if (mode == "descend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6094 smode = DESCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6095 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6096 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6097 error ("sort: MODE must be either \"ascend\" or \"descend\"");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6098 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6099 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6100 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6101
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
6102 const dim_vector dv = arg.dims ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6103 if (nargin == 1 || args(1).is_string ())
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6104 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6105 // Find first non singleton dimension
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
6106 dim = dv.first_non_singleton ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6107 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6108 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6109 {
10703
5eb420d92307 fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents: 10695
diff changeset
6110 if (dim < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6111 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6112 error ("sort: DIM must be a valid dimension");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6113 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6114 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6115 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6116
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6117 if (return_idx)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6118 {
14022
de90542b7afc Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents: 13929
diff changeset
6119 retval.resize (2);
de90542b7afc Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents: 13929
diff changeset
6120
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6121 Array<octave_idx_type> sidx;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6122
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
6123 retval(0) = arg.sort (sidx, dim, smode);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6124 retval(1) = idx_vector (sidx, dv(dim)); // No checking, extent is known.
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6125 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6126 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6127 retval(0) = arg.sort (dim, smode);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6128
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6129 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6130 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6131
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6132 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6133 ## Double
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6134 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6135 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6136 %!assert (sort ([NaN, 1, -1, 2, Inf], 2), [-1, 1, 2, Inf, NaN])
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6137 %!assert (sort ([NaN, 1, -1, 2, Inf], 3), [NaN, 1, -1, 2, Inf])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6138 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6139 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "ascend"), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6140 %!assert (sort ([NaN, 1, -1, 2, Inf], "descend"), [NaN, Inf, 2, 1, -1])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6141 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, 1, -1])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6142 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4]), [3, 1, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6143 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 1), [3, 1, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6144 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6145 %!assert (sort (1), 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6146
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6147 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6148 %! [v, i] = sort ([NaN, 1, -1, Inf, 1]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6149 %! assert (v, [-1, 1, 1, Inf, NaN]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6150 %! assert (i, [3, 2, 5, 4, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6151
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6152 ## Complex
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6153 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6154 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6155 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2), [1i, -1, 2, Inf, NaN])
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6156 %!assert (sort ([NaN, 1i, -1, 2, Inf], 3), [NaN, 1i, -1, 2, Inf])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6157 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6158 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "ascend"), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6159 %!assert (sort ([NaN, 1i, -1, 2, Inf], "descend"), [NaN, Inf, 2, -1, 1i])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6160 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, -1, 1i])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6161 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4]), [3, 1i, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6162 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 1), [3, 1i, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6163 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6164 %!assert (sort (1i), 1i)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6165
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6166 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6167 %! [v, i] = sort ([NaN, 1i, -1, Inf, 1, 1i]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6168 %! assert (v, [1, 1i, 1i, -1, Inf, NaN]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6169 %! assert (i, [5, 2, 6, 3, 4, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6170
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6171 ## Single
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6172 %!assert (sort (single ([NaN, 1, -1, 2, Inf])), single ([-1, 1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6173 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 1), single ([NaN, 1, -1, 2, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6174 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2), single ([-1, 1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6175 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 3), single ([NaN, 1, -1, 2, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6176 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "ascend"), single ([-1, 1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6177 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "ascend"), single ([-1, 1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6178 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, 1, -1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6179 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, 1, -1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6180 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4])), single ([3, 1, 6, 4; 8, 2, 7, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6181 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1, 6, 4; 8, 2, 7, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6182 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 2), single ([1, 3, 5, 7; 2, 4, 6, 8]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6183 %!assert (sort (single (1)), single (1))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6184
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6185 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6186 %! [v, i] = sort (single ([NaN, 1, -1, Inf, 1]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6187 %! assert (v, single ([-1, 1, 1, Inf, NaN]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6188 %! assert (i, [3, 2, 5, 4, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6189
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6190 ## Single Complex
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6191 %!assert (sort (single ([NaN, 1i, -1, 2, Inf])), single ([1i, -1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6192 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 1), single ([NaN, 1i, -1, 2, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6193 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2), single ([1i, -1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6194 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 3), single ([NaN, 1i, -1, 2, Inf]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6195 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "ascend"), single ([1i, -1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6196 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "ascend"), single ([1i, -1, 2, Inf, NaN]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6197 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, -1, 1i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6198 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, -1, 1i]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6199 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4])), single ([3, 1i, 6, 4; 8, 2, 7, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6200 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1i, 6, 4; 8, 2, 7, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6201 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 2), single ([1i, 3, 5, 7; 2, 4, 6, 8]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6202 %!assert (sort (single (1i)), single (1i))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6203
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6204 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6205 %! [v, i] = sort (single ([NaN, 1i, -1, Inf, 1, 1i]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6206 %! assert (v, single ([1, 1i, 1i, -1, Inf, NaN]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6207 %! assert (i, [5, 2, 6, 3, 4, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6208
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6209 ## Bool
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6210 %!assert (sort ([true, false, true, false]), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6211 %!assert (sort ([true, false, true, false], 1), [true, false, true, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6212 %!assert (sort ([true, false, true, false], 2), [false, false, true, true])
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6213 %!assert (sort ([true, false, true, false], 3), [true, false, true, false])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6214 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6215 %!assert (sort ([true, false, true, false], 2, "ascend"), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6216 %!assert (sort ([true, false, true, false], "descend"), [true, true, false, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6217 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6218 %!assert (sort (true), true)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6219
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6220 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6221 %! [v, i] = sort ([true, false, true, false]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6222 %! assert (v, [false, false, true, true]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6223 %! assert (i, [2, 4, 1, 3]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6224
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6225 ## Sparse Double
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6226 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6227 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6228 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6229 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1, 0, -1, 2, Inf]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6230 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6231 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6232 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6233 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6234
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6235 %!shared a
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6236 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6237 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6238 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6239 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6240 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6241 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6242 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6243 %! [vs, is] = sort (sparse (a));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6244 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6245 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6246
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6247 ## Sparse Complex
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6248 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6249 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6250 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6251 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6252 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6253 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6254 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6255 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6256
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6257 %!shared a
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6258 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6259 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6260 %! a = 1i * a;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6261 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6262 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6263 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6264 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6265 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6266 %! [vs, is] = sort (sparse (a));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6267 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6268 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6269
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6270 ## Sparse Bool
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6271 %!assert (sort (sparse ([true, false, true, false])), sparse ([false, false, true, true]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6272 %!assert (sort (sparse ([true, false, true, false]), 1), sparse ([true, false, true, false]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6273 %!assert (sort (sparse ([true, false, true, false]), 2), sparse ([false, false, true, true]))
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6274 %!assert (sort (sparse ([true, false, true, false]), 3), sparse ([true, false, true, false]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6275 %!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse ([false, false, true, true]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6276 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse ([false, false, true, true]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6277 %!assert (sort (sparse ([true, false, true, false]), "descend"), sparse ([true, true, false, false]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6278 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse ([true, true, false, false]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6279
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6280 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6281 %! [v, i] = sort (sparse ([true, false, true, false]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6282 %! assert (v, sparse ([false, false, true, true]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6283 %! assert (i, [2, 4, 1, 3]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6284
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6285 ## Cell string array
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6286 %!shared a, b, c
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6287 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6288 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6289 %! c = {"Eric", "David", "Cecile", "Barry", "Alice"};
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6290 %!assert (sort (a), b)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6291 %!assert (sort (a, 1), a)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6292 %!assert (sort (a, 2), b)
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
6293 %!assert (sort (a, 3), a)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6294 %!assert (sort (a, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6295 %!assert (sort (a, 2, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6296 %!assert (sort (a, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6297 %!assert (sort (a, 2, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6298
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6299 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6300 %! [v, i] = sort (a);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6301 %! assert (i, [1, 4, 2, 5, 3]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6302
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6303 %!error sort ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6304 %!error sort (1, 2, 3, 4)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6305 */
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6306
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6307 // Sort the rows of the matrix @var{a} according to the order
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 15428
diff changeset
6308 // specified by @var{mode}, which can either be 'ascend' or 'descend'
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6309 // and return the index vector corresponding to the sort order.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6310 //
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6311 // This function does not yet support sparse matrices.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6312
8733
3ef774603887 rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
6313 DEFUN (__sort_rows_idx__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6314 "-*- texinfo -*-\n\
9517
a85dbf7b6ff9 fix some functions help markup
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
6315 @deftypefn {Built-in Function} {} __sort_rows_idx__ (@var{a}, @var{mode})\n\
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
6316 Undocumented internal function.\n\
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6317 @end deftypefn\n")
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6318 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6319 octave_value retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6320
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6321 int nargin = args.length ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6322 sortmode smode = ASCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6323
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6324 if (nargin < 1 || nargin > 2 || (nargin == 2 && ! args(1).is_string ()))
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6325 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6326 print_usage ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6327 return retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6328 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6329
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6330 if (nargin > 1)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6331 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
6332 std::string mode = args(1).string_value ();
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6333 if (mode == "ascend")
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6334 smode = ASCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6335 else if (mode == "descend")
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6336 smode = DESCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6337 else
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6338 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6339 error ("__sort_rows_idx__: MODE must be either \"ascend\" or \"descend\"");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6340 return retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6341 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6342 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6343
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6344 octave_value arg = args(0);
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6345
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6346 if (arg.is_sparse_type ())
8733
3ef774603887 rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
6347 error ("__sort_rows_idx__: sparse matrices not yet supported");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6348 if (arg.ndims () == 2)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6349 {
8733
3ef774603887 rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
6350 Array<octave_idx_type> idx = arg.sort_rows_idx (smode);
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6351
9351
e2344f4af0cb autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents: 9339
diff changeset
6352 retval = octave_value (idx, true, true);
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6353 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6354 else
8733
3ef774603887 rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
6355 error ("__sort_rows_idx__: needs a 2-dimensional object");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6356
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6357 return retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6358 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6359
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6360 static sortmode
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6361 get_sort_mode_option (const octave_value& arg, const char *argn)
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6362 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6363 // FIXME: we initialize to UNSORTED here to avoid a GCC warning
10076
4b270d1540f7 avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents: 10073
diff changeset
6364 // about possibly using sortmode uninitialized.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6365 // FIXME: shouldn't these modes be scoped inside a class?
10076
4b270d1540f7 avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents: 10073
diff changeset
6366 sortmode smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6367
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6368 std::string mode = arg.string_value ();
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6369
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6370 if (error_state)
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6371 error ("issorted: expecting %s argument to be a character string", argn);
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6372 else if (mode == "ascending")
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6373 smode = ASCENDING;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6374 else if (mode == "descending")
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6375 smode = DESCENDING;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6376 else if (mode == "either")
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6377 smode = UNSORTED;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6378 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6379 error ("issorted: MODE must be \"ascending\", \"descending\", or \"either\"");
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6380
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6381 return smode;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6382 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6383
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6384 DEFUN (issorted, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6385 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6386 @deftypefn {Built-in Function} {} issorted (@var{a})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6387 @deftypefnx {Built-in Function} {} issorted (@var{a}, @var{mode})\n\
12681
c09ed93d1a8b doc: Don't use @code{} within @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
6388 @deftypefnx {Built-in Function} {} issorted (@var{a}, \"rows\", @var{mode})\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
6389 Return true if the array is sorted according to @var{mode}, which\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
6390 may be either @qcode{\"ascending\"}, @qcode{\"descending\"}, or\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
6391 @qcode{\"either\"}. By default, @var{mode} is @qcode{\"ascending\"}. NaNs\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
6392 are treated in the same manner as @code{sort}.\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
6393 \n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17268
diff changeset
6394 If the optional argument @qcode{\"rows\"} is supplied, check whether\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
6395 the array is sorted by rows as output by the function @code{sortrows}\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
6396 (with no options).\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
6397 \n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
6398 This function does not support sparse matrices.\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11422
diff changeset
6399 @seealso{sort, sortrows}\n\
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6400 @end deftypefn\n")
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6401 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6402 octave_value retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6403
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6404 int nargin = args.length ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6405
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6406 if (nargin < 1 || nargin > 3)
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6407 {
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6408 print_usage ();
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6409 return retval;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6410 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6411
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6412 bool by_rows = false;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6413
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6414 sortmode smode = ASCENDING;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6415
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6416 if (nargin > 1)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6417 {
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6418 octave_value mode_arg;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6419
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6420 if (nargin == 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6421 smode = get_sort_mode_option (args(2), "third");
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6422
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6423 std::string tmp = args(1).string_value ();
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6424
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6425 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6426 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6427 if (tmp == "rows")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6428 by_rows = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6429 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6430 smode = get_sort_mode_option (args(1), "second");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6431 }
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6432 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6433 error ("expecting second argument to be character string");
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6434
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6435 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6436 return retval;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6437 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6438
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6439 octave_value arg = args(0);
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6440
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6441 if (by_rows)
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6442 {
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6443 if (arg.is_sparse_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6444 error ("issorted: sparse matrices not yet supported");
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6445 if (arg.ndims () == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6446 retval = arg.is_sorted_rows (smode) != UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6447 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6448 error ("issorted: A must be a 2-dimensional object");
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6449 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6450 else
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6451 {
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6452 if (arg.dims ().is_vector ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6453 retval = args(0).is_sorted (smode) != UNSORTED;
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6454 else
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6455 error ("issorted: needs a vector");
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6456 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6457
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6458 return retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6459 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6460
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6461 /*
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6462 %!shared sm, um, sv, uv
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6463 %! sm = [1, 2; 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6464 %! um = [3, 1; 2, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6465 %! sv = [1, 2, 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6466 %! uv = [2, 1, 4, 3];
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6467 %!assert (issorted (sm, "rows"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6468 %!assert (!issorted (um, "rows"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6469 %!assert (issorted (sv))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6470 %!assert (!issorted (uv))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6471 %!assert (issorted (sv'))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6472 %!assert (!issorted (uv'))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6473 %!assert (issorted (sm, "rows", "ascending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6474 %!assert (!issorted (um, "rows", "ascending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6475 %!assert (issorted (sv, "ascending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6476 %!assert (!issorted (uv, "ascending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6477 %!assert (issorted (sv', "ascending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6478 %!assert (!issorted (uv', "ascending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6479 %!assert (!issorted (sm, "rows", "descending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6480 %!assert (issorted (flipud (sm), "rows", "descending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6481 %!assert (!issorted (sv, "descending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6482 %!assert (issorted (fliplr (sv), "descending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6483 %!assert (!issorted (sv', "descending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6484 %!assert (issorted (fliplr (sv)', "descending"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6485 %!assert (!issorted (um, "rows", "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6486 %!assert (!issorted (uv, "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6487 %!assert (issorted (sm, "rows", "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6488 %!assert (issorted (flipud (sm), "rows", "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6489 %!assert (issorted (sv, "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6490 %!assert (issorted (fliplr (sv), "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6491 %!assert (issorted (sv', "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6492 %!assert (issorted (fliplr (sv)', "either"))
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6493 */
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
6494
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6495 DEFUN (nth_element, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6496 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
6497 @deftypefn {Built-in Function} {} nth_element (@var{x}, @var{n})\n\
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6498 @deftypefnx {Built-in Function} {} nth_element (@var{x}, @var{n}, @var{dim})\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
6499 Select the n-th smallest element of a vector, using the ordering defined by\n\
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
6500 @code{sort}. In other words, the result is equivalent to\n\
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
6501 @code{sort(@var{x})(@var{n})}.\n\
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6502 @var{n} can also be a contiguous range, either ascending @code{l:u}\n\
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6503 or descending @code{u:-1:l}, in which case a range of elements is returned.\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6504 If @var{x} is an array, @code{nth_element} operates along the dimension\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6505 defined by @var{dim}, or the first non-singleton dimension if @var{dim} is\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6506 not given.\n\
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6507 \n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
6508 nth_element encapsulates the C++ standard library algorithms nth_element and\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6509 partial_sort. On average, the complexity of the operation is O(M*log(K)),\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6510 where @w{@code{M = size (@var{x}, @var{dim})}} and\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
6511 @w{@code{K = length (@var{n})}}.\n\
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6512 This function is intended for cases where the ratio K/M is small; otherwise,\n\
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6513 it may be better to use @code{sort}.\n\
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6514 @seealso{sort, min, max}\n\
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6515 @end deftypefn")
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6516 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6517 octave_value retval;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6518 int nargin = args.length ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6519
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6520 if (nargin == 2 || nargin == 3)
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6521 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6522 octave_value argx = args(0);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6523
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6524 int dim = -1;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6525 if (nargin == 3)
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6526 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6527 dim = args(2).int_value (true) - 1;
10703
5eb420d92307 fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents: 10695
diff changeset
6528 if (dim < 0)
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6529 error ("nth_element: DIM must be a valid dimension");
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6530 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6531 if (dim < 0)
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6532 dim = argx.dims ().first_non_singleton ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6533
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6534 idx_vector n = args(1).index_vector ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6535
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6536 if (error_state)
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6537 return retval;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6538
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6539 switch (argx.builtin_type ())
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6540 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6541 case btyp_double:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6542 retval = argx.array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6543 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6544 case btyp_float:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6545 retval = argx.float_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6546 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6547 case btyp_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6548 retval = argx.complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6549 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6550 case btyp_float_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6551 retval = argx.float_complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6552 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6553 #define MAKE_INT_BRANCH(X) \
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6554 case btyp_ ## X: \
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6555 retval = argx.X ## _array_value ().nth_element (n, dim); \
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6556 break
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6557
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6558 MAKE_INT_BRANCH (int8);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6559 MAKE_INT_BRANCH (int16);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6560 MAKE_INT_BRANCH (int32);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6561 MAKE_INT_BRANCH (int64);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6562 MAKE_INT_BRANCH (uint8);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6563 MAKE_INT_BRANCH (uint16);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6564 MAKE_INT_BRANCH (uint32);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6565 MAKE_INT_BRANCH (uint64);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6566 #undef MAKE_INT_BRANCH
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6567 default:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6568 if (argx.is_cellstr ())
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6569 retval = argx.cellstr_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6570 else
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6571 gripe_wrong_type_arg ("nth_element", argx);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6572 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6573 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6574 else
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6575 print_usage ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6576
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6577 return retval;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6578 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
6579
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6580 template <class NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6581 static NDT
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6582 do_accumarray_sum (const idx_vector& idx, const NDT& vals,
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6583 octave_idx_type n = -1)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6584 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6585 typedef typename NDT::element_type T;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6586 if (n < 0)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6587 n = idx.extent (0);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6588 else if (idx.extent (n) > n)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6589 error ("accumarray: index out of range");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6590
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
6591 NDT retval (dim_vector (n, 1), T ());
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6592
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6593 if (vals.numel () == 1)
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
6594 retval.idx_add (idx, vals (0));
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
6595 else if (vals.numel () == idx.length (n))
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
6596 retval.idx_add (idx, vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6597 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6598 error ("accumarray: dimensions mismatch");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6599
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
6600 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6601 }
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6602
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6603 DEFUN (__accumarray_sum__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6604 "-*- texinfo -*-\n\
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6605 @deftypefn {Built-in Function} {} __accumarray_sum__ (@var{idx}, @var{vals}, @var{n})\n\
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6606 Undocumented internal function.\n\
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6607 @end deftypefn")
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6608 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6609 octave_value retval;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6610 int nargin = args.length ();
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6611 if (nargin >= 2 && nargin <= 3 && args(0).is_numeric_type ())
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6612 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6613 idx_vector idx = args(0).index_vector ();
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6614 octave_idx_type n = -1;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6615 if (nargin == 3)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6616 n = args(2).idx_type_value (true);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6617
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6618 if (! error_state)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6619 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6620 octave_value vals = args(1);
9198
3b9aacf07744 optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9197
diff changeset
6621 if (vals.is_range ())
3b9aacf07744 optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9197
diff changeset
6622 {
3b9aacf07744 optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9197
diff changeset
6623 Range r = vals.range_value ();
3b9aacf07744 optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9197
diff changeset
6624 if (r.inc () == 0)
3b9aacf07744 optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9197
diff changeset
6625 vals = r.base ();
3b9aacf07744 optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9197
diff changeset
6626 }
3b9aacf07744 optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents: 9197
diff changeset
6627
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6628 if (vals.is_single_type ())
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6629 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6630 if (vals.is_complex_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6631 retval = do_accumarray_sum (idx,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6632 vals.float_complex_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6633 n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6634 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6635 retval = do_accumarray_sum (idx, vals.float_array_value (), n);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6636 }
10269
217d36560dfa small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10268
diff changeset
6637 else if (vals.is_numeric_type () || vals.is_bool_type ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6638 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6639 if (vals.is_complex_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6640 retval = do_accumarray_sum (idx,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6641 vals.complex_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6642 n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6643 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6644 retval = do_accumarray_sum (idx, vals.array_value (), n);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6645 }
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6646 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6647 gripe_wrong_type_arg ("accumarray", vals);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6648 }
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6649 }
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6650 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6651 print_usage ();
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6652
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6653 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
6654 }
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
6655
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6656 template <class NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6657 static NDT
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6658 do_accumarray_minmax (const idx_vector& idx, const NDT& vals,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6659 octave_idx_type n, bool ismin,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6660 const typename NDT::element_type& zero_val)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6661 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6662 typedef typename NDT::element_type T;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6663 if (n < 0)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6664 n = idx.extent (0);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6665 else if (idx.extent (n) > n)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6666 error ("accumarray: index out of range");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6667
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6668 NDT retval (dim_vector (n, 1), zero_val);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6669
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6670 // Pick minimizer or maximizer.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6671 void (MArray<T>::*op) (const idx_vector&, const MArray<T>&) =
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
6672 ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6673
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6674 octave_idx_type l = idx.length (n);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6675 if (vals.numel () == 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6676 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0)));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6677 else if (vals.numel () == l)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6678 (retval.*op) (idx, vals);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6679 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6680 error ("accumarray: dimensions mismatch");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6681
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6682 return retval;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6683 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6684
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6685 static octave_value_list
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6686 do_accumarray_minmax_fun (const octave_value_list& args,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6687 bool ismin)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6688 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6689 octave_value retval;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6690 int nargin = args.length ();
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6691 if (nargin >= 3 && nargin <= 4 && args(0).is_numeric_type ())
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6692 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6693 idx_vector idx = args(0).index_vector ();
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6694 octave_idx_type n = -1;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6695 if (nargin == 4)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6696 n = args(3).idx_type_value (true);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6697
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6698 if (! error_state)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6699 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6700 octave_value vals = args(1), zero = args (2);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6701
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6702 switch (vals.builtin_type ())
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6703 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6704 case btyp_double:
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6705 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6706 zero.double_value ());
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6707 break;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6708 case btyp_float:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6709 retval = do_accumarray_minmax (idx, vals.float_array_value (), n,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6710 ismin, zero.float_value ());
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6711 break;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6712 case btyp_complex:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6713 retval = do_accumarray_minmax (idx, vals.complex_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6714 n, ismin, zero.complex_value ());
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6715 break;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6716 case btyp_float_complex:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6717 retval = do_accumarray_minmax (idx,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6718 vals.float_complex_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6719 n, ismin,
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6720 zero.float_complex_value ());
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6721 break;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6722 #define MAKE_INT_BRANCH(X) \
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6723 case btyp_ ## X: \
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6724 retval = do_accumarray_minmax (idx, vals.X ## _array_value (), \
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6725 n, ismin, \
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6726 zero.X ## _scalar_value ()); \
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6727 break
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6728
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6729 MAKE_INT_BRANCH (int8);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6730 MAKE_INT_BRANCH (int16);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6731 MAKE_INT_BRANCH (int32);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6732 MAKE_INT_BRANCH (int64);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6733 MAKE_INT_BRANCH (uint8);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6734 MAKE_INT_BRANCH (uint16);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6735 MAKE_INT_BRANCH (uint32);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6736 MAKE_INT_BRANCH (uint64);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6737 #undef MAKE_INT_BRANCH
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6738 case btyp_bool:
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6739 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6740 zero.bool_value ());
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6741 break;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6742 default:
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6743 gripe_wrong_type_arg ("accumarray", vals);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6744 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6745 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6746 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6747 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6748 print_usage ();
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6749
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6750 return retval;
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6751 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6752
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6753 DEFUN (__accumarray_min__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6754 "-*- texinfo -*-\n\
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6755 @deftypefn {Built-in Function} {} __accumarray_min__ (@var{idx}, @var{vals}, @var{zero}, @var{n})\n\
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6756 Undocumented internal function.\n\
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6757 @end deftypefn")
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6758 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6759 return do_accumarray_minmax_fun (args, true);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6760 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6761
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6762 DEFUN (__accumarray_max__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6763 "-*- texinfo -*-\n\
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6764 @deftypefn {Built-in Function} {} __accumarray_max__ (@var{idx}, @var{vals}, @var{zero}, @var{n})\n\
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6765 Undocumented internal function.\n\
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6766 @end deftypefn")
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6767 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6768 return do_accumarray_minmax_fun (args, false);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6769 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6770
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
6771 template <class NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6772 static NDT
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6773 do_accumdim_sum (const idx_vector& idx, const NDT& vals,
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6774 int dim = -1, octave_idx_type n = -1)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6775 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6776 typedef typename NDT::element_type T;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6777 if (n < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6778 n = idx.extent (0);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6779 else if (idx.extent (n) > n)
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
6780 error ("accumdim: index out of range");
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
6781
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
6782 dim_vector vals_dim = vals.dims (), rdv = vals_dim;
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
6783
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6784 if (dim < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6785 dim = vals.dims ().first_non_singleton ();
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6786 else if (dim >= rdv.length ())
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6787 rdv.resize (dim+1, 1);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6788
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6789 rdv(dim) = n;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6790
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14843
diff changeset
6791 NDT retval (rdv, T ());
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6792
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
6793 if (idx.length () != vals_dim(dim))
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
6794 error ("accumdim: dimension mismatch");
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
6795
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6796 retval.idx_add_nd (idx, vals, dim);
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
6797
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6798 return retval;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6799 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6800
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6801 DEFUN (__accumdim_sum__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6802 "-*- texinfo -*-\n\
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6803 @deftypefn {Built-in Function} {} __accumdim_sum__ (@var{idx}, @var{vals}, @var{dim}, @var{n})\n\
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6804 Undocumented internal function.\n\
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6805 @end deftypefn")
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6806 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6807 octave_value retval;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6808 int nargin = args.length ();
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6809 if (nargin >= 2 && nargin <= 4 && args(0).is_numeric_type ())
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6810 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6811 idx_vector idx = args(0).index_vector ();
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6812 int dim = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6813 if (nargin >= 3)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6814 dim = args(2).int_value () - 1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6815
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6816 octave_idx_type n = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6817 if (nargin == 4)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6818 n = args(3).idx_type_value (true);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6819
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6820 if (! error_state)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6821 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6822 octave_value vals = args(1);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6823
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6824 if (vals.is_single_type ())
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6825 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6826 if (vals.is_complex_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6827 retval = do_accumdim_sum (idx,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6828 vals.float_complex_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6829 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6830 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6831 retval = do_accumdim_sum (idx, vals.float_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6832 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6833 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6834 else if (vals.is_numeric_type () || vals.is_bool_type ())
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6835 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6836 if (vals.is_complex_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6837 retval = do_accumdim_sum (idx, vals.complex_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6838 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6839 else
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6840 retval = do_accumdim_sum (idx, vals.array_value (), dim, n);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6841 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6842 else
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6843 gripe_wrong_type_arg ("accumdim", vals);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6844 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6845 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6846 else
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6847 print_usage ();
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6848
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6849 return retval;
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6850 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6851
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
6852 template <class NDT>
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6853 static NDT
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6854 do_merge (const Array<bool>& mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6855 const NDT& tval, const NDT& fval)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6856 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6857 typedef typename NDT::element_type T;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6858 dim_vector dv = mask.dims ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6859 NDT retval (dv);
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6860
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6861 bool tscl = tval.numel () == 1, fscl = fval.numel () == 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6862
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6863 if ((! tscl && tval.dims () != dv)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6864 || (! fscl && fval.dims () != dv))
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
6865 error ("merge: MASK, TVAL, and FVAL dimensions must match");
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6866 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6867 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6868 T *rv = retval.fortran_vec ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6869 octave_idx_type n = retval.numel ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6870
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6871 const T *tv = tval.data (), *fv = fval.data ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6872 const bool *mv = mask.data ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6873
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6874 if (tscl)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6875 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6876 if (fscl)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6877 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6878 T ts = tv[0], fs = fv[0];
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6879 for (octave_idx_type i = 0; i < n; i++)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6880 rv[i] = mv[i] ? ts : fs;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6881 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6882 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6883 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6884 T ts = tv[0];
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6885 for (octave_idx_type i = 0; i < n; i++)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6886 rv[i] = mv[i] ? ts : fv[i];
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6887 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6888 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6889 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6890 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6891 if (fscl)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6892 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6893 T fs = fv[0];
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6894 for (octave_idx_type i = 0; i < n; i++)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6895 rv[i] = mv[i] ? tv[i] : fs;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6896 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6897 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6898 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6899 for (octave_idx_type i = 0; i < n; i++)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6900 rv[i] = mv[i] ? tv[i] : fv[i];
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6901 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6902 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6903 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6904
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6905 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6906 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6907
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6908 #define MAKE_INT_BRANCH(INTX) \
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6909 else if (tval.is_ ## INTX ## _type () && fval.is_ ## INTX ## _type ()) \
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6910 { \
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6911 retval = do_merge (mask, \
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6912 tval.INTX ## _array_value (), \
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6913 fval.INTX ## _array_value ()); \
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6914 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6915
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
6916 DEFUN (merge, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6917 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
6918 @deftypefn {Built-in Function} {} merge (@var{mask}, @var{tval}, @var{fval})\n\
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
6919 @deftypefnx {Built-in Function} {} ifelse (@var{mask}, @var{tval}, @var{fval})\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11570
diff changeset
6920 Merge elements of @var{true_val} and @var{false_val}, depending on the\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6921 value of @var{mask}. If @var{mask} is a logical scalar, the other two\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6922 arguments can be arbitrary values. Otherwise, @var{mask} must be a logical\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6923 array, and @var{tval}, @var{fval} should be arrays of matching class, or\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6924 cell arrays. In the scalar mask case, @var{tval} is returned if @var{mask}\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6925 is true, otherwise @var{fval} is returned.\n\
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6926 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6927 In the array mask case, both @var{tval} and @var{fval} must be either\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
6928 scalars or arrays with dimensions equal to @var{mask}. The result is\n\
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12639
diff changeset
6929 constructed as follows:\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
6930 \n\
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6931 @example\n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9736
diff changeset
6932 @group\n\
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6933 result(mask) = tval(mask);\n\
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6934 result(! mask) = fval(! mask);\n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9736
diff changeset
6935 @end group\n\
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6936 @end example\n\
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6937 \n\
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6938 @var{mask} can also be arbitrary numeric type, in which case\n\
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6939 it is first converted to logical.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
6940 @seealso{logical, diff}\n\
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6941 @end deftypefn")
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6942 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6943 int nargin = args.length ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6944 octave_value retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6945
9856
870a69bac55c fix test in merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9848
diff changeset
6946 if (nargin == 3 && (args(0).is_bool_type () || args(0).is_numeric_type ()))
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6947 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6948 octave_value mask_val = args(0);
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6949
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6950 if (mask_val.is_scalar_type ())
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6951 retval = mask_val.is_true () ? args(1) : args(2);
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6952 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6953 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6954 boolNDArray mask = mask_val.bool_array_value ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6955 octave_value tval = args(1), fval = args(2);
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6956 if (tval.is_double_type () && fval.is_double_type ())
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6957 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6958 if (tval.is_complex_type () || fval.is_complex_type ())
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6959 retval = do_merge (mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6960 tval.complex_array_value (),
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6961 fval.complex_array_value ());
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6962 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6963 retval = do_merge (mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6964 tval.array_value (),
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6965 fval.array_value ());
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6966 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6967 else if (tval.is_single_type () && fval.is_single_type ())
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6968 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6969 if (tval.is_complex_type () || fval.is_complex_type ())
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6970 retval = do_merge (mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6971 tval.float_complex_array_value (),
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6972 fval.float_complex_array_value ());
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6973 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6974 retval = do_merge (mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6975 tval.float_array_value (),
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6976 fval.float_array_value ());
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6977 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6978 else if (tval.is_string () && fval.is_string ())
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6979 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6980 bool sq_string = tval.is_sq_string () || fval.is_sq_string ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6981 retval = octave_value (do_merge (mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6982 tval.char_array_value (),
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6983 fval.char_array_value ()),
9689
34d6f005db4b eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents: 9685
diff changeset
6984 sq_string ? '\'' : '"');
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6985 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6986 else if (tval.is_cell () && fval.is_cell ())
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6987 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6988 retval = do_merge (mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6989 tval.cell_value (),
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6990 fval.cell_value ());
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6991 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6992
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6993 MAKE_INT_BRANCH (int8)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6994 MAKE_INT_BRANCH (int16)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6995 MAKE_INT_BRANCH (int32)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6996 MAKE_INT_BRANCH (int64)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6997 MAKE_INT_BRANCH (uint8)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6998 MAKE_INT_BRANCH (uint16)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
6999 MAKE_INT_BRANCH (uint32)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7000 MAKE_INT_BRANCH (uint64)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7001
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7002 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7003 error ("merge: cannot merge %s with %s with array mask",
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7004 tval.class_name ().c_str (),
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7005 fval.class_name ().c_str ());
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7006 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7007 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7008 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7009 print_usage ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7010
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7011 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7012 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7013
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
7014 DEFALIAS (ifelse, merge);
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
7015
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7016 #undef MAKE_INT_BRANCH
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7017
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7018 template <class SparseT>
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7019 static SparseT
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7020 do_sparse_diff (const SparseT& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7021 int dim)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7022 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7023 SparseT retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7024 if (dim == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7025 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7026 octave_idx_type k = retval.columns ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7027 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7028 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7029 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7030 retval = SparseT (retval.index (col1, sl1))
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7031 - SparseT (retval.index (col2, sl2));
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7032 assert (retval.columns () == k-1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7033 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7034 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7035 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7036 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7037 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7038 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7039 octave_idx_type k = retval.rows ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7040 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7041 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7042 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7043 retval = SparseT (retval.index (sl1, col1))
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7044 - SparseT (retval.index (sl2, col2));
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7045 assert (retval.rows () == k-1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7046 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7047 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7048 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7049 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7050
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7051 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7052 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7053
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7054 static octave_value
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7055 do_diff (const octave_value& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7056 int dim = -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7057 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7058 octave_value retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7059
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7060 const dim_vector& dv = array.dims ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7061 if (dim == -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7062 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7063 dim = array.dims ().first_non_singleton ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7064
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7065 // Bother Matlab. This behavior is really wicked.
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7066 if (dv(dim) <= order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7067 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7068 if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7069 retval = array.resize (dim_vector (0, 0));
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7070 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7071 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7072 retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7073 while (order > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7074 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7075 if (dim == dv.length ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7076 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7077 retval = do_diff (array, order, dim - 1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7078 order = 0;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7079 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7080 else if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7081 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7082 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7083 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7084 retval = do_diff (array, dv(dim) - 1, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7085 order -= dv(dim) - 1;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7086 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7087 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7088 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7089 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7090
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7091 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7092 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7093 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7094
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7095 if (array.is_integer_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7096 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7097 if (array.is_int8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7098 retval = array.int8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7099 else if (array.is_int16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7100 retval = array.int16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7101 else if (array.is_int32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7102 retval = array.int32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7103 else if (array.is_int64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7104 retval = array.int64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7105 else if (array.is_uint8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7106 retval = array.uint8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7107 else if (array.is_uint16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7108 retval = array.uint16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7109 else if (array.is_uint32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7110 retval = array.uint32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7111 else if (array.is_uint64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7112 retval = array.uint64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7113 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7114 panic_impossible ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7115 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7116 else if (array.is_sparse_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7117 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7118 if (array.is_complex_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7119 retval = do_sparse_diff (array.sparse_complex_matrix_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7120 order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7121 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7122 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7123 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7124 else if (array.is_single_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7125 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7126 if (array.is_complex_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7127 retval = array.float_complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7128 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7129 retval = array.float_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7130 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7131 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7132 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7133 if (array.is_complex_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7134 retval = array.complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7135 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7136 retval = array.array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7137 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7138
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7139 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7140 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7141
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7142 DEFUN (diff, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7143 "-*- texinfo -*-\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
7144 @deftypefn {Built-in Function} {} diff (@var{x})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
7145 @deftypefnx {Built-in Function} {} diff (@var{x}, @var{k})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
7146 @deftypefnx {Built-in Function} {} diff (@var{x}, @var{k}, @var{dim})\n\
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
7147 If @var{x} is a vector of length @math{n}, @code{diff (@var{x})} is the\n\
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7148 vector of first differences\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7149 @tex\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7150 $x_2 - x_1, \\ldots{}, x_n - x_{n-1}$.\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7151 @end tex\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7152 @ifnottex\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7153 @var{x}(2) - @var{x}(1), @dots{}, @var{x}(n) - @var{x}(n-1).\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7154 @end ifnottex\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7155 \n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7156 If @var{x} is a matrix, @code{diff (@var{x})} is the matrix of column\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7157 differences along the first non-singleton dimension.\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7158 \n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7159 The second argument is optional. If supplied, @code{diff (@var{x},\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7160 @var{k})}, where @var{k} is a non-negative integer, returns the\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7161 @var{k}-th differences. It is possible that @var{k} is larger than\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
7162 the first non-singleton dimension of the matrix. In this case,\n\
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7163 @code{diff} continues to take the differences along the next\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7164 non-singleton dimension.\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7165 \n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7166 The dimension along which to take the difference can be explicitly\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
7167 stated with the optional variable @var{dim}. In this case the\n\
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7168 @var{k}-th order differences are calculated along this dimension.\n\
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7169 In the case where @var{k} exceeds @code{size (@var{x}, @var{dim})}\n\
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12584
diff changeset
7170 an empty matrix is returned.\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
7171 @seealso{sort, merge}\n\
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7172 @end deftypefn")
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7173 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7174 int nargin = args.length ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7175 octave_value retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7176
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7177 if (nargin < 1 || nargin > 3)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7178 print_usage ();
10880
92c3e8068f28 allow diff(logical)
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
7179 else if (! (args(0).is_numeric_type () || args(0).is_bool_type ()))
92c3e8068f28 allow diff(logical)
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
7180 error ("diff: X must be numeric or logical");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7181
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7182 if (! error_state)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7183 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7184 int dim = -1;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7185 octave_idx_type order = 1;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7186 if (nargin > 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7187 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7188 if (args(1).is_scalar_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7189 order = args(1).idx_type_value (true, false);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7190 else if (! args(1).is_zero_by_zero ())
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
7191 error ("order K must be a scalar or []");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7192 if (! error_state && order < 0)
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
7193 error ("order K must be non-negative");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7194 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7195
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7196 if (nargin > 2)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7197 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7198 dim = args(2).int_value (true, false);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7199 if (! error_state && (dim < 1 || dim > args(0).ndims ()))
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
7200 error ("DIM must be a valid dimension");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7201 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7202 dim -= 1;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7203 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7204
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7205 if (! error_state)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7206 retval = do_diff (args(0), order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7207 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7208
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7209 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7210 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7211
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7212 /*
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7213 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7214 %!assert (diff ([1, 3, 7, 19], 2), [2, 8])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7215 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1]), [4, 2; 3, 3; 1, -1; -6, -5])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7216 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1], 3), [-1, -5; -5, 0])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7217 %!assert (isempty (diff (1)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7218
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7219 %!error diff ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7220 %!error diff (1, 2, 3, 4)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7221 %!error diff ("foo")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7222 %!error diff ([1, 2; 3, 4], -1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
7223 */
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7224
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7225 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7226 static Array<T>
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7227 do_repelems (const Array<T>& src, const Array<octave_idx_type>& rep)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7228 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7229 Array<T> retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7230
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7231 assert (rep.ndims () == 2 && rep.rows () == 2);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7232
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7233 octave_idx_type n = rep.columns (), l = 0;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7234 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7235 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7236 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7237 if (k < 0)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7238 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
7239 error ("repelems: second row must contain non-negative numbers");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7240 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7241 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7242
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7243 l += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7244 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7245
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7246 retval.clear (1, l);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7247 T *dest = retval.fortran_vec ();
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7248 l = 0;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7249 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7250 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7251 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7252 std::fill_n (dest, k, src.checkelem (rep(0, i) - 1));
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7253 dest += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7254 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7255
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7256 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7257 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7258
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7259 DEFUN (repelems, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7260 "-*- texinfo -*-\n\
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7261 @deftypefn {Built-in Function} {} repelems (@var{x}, @var{r})\n\
10801
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7262 Construct a vector of repeated elements from @var{x}. @var{r}\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7263 is a 2x@var{N} integer matrix specifying which elements to repeat and\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7264 how often to repeat each element.\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7265 \n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7266 Entries in the first row, @var{r}(1,j), select an element to repeat.\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7267 The corresponding entry in the second row, @var{r}(2,j), specifies\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7268 the repeat count. If @var{x} is a matrix then the columns of @var{x} are\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7269 imagined to be stacked on top of each other for purposes of the selection\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7270 index. A row vector is always returned.\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7271 \n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7272 Conceptually the result is calculated as follows:\n\
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7273 \n\
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7274 @example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
7275 @group\n\
10801
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7276 y = [];\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7277 for i = 1:columns (@var{r})\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7278 y = [y, @var{x}(@var{r}(1,i)*ones(1, @var{r}(2,i)))];\n\
a40e32927b3a Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents: 10799
diff changeset
7279 endfor\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10801
diff changeset
7280 @end group\n\
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7281 @end example\n\
15028
397f0d80bd47 Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents: 15024
diff changeset
7282 @seealso{repmat, cat}\n\
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7283 @end deftypefn")
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7284 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7285 octave_value retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7286
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7287 if (args.length () == 2)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7288 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7289 octave_value x = args(0);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7290
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7291 const Matrix rm = args(1).matrix_value ();
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7292 if (error_state)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7293 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7294 else if (rm.rows () != 2 || rm.ndims () != 2)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7295 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
7296 error ("repelems: R must be a matrix with two rows");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7297 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7298 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7299 else
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7300 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7301 NoAlias< Array<octave_idx_type> > r (rm.dims ());
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7302
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7303 for (octave_idx_type i = 0; i < rm.numel (); i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7304 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7305 octave_idx_type rx = rm(i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7306 if (static_cast<double> (rx) != rm(i))
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7307 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11591
diff changeset
7308 error ("repelems: R must be a matrix of integers");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7309 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7310 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7311
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7312 r(i) = rx;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7313 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7314
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7315 switch (x.builtin_type ())
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7316 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7317 #define BTYP_BRANCH(X, EX) \
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7318 case btyp_ ## X: \
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7319 retval = do_repelems (x.EX ## _value (), r); \
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7320 break
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7321
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7322 BTYP_BRANCH (double, array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7323 BTYP_BRANCH (float, float_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7324 BTYP_BRANCH (complex, complex_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7325 BTYP_BRANCH (float_complex, float_complex_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7326 BTYP_BRANCH (bool, bool_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7327 BTYP_BRANCH (char, char_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7328
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7329 BTYP_BRANCH (int8, int8_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7330 BTYP_BRANCH (int16, int16_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7331 BTYP_BRANCH (int32, int32_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7332 BTYP_BRANCH (int64, int64_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7333 BTYP_BRANCH (uint8, uint8_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7334 BTYP_BRANCH (uint16, uint16_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7335 BTYP_BRANCH (uint32, uint32_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7336 BTYP_BRANCH (uint64, uint64_array);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7337
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7338 BTYP_BRANCH (cell, cell);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7339 //BTYP_BRANCH (struct, map);//FIXME
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7340 #undef BTYP_BRANCH
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7341
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7342 default:
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7343 gripe_wrong_type_arg ("repelems", x);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7344 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7345 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7346 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7347 else
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7348 print_usage ();
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7349
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7350 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
7351 }
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7352
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7353 DEFUN (base64_encode, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7354 "-*- texinfo -*-\n\
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7355 @deftypefn {Built-in Function} {@var{s} =} base64_encode (@var{x})\n\
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7356 Encode a double matrix or array @var{x} into the base64 format string\n\
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7357 @var{s}.\n\
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7358 \n\
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7359 @seealso{base64_decode}\n\
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7360 @end deftypefn")
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7361 {
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7362 octave_value_list retval;
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7363 int nargin = args.length ();
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7364
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7365 if (nargin != 1)
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7366 print_usage ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7367 else
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7368 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7369 if (! args(0).is_numeric_type ())
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7370 error ("base64_encode: encoding is supported only for numeric arrays");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7371 else if (args(0).is_complex_type ()
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7372 || args(0).is_sparse_type ())
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7373 error ("base64_encode: encoding complex or sparse data is not supported");
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7374 else if (args(0).is_integer_type ())
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7375 {
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7376 #define MAKE_INT_BRANCH(X) \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7377 if (args(0).is_ ## X ## _type ()) \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7378 { \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7379 const X##NDArray in = args(0). X## _array_value (); \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7380 size_t inlen = \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7381 in.numel () * sizeof (X## _t) / sizeof (char); \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7382 const char* inc = \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7383 reinterpret_cast<const char*> (in.data ()); \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7384 char* out; \
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7385 if (! error_state \
17621
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7386 && octave_base64_encode (inc, inlen, &out)) \
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7387 { \
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7388 retval(0) = octave_value (out); \
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7389 ::free (out); \
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7390 } \
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7391 }
17621
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7392
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7393 MAKE_INT_BRANCH(int8)
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7394 else MAKE_INT_BRANCH(int16)
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7395 else MAKE_INT_BRANCH(int32)
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7396 else MAKE_INT_BRANCH(int64)
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7397 else MAKE_INT_BRANCH(uint8)
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7398 else MAKE_INT_BRANCH(uint16)
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7399 else MAKE_INT_BRANCH(uint32)
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7400 else MAKE_INT_BRANCH(uint64)
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7401 #undef MAKE_INT_BRANCH
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7402
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7403 else
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7404 panic_impossible ();
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7405 }
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7406 else if (args(0).is_single_type ())
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7407 {
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7408 const Array<float> in = args(0).float_array_value ();
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7409 size_t inlen;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7410 inlen = in.numel () * sizeof (float) / sizeof (char);
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7411 const char* inc;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7412 inc = reinterpret_cast<const char*> (in.data ());
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7413 char* out;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7414 if (! error_state
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7415 && octave_base64_encode (inc, inlen, &out))
17621
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7416 {
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7417 retval(0) = octave_value (out);
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7418 ::free (out);
d41c8f96ed06 avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
7419 }
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7420 }
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7421 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7422 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7423 const Array<double> in = args(0).array_value ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7424 size_t inlen;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7425 inlen = in.numel () * sizeof (double) / sizeof (char);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7426 const char* inc;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7427 inc = reinterpret_cast<const char*> (in.data ());
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7428 char* out;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7429 if (! error_state
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7430 && octave_base64_encode (inc, inlen, &out))
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7431 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7432 retval(0) = octave_value (out);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7433 ::free (out);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7434 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7435 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7436 }
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7437 return retval;
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7438 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7439
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7440 /*
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7441 %!assert (base64_encode (single (pi)), "2w9JQA==")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7442 %!assert (base64_encode (uint8 ([0 0 0])), "AAAA")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7443 %!assert (base64_encode (uint16 ([0 0 0])), "AAAAAAAA")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7444 %!assert (base64_encode (uint32 ([0 0 0])), "AAAAAAAAAAAAAAAA")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7445 %!assert (base64_encode (uint64 ([0 0 0])), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7446 %!assert (base64_encode (uint8 ([255 255 255])), "////")
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7447
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7448 %!error base64_encode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7449 %!error base64_encode (1,2)
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7450 %!error base64_encode ("A string")
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7451 %!error base64_encode ({"A cell array"})
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7452 %!error base64_encode (struct ())
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7453 */
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7454
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7455 DEFUN (base64_decode, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7456 "-*- texinfo -*-\n\
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7457 @deftypefn {Built-in Function} {@var{x} =} base64_decode (@var{s})\n\
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7458 @deftypefnx {Built-in Function} {@var{x} =} base64_decode (@var{s}, @var{dims})\n\
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7459 Decode the double matrix or array @var{x} from the base64 encoded string\n\
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7460 @var{s}. The optional input parameter @var{dims} should be a vector\n\
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7461 containing the dimensions of the decoded array.\n\
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7462 @seealso{base64_encode}\n\
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7463 @end deftypefn")
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7464 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7465 octave_value retval;
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7466
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7467 int nargin = args.length ();
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7468
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7469 if (nargin < 1 || nargin > 2)
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7470 print_usage ();
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7471 else
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7472 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7473 dim_vector dims;
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7474
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7475 if (nargin > 1)
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7476 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7477 const Array<octave_idx_type> size =
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
7478 args(1).octave_idx_type_vector_value ();
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7479
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7480 if (! error_state)
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7481 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7482 dims = dim_vector::alloc (size.length ());
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7483 for (octave_idx_type i = 0; i < size.length (); i++)
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7484 dims(i) = size(i);
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7485 }
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7486 }
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7487
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7488 const std::string str = args(0).string_value ();
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7489
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7490 if (! error_state)
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7491 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7492 Array<double> res = octave_base64_decode (str);
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7493
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7494 if (nargin > 1)
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7495 res = res.reshape (dims);
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7496
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
7497 retval = res;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7498 }
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7499 }
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7500
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7501 return retval;
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7502 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7503
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7504 /*
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7505 %!assert (base64_decode (base64_encode (pi)), pi)
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7506 %!
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7507 %!test
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7508 %! in = randn (10);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7509 %! outv = base64_decode (base64_encode (in));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7510 %! outm = base64_decode (base64_encode (in), size (in));
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7511 %! assert (outv, in(:).');
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7512 %! assert (outm, in);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7513
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7514 %!error base64_decode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7515 %!error base64_decode (1,2,3)
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7516 %!error base64_decode (1, "this is not a valid set of dimensions")
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7517 %!error <input was not valid base64> base64_decode (1)
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7518 %!error <input was not valid base64> base64_decode ("AQ=")
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
7519 %!error <incorrect input size> base64_decode ("AQ==")
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
7520 */