annotate liboctave/array/Sparse.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 a83e7a384ee0
children ae4d7dfea337
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1 // Template sparse classes
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2 /*
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19381
diff changeset
4 Copyright (C) 2004-2015 David Bateman
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10716
diff changeset
5 Copyright (C) 1998-2004 Andy Adler
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10515
diff changeset
6 Copyright (C) 2010 VZLU Prague
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
7
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
8 This file is part of Octave.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
9
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
10 Octave is free software; you can redistribute it and/or modify it
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
11 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
12 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
13 option) any later version.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
14
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
15 Octave is distributed in the hope that it will be useful, but WITHOUT
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
18 for more details.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
19
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
21 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6708
diff changeset
22 <http://www.gnu.org/licenses/>.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
23
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
24 */
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20232
diff changeset
26 #if ! defined (octave_Sparse_h)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
27 #define octave_Sparse_h 1
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
30
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
31 #include <cassert>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
32 #include <cstddef>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
33
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
34 #include <iosfwd>
10514
40c58502a78b improve conversion & copy ctors of sparse matrix
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
35 #include <algorithm>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
36
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
37 #include "Array.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
38 #include "dim-vector.h"
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
39 #include "lo-error.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
40 #include "lo-utils.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
42 #include "oct-sort.h"
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
43
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
44 class idx_vector;
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
45 class PermMatrix;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
47 // Two dimensional sparse class. Handles the reference counting for
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
48 // all the derived classes.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
49
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
50 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
51 class
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
52 Sparse
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
53 {
8181
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
54 public:
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
55
8918
f5408862892f Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents: 8181
diff changeset
56 typedef T element_type;
8181
1ebcb9872ced fix sparse-matrix bool/cmp op instantiation problem
John W. Eaton <jwe@octave.org>
parents: 7717
diff changeset
57
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
58 protected:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
59 //--------------------------------------------------------------------
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
60 // The real representation of all Sparse arrays.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
61 //--------------------------------------------------------------------
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
62
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5900
diff changeset
63 class OCTAVE_API SparseRep
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
64 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
65 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
66
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
67 T *d;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
68 octave_idx_type *r;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
69 octave_idx_type *c;
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
70 octave_idx_type nzmx;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
71 octave_idx_type nrows;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
72 octave_idx_type ncols;
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
73 octave_refcount<int> count;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
74
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
75 SparseRep (void)
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 15018
diff changeset
76 : d (0), r (0), c (new octave_idx_type [1]), nzmx (0), nrows (0),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
77 ncols (0), count (1)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
78 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
79 c[0] = 0;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
80 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
81
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
82 SparseRep (octave_idx_type n)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
83 : d (0), r (0), c (new octave_idx_type [n+1]), nzmx (0), nrows (n),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
84 ncols (n), count (1)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
85 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
86 for (octave_idx_type i = 0; i < n + 1; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
87 c[i] = 0;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
88 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
89
14793
cda76da34693 Remove SparseRep constructor without nz parameter
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14792
diff changeset
90 SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz = 0)
15724
911a6ad10e9c fix incorrect sparse array allocation introduced in cda76da34693
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
91 : d (nz > 0 ? new T [nz] : 0),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
92 r (nz > 0 ? new octave_idx_type [nz] : 0),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
93 c (new octave_idx_type [nc+1]), nzmx (nz), nrows (nr),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
94 ncols (nc), count (1)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
95 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
96 for (octave_idx_type i = 0; i < nc + 1; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
97 c[i] = 0;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
98 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
99
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
100 SparseRep (const SparseRep& a)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
101 : d (new T [a.nzmx]), r (new octave_idx_type [a.nzmx]),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
102 c (new octave_idx_type [a.ncols + 1]),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
103 nzmx (a.nzmx), nrows (a.nrows), ncols (a.ncols), count (1)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
104 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
105 octave_idx_type nz = a.nnz ();
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18812
diff changeset
106 std::copy (a.d, a.d + nz, d);
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18812
diff changeset
107 std::copy (a.r, a.r + nz, r);
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18812
diff changeset
108 std::copy (a.c, a.c + ncols + 1, c);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
109 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
110
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
111 ~SparseRep (void) { delete [] d; delete [] r; delete [] c; }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
112
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
113 octave_idx_type length (void) const { return nzmx; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
114
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
115 octave_idx_type nnz (void) const { return c[ncols]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
116
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
117 T& elem (octave_idx_type _r, octave_idx_type _c);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
118
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
119 T celem (octave_idx_type _r, octave_idx_type _c) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
120
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
121 T& data (octave_idx_type i) { return d[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
122
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
123 T cdata (octave_idx_type i) const { return d[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
124
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
125 octave_idx_type& ridx (octave_idx_type i) { return r[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
126
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
127 octave_idx_type cridx (octave_idx_type i) const { return r[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
128
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
129 octave_idx_type& cidx (octave_idx_type i) { return c[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
130
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
131 octave_idx_type ccidx (octave_idx_type i) const { return c[i]; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
132
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
133 void maybe_compress (bool remove_zeros);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
134
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
135 void change_length (octave_idx_type nz);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
136
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
137 bool indices_ok (void) const;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
138
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
139 private:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
140
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
141 // No assignment!
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
142
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
143 SparseRep& operator = (const SparseRep& a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
144 };
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
145
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
146 //--------------------------------------------------------------------
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
147
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
148 void make_unique (void)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
149 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
150 if (rep->count > 1)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
151 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
152 SparseRep *r = new SparseRep (*rep);
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13030
diff changeset
153
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
154 if (--rep->count == 0)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
155 delete rep;
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13030
diff changeset
156
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
157 rep = r;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
158 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
159 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
160
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
161 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
162
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
163 // !!! WARNING !!! -- these should be protected, not public. You
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
164 // should not access these data members directly!
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
165
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
166 typename Sparse<T>::SparseRep *rep;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
167
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
168 dim_vector dimensions;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
169
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
170 private:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
171
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
172 typename Sparse<T>::SparseRep *nil_rep (void) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
173 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
174 static typename Sparse<T>::SparseRep nr;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
175 return &nr;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
176 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
177
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
178 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
179
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
180 Sparse (void)
13995
8a566473361e use static storage for Sparse nil rep instead of allocating it with new
John W. Eaton <jwe@octave.org>
parents: 13985
diff changeset
181 : rep (nil_rep ()), dimensions (dim_vector(0,0))
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
182 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
183 rep->count++;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
184 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
185
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
186 explicit Sparse (octave_idx_type n)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
187 : rep (new typename Sparse<T>::SparseRep (n)),
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
188 dimensions (dim_vector (n, n)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
189
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
190 explicit Sparse (octave_idx_type nr, octave_idx_type nc)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
191 : rep (new typename Sparse<T>::SparseRep (nr, nc)),
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
192 dimensions (dim_vector (nr, nc)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
193
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
194 explicit Sparse (octave_idx_type nr, octave_idx_type nc, T val);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
195
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
196 Sparse (const dim_vector& dv, octave_idx_type nz)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
197 : rep (new typename Sparse<T>::SparseRep (dv(0), dv(1), nz)),
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
198 dimensions (dv) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
199
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
200 Sparse (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
201 : rep (new typename Sparse<T>::SparseRep (nr, nc, nz)),
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
202 dimensions (dim_vector (nr, nc)) { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
203
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
204 // Both SparseMatrix and SparseBoolMatrix need this ctor, and this
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
205 // is their only common ancestor.
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
206 explicit Sparse (const PermMatrix& a);
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12125
diff changeset
207
10514
40c58502a78b improve conversion & copy ctors of sparse matrix
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
208 // Type conversion case. Preserves capacity ().
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
209 template <typename U>
10515
189274f6c7c4 omissions from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 10514
diff changeset
210 Sparse (const Sparse<U>& a)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
211 : rep (new typename Sparse<T>::SparseRep (a.rep->nrows, a.rep->ncols,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
212 a.rep->nzmx)),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
213 dimensions (a.dimensions)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
214 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
215 octave_idx_type nz = a.nnz ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
216 std::copy (a.rep->d, a.rep->d + nz, rep->d);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18812
diff changeset
217 std::copy (a.rep->r, a.rep->r + nz, rep->r);
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18812
diff changeset
218 std::copy (a.rep->c, a.rep->c + rep->ncols + 1, rep->c);
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
219 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
220
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
221 // No type conversion case.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
222 Sparse (const Sparse<T>& a)
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
223 : rep (a.rep), dimensions (a.dimensions)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
224 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
225 rep->count++;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
226 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
227
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
228 public:
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
229
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
230 Sparse (const dim_vector& dv);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
231
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
232 Sparse (const Sparse<T>& a, const dim_vector& dv);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
233
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
234 Sparse (const Array<T>& a, const idx_vector& r, const idx_vector& c,
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
235 octave_idx_type nr = -1, octave_idx_type nc = -1,
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
236 bool sum_terms = true, octave_idx_type nzm = -1);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
237
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
238 // Sparsify a normal matrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
239 Sparse (const Array<T>& a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
240
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
241 virtual ~Sparse (void);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
242
7717
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
243 Sparse<T>& operator = (const Sparse<T>& a);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
244
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
245 //! Amount of storage for nonzero elements.
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
246 //! This may differ from the actual number of elements, see nnz().
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
247 octave_idx_type nzmax (void) const { return rep->length (); }
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
248
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
249 //! Amount of storage for nonzero elements.
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
250 //! Synonymous with nzmax().
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
251 OCTAVE_DEPRECATED ("use 'nzmax' instead")
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
252 octave_idx_type capacity (void) const { return nzmax (); }
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
253
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20791
diff changeset
254 //! Actual number of nonzero terms.
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5307
diff changeset
255 octave_idx_type nnz (void) const { return rep->nnz (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
256
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
257 // Querying the number of elements (incl. zeros) may overflow the index type,
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
258 // so don't do it unless you really need it.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
259 octave_idx_type numel (void) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
260 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
261 return dimensions.safe_numel ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
262 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
263
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
264 OCTAVE_DEPRECATED ("use 'nzmax' instead")
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
265 octave_idx_type nelem (void) const { return nzmax (); }
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
266
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
267 OCTAVE_DEPRECATED ("use 'numel' instead")
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
268 octave_idx_type length (void) const { return numel (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
269
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
270 octave_idx_type dim1 (void) const { return dimensions(0); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
271 octave_idx_type dim2 (void) const { return dimensions(1); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
272
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
273 octave_idx_type rows (void) const { return dim1 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
274 octave_idx_type cols (void) const { return dim2 (); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
275 octave_idx_type columns (void) const { return dim2 (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
276
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
277 octave_idx_type get_row_index (octave_idx_type k) { return ridx (k); }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
278 octave_idx_type get_col_index (octave_idx_type k)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
279 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
280 octave_idx_type ret = 0;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
281 while (cidx (ret+1) < k)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
282 ret++;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
283 return ret;
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
284 }
10358
72fab01e5d68 improve some size_t queries
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
285
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
286 size_t byte_size (void) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
287 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
288 return (static_cast<size_t>(cols () + 1) * sizeof (octave_idx_type)
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
289 + static_cast<size_t> (nzmax ())
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
290 * (sizeof (T) + sizeof (octave_idx_type)));
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
291 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
292
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
293 dim_vector dims (void) const { return dimensions; }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
294
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
295 Sparse<T> squeeze (void) const { return *this; }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
296
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
297 octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
298
21137
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
299 OCTAVE_NORETURN T range_error (const char *fcn, octave_idx_type n) const;
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
300 OCTAVE_NORETURN T& range_error (const char *fcn, octave_idx_type n);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
301
21137
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
302 OCTAVE_NORETURN T range_error (const char *fcn,
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
303 octave_idx_type i, octave_idx_type j) const;
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
304 OCTAVE_NORETURN T& range_error (const char *fcn,
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
305 octave_idx_type i, octave_idx_type j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
306
21137
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
307 OCTAVE_NORETURN T range_error (const char *fcn,
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
308 const Array<octave_idx_type>& ra_idx) const;
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
309 OCTAVE_NORETURN T& range_error (const char *fcn,
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
310 const Array<octave_idx_type>& ra_idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
311
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
312 // No checking, even for multiple references, ever.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
313
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
314 T& xelem (octave_idx_type n)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
315 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
316 octave_idx_type i = n % rows ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
317 octave_idx_type j = n / rows ();
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
318 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
319 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
320
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
321 T xelem (octave_idx_type n) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
322 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
323 octave_idx_type i = n % rows ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
324 octave_idx_type j = n / rows ();
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
325 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
326 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
327
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
328 T& xelem (octave_idx_type i, octave_idx_type j) { return rep->elem (i, j); }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
329 T xelem (octave_idx_type i, octave_idx_type j) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
330 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
331 return rep->celem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
332 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
333
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
334 T& xelem (const Array<octave_idx_type>& ra_idx)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
335 { return xelem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
336
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
337 T xelem (const Array<octave_idx_type>& ra_idx) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
338 { return xelem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
339
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
340 // FIXME: would be nice to fix this so that we don't
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
341 // unnecessarily force a copy, but that is not so easy, and I see no
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
342 // clean way to do it.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
343
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
344 T& checkelem (octave_idx_type n)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
345 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
346 if (n < 0 || n >= numel ())
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
347 return range_error ("T& Sparse<T>::checkelem", n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
348 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
349 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
350 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
351 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
352 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
353 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
354
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
355 T& checkelem (octave_idx_type i, octave_idx_type j)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
356 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
357 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
358 return range_error ("T& Sparse<T>::checkelem", i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
359 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
360 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
361 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
362 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
363 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
364 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
365
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
366 T& checkelem (const Array<octave_idx_type>& ra_idx)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
367 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
368 octave_idx_type i = compute_index (ra_idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
369
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
370 if (i < 0)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
371 return range_error ("T& Sparse<T>::checkelem", ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
372 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
373 return elem (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
374 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
375
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
376 T& elem (octave_idx_type n)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
377 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
378 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
379 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
380 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
381
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
382 T& elem (octave_idx_type i, octave_idx_type j)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
383 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
384 make_unique ();
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
385 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
386 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
387
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
388 T& elem (const Array<octave_idx_type>& ra_idx)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
389 { return Sparse<T>::elem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
390
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
391 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
392 T& operator () (octave_idx_type n)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
393 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
394 return checkelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
395 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
396
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
397 T& operator () (octave_idx_type i, octave_idx_type j)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
398 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
399 return checkelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
400 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
401
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
402 T& operator () (const Array<octave_idx_type>& ra_idx)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
403 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
404 return checkelem (ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
405 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
406
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
407 #else
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
408 T& operator () (octave_idx_type n)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
409 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
410 return elem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
411 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
412
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
413 T& operator () (octave_idx_type i, octave_idx_type j)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
414 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
415 return elem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
416 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
417
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
418 T& operator () (const Array<octave_idx_type>& ra_idx)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
419 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
420 return elem (ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
421 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
422
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
423 #endif
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
424
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
425 T checkelem (octave_idx_type n) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
426 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
427 if (n < 0 || n >= numel ())
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
428 return range_error ("T Sparse<T>::checkelem", n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
429 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
430 return xelem (n);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
431 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
432
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
433 T checkelem (octave_idx_type i, octave_idx_type j) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
434 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
435 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ())
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
436 return range_error ("T Sparse<T>::checkelem", i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
437 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
438 return xelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
439 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
440
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
441 T checkelem (const Array<octave_idx_type>& ra_idx) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
442 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
443 octave_idx_type i = compute_index (ra_idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
444
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
445 if (i < 0)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
446 return range_error ("T Sparse<T>::checkelem", ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
447 else
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
448 return Sparse<T>::elem (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
449 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
450
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
451 T elem (octave_idx_type n) const { return xelem (n); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
452
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
453 T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
454
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
455 T elem (const Array<octave_idx_type>& ra_idx) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
456 { return Sparse<T>::elem (compute_index (ra_idx)); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
457
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
458 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
459 T operator () (octave_idx_type n) const { return checkelem (n); }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
460 T operator () (octave_idx_type i, octave_idx_type j) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
461 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
462 return checkelem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
463 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
464
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
465 T operator () (const Array<octave_idx_type>& ra_idx) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
466 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
467 return checkelem (ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
468 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
469
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
470 #else
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
471 T operator () (octave_idx_type n) const { return elem (n); }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
472 T operator () (octave_idx_type i, octave_idx_type j) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
473 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
474 return elem (i, j);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
475 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
476
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
477 T operator () (const Array<octave_idx_type>& ra_idx) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
478 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
479 return elem (ra_idx);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
480 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
481 #endif
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
482
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
483 Sparse<T> maybe_compress (bool remove_zeros = false)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
484 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
485 if (remove_zeros)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
486 make_unique (); // Needs to unshare because elements are removed.
10497
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
487
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
488 rep->maybe_compress (remove_zeros);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
489 return (*this);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
490 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
491
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
492 Sparse<T> reshape (const dim_vector& new_dims) const;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
493
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
494 Sparse<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
495
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
496 Sparse<T> ipermute (const Array<octave_idx_type>& vec) const
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
497 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
498 return permute (vec, true);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
499 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
500
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
501 void resize1 (octave_idx_type n);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
502
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
503 void resize (octave_idx_type r, octave_idx_type c);
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
504
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
505 void resize (const dim_vector& dv);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
506
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
507 void change_capacity (octave_idx_type nz)
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
508 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
509 if (nz < nnz ())
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
510 make_unique (); // Unshare now because elements will be truncated.
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
511 rep->change_length (nz);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
512 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
513
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
514 Sparse<T>& insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
515 Sparse<T>& insert (const Sparse<T>& a, const Array<octave_idx_type>& idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
516
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
517 bool is_square (void) const { return (dim1 () == dim2 ()); }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
518
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
519 bool is_empty (void) const { return (rows () < 1 && cols () < 1); }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
520
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
521 Sparse<T> transpose (void) const;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
522
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
523 T* data (void) { make_unique (); return rep->d; }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
524 T& data (octave_idx_type i) { make_unique (); return rep->data (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
525 T* xdata (void) { return rep->d; }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
526 T& xdata (octave_idx_type i) { return rep->data (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
527
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
528 T data (octave_idx_type i) const { return rep->data (i); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
529 // FIXME: shouldn't this be returning const T*?
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
530 T* data (void) const { return rep->d; }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
531
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
532 octave_idx_type* ridx (void) { make_unique (); return rep->r; }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
533 octave_idx_type& ridx (octave_idx_type i)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
534 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
535 make_unique (); return rep->ridx (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
536 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
537
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
538 octave_idx_type* xridx (void) { return rep->r; }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
539 octave_idx_type& xridx (octave_idx_type i) { return rep->ridx (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
540
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
541 octave_idx_type ridx (octave_idx_type i) const { return rep->cridx (i); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
542 // FIXME: shouldn't this be returning const octave_idx_type*?
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
543 octave_idx_type* ridx (void) const { return rep->r; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
544
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
545 octave_idx_type* cidx (void) { make_unique (); return rep->c; }
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
546 octave_idx_type& cidx (octave_idx_type i)
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
547 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
548 make_unique (); return rep->cidx (i);
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
549 }
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
550
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
551 octave_idx_type* xcidx (void) { return rep->c; }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
552 octave_idx_type& xcidx (octave_idx_type i) { return rep->cidx (i); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
553
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
554 octave_idx_type cidx (octave_idx_type i) const { return rep->ccidx (i); }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
555 // FIXME: shouldn't this be returning const octave_idx_type*?
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
556 octave_idx_type* cidx (void) const { return rep->c; }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
557
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
558 octave_idx_type ndims (void) const { return dimensions.length (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
559
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
560 void delete_elements (const idx_vector& i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
561
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
562 void delete_elements (int dim, const idx_vector& i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
563
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
564 void delete_elements (const idx_vector& i, const idx_vector& j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
565
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10382
diff changeset
566 Sparse<T> index (const idx_vector& i, bool resize_ok = false) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
567
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
568 Sparse<T> index (const idx_vector& i, const idx_vector& j,
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
569 bool resize_ok = false) const;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
570
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
571 void assign (const idx_vector& i, const Sparse<T>& rhs);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
572
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
573 void assign (const idx_vector& i, const idx_vector& j, const Sparse<T>& rhs);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
574
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
575 void print_info (std::ostream& os, const std::string& prefix) const;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
576
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
577 // Unsafe. These functions exist to support the MEX interface.
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
578 // You should not use them anywhere else.
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
579 void *mex_get_data (void) const { return const_cast<T *> (data ()); }
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
580
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
581 octave_idx_type *mex_get_ir (void) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
582 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
583 return const_cast<octave_idx_type *> (ridx ());
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
584 }
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5775
diff changeset
585
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
586 octave_idx_type *mex_get_jc (void) const
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
587 {
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
588 return const_cast<octave_idx_type *> (cidx ());
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
589 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
590
7463
2467639bd8c0 eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents: 7433
diff changeset
591 Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
592 Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
14792
8483286c0a13 Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
593 sortmode mode = ASCENDING) const;
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
594
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7602
diff changeset
595 Sparse<T> diag (octave_idx_type k = 0) const;
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7602
diff changeset
596
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10537
diff changeset
597 // dim = -1 and dim = -2 are special; see Array<T>::cat description.
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
598 static Sparse<T>
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
599 cat (int dim, octave_idx_type n, const Sparse<T> *sparse_list);
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
600
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
601 Array<T> array_value (void) const;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
602
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
603 // Generic any/all test functionality with arbitrary predicate.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
604 template <typename F, bool zero>
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
605 bool test (F fcn) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
606 {
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
607 return any_all_test<F, T, zero> (fcn, data (), nnz ());
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
608 }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
609
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
610 // Simpler calls.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
611 template <typename F>
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
612 bool test_any (F fcn) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
613 { return test<F, false> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
614
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
615 template <typename F>
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
616 bool test_all (F fcn) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
617 { return test<F, true> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
618
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
619 // Overloads for function references.
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
620 bool test_any (bool (&fcn) (T)) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
621 { return test<bool (&) (T), false> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
622
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
623 bool test_any (bool (&fcn) (const T&)) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
624 { return test<bool (&) (const T&), false> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
625
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
626 bool test_all (bool (&fcn) (T)) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
627 { return test<bool (&) (T), true> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
628
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
629 bool test_all (bool (&fcn) (const T&)) const
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
630 { return test<bool (&) (const T&), true> (fcn); }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
631
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
632 template <typename U, typename F>
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
633 Sparse<U>
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
634 map (F fcn) const
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
635 {
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
636 Sparse<U> result;
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
637 U f_zero = fcn (0.);
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
638
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
639 if (f_zero != 0.)
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
640 {
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
641 octave_idx_type nr = rows ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
642 octave_idx_type nc = cols ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
643
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
644 result = Sparse<U> (nr, nc, f_zero);
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
645
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
646 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
647 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
648 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
649 octave_quit ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
650 /* Use data instead of elem for better performance. */
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
651 result.data (ridx (i) + j * nr) = fcn (data (i));
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
652 }
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
653
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
654 result.maybe_compress (true);
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
655 }
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
656 else
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
657 {
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
658 octave_idx_type nz = nnz ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
659 octave_idx_type nr = rows ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
660 octave_idx_type nc = cols ();
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
661
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
662 result = Sparse<U> (nr, nc, nz);
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
663 octave_idx_type ii = 0;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
664 result.cidx (ii) = 0;
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
665
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
666 for (octave_idx_type j = 0; j < nc; j++)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
667 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
668 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
669 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
670 U val = fcn (data (i));
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
671 if (val != 0.0)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
672 {
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
673 result.data (ii) = val;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
674 result.ridx (ii++) = ridx (i);
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
675 }
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
676 octave_quit ();
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
677 }
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
678 result.cidx (j+1) = ii;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
679 }
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
680
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
681 result.maybe_compress (false);
7602
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
682 }
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
683
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
684 return result;
7bfaa9611558 Rewrite sparse mappers in terms of a functor template function
David Bateman <dbateman@free.fr>
parents: 7470
diff changeset
685 }
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
686
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
687 // Overloads for function references.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
688 template <typename U>
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
689 Sparse<U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
690 map (U (&fcn) (T)) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
691 { return map<U, U (&) (T)> (fcn); }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
692
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
693 template <typename U>
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
694 Sparse<U>
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
695 map (U (&fcn) (const T&)) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
696 { return map<U, U (&) (const T&)> (fcn); }
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
697
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
698 bool indices_ok (void) const { return rep->indices_ok (); }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
699 };
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
700
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21137
diff changeset
701 template <typename T>
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
702 std::istream&
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
703 read_sparse_matrix (std::istream& is, Sparse<T>& a,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
704 T (*read_fcn) (std::istream&))
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
705 {
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
706 octave_idx_type nr = a.rows ();
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
707 octave_idx_type nc = a.cols ();
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
708 octave_idx_type nz = a.nzmax ();
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
709
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
710 if (nr > 0 && nc > 0)
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
711 {
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
712 octave_idx_type itmp;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
713 octave_idx_type jtmp;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
714 octave_idx_type iold = 0;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
715 octave_idx_type jold = 0;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
716 octave_idx_type ii = 0;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
717 T tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
718
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
719 a.cidx (0) = 0;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
720 for (octave_idx_type i = 0; i < nz; i++)
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
721 {
9829
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
722 itmp = 0; jtmp = 0;
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
723 is >> itmp;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
724 itmp--;
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
725
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
726 is >> jtmp;
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
727 jtmp--;
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
728
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
729 if (itmp < 0 || itmp >= nr)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
730 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
731 is.setstate (std::ios::failbit);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
732
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
733 (*current_liboctave_error_handler)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
734 ("invalid sparse matrix: row index = %d out of range",
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
735 itmp + 1);
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
736 }
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
737
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
738 if (jtmp < 0 || jtmp >= nc)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
739 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
740 is.setstate (std::ios::failbit);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
741
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
742 (*current_liboctave_error_handler)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
743 ("invalid sparse matrix: column index = %d out of range",
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
744 jtmp + 1);
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
745 }
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
746
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
747 if (jtmp < jold)
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
748 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
749 is.setstate (std::ios::failbit);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
750
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
751 (*current_liboctave_error_handler)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
752 ("invalid sparse matrix: "
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
753 "column indices must appear in ascending order");
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
754 }
9829
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
755 else if (jtmp > jold)
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
756 {
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
757 for (octave_idx_type j = jold; j < jtmp; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
758 a.cidx (j+1) = ii;
9829
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
759 }
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
760 else if (itmp < iold)
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
761 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
762 is.setstate (std::ios::failbit);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
763
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
764 (*current_liboctave_error_handler)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
765 ("invalid sparse matrix: "
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
766 "row indices must appear in ascending order in each column");
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
767 }
9829
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
768
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
769 iold = itmp;
9829
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
770 jold = jtmp;
8fd88cc36fa4 fix loading sparse matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
771
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
772 tmp = read_fcn (is);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
773
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
774 if (! is)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
775 return is; // Problem, return is in error state
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
776
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
777 a.data (ii) = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21134
diff changeset
778 a.ridx (ii++) = itmp;
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
779 }
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
780
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
781 for (octave_idx_type j = jold; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
782 a.cidx (j+1) = ii;
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
783 }
21137
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
784
623fc7d08cc6 maint: Clean up compile warnings in liboctave from cset 7cac4e7458f2.
Rik <rik@octave.org>
parents: 21136
diff changeset
785 return is;
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
786 }
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
787
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
788 #endif