annotate liboctave/util/oct-binmap.h @ 21244:1473547f50f5

include octave-config.h in public header files * mk-opts.pl, mkbuiltins, mk-ops.awk, sparse-mk-ops.awk: Emit "#include octave-config.h" statement for generated header files. * build-env.h, builtins.h, Cell.h, base-text-renderer.h, c-file-ptr-stream.h, cdisplay.h, comment-list.h, data.h, debug.h, defaults.in.h, defun-dld.h, defun-int.h, defun.h, dirfns.h, display.h, dynamic-ld.h, error.h, errwarn.h, event-queue.h, file-io.h, ft-text-renderer.h, gl-render.h, gl2ps-print.h, graphics.in.h, gripes.h, help.h, hook-fcn.h, input.h, jit-ir.h, jit-typeinfo.h, jit-util.h, load-path.h, load-save.h, ls-ascii-helper.h, ls-hdf5.h, ls-mat-ascii.h, ls-mat4.h, ls-mat5.h, ls-oct-binary.h, ls-oct-text.h, ls-utils.h, mex.h, mexproto.h, mxarray.in.h, oct-errno.h, oct-fstrm.h, oct-handle.h, oct-hdf5-types.h, oct-hdf5.h, oct-hist.h, oct-iostrm.h, oct-lvalue.h, oct-map.h, oct-obj.h, oct-opengl.h, oct-prcstrm.h, oct-procbuf.h, oct-stdstrm.h, oct-stream.h, oct-strstrm.h, oct.h, octave-default-image.h, octave-link.h, octave-preserve-stream-state.h, pager.h, pr-output.h, procstream.h, profiler.h, pt-jit.h, sighandlers.h, siglist.h, sparse-xdiv.h, sparse-xpow.h, symtab.h, sysdep.h, text-renderer.h, toplev.h, txt-eng.h, utils.h, variables.h, workspace-element.h, xdiv.h, xnorm.h, xpow.h, zfstream.h, oct-qhull.h, ov-base-diag.h, ov-base-int.h, ov-base-mat.h, ov-base-scalar.h, ov-base-sparse.h, ov-base.h, ov-bool-mat.h, ov-bool-sparse.h, ov-bool.h, ov-builtin.h, ov-cell.h, ov-ch-mat.h, ov-class.h, ov-classdef.h, ov-colon.h, ov-complex.h, ov-cs-list.h, ov-cx-diag.h, ov-cx-mat.h, ov-cx-sparse.h, ov-dld-fcn.h, ov-fcn-handle.h, ov-fcn-inline.h, ov-fcn.h, ov-float.h, ov-flt-complex.h, ov-flt-cx-diag.h, ov-flt-cx-mat.h, ov-flt-re-diag.h, ov-flt-re-mat.h, ov-int-traits.h, ov-int16.h, ov-int32.h, ov-int64.h, ov-int8.h, ov-intx.h, ov-java.h, ov-lazy-idx.h, ov-mex-fcn.h, ov-null-mat.h, ov-oncleanup.h, ov-perm.h, ov-range.h, ov-re-diag.h, ov-re-mat.h, ov-re-sparse.h, ov-scalar.h, ov-str-mat.h, ov-struct.h, ov-type-conv.h, ov-typeinfo.h, ov-uint16.h, ov-uint32.h, ov-uint64.h, ov-uint8.h, ov-usr-fcn.h, ov.h, ovl.h, octave.h, op-int.h, ops.h, options-usage.h, lex.h, parse.h, pt-all.h, pt-arg-list.h, pt-array-list.h, pt-assign.h, pt-binop.h, pt-bp.h, pt-cbinop.h, pt-cell.h, pt-check.h, pt-classdef.h, pt-cmd.h, pt-colon.h, pt-const.h, pt-decl.h, pt-eval.h, pt-except.h, pt-exp.h, pt-fcn-handle.h, pt-funcall.h, pt-id.h, pt-idx.h, pt-jump.h, pt-loop.h, pt-mat.h, pt-misc.h, pt-pr-code.h, pt-select.h, pt-stmt.h, pt-unop.h, pt-walk.h, pt.h, token.h, version.in.h, Array-util.h, Array.h, CColVector.h, CDiagMatrix.h, CMatrix.h, CNDArray.h, CRowVector.h, CSparse.h, DiagArray2.h, MArray.h, MDiagArray2.h, MSparse.h, Matrix.h, MatrixType.h, PermMatrix.h, Range.h, Sparse.h, boolMatrix.h, boolNDArray.h, boolSparse.h, chMatrix.h, chNDArray.h, dColVector.h, dDiagMatrix.h, dMatrix.h, dNDArray.h, dRowVector.h, dSparse.h, dim-vector.h, fCColVector.h, fCDiagMatrix.h, fCMatrix.h, fCNDArray.h, fCRowVector.h, fColVector.h, fDiagMatrix.h, fMatrix.h, fNDArray.h, fRowVector.h, idx-vector.h, int16NDArray.h, int32NDArray.h, int64NDArray.h, int8NDArray.h, intNDArray.h, uint16NDArray.h, uint32NDArray.h, uint64NDArray.h, uint8NDArray.h, f77-fcn.h, lo-error.h, quit.h, CmplxAEPBAL.h, CmplxCHOL.h, CmplxGEPBAL.h, CmplxHESS.h, CmplxLU.h, CmplxQR.h, CmplxQRP.h, CmplxSCHUR.h, CmplxSVD.h, CollocWt.h, DAE.h, DAEFunc.h, DAERT.h, DAERTFunc.h, DASPK.h, DASRT.h, DASSL.h, DET.h, EIG.h, LSODE.h, ODE.h, ODEFunc.h, ODES.h, ODESFunc.h, Quad.h, base-aepbal.h, base-dae.h, base-de.h, base-lu.h, base-min.h, base-qr.h, bsxfun-decl.h, bsxfun.h, dbleAEPBAL.h, dbleCHOL.h, dbleGEPBAL.h, dbleHESS.h, dbleLU.h, dbleQR.h, dbleQRP.h, dbleSCHUR.h, dbleSVD.h, eigs-base.h, fCmplxAEPBAL.h, fCmplxCHOL.h, fCmplxGEPBAL.h, fCmplxHESS.h, fCmplxLU.h, fCmplxQR.h, fCmplxQRP.h, fCmplxSCHUR.h, fCmplxSVD.h, fEIG.h, floatAEPBAL.h, floatCHOL.h, floatGEPBAL.h, floatHESS.h, floatLU.h, floatQR.h, floatQRP.h, floatSCHUR.h, floatSVD.h, lo-mappers.h, lo-specfun.h, oct-convn.h, oct-fftw.h, oct-norm.h, oct-rand.h, oct-spparms.h, randgamma.h, randmtzig.h, randpoisson.h, sparse-chol.h, sparse-dmsolve.h, sparse-lu.h, sparse-qr.h, Sparse-diag-op-defs.h, Sparse-op-decls.h, Sparse-op-defs.h, Sparse-perm-op-defs.h, mx-base.h, mx-defs.h, mx-ext.h, mx-op-decl.h, mx-op-defs.h, dir-ops.h, file-ops.h, file-stat.h, lo-sysdep.h, mach-info.h, oct-env.h, oct-group.h, oct-openmp.h, oct-passwd.h, oct-syscalls.h, oct-time.h, oct-uname.h, pathlen.h, sysdir.h, syswait.h, action-container.h, base-list.h, byte-swap.h, caseless-str.h, cmd-edit.h, cmd-hist.h, data-conv.h, functor.h, glob-match.h, lo-array-errwarn.h, lo-array-gripes.h, lo-cutils.h, lo-ieee.h, lo-macros.h, lo-math.h, lo-regexp.h, lo-traits.h, lo-utils.h, oct-alloc.h, oct-base64.h, oct-binmap.h, oct-cmplx.h, oct-glob.h, oct-inttypes.h, oct-locbuf.h, oct-mutex.h, oct-refcount.h, oct-rl-edit.h, oct-rl-hist.h, oct-shlib.h, oct-sort.h, oct-sparse.h, pathsearch.h, singleton-cleanup.h, sparse-sort.h, sparse-util.h, statdefs.h, str-vec.h, sun-utils.h, unwind-prot.h, url-transfer.h: Include octave-config.h.
author John W. Eaton <jwe@octave.org>
date Wed, 10 Feb 2016 14:25:53 -0500
parents 538b57866b90
children b571fc85953f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
1 /*
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19381
diff changeset
3 Copyright (C) 2010-2015 VZLU Prague
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
4
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
5 This file is part of Octave.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 option) any later version.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 for more details.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 */
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 19697
diff changeset
23 #if ! defined (octave_oct_binmap_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17769
diff changeset
24 #define octave_oct_binmap_h 1
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
26 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
27
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28 #include "Array.h"
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29 #include "Sparse.h"
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30 #include "Array-util.h"
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
32 #include "bsxfun.h"
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
33
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
34 // This source file implements a general binary maping function for
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
35 // arrays. The syntax is binmap<type> (a, b, f,[name]). type denotes
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
36 // the expected return type of the operation. a, b, should be one of
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
37 // the 6 combinations:
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
38 //
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
39 // Array-Array
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40 // Array-scalar
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 // scalar-Array
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 // Sparse-Sparse
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
43 // Sparse-scalar
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
44 // scalar-Sparse
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
45 //
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
46 // If both operands are nonscalar, name must be supplied. It is used
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
47 // as the base for error message when operands are nonconforming.
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
48 //
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
49 // The operation needs not be homogeneous, i.e. a, b and the result
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
50 // may be of distinct types. f can have any of the four signatures:
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
51 //
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52 // U f (T, R)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53 // U f (const T&, R)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 // U f (T, const R&)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 // U f (const T&, const R&)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 //
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 // Additionally, f can be an arbitrary functor object.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 //
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
59 // octave_quit() is called at appropriate places, hence the operation
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
60 // is breakable.
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
61
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
62 // The following template wrappers are provided for automatic bsxfun
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
63 // calls (see the function signature for do_bsxfun_op).
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
64
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
65 template <typename R, typename X, typename Y, typename F>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
66 class bsxfun_wrapper
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
67 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
68 private:
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
69 static F f;
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
70
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
71 public:
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
72 static void
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
73 set_f (const F& f_in)
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
74 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
75 f = f_in;
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
76 }
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
77
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
78 static void
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
79 op_mm (size_t n, R* r, const X* x , const Y* y)
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
80 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
81 for (size_t i = 0; i < n; i++)
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
82 r[i] = f (x[i], y[i]);
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
83 }
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
84
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
85 static void
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
86 op_sm (size_t n, R* r, X x, const Y* y)
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
87 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
88 for (size_t i = 0; i < n; i++)
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
89 r[i] = f (x, y[i]);
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
90 }
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
91
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
92 static void
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
93 op_ms (size_t n , R* r, const X* x, Y y)
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
94 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
95 for (size_t i = 0; i < n; i++)
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
96 r[i] = f (x[i], y);
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
97 }
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
98 };
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
99
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
100 // Static init
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
101 template <typename R, typename X, typename Y, typename F>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
102 F bsxfun_wrapper<R, X, Y, F>::f;
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
103
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
104
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
105 // scalar-Array
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
106 template <typename U, typename T, typename R, typename F>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107 Array<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108 binmap (const T& x, const Array<R>& ya, F fcn)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
109 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
110 octave_idx_type len = ya.numel ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
111
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
112 const R *y = ya.data ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
113
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
114 Array<U> result (ya.dims ());
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
115 U *p = result.fortran_vec ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
116
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
117 octave_idx_type i;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
118 for (i = 0; i < len - 3; i += 4)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
119 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
120 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
121
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
122 p[i] = fcn (x, y[i]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
123 p[i+1] = fcn (x, y[i+1]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124 p[i+2] = fcn (x, y[i+2]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
125 p[i+3] = fcn (x, y[i+3]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
127
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
128 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
129
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130 for (; i < len; i++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 p[i] = fcn (x, y[i]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
133 return result;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
134 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
135
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
136 // Array-scalar
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
137 template <typename U, typename T, typename R, typename F>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
138 Array<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
139 binmap (const Array<T>& xa, const R& y, F fcn)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
140 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
141 octave_idx_type len = xa.numel ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
142
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
143 const R *x = xa.data ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
144
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
145 Array<U> result (xa.dims ());
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
146 U *p = result.fortran_vec ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
147
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
148 octave_idx_type i;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
149 for (i = 0; i < len - 3; i += 4)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
150 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
151 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
152
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
153 p[i] = fcn (x[i], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
154 p[i+1] = fcn (x[i+1], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
155 p[i+2] = fcn (x[i+2], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
156 p[i+3] = fcn (x[i+3], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
157 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
158
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
159 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
160
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
161 for (; i < len; i++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
162 p[i] = fcn (x[i], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
163
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
164 return result;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
165 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
166
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
167 // Array-Array (treats singletons as scalars)
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
168 template <typename U, typename T, typename R, typename F>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
169 Array<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
170 binmap (const Array<T>& xa, const Array<R>& ya, F fcn, const char *name)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
171 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17822
diff changeset
172 dim_vector xad = xa.dims ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17822
diff changeset
173 dim_vector yad = ya.dims ();
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
174 if (xa.numel () == 1)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
175 return binmap<U, T, R, F> (xa(0), ya, fcn);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
176 else if (ya.numel () == 1)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
177 return binmap<U, T, R, F> (xa, ya(0), fcn);
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
178 else if (xad != yad)
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
179 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
180 if (! is_valid_bsxfun (name, xad, yad))
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20791
diff changeset
181 err_nonconformant (name, xad, yad);
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
182
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
183 bsxfun_wrapper<U, T, R, F>::set_f(fcn);
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
184 return do_bsxfun_op (xa, ya,
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
185 bsxfun_wrapper<U, T, R, F>::op_mm,
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
186 bsxfun_wrapper<U, T, R, F>::op_sm,
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
187 bsxfun_wrapper<U, T, R, F>::op_ms);
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
188 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
189
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
190 octave_idx_type len = xa.numel ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
191
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
192 const T *x = xa.data ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
193 const T *y = ya.data ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
194
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
195 Array<U> result (xa.dims ());
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
196 U *p = result.fortran_vec ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
197
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
198 octave_idx_type i;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
199 for (i = 0; i < len - 3; i += 4)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
200 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
201 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
202
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
203 p[i] = fcn (x[i], y[i]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
204 p[i+1] = fcn (x[i+1], y[i+1]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
205 p[i+2] = fcn (x[i+2], y[i+2]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
206 p[i+3] = fcn (x[i+3], y[i+3]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
207 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
208
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
209 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
210
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
211 for (; i < len; i++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
212 p[i] = fcn (x[i], y[i]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
213
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
214 return result;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
215 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
216
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
217 // scalar-Sparse
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
218 template <typename U, typename T, typename R, typename F>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
219 Sparse<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
220 binmap (const T& x, const Sparse<R>& ys, F fcn)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
221 {
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
222 R yzero = R ();
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
223 U fz = fcn (x, yzero);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
224
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
225 if (fz == U ()) // Sparsity preserving fcn
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
226 {
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
227 octave_idx_type nz = ys.nnz ();
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
228 Sparse<U> retval (ys.rows (), ys.cols (), nz);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18791
diff changeset
229 std::copy (ys.ridx (), ys.ridx () + nz, retval.ridx ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18791
diff changeset
230 std::copy (ys.cidx (), ys.cidx () + ys.cols () + 1, retval.cidx ());
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
231
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
232 for (octave_idx_type i = 0; i < nz; i++)
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
233 {
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
234 octave_quit ();
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
235 // FIXME: Could keep track of whether fcn call results in a 0.
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
236 // If no zeroes are created could skip maybe_compress()
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
237 retval.xdata (i) = fcn (x, ys.data (i));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
238 }
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
239
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
240 octave_quit ();
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
241 retval.maybe_compress (true);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
242 return retval;
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
243 }
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
244 else
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
245 return Sparse<U> (binmap<U, T, R, F> (x, ys.array_value (), fcn));
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
246 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
247
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
248 // Sparse-scalar
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
249 template <typename U, typename T, typename R, typename F>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
250 Sparse<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
251 binmap (const Sparse<T>& xs, const R& y, F fcn)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
252 {
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
253 T xzero = T ();
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
254 U fz = fcn (xzero, y);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
255
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
256 if (fz == U ()) // Sparsity preserving fcn
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
257 {
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
258 octave_idx_type nz = xs.nnz ();
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
259 Sparse<U> retval (xs.rows (), xs.cols (), nz);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18791
diff changeset
260 std::copy (xs.ridx (), xs.ridx () + nz, retval.ridx ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18791
diff changeset
261 std::copy (xs.cidx (), xs.cidx () + xs.cols () + 1, retval.cidx ());
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
262
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
263 for (octave_idx_type i = 0; i < nz; i++)
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
264 {
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
265 octave_quit ();
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
266 // FIXME: Could keep track of whether fcn call results in a 0.
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
267 // If no zeroes are created could skip maybe_compress()
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
268 retval.xdata (i) = fcn (xs.data (i), y);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
269 }
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
270
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
271 octave_quit ();
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
272 retval.maybe_compress (true);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
273 return retval;
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
274 }
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
275 else
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
276 return Sparse<U> (binmap<U, T, R, F> (xs.array_value (), y, fcn));
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
277 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
278
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
279 // Sparse-Sparse (treats singletons as scalars)
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
280 template <typename U, typename T, typename R, typename F>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
281 Sparse<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
282 binmap (const Sparse<T>& xs, const Sparse<R>& ys, F fcn, const char *name)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
283 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
284 if (xs.rows () == 1 && xs.cols () == 1)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
285 return binmap<U, T, R, F> (xs(0,0), ys, fcn);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
286 else if (ys.rows () == 1 && ys.cols () == 1)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
287 return binmap<U, T, R, F> (xs, ys(0,0), fcn);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
288 else if (xs.dims () != ys.dims ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20791
diff changeset
289 err_nonconformant (name, xs.dims (), ys.dims ());
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
290
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
291 T xzero = T ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
292 R yzero = R ();
18788
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
293 U fz = fcn (xzero, yzero);
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
294
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
295 if (fz == U ())
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
296 {
18788
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
297 // Sparsity-preserving function. Do it efficiently.
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
298 octave_idx_type nr = xs.rows ();
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
299 octave_idx_type nc = xs.cols ();
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
300 Sparse<T> retval (nr, nc, xs.nnz () + ys.nnz ());
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
301
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
302 octave_idx_type nz = 0;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
303 for (octave_idx_type j = 0; j < nc; j++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
304 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
305 octave_quit ();
18788
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
306
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
307 octave_idx_type jx = xs.cidx (j);
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
308 octave_idx_type jx_max = xs.cidx (j+1);
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
309 bool jx_lt_max = jx < jx_max;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
310
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
311 octave_idx_type jy = ys.cidx (j);
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
312 octave_idx_type jy_max = ys.cidx (j+1);
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
313 bool jy_lt_max = jy < jy_max;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
314
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
315 while (jx_lt_max || jy_lt_max)
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
316 {
18788
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
317 if (! jy_lt_max
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
318 || (jx_lt_max && (xs.ridx (jx) < ys.ridx (jy))))
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
319 {
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
320 retval.xridx (nz) = xs.ridx (jx);
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
321 retval.xdata (nz) = fcn (xs.data (jx), yzero);
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
322 jx++;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
323 jx_lt_max = jx < jx_max;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
324 }
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
325 else if (! jx_lt_max
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18788
diff changeset
326 || (jy_lt_max && (ys.ridx (jy) < xs.ridx (jx))))
18788
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
327 {
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
328 retval.xridx (nz) = ys.ridx (jy);
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
329 retval.xdata (nz) = fcn (xzero, ys.data (jy));
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
330 jy++;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
331 jy_lt_max = jy < jy_max;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
332 }
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
333 else
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
334 {
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
335 retval.xridx (nz) = xs.ridx (jx);
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
336 retval.xdata (nz) = fcn (xs.data (jx), ys.data (jy));
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
337 jx++;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
338 jx_lt_max = jx < jx_max;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
339 jy++;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
340 jy_lt_max = jy < jy_max;
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
341 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
342 nz++;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
343 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
344 retval.xcidx (j+1) = nz;
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
345 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
346
18788
658d23da2c46 Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents: 17822
diff changeset
347 retval.maybe_compress (true);
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
348 return retval;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
349 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
350 else
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
351 return Sparse<U> (binmap<U, T, R, F> (xs.array_value (), ys.array_value (),
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
352 fcn, name));
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
353 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
354
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
355 // Overloads for function pointers.
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
356
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
357 // Signature (T, R)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
358
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
359 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
360 inline Array<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
361 binmap (const Array<T>& xa, const Array<R>& ya, U (*fcn) (T, R),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
362 const char *name)
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
363 { return binmap<U, T, R, U (*) (T, R)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
364
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
365 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
366 inline Array<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
367 binmap (const T& x, const Array<R>& ya, U (*fcn) (T, R))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
368 { return binmap<U, T, R, U (*) (T, R)> (x, ya, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
369
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
370 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
371 inline Array<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
372 binmap (const Array<T>& xa, const R& y, U (*fcn) (T, R))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
373 { return binmap<U, T, R, U (*) (T, R)> (xa, y, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
374
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
375 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
376 inline Sparse<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
377 binmap (const Sparse<T>& xa, const Sparse<R>& ya, U (*fcn) (T, R),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
378 const char *name)
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
379 { return binmap<U, T, R, U (*) (T, R)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
380
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
381 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
382 inline Sparse<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
383 binmap (const T& x, const Sparse<R>& ya, U (*fcn) (T, R))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
384 { return binmap<U, T, R, U (*) (T, R)> (x, ya, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
385
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
386 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
387 inline Sparse<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
388 binmap (const Sparse<T>& xa, const R& y, U (*fcn) (T, R))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
389 { return binmap<U, T, R, U (*) (T, R)> (xa, y, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
390
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
391 // Signature (const T&, const R&)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
392
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
393 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
394 inline Array<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
395 binmap (const Array<T>& xa, const Array<R>& ya, U (*fcn) (const T&, const R&),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
396 const char *name)
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
397 { return binmap<U, T, R, U (*) (const T&, const R&)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
398
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
399 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
400 inline Array<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
401 binmap (const T& x, const Array<R>& ya, U (*fcn) (const T&, const R&))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
402 { return binmap<U, T, R, U (*) (const T&, const R&)> (x, ya, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
403
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
404 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
405 inline Array<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
406 binmap (const Array<T>& xa, const R& y, U (*fcn) (const T&, const R&))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
407 { return binmap<U, T, R, U (*) (const T&, const R&)> (xa, y, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
408
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
409 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
410 inline Sparse<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
411 binmap (const Sparse<T>& xa, const Sparse<R>& ya, U (*fcn) (const T&, const R&),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
412 const char *name)
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
413 { return binmap<U, T, R, U (*) (const T&, const R&)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
414
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
415 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
416 inline Sparse<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
417 binmap (const T& x, const Sparse<R>& ya, U (*fcn) (const T&, const R&))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
418 { return binmap<U, T, R, U (*) (const T&, const R&)> (x, ya, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
419
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
420 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
421 inline Sparse<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
422 binmap (const Sparse<T>& xa, const R& y, U (*fcn) (const T&, const R&))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
423 { return binmap<U, T, R, U (*) (const T&, const R&)> (xa, y, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
424
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
425 // Signature (const T&, R)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
426
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
427 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
428 inline Array<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
429 binmap (const Array<T>& xa, const Array<R>& ya, U (*fcn) (const T&, R),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
430 const char *name)
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
431 { return binmap<U, T, R, U (*) (const T&, R)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
432
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
433 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
434 inline Array<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
435 binmap (const T& x, const Array<R>& ya, U (*fcn) (const T&, R))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
436 { return binmap<U, T, R, U (*) (const T&, R)> (x, ya, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
437
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
438 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
439 inline Array<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
440 binmap (const Array<T>& xa, const R& y, U (*fcn) (const T&, R))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
441 { return binmap<U, T, R, U (*) (const T&, R)> (xa, y, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
442
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
443 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
444 inline Sparse<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
445 binmap (const Sparse<T>& xa, const Sparse<R>& ya, U (*fcn) (const T&, R),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
446 const char *name)
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
447 { return binmap<U, T, R, U (*) (const T&, R)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
448
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
449 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
450 inline Sparse<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
451 binmap (const T& x, const Sparse<R>& ya, U (*fcn) (const T&, R))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
452 { return binmap<U, T, R, U (*) (const T&, R)> (x, ya, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
453
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
454 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
455 inline Sparse<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
456 binmap (const Sparse<T>& xa, const R& y, U (*fcn) (const T&, R))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
457 { return binmap<U, T, R, U (*) (const T&, R)> (xa, y, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
458
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
459 // Signature (T, const R&)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
460
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
461 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
462 inline Array<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
463 binmap (const Array<T>& xa, const Array<R>& ya, U (*fcn) (T, const R&),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
464 const char *name)
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
465 { return binmap<U, T, R, U (*) (T, const R&)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
466
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
467 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
468 inline Array<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
469 binmap (const T& x, const Array<R>& ya, U (*fcn) (T, const R&))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
470 { return binmap<U, T, R, U (*) (T, const R&)> (x, ya, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
471
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
472 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
473 inline Array<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
474 binmap (const Array<T>& xa, const R& y, U (*fcn) (T, const R&))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
475 { return binmap<U, T, R, U (*) (T, const R&)> (xa, y, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
476
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
477 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
478 inline Sparse<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
479 binmap (const Sparse<T>& xa, const Sparse<R>& ya, U (*fcn) (T, const R&),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
480 const char *name)
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
481 { return binmap<U, T, R, U (*) (T, const R&)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
482
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
483 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
484 inline Sparse<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
485 binmap (const T& x, const Sparse<R>& ya, U (*fcn) (T, const R&))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
486 { return binmap<U, T, R, U (*) (T, const R&)> (x, ya, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
487
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21118
diff changeset
488 template <typename U, typename T, typename R>
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
489 inline Sparse<U>
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
490 binmap (const Sparse<T>& xa, const R& y, U (*fcn) (T, const R&))
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
491 { return binmap<U, T, R, U (*) (T, const R&)> (xa, y, fcn); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
492
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
493 #endif