annotate liboctave/util/oct-binmap.h @ 17822:ebb3ef964372

maint: Use common #define syntax "octave_filename_h" in h_files. * libgui/src/dialog.h, libgui/src/find-files-dialog.h, libgui/src/find-files-model.h, libgui/src/m-editor/file-editor-tab.h, libgui/src/m-editor/octave-qscintilla.h, libgui/src/main-window.h, libgui/src/octave-dock-widget.h, libgui/src/workspace-model.h, libgui/src/workspace-view.h, libinterp/corefcn/Cell.h, libinterp/corefcn/gl-render.h, libinterp/corefcn/gl2ps-renderer.h, libinterp/corefcn/graphics.in.h, libinterp/corefcn/oct-errno.h, libinterp/corefcn/oct-fstrm.h, libinterp/corefcn/oct-handle.h, libinterp/corefcn/oct-hdf5.h, libinterp/corefcn/oct-hist.h, libinterp/corefcn/oct-iostrm.h, libinterp/corefcn/oct-lvalue.h, libinterp/corefcn/oct-prcstrm.h, libinterp/corefcn/oct-procbuf.h, libinterp/corefcn/oct-stdstrm.h, libinterp/corefcn/oct-stream.h, libinterp/corefcn/oct-strstrm.h, libinterp/corefcn/octave-link.h, libinterp/corefcn/pt-jit.h, libinterp/octave-value/ov-base-diag.h, libinterp/octave-value/ov-base-int.h, libinterp/octave-value/ov-base-mat.h, libinterp/octave-value/ov-base-scalar.h, libinterp/octave-value/ov-base-sparse.h, libinterp/octave-value/ov-base.h, libinterp/octave-value/ov-bool-mat.h, libinterp/octave-value/ov-bool-sparse.h, libinterp/octave-value/ov-bool.h, libinterp/octave-value/ov-builtin.h, libinterp/octave-value/ov-cell.h, libinterp/octave-value/ov-ch-mat.h, libinterp/octave-value/ov-class.h, libinterp/octave-value/ov-colon.h, libinterp/octave-value/ov-complex.h, libinterp/octave-value/ov-cs-list.h, libinterp/octave-value/ov-cx-diag.h, libinterp/octave-value/ov-cx-mat.h, libinterp/octave-value/ov-cx-sparse.h, libinterp/octave-value/ov-dld-fcn.h, libinterp/octave-value/ov-fcn-handle.h, libinterp/octave-value/ov-fcn-inline.h, libinterp/octave-value/ov-fcn.h, libinterp/octave-value/ov-float.h, libinterp/octave-value/ov-flt-complex.h, libinterp/octave-value/ov-flt-cx-diag.h, libinterp/octave-value/ov-flt-cx-mat.h, libinterp/octave-value/ov-flt-re-diag.h, libinterp/octave-value/ov-flt-re-mat.h, libinterp/octave-value/ov-int-traits.h, libinterp/octave-value/ov-int16.h, libinterp/octave-value/ov-int32.h, libinterp/octave-value/ov-int64.h, libinterp/octave-value/ov-int8.h, libinterp/octave-value/ov-java.h, libinterp/octave-value/ov-lazy-idx.h, libinterp/octave-value/ov-mex-fcn.h, libinterp/octave-value/ov-null-mat.h, libinterp/octave-value/ov-perm.h, libinterp/octave-value/ov-range.h, libinterp/octave-value/ov-re-diag.h, libinterp/octave-value/ov-re-mat.h, libinterp/octave-value/ov-re-sparse.h, libinterp/octave-value/ov-scalar.h, libinterp/octave-value/ov-str-mat.h, libinterp/octave-value/ov-struct.h, libinterp/octave-value/ov-typeinfo.h, libinterp/octave-value/ov-uint16.h, libinterp/octave-value/ov-uint32.h, libinterp/octave-value/ov-uint64.h, libinterp/octave-value/ov-uint8.h, libinterp/octave-value/ov-usr-fcn.h, libinterp/octave-value/ov.h, libinterp/parse-tree/pt-all.h, libinterp/parse-tree/pt-arg-list.h, libinterp/parse-tree/pt-array-list.h, libinterp/parse-tree/pt-assign.h, libinterp/parse-tree/pt-binop.h, libinterp/parse-tree/pt-bp.h, libinterp/parse-tree/pt-cbinop.h, libinterp/parse-tree/pt-cell.h, libinterp/parse-tree/pt-check.h, libinterp/parse-tree/pt-cmd.h, libinterp/parse-tree/pt-colon.h, libinterp/parse-tree/pt-const.h, libinterp/parse-tree/pt-decl.h, libinterp/parse-tree/pt-eval.h, libinterp/parse-tree/pt-except.h, libinterp/parse-tree/pt-exp.h, libinterp/parse-tree/pt-fcn-handle.h, libinterp/parse-tree/pt-id.h, libinterp/parse-tree/pt-idx.h, libinterp/parse-tree/pt-jump.h, libinterp/parse-tree/pt-loop.h, libinterp/parse-tree/pt-mat.h, libinterp/parse-tree/pt-misc.h, libinterp/parse-tree/pt-pr-code.h, libinterp/parse-tree/pt-select.h, libinterp/parse-tree/pt-stmt.h, libinterp/parse-tree/pt-unop.h, libinterp/parse-tree/pt-walk.h, libinterp/parse-tree/pt.h, liboctave/array/CColVector.h, liboctave/array/CDiagMatrix.h, liboctave/array/CMatrix.h, liboctave/array/CNDArray.h, liboctave/array/CRowVector.h, liboctave/array/boolMatrix.h, liboctave/array/chMatrix.h, liboctave/array/chNDArray.h, liboctave/array/dColVector.h, liboctave/array/dDiagMatrix.h, liboctave/array/dMatrix.h, liboctave/array/dNDArray.h, liboctave/array/dRowVector.h, liboctave/array/fCColVector.h, liboctave/array/fCDiagMatrix.h, liboctave/array/fCMatrix.h, liboctave/array/fCNDArray.h, liboctave/array/fCRowVector.h, liboctave/array/fColVector.h, liboctave/array/fDiagMatrix.h, liboctave/array/fMatrix.h, liboctave/array/fNDArray.h, liboctave/array/fRowVector.h, liboctave/cruft/misc/lo-error.h, liboctave/numeric/CmplxAEPBAL.h, liboctave/numeric/CmplxCHOL.h, liboctave/numeric/CmplxGEPBAL.h, liboctave/numeric/CmplxHESS.h, liboctave/numeric/CmplxLU.h, liboctave/numeric/CmplxQR.h, liboctave/numeric/CmplxQRP.h, liboctave/numeric/CmplxSCHUR.h, liboctave/numeric/CmplxSVD.h, liboctave/numeric/Quad.h, liboctave/numeric/SparseCmplxCHOL.h, liboctave/numeric/SparseCmplxLU.h, liboctave/numeric/SparseCmplxQR.h, liboctave/numeric/SparseQR.h, liboctave/numeric/SparsedbleCHOL.h, liboctave/numeric/SparsedbleLU.h, liboctave/numeric/bsxfun.h, liboctave/numeric/dbleAEPBAL.h, liboctave/numeric/dbleCHOL.h, liboctave/numeric/dbleGEPBAL.h, liboctave/numeric/dbleHESS.h, liboctave/numeric/dbleLU.h, liboctave/numeric/dbleQR.h, liboctave/numeric/dbleQRP.h, liboctave/numeric/dbleSCHUR.h, liboctave/numeric/dbleSVD.h, liboctave/numeric/fCmplxAEPBAL.h, liboctave/numeric/fCmplxCHOL.h, liboctave/numeric/fCmplxGEPBAL.h, liboctave/numeric/fCmplxHESS.h, liboctave/numeric/fCmplxLU.h, liboctave/numeric/fCmplxQR.h, liboctave/numeric/fCmplxQRP.h, liboctave/numeric/fCmplxSCHUR.h, liboctave/numeric/fCmplxSVD.h, liboctave/numeric/fEIG.h, liboctave/numeric/floatAEPBAL.h, liboctave/numeric/floatCHOL.h, liboctave/numeric/floatGEPBAL.h, liboctave/numeric/floatHESS.h, liboctave/numeric/floatLU.h, liboctave/numeric/floatQR.h, liboctave/numeric/floatQRP.h, liboctave/numeric/floatSCHUR.h, liboctave/numeric/floatSVD.h, liboctave/numeric/lo-mappers.h, liboctave/numeric/lo-specfun.h, liboctave/numeric/oct-convn.h, liboctave/numeric/oct-norm.h, liboctave/numeric/oct-rand.h, liboctave/operators/Sparse-diag-op-defs.h, liboctave/operators/Sparse-op-defs.h, liboctave/operators/Sparse-perm-op-defs.h, liboctave/system/lo-sysdep.h, liboctave/system/oct-env.h, liboctave/system/oct-group.h, liboctave/system/oct-openmp.h, liboctave/system/oct-passwd.h, liboctave/system/oct-syscalls.h, liboctave/system/oct-time.h, liboctave/system/oct-uname.h, liboctave/util/lo-array-gripes.h, liboctave/util/lo-cutils.h, liboctave/util/lo-ieee.h, liboctave/util/lo-macros.h, liboctave/util/lo-math.h, liboctave/util/lo-regexp.h, liboctave/util/lo-traits.h, liboctave/util/lo-utils.h, liboctave/util/oct-base64.h, liboctave/util/oct-binmap.h, liboctave/util/oct-glob.h, liboctave/util/oct-inttypes.h, liboctave/util/oct-locbuf.h, liboctave/util/oct-mem.h, liboctave/util/oct-mutex.h, liboctave/util/oct-refcount.h, liboctave/util/oct-rl-edit.h, liboctave/util/oct-rl-hist.h, liboctave/util/oct-shlib.h, liboctave/util/oct-sort.h, liboctave/util/oct-sparse.h: Use common #define syntax "octave_filename_h" in h_files.
author Rik <rik@octave.org>
date Thu, 31 Oct 2013 22:19:07 -0700
parents 49a5a4be04a1
children 8e056300994b 658d23da2c46
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
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
3 Copyright (C) 2010-2013 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
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17769
diff changeset
23 #if !defined (octave_oct_binmap_h)
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
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26 #include "Array.h"
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27 #include "Sparse.h"
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28 #include "Array-util.h"
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
30 #include "bsxfun.h"
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
31
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
32 // 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
33 // 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
34 // 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
35 // the 6 combinations:
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
36 //
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
37 // Array-Array
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
38 // Array-scalar
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
39 // scalar-Array
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40 // Sparse-Sparse
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 // Sparse-scalar
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 // scalar-Sparse
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
43 //
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
44 // 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
45 // 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
46 //
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
47 // 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
48 // 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
49 //
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50 // U f (T, R)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 // U f (const T&, R)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52 // U f (T, const R&)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53 // U f (const T&, const R&)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 //
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 // Additionally, f can be an arbitrary functor object.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 //
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
57 // 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
58 // is breakable.
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
59
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
60 // 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
61 // 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
62
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
63 template<typename R, typename X, typename Y, typename F>
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
64 class bsxfun_wrapper
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
65 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
66 private:
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
67 static F f;
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
68
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
69 public:
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
70 static void
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
71 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
72 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
73 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
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
76 static void
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
77 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
78 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
79 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
80 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
81 }
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
82
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
83 static void
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
84 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
85 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
86 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
87 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
88 }
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
89
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
90 static void
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
91 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
92 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
93 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
94 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
95 }
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
96 };
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 // Static init
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
99 template<typename R, typename X, typename Y, typename F>
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
100 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
101
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
102
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
103 // scalar-Array
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
104 template <class U, class T, class R, class F>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
105 Array<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
106 binmap (const T& x, const Array<R>& ya, F fcn)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108 octave_idx_type len = ya.numel ();
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 const R *y = ya.data ();
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 Array<U> result (ya.dims ());
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
113 U *p = result.fortran_vec ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
114
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
115 octave_idx_type i;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
116 for (i = 0; i < len - 3; i += 4)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
117 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
118 octave_quit ();
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 p[i] = fcn (x, y[i]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
121 p[i+1] = fcn (x, y[i+1]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
122 p[i+2] = fcn (x, y[i+2]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
123 p[i+3] = fcn (x, y[i+3]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
125
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126 octave_quit ();
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 for (; i < len; i++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
129 p[i] = fcn (x, y[i]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 return result;
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
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
134 // Array-scalar
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
135 template <class U, class T, class R, class F>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
136 Array<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
137 binmap (const Array<T>& xa, const R& y, F fcn)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
138 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
139 octave_idx_type len = xa.numel ();
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 const R *x = xa.data ();
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 Array<U> result (xa.dims ());
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
144 U *p = result.fortran_vec ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
145
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
146 octave_idx_type i;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
147 for (i = 0; i < len - 3; i += 4)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
148 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
149 octave_quit ();
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 p[i] = fcn (x[i], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
152 p[i+1] = fcn (x[i+1], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
153 p[i+2] = fcn (x[i+2], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
154 p[i+3] = fcn (x[i+3], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
155 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
156
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
157 octave_quit ();
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 for (; i < len; i++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
160 p[i] = fcn (x[i], y);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
161
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
162 return result;
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
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
165 // Array-Array (treats singletons as scalars)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
166 template <class U, class T, class R, class F>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
167 Array<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
168 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
169 {
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
170 dim_vector xad = xa.dims (), yad = ya.dims ();
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
171 if (xa.numel () == 1)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
172 return binmap<U, T, R, F> (xa(0), ya, fcn);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
173 else if (ya.numel () == 1)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
174 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
175 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
176 {
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13006
diff changeset
177 if (is_valid_bsxfun (name, xad, yad))
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
178 {
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
179 bsxfun_wrapper<U, T, R, F>::set_f(fcn);
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
180 return do_bsxfun_op (xa, ya,
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
181 bsxfun_wrapper<U, T, R, F>::op_mm,
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
182 bsxfun_wrapper<U, T, R, F>::op_sm,
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
183 bsxfun_wrapper<U, T, R, F>::op_ms);
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
184 }
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
185 else
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
186 gripe_nonconformant (name, xad, yad);
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
187 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
188
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
189 octave_idx_type len = xa.numel ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
190
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
191 const T *x = xa.data ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
192 const T *y = ya.data ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
193
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
194 Array<U> result (xa.dims ());
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
195 U *p = result.fortran_vec ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
196
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
197 octave_idx_type i;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
198 for (i = 0; i < len - 3; i += 4)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
199 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
200 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
201
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
202 p[i] = fcn (x[i], y[i]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
203 p[i+1] = fcn (x[i+1], y[i+1]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
204 p[i+2] = fcn (x[i+2], y[i+2]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
205 p[i+3] = fcn (x[i+3], y[i+3]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
206 }
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 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
209
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
210 for (; i < len; i++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
211 p[i] = fcn (x[i], y[i]);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
212
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
213 return result;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
214 }
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 // scalar-Sparse
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
217 template <class U, class T, class R, class F>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
218 Sparse<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
219 binmap (const T& x, const Sparse<R>& ys, F fcn)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
220 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
221 octave_idx_type nz = ys.nnz ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
222 Sparse<U> retval (ys.rows (), ys.cols (), nz);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
223 for (octave_idx_type i = 0; i < nz; i++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
224 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
225 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
226 retval.xdata (i) = fcn (x, ys.data (i));
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
227 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
228
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
229 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
230 retval.maybe_compress ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
231 return retval;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
232 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
233
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
234 // Sparse-scalar
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
235 template <class U, class T, class R, class F>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
236 Sparse<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
237 binmap (const Sparse<T>& xs, const R& y, F fcn)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
238 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
239 octave_idx_type nz = xs.nnz ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
240 Sparse<U> retval (xs.rows (), xs.cols (), nz);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
241 for (octave_idx_type i = 0; i < nz; i++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
242 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
243 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
244 retval.xdata (i) = fcn (xs.data (i), y);
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
245 }
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 octave_quit ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
248 retval.maybe_compress ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
249 return retval;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
250 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
251
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
252 // Sparse-Sparse (treats singletons as scalars)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
253 template <class U, class T, class R, class F>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
254 Sparse<U>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
255 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
256 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
257 if (xs.rows () == 1 && xs.cols () == 1)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
258 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
259 else if (ys.rows () == 1 && ys.cols () == 1)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
260 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
261 else if (xs.dims () != ys.dims ())
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
262 gripe_nonconformant (name, xs.dims (), ys.dims ());
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
263
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
264 T xzero = T ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
265 R yzero = R ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
266
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
267 U fz = fcn (xzero, yzero);
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
268 if (fz == U ())
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
269 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
270 // Sparsity-preserving function. Do it efficiently.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
271 octave_idx_type nr = xs.rows (), nc = xs.cols ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
272 Sparse<T> retval (nr, nc);
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
273
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
274 octave_idx_type nz = 0;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
275 // Count nonzeros.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
276 for (octave_idx_type j = 0; j < nc; j++)
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 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
279 octave_idx_type ix = xs.cidx (j), iy = ys.cidx (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
280 octave_idx_type ux = xs.cidx (j+1), uy = ys.cidx (j+1);
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
281 while (ix != ux || iy != uy)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
282 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
283 octave_idx_type rx = xs.ridx (ix), ry = ys.ridx (ix);
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
284 ix += rx <= ry;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
285 iy += ry <= rx;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
286 nz++;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
287 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
288
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
289 retval.xcidx (j+1) = nz;
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
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
292 // Allocate space.
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
293 retval.change_capacity (retval.xcidx (nc));
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
294
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
295 // Fill.
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
296 nz = 0;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
297 for (octave_idx_type j = 0; j < nc; j++)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
298 {
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
299 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
300 octave_idx_type ix = xs.cidx (j), iy = ys.cidx (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
301 octave_idx_type ux = xs.cidx (j+1), uy = ys.cidx (j+1);
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
302 while (ix != ux || iy != uy)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
303 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
304 octave_idx_type rx = xs.ridx (ix), ry = ys.ridx (ix);
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
305 if (rx == ry)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
306 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
307 retval.xridx (nz) = rx;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
308 retval.xdata (nz) = fcn (xs.data (ix), ys.data (iy));
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
309 ix++;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
310 iy++;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
311 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
312 else if (rx < ry)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
313 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
314 retval.xridx (nz) = rx;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
315 retval.xdata (nz) = fcn (xs.data (ix), yzero);
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
316 ix++;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
317 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
318 else if (ry < rx)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
319 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
320 retval.xridx (nz) = ry;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
321 retval.xdata (nz) = fcn (xzero, ys.data (iy));
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
322 iy++;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
323 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
324
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
325 nz++;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
326 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
327 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
328
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
329 retval.maybe_compress ();
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
330 return retval;
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
331 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
332 else
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
333 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
334 fcn, name));
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
335 }
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
336
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
337 // Overloads for function pointers.
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
338
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
339 // Signature (T, R)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
340
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
341 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
342 inline Array<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
343 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
344 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
345 { 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
346
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
347 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
348 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
349 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
350 { 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
351
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
352 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
353 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
354 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
355 { 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
356
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
357 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
358 inline Sparse<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
359 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
360 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
361 { 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
362
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
363 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
364 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
365 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
366 { 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
367
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
368 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
369 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
370 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
371 { 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
372
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
373 // Signature (const T&, const R&)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
374
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
375 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
376 inline Array<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
377 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
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 (*) (const T&, const R&)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
380
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
381 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
382 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
383 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
384 { 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
385
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
386 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
387 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
388 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
389 { 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
390
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
391 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
392 inline Sparse<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
393 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
394 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
395 { 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
396
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
397 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
398 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
399 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
400 { 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
401
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
402 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
403 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
404 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
405 { 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
406
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
407 // Signature (const T&, R)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
408
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
409 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
410 inline Array<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
411 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
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&, R)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
414
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
415 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
416 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
417 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
418 { 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
419
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
420 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
421 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
422 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
423 { 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
424
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
425 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
426 inline Sparse<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
427 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
428 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
429 { 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
430
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
431 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
432 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
433 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
434 { 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
435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
436 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
437 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
438 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
439 { 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
440
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
441 // Signature (T, const R&)
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
442
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
443 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
444 inline Array<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
445 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
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 (*) (T, const R&)> (xa, ya, fcn, name); }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
448
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
449 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
450 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
451 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
452 { 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
453
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
454 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
455 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
456 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
457 { 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
458
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
459 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
460 inline Sparse<U>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
461 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
462 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
463 { 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
464
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
465 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
466 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
467 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
468 { 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
469
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
470 template <class U, class T, class R>
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
471 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
472 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
473 { 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
474
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
475 #endif