Mercurial > octave
annotate liboctave/array/Sparse.cc @ 31771:21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
* mk-opts.pl, external.txi, embedded.cc, make_int.cc, standalone.cc,
standalonebuiltin.cc, BaseControl.cc, BaseControl.h, ButtonControl.cc,
ButtonControl.h, ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h,
CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h,
ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h, Figure.cc,
Figure.h, FigureWindow.cc, FigureWindow.h, GLCanvas.cc, GLCanvas.h,
GenericEventNotify.h, KeyMap.cc, ListBoxControl.cc, ListBoxControl.h,
Logger.cc, Logger.h, Menu.cc, Menu.h, MenuContainer.h, Object.cc, Object.h,
ObjectProxy.cc, ObjectProxy.h, Panel.cc, Panel.h, PopupMenuControl.cc,
PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h, PushTool.cc,
PushTool.h, RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc,
SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h, TextEdit.h,
ToggleButtonControl.cc, ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h,
ToolBar.cc, ToolBar.h, ToolBarButton.cc, ToolBarButton.h, gl-select.cc,
gl-select.h, qopengl-functions.h, qt-graphics-toolkit.h, qdialog.cpp,
qfontdialog.cpp, qprintdialog_win.cpp, liboctgui-build-info.h,
liboctgui-build-info.in.cc, color-picker.cc, color-picker.h, command-widget.cc,
command-widget.h, community-news.cc, community-news.h, dialog.cc, dialog.h,
documentation-bookmarks.cc, documentation-bookmarks.h,
documentation-dock-widget.cc, documentation-dock-widget.h, documentation.cc,
documentation.h, dw-main-window.cc, dw-main-window.h,
external-editor-interface.cc, external-editor-interface.h,
files-dock-widget.cc, files-dock-widget.h, find-files-dialog.cc,
find-files-dialog.h, find-files-model.cc, find-files-model.h,
gui-preferences.cc, gui-preferences.h, gui-settings.cc, gui-settings.h,
history-dock-widget.cc, history-dock-widget.h, interpreter-qobject.cc,
interpreter-qobject.h, file-editor-interface.h, file-editor-tab.cc,
file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc,
find-dialog.h, marker.cc, marker.h, octave-qscintilla.cc, octave-qscintilla.h,
octave-txt-lexer.cc, octave-txt-lexer.h, main-window.cc, main-window.h,
news-reader.cc, news-reader.h, octave-dock-widget.cc, octave-dock-widget.h,
octave-qobject.cc, octave-qobject.h, qt-application.cc, qt-application.h,
qt-interpreter-events.cc, qt-interpreter-events.h, release-notes.cc,
release-notes.h, set-path-dialog.cc, set-path-dialog.h, set-path-model.cc,
set-path-model.h, settings-dialog.cc, settings-dialog.h,
shortcuts-tree-widget.cc, shortcuts-tree-widget.h, tab-bar.cc, tab-bar.h,
terminal-dock-widget.cc, terminal-dock-widget.h, variable-editor-model.cc,
variable-editor-model.h, variable-editor.cc, variable-editor.h,
welcome-wizard.cc, welcome-wizard.h, workspace-model.cc, workspace-model.h,
workspace-view.cc, workspace-view.h, build-env.h, Cell.cc, Cell.h,
__contourc__.cc, __magick_read__.cc, auto-shlib.cc, auto-shlib.h,
base-text-renderer.h, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, debug.cc, defaults.cc, defaults.h, defun.cc,
display.cc, display.h, dynamic-ld.cc, dynamic-ld.h, environment.cc,
environment.h, error.cc, error.h, errwarn.cc, errwarn.h, event-manager.cc,
event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h,
ft-text-renderer.cc, ft-text-renderer.h, genprops.awk, gh-manager.cc,
gh-manager.h, gl-render.cc, gl-render.h, gl2ps-print.cc, graphics-toolkit.h,
graphics.cc, graphics.in.h, gtk-manager.cc, gtk-manager.h, help.cc, help.h,
hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h,
interpreter.cc, interpreter.h, jsondecode.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
ls-hdf5.cc, ls-hdf5.h, mxarray.h, oct-errno.h, oct-errno.in.cc, oct-fstrm.cc,
oct-fstrm.h, oct-handle.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc,
oct-iostrm.h, oct-map.cc, oct-map.h, oct-opengl.h, oct-prcstrm.cc,
oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.h, oct-stdstrm.h,
oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h,
oct-tex-lexer.in.ll, pager.cc, pager.h, pr-flt-fmt.cc, pr-flt-fmt.h,
pr-output.cc, pr-output.h, procstream.cc, procstream.h, settings.cc,
settings.h, sighandlers.cc, sighandlers.h, stack-frame.cc, stack-frame.h,
svd.cc, syminfo.cc, syminfo.h, symrec.cc, symrec.h, symscope.cc, symscope.h,
symtab.cc, symtab.h, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h,
text-renderer.cc, text-renderer.h, toplev.cc, url-handle-manager.cc,
url-handle-manager.h, variables.cc, xpow.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, audiodevinfo.cc, gzip.cc,
liboctinterp-build-info.h, liboctinterp-build-info.in.cc,
mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base-diag.cc, ov-base-diag.h, ov-base-int.cc,
ov-base-int.h, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc,
ov-base-scalar.h, ov-base-sparse.cc, ov-base-sparse.h, ov-base.cc, ov-base.h,
ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc,
ov-bool.h, ov-builtin.cc, ov-builtin.h, ov-cell.cc, ov-cell.h, ov-ch-mat.cc,
ov-ch-mat.h, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h,
ov-colon.h, ov-complex.cc, ov-complex.h, ov-cs-list.h, ov-cx-diag.cc,
ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc, ov-cx-sparse.h,
ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.cc,
ov-fcn.h, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h,
ov-flt-cx-diag.cc, ov-flt-cx-diag.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h,
ov-flt-re-diag.cc, ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-flt-re-mat.h,
ov-intx.h, ov-java.cc, ov-java.h, ov-lazy-idx.cc, ov-lazy-idx.h,
ov-legacy-range.cc, ov-legacy-range.h, ov-magic-int.cc, ov-magic-int.h,
ov-mex-fcn.cc, ov-mex-fcn.h, ov-null-mat.cc, ov-null-mat.h, ov-oncleanup.cc,
ov-oncleanup.h, ov-perm.cc, ov-perm.h, ov-range.cc, ov-range.h, ov-re-diag.cc,
ov-re-diag.h, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h,
ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov-str-mat.h, ov-struct.cc,
ov-struct.h, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc,
ov.h, ovl.cc, ovl.h, octave.cc, octave.h, anon-fcn-validator.h, bp-table.cc,
bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll,
oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc,
pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h,
pt-binop.cc, pt-binop.h, pt-bp.h, pt-cbinop.h, pt-cell.h, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.h, pt-const.h, pt-decl.cc,
pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc,
pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc,
pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.h, pt-misc.cc, pt-misc.h,
pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h,
pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h,
pt-walk.h, pt.cc, pt.h, token.cc, token.h, usage.h, Array-base.cc, Array.h,
CColVector.cc, CColVector.h, CDiagMatrix.cc, CDiagMatrix.h, CMatrix.cc,
CMatrix.h, CNDArray.cc, CNDArray.h, CRowVector.cc, CRowVector.h, CSparse.cc,
CSparse.h, DiagArray2.cc, DiagArray2.h, MArray.cc, MArray.h, MDiagArray2.h,
MSparse.h, MatrixType.cc, MatrixType.h, PermMatrix.cc, PermMatrix.h, Range.cc,
Range.h, Sparse-b.cc, Sparse.cc, Sparse.h, boolMatrix.cc, boolMatrix.h,
boolNDArray.cc, boolNDArray.h, boolSparse.cc, boolSparse.h, chMatrix.h,
chNDArray.h, dColVector.cc, dColVector.h, dDiagMatrix.cc, dDiagMatrix.h,
dMatrix.cc, dMatrix.h, dNDArray.cc, dNDArray.h, dRowVector.cc, dRowVector.h,
dSparse.cc, dSparse.h, dim-vector.cc, dim-vector.h, fCColVector.cc,
fCColVector.h, fCDiagMatrix.cc, fCDiagMatrix.h, fCMatrix.cc, fCMatrix.h,
fCNDArray.cc, fCNDArray.h, fCRowVector.cc, fCRowVector.h, fColVector.cc,
fColVector.h, fDiagMatrix.cc, fDiagMatrix.h, fMatrix.cc, fMatrix.h,
fNDArray.cc, fNDArray.h, fRowVector.cc, fRowVector.h, idx-vector.cc,
idx-vector.h, intNDArray.cc, intNDArray.h, liboctave-build-info.h,
liboctave-build-info.in.cc, CollocWt.cc, CollocWt.h, DAE.h, DAEFunc.h, DAERT.h,
DAERTFunc.h, DASPK.cc, DASPK.h, DASRT.cc, DASRT.h, DASSL.cc, DASSL.h, DET.h,
EIG.h, LSODE.cc, LSODE.h, ODE.h, ODEFunc.h, ODES.h, ODESFunc.h, Quad.h,
aepbalance.cc, aepbalance.h, base-dae.h, base-de.h, chol.cc, chol.h,
eigs-base.cc, fEIG.h, gepbalance.h, gsvd.cc, gsvd.h, hess.h, lu.cc, lu.h,
oct-fftw.cc, oct-fftw.h, oct-rand.cc, oct-rand.h, oct-spparms.cc,
oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randmtzig.cc, randmtzig.h, schur.h,
sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc,
sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h,
file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h,
lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h,
oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc,
oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h,
action-container.h, base-list.h, caseless-str.h, cmd-edit.cc, cmd-edit.h,
cmd-hist.cc, cmd-hist.h, data-conv.cc, file-info.h, glob-match.cc,
glob-match.h, kpse.cc, kpse.h, lo-array-errwarn.cc, lo-array-errwarn.h,
lo-hash.cc, lo-hash.h, lo-ieee.cc, lo-ieee.h, lo-regexp.cc, lo-regexp.h,
oct-inttypes.cc, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h,
oct-shlib.cc, oct-shlib.h, oct-sort.cc, oct-sort.h, oct-sparse.cc,
octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc,
singleton-cleanup.cc, singleton-cleanup.h, str-vec.cc, str-vec.h,
unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h, version.cc,
version.in.h, cxx-signal-helpers.cc, acinclude.m4, main-cli.cc, main-gui.cc,
main.in.cc, mkoctfile.in.cc, octave-build-info.h, octave-build-info.in.cc,
octave-config.in.cc, octave-svgconvert.cc, shared-fcns.h:
maint: Eliminate "(void)" in C++ function prototypes/declarations.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 24 Jan 2023 17:19:44 -0800 |
parents | 597f3ee61a48 |
children | 39700c1ea93e |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30883
diff
changeset
|
3 // Copyright (C) 1998-2023 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
5164 | 25 |
21690
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
26 // This file should not include config.h. It is only included in other |
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
27 // C++ source files that should have included config.h before including |
b6a686543080
Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
28 // this file. |
5164 | 29 |
30 #include <cassert> | |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
31 #include <cinttypes> |
5164 | 32 |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
33 #include <algorithm> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
34 #include <istream> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
35 #include <ostream> |
5765 | 36 #include <sstream> |
5164 | 37 #include <vector> |
38 | |
39 #include "Array.h" | |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
40 #include "MArray.h" |
5164 | 41 #include "Array-util.h" |
42 #include "Range.h" | |
43 #include "idx-vector.h" | |
44 #include "lo-error.h" | |
45 #include "quit.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
46 #include "oct-locbuf.h" |
5164 | 47 |
48 #include "Sparse.h" | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
49 #include "sparse-util.h" |
5164 | 50 #include "oct-spparms.h" |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
51 #include "mx-inlines.cc" |
5164 | 52 |
13030
b646413c3d0e
Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12511
diff
changeset
|
53 #include "PermMatrix.h" |
b646413c3d0e
Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12511
diff
changeset
|
54 |
30791 | 55 template <typename T, typename Alloc> |
56 OCTAVE_API typename Sparse<T, Alloc>::SparseRep * | |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
57 Sparse<T, Alloc>::nil_rep () |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21256
diff
changeset
|
58 { |
30791 | 59 static typename Sparse<T, Alloc>::SparseRep nr; |
21573
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21256
diff
changeset
|
60 return &nr; |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21256
diff
changeset
|
61 } |
f3f8e1d3e399
avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
21256
diff
changeset
|
62 |
30791 | 63 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
64 OCTAVE_API |
5164 | 65 T& |
30791 | 66 Sparse<T, Alloc>::SparseRep::elem (octave_idx_type r, octave_idx_type c) |
5164 | 67 { |
5275 | 68 octave_idx_type i; |
5164 | 69 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
70 if (m_nzmax <= 0) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
71 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
72 ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
73 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
74 for (i = m_cidx[c]; i < m_cidx[c + 1]; i++) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
75 if (m_ridx[i] == r) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
76 return m_data[i]; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
77 else if (m_ridx[i] > r) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
78 break; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
79 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
80 // Ok, If we've gotten here, we're in trouble. Have to create a |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
81 // new element in the sparse array. This' gonna be slow!!! |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
82 if (m_cidx[m_ncols] == m_nzmax) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
83 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
84 ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
85 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
86 octave_idx_type to_move = m_cidx[m_ncols] - i; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
87 if (to_move != 0) |
5164 | 88 { |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
89 for (octave_idx_type j = m_cidx[m_ncols]; j > i; j--) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 { |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
91 m_data[j] = m_data[j-1]; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
92 m_ridx[j] = m_ridx[j-1]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 } |
5164 | 94 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
95 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
96 for (octave_idx_type j = c + 1; j < m_ncols + 1; j++) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
97 m_cidx[j] = m_cidx[j] + 1; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
98 |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
99 m_data[i] = 0.; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
100 m_ridx[i] = r; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
101 |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
102 return m_data[i]; |
5164 | 103 } |
104 | |
30791 | 105 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
106 OCTAVE_API |
5164 | 107 T |
30791 | 108 Sparse<T, Alloc>::SparseRep::celem (octave_idx_type r, octave_idx_type c) const |
5164 | 109 { |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
110 if (m_nzmax > 0) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
111 for (octave_idx_type i = m_cidx[c]; i < m_cidx[c + 1]; i++) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
112 if (m_ridx[i] == r) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
113 return m_data[i]; |
5164 | 114 return T (); |
115 } | |
116 | |
30791 | 117 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
118 OCTAVE_API |
5164 | 119 void |
30791 | 120 Sparse<T, Alloc>::SparseRep::maybe_compress (bool remove_zeros) |
5164 | 121 { |
122 if (remove_zeros) | |
123 { | |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
124 octave_idx_type i = 0; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
125 octave_idx_type k = 0; |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
126 for (octave_idx_type j = 1; j <= m_ncols; j++) |
10497
cb7ffe7288f0
improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents:
10494
diff
changeset
|
127 { |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
128 octave_idx_type u = m_cidx[j]; |
21337
cfe11042fbc0
eliminate useless assignment in for loop
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
129 for (; i < u; i++) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
130 if (m_data[i] != T ()) |
10497
cb7ffe7288f0
improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents:
10494
diff
changeset
|
131 { |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
132 m_data[k] = m_data[i]; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
133 m_ridx[k++] = m_ridx[i]; |
10497
cb7ffe7288f0
improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents:
10494
diff
changeset
|
134 } |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
135 m_cidx[j] = k; |
10497
cb7ffe7288f0
improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents:
10494
diff
changeset
|
136 } |
5164 | 137 } |
10497
cb7ffe7288f0
improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents:
10494
diff
changeset
|
138 |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
139 change_length (m_cidx[m_ncols]); |
5164 | 140 } |
141 | |
30791 | 142 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
143 OCTAVE_API |
5164 | 144 void |
30791 | 145 Sparse<T, Alloc>::SparseRep::change_length (octave_idx_type nz) |
5164 | 146 { |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
147 for (octave_idx_type j = m_ncols; j > 0 && m_cidx[j] > nz; j--) |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
148 m_cidx[j] = nz; |
10497
cb7ffe7288f0
improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents:
10494
diff
changeset
|
149 |
27081
c0d8ce61c1c9
Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents:
26569
diff
changeset
|
150 // Always preserve space for 1 element. |
c0d8ce61c1c9
Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents:
26569
diff
changeset
|
151 nz = (nz > 0 ? nz : 1); |
c0d8ce61c1c9
Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents:
26569
diff
changeset
|
152 |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
153 // Skip reallocation if we have less than 1/frac extra elements to discard. |
10497
cb7ffe7288f0
improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents:
10494
diff
changeset
|
154 static const int frac = 5; |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
155 if (nz > m_nzmax || nz < m_nzmax - m_nzmax/frac) |
5164 | 156 { |
10497
cb7ffe7288f0
improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents:
10494
diff
changeset
|
157 // Reallocate. |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
158 octave_idx_type min_nzmax = std::min (nz, m_nzmax); |
5275 | 159 |
30791 | 160 octave_idx_type *new_ridx = idx_type_allocate (nz); |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
161 std::copy_n (m_ridx, min_nzmax, new_ridx); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
162 |
30791 | 163 idx_type_deallocate (m_ridx, m_nzmax); |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
164 m_ridx = new_ridx; |
5164 | 165 |
30791 | 166 T *new_data = T_allocate (nz); |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
167 std::copy_n (m_data, min_nzmax, new_data); |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
168 |
30791 | 169 T_deallocate (m_data, m_nzmax); |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
170 m_data = new_data; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
171 |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
172 m_nzmax = nz; |
5164 | 173 } |
174 } | |
175 | |
30791 | 176 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
177 OCTAVE_API |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
178 bool |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
179 Sparse<T, Alloc>::SparseRep::indices_ok () const |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
180 { |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
181 return sparse_indices_ok (m_ridx, m_cidx, m_nrows, m_ncols, nnz ()); |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
182 } |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
183 |
30791 | 184 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
185 OCTAVE_API |
21990
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
186 bool |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
187 Sparse<T, Alloc>::SparseRep::any_element_is_nan () const |
21990
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
188 { |
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
189 octave_idx_type nz = nnz (); |
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
190 |
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
191 for (octave_idx_type i = 0; i < nz; i++) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
192 if (octave::math::isnan (m_data[i])) |
21990
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
193 return true; |
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
194 |
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
195 return false; |
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
196 } |
efce657ceb86
Provide a warning when an array is used in an if/while/until (bug #43098).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21751
diff
changeset
|
197 |
30791 | 198 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
199 OCTAVE_API |
30791 | 200 Sparse<T, Alloc>::Sparse (octave_idx_type nr, octave_idx_type nc, |
201 T val) | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
202 : m_rep (nullptr), m_dimensions (dim_vector (nr, nc)) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
203 { |
5630 | 204 if (val != T ()) |
5164 | 205 { |
30791 | 206 m_rep = new typename Sparse<T, Alloc>::SparseRep (nr, nc, m_dimensions.safe_numel ()); |
5630 | 207 |
208 octave_idx_type ii = 0; | |
209 xcidx (0) = 0; | |
210 for (octave_idx_type j = 0; j < nc; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
211 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
212 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
213 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
214 xdata (ii) = val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
215 xridx (ii++) = i; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
216 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
217 xcidx (j+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
218 } |
5630 | 219 } |
220 else | |
221 { | |
30791 | 222 m_rep = new typename Sparse<T, Alloc>::SparseRep (nr, nc, 0); |
5630 | 223 for (octave_idx_type j = 0; j < nc+1; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
224 xcidx (j) = 0; |
5164 | 225 } |
226 } | |
227 | |
30791 | 228 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
229 OCTAVE_API |
30791 | 230 Sparse<T, Alloc>::Sparse (const PermMatrix& a) |
231 : m_rep (new typename Sparse<T, Alloc>::SparseRep (a.rows (), a.cols (), a.rows ())), | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
232 m_dimensions (dim_vector (a.rows (), a.cols ())) |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
233 { |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
234 octave_idx_type n = a.rows (); |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
235 for (octave_idx_type i = 0; i <= n; i++) |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
236 cidx (i) = i; |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
237 |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
238 const Array<octave_idx_type> pv = a.col_perm_vec (); |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
239 |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
240 for (octave_idx_type i = 0; i < n; i++) |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
241 ridx (i) = pv(i); |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
242 |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
243 for (octave_idx_type i = 0; i < n; i++) |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
244 data (i) = 1.0; |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
245 } |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
246 |
30791 | 247 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
248 OCTAVE_API |
30791 | 249 Sparse<T, Alloc>::Sparse (const dim_vector& dv) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
250 : m_rep (nullptr), m_dimensions (dv) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
251 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
252 if (dv.ndims () != 2) |
5164 | 253 (*current_liboctave_error_handler) |
254 ("Sparse::Sparse (const dim_vector&): dimension mismatch"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
255 |
30791 | 256 m_rep = new typename Sparse<T, Alloc>::SparseRep (dv(0), dv(1), 0); |
5164 | 257 } |
258 | |
30791 | 259 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
260 OCTAVE_API |
30791 | 261 Sparse<T, Alloc>::Sparse (const Sparse<T, Alloc>& a, const dim_vector& dv) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
262 : m_rep (nullptr), m_dimensions (dv) |
5164 | 263 { |
264 | |
265 // Work in unsigned long long to avoid overflow issues with numel | |
266 unsigned long long a_nel = static_cast<unsigned long long>(a.rows ()) * | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
267 static_cast<unsigned long long>(a.cols ()); |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
268 unsigned long long dv_nel = static_cast<unsigned long long>(dv(0)) * |
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
269 static_cast<unsigned long long>(dv(1)); |
5164 | 270 |
271 if (a_nel != dv_nel) | |
272 (*current_liboctave_error_handler) | |
273 ("Sparse::Sparse (const Sparse&, const dim_vector&): dimension mismatch"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
274 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
275 dim_vector old_dims = a.dims (); |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
276 octave_idx_type new_nzmax = a.nnz (); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
277 octave_idx_type new_nr = dv(0); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
278 octave_idx_type new_nc = dv(1); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
279 octave_idx_type old_nr = old_dims(0); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
280 octave_idx_type old_nc = old_dims(1); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
281 |
30791 | 282 m_rep = new typename Sparse<T, Alloc>::SparseRep (new_nr, new_nc, new_nzmax); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
283 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
284 octave_idx_type kk = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
285 xcidx (0) = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
286 for (octave_idx_type i = 0; i < old_nc; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
287 for (octave_idx_type j = a.cidx (i); j < a.cidx (i+1); j++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
288 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
289 octave_idx_type tmp = i * old_nr + a.ridx (j); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
290 octave_idx_type ii = tmp % new_nr; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
291 octave_idx_type jj = (tmp - ii) / new_nr; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
292 for (octave_idx_type k = kk; k < jj; k++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
293 xcidx (k+1) = j; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
294 kk = jj; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
295 xdata (j) = a.data (j); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
296 xridx (j) = ii; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
297 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
298 for (octave_idx_type k = kk; k < new_nc; k++) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
299 xcidx (k+1) = new_nzmax; |
5164 | 300 } |
301 | |
30791 | 302 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
303 OCTAVE_API |
30791 | 304 Sparse<T, Alloc>::Sparse (const Array<T>& a, |
305 const octave::idx_vector& r, | |
306 const octave::idx_vector& c, | |
307 octave_idx_type nr, octave_idx_type nc, | |
308 bool sum_terms, octave_idx_type nzm) | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
309 : m_rep (nullptr), m_dimensions () |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
310 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
311 if (nr < 0) |
11508
41866901ec62
Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11311
diff
changeset
|
312 nr = r.extent (0); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
313 else if (r.extent (nr) > nr) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
314 (*current_liboctave_error_handler) |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
315 ("sparse: row index %" OCTAVE_IDX_TYPE_FORMAT "out of bound " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
316 "%" OCTAVE_IDX_TYPE_FORMAT, r.extent (nr), nr); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
317 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
318 if (nc < 0) |
11508
41866901ec62
Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11311
diff
changeset
|
319 nc = c.extent (0); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
320 else if (c.extent (nc) > nc) |
11508
41866901ec62
Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents:
11311
diff
changeset
|
321 (*current_liboctave_error_handler) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
322 ("sparse: column index %" OCTAVE_IDX_TYPE_FORMAT " out of bound " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
323 "%" OCTAVE_IDX_TYPE_FORMAT, r.extent (nc), nc); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
324 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
325 m_dimensions = dim_vector (nr, nc); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
326 |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
327 octave_idx_type n = a.numel (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
328 octave_idx_type rl = r.length (nr); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
329 octave_idx_type cl = c.length (nc); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
330 bool a_scalar = n == 1; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
331 if (a_scalar) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
332 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
333 if (rl != 1) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
334 n = rl; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
335 else if (cl != 1) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
336 n = cl; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
337 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
338 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
339 if ((rl != 1 && rl != n) || (cl != 1 && cl != n)) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
340 (*current_liboctave_error_handler) ("sparse: dimension mismatch"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
341 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
342 // Only create m_rep after input validation to avoid memory leak. |
30791 | 343 m_rep = new typename Sparse<T, Alloc>::SparseRep (nr, nc, (nzm > 0 ? nzm : 0)); |
17664
f4b0430fa5fd
Avoid memory leak in Sparse constructor.
Rik <rik@octave.org>
parents:
17642
diff
changeset
|
344 |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
345 if (rl <= 1 && cl <= 1) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
346 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
347 if (n == 1 && a(0) != T ()) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
348 { |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
349 change_capacity (nzm > 1 ? nzm : 1); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
350 xridx (0) = r(0); |
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
351 xdata (0) = a(0); |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
352 std::fill_n (xcidx () + c(0) + 1, nc - c(0), 1); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
353 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
354 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
355 else if (a_scalar) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
356 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
357 // This is completely specialized, because the sorts can be simplified. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
358 T a0 = a(0); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
359 if (a0 == T ()) |
10509
ddbd812d09aa
properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
360 { |
ddbd812d09aa
properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
361 // Do nothing, it's an empty matrix. |
ddbd812d09aa
properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
362 } |
ddbd812d09aa
properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
363 else if (cl == 1) |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
364 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
365 // Sparse column vector. Sort row indices. |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
366 octave::idx_vector rs = r.sorted (); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
367 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
368 octave_quit (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
369 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
370 const octave_idx_type *rd = rs.raw (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
371 // Count unique indices. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
372 octave_idx_type new_nz = 1; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
373 for (octave_idx_type i = 1; i < n; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
374 new_nz += rd[i-1] != rd[i]; |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
375 |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
376 // Allocate result. |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
377 change_capacity (nzm > new_nz ? nzm : new_nz); |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
378 std::fill_n (xcidx () + c(0) + 1, nc - c(0), new_nz); |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
379 |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
380 octave_idx_type *rri = ridx (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
381 T *rrd = data (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
382 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
383 octave_quit (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
384 |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
385 octave_idx_type k = -1; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
386 octave_idx_type l = -1; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
387 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
388 if (sum_terms) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
389 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
390 // Sum repeated indices. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
391 for (octave_idx_type i = 0; i < n; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
392 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
393 if (rd[i] != l) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
394 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
395 l = rd[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
396 rri[++k] = rd[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
397 rrd[k] = a0; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
398 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
399 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
400 rrd[k] += a0; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
401 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
402 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
403 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
404 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
405 // Pick the last one. |
11571
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
406 for (octave_idx_type i = 0; i < n; i++) |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
407 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
408 if (rd[i] != l) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
409 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
410 l = rd[i]; |
11571
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
411 rri[++k] = rd[i]; |
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
412 rrd[k] = a0; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
413 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
414 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
415 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
416 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
417 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
418 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
419 { |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
420 octave::idx_vector rr = r; |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
421 octave::idx_vector cc = c; |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
422 const octave_idx_type *rd = rr.raw (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
423 const octave_idx_type *cd = cc.raw (); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
424 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ci, nc+1, 0); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
425 ci[0] = 0; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
426 // Bin counts of column indices. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
427 for (octave_idx_type i = 0; i < n; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
428 ci[cd[i]+1]++; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
429 // Make them cumulative, shifted one to right. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
430 for (octave_idx_type i = 1, s = 0; i <= nc; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
431 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
432 octave_idx_type s1 = s + ci[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
433 ci[i] = s; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
434 s = s1; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
435 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
436 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
437 octave_quit (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
438 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
439 // Bucket sort. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
440 OCTAVE_LOCAL_BUFFER (octave_idx_type, sidx, n); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
441 for (octave_idx_type i = 0; i < n; i++) |
11571
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
442 if (rl == 1) |
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
443 sidx[ci[cd[i]+1]++] = rd[0]; |
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
444 else |
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
445 sidx[ci[cd[i]+1]++] = rd[i]; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
446 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
447 // Subsorts. We don't need a stable sort, all values are equal. |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
448 xcidx (0) = 0; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
449 for (octave_idx_type j = 0; j < nc; j++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
450 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
451 std::sort (sidx + ci[j], sidx + ci[j+1]); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
452 octave_idx_type l = -1; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
453 octave_idx_type nzj = 0; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
454 // Count. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
455 for (octave_idx_type i = ci[j]; i < ci[j+1]; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
456 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
457 octave_idx_type k = sidx[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
458 if (k != l) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
459 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
460 l = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
461 nzj++; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
462 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
463 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
464 // Set column pointer. |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
465 xcidx (j+1) = xcidx (j) + nzj; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
466 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
467 |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
468 change_capacity (nzm > xcidx (nc) ? nzm : xcidx (nc)); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
469 octave_idx_type *rri = ridx (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
470 T *rrd = data (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
471 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
472 // Fill-in data. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
473 for (octave_idx_type j = 0, jj = -1; j < nc; j++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
474 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
475 octave_quit (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
476 octave_idx_type l = -1; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
477 if (sum_terms) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
478 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
479 // Sum adjacent terms. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
480 for (octave_idx_type i = ci[j]; i < ci[j+1]; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
481 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
482 octave_idx_type k = sidx[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
483 if (k != l) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
484 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
485 l = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
486 rrd[++jj] = a0; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
487 rri[jj] = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
488 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
489 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
490 rrd[jj] += a0; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
491 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
492 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
493 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
494 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
495 // Use the last one. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
496 for (octave_idx_type i = ci[j]; i < ci[j+1]; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
497 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
498 octave_idx_type k = sidx[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
499 if (k != l) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
500 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
501 l = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
502 rrd[++jj] = a0; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
503 rri[jj] = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
504 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
505 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
506 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
507 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
508 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
509 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
510 else if (cl == 1) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
511 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
512 // Sparse column vector. Sort row indices. |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
513 Array<octave_idx_type> rsi; |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
514 octave::idx_vector rs = r.sorted (rsi); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
515 |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
516 octave_quit (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
517 |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
518 const octave_idx_type *rd = rs.raw (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
519 const octave_idx_type *rdi = rsi.data (); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
520 // Count unique indices. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
521 octave_idx_type new_nz = 1; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
522 for (octave_idx_type i = 1; i < n; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
523 new_nz += rd[i-1] != rd[i]; |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
524 |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
525 // Allocate result. |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
526 change_capacity (nzm > new_nz ? nzm : new_nz); |
24010
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
527 std::fill_n (xcidx () + c(0) + 1, nc - c(0), new_nz); |
584971932def
Improve performance of Sparse constructors (bug #51880).
Rik <rik@octave.org>
parents:
23956
diff
changeset
|
528 |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
529 octave_idx_type *rri = ridx (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
530 T *rrd = data (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
531 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
532 octave_quit (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
533 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
534 octave_idx_type k = 0; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
535 rri[k] = rd[0]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
536 rrd[k] = a(rdi[0]); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
537 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
538 if (sum_terms) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
539 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
540 // Sum repeated indices. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
541 for (octave_idx_type i = 1; i < n; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
542 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
543 if (rd[i] != rd[i-1]) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
544 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
545 rri[++k] = rd[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
546 rrd[k] = a(rdi[i]); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
547 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
548 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
549 rrd[k] += a(rdi[i]); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
550 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
551 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
552 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
553 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
554 // Pick the last one. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
555 for (octave_idx_type i = 1; i < n; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
556 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
557 if (rd[i] != rd[i-1]) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
558 rri[++k] = rd[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
559 rrd[k] = a(rdi[i]); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
560 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
561 } |
10509
ddbd812d09aa
properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
562 |
ddbd812d09aa
properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
563 maybe_compress (true); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
564 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
565 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
566 { |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
567 octave::idx_vector rr = r; |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
568 octave::idx_vector cc = c; |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
569 const octave_idx_type *rd = rr.raw (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
570 const octave_idx_type *cd = cc.raw (); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
571 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ci, nc+1, 0); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
572 ci[0] = 0; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
573 // Bin counts of column indices. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
574 for (octave_idx_type i = 0; i < n; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
575 ci[cd[i]+1]++; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
576 // Make them cumulative, shifted one to right. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
577 for (octave_idx_type i = 1, s = 0; i <= nc; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
578 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
579 octave_idx_type s1 = s + ci[i]; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
580 ci[i] = s; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
581 s = s1; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
582 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
583 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
584 octave_quit (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
585 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
586 typedef std::pair<octave_idx_type, octave_idx_type> idx_pair; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
587 // Bucket sort. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
588 OCTAVE_LOCAL_BUFFER (idx_pair, spairs, n); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
589 for (octave_idx_type i = 0; i < n; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
590 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
591 idx_pair& p = spairs[ci[cd[i]+1]++]; |
11571
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
592 if (rl == 1) |
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
593 p.first = rd[0]; |
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
594 else |
0e414f837c58
Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents:
11570
diff
changeset
|
595 p.first = rd[i]; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
596 p.second = i; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
597 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
598 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
599 // Subsorts. We don't need a stable sort, the second index stabilizes it. |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
600 xcidx (0) = 0; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
601 for (octave_idx_type j = 0; j < nc; j++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
602 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
603 std::sort (spairs + ci[j], spairs + ci[j+1]); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
604 octave_idx_type l = -1; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
605 octave_idx_type nzj = 0; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
606 // Count. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
607 for (octave_idx_type i = ci[j]; i < ci[j+1]; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
608 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
609 octave_idx_type k = spairs[i].first; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
610 if (k != l) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
611 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
612 l = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
613 nzj++; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
614 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
615 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
616 // Set column pointer. |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
617 xcidx (j+1) = xcidx (j) + nzj; |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
618 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
619 |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
620 change_capacity (nzm > xcidx (nc) ? nzm : xcidx (nc)); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
621 octave_idx_type *rri = ridx (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
622 T *rrd = data (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
623 |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
624 // Fill-in data. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
625 for (octave_idx_type j = 0, jj = -1; j < nc; j++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
626 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
627 octave_quit (); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
628 octave_idx_type l = -1; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
629 if (sum_terms) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
630 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
631 // Sum adjacent terms. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
632 for (octave_idx_type i = ci[j]; i < ci[j+1]; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
633 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
634 octave_idx_type k = spairs[i].first; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
635 if (k != l) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
636 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
637 l = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
638 rrd[++jj] = a(spairs[i].second); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
639 rri[jj] = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
640 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
641 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
642 rrd[jj] += a(spairs[i].second); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
643 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
644 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
645 else |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
646 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
647 // Use the last one. |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
648 for (octave_idx_type i = ci[j]; i < ci[j+1]; i++) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
649 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
650 octave_idx_type k = spairs[i].first; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
651 if (k != l) |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
652 { |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
653 l = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
654 rri[++jj] = k; |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
655 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
656 rrd[jj] = a(spairs[i].second); |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
657 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
658 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
659 } |
10509
ddbd812d09aa
properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
660 |
ddbd812d09aa
properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
661 maybe_compress (true); |
10479
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
662 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
663 } |
ded9beac7582
optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents:
10468
diff
changeset
|
664 |
23955
520c37805969
sparse: correctly handle scalar column index (bug #51880)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
665 /* |
28579
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
666 %!assert <*51880> (sparse (1:2, 2, 1:2, 2, 2), sparse ([0, 1; 0, 2])) |
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
667 %!assert <*51880> (sparse (1:2, 1, 1:2, 2, 2), sparse ([1, 0; 2, 0])) |
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
668 %!assert <*51880> (sparse (1:2, 2, 1:2, 2, 3), sparse ([0, 1, 0; 0, 2, 0])) |
23955
520c37805969
sparse: correctly handle scalar column index (bug #51880)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
669 */ |
520c37805969
sparse: correctly handle scalar column index (bug #51880)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
670 |
30791 | 671 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
672 OCTAVE_API |
30791 | 673 Sparse<T, Alloc>::Sparse (const Array<T>& a) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
674 : m_rep (nullptr), m_dimensions (a.dims ()) |
5164 | 675 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
676 if (m_dimensions.ndims () > 2) |
5164 | 677 (*current_liboctave_error_handler) |
678 ("Sparse::Sparse (const Array<T>&): dimension mismatch"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
679 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
680 octave_idx_type nr = rows (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
681 octave_idx_type nc = cols (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
682 octave_idx_type len = a.numel (); |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
683 octave_idx_type new_nzmax = 0; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
684 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
685 // First count the number of nonzero terms |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
686 for (octave_idx_type i = 0; i < len; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
687 if (a(i) != T ()) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
688 new_nzmax++; |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
689 |
30791 | 690 m_rep = new typename Sparse<T, Alloc>::SparseRep (nr, nc, new_nzmax); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
691 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
692 octave_idx_type ii = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
693 xcidx (0) = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
694 for (octave_idx_type j = 0; j < nc; j++) |
5164 | 695 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
696 for (octave_idx_type i = 0; i < nr; i++) |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30099
diff
changeset
|
697 if (a.elem (i, j) != T ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
698 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30099
diff
changeset
|
699 xdata (ii) = a.elem (i, j); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
700 xridx (ii++) = i; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
701 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
702 xcidx (j+1) = ii; |
5164 | 703 } |
704 } | |
705 | |
30791 | 706 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
707 OCTAVE_API |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
708 Sparse<T, Alloc>::~Sparse () |
5164 | 709 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
710 if (--m_rep->m_count == 0) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
711 delete m_rep; |
5164 | 712 } |
713 | |
30791 | 714 template <typename T, typename Alloc> |
715 Sparse<T, Alloc>& | |
716 Sparse<T, Alloc>::operator = (const Sparse<T, Alloc>& a) | |
7717
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
717 { |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
718 if (this != &a) |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
719 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
720 if (--m_rep->m_count == 0) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
721 delete m_rep; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
722 |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
723 m_rep = a.m_rep; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
724 m_rep->m_count++; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
725 |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
726 m_dimensions = a.m_dimensions; |
7717
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
727 } |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
728 |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
729 return *this; |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
730 } |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
731 |
30791 | 732 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
733 OCTAVE_API |
5275 | 734 octave_idx_type |
30791 | 735 Sparse<T, Alloc>::compute_index (const Array<octave_idx_type>& ra_idx) const |
5164 | 736 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
737 octave_idx_type n = m_dimensions.ndims (); |
5164 | 738 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
739 if (n <= 0 || n != ra_idx.numel ()) |
5164 | 740 (*current_liboctave_error_handler) |
30791 | 741 ("Sparse<T, Alloc>::compute_index: invalid ra_idxing operation"); |
5164 | 742 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
743 octave_idx_type retval = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
744 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
745 retval = ra_idx(--n); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
746 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
747 while (--n >= 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
748 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
749 retval *= m_dimensions(n); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
750 retval += ra_idx(n); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
751 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
752 |
5164 | 753 return retval; |
754 } | |
755 | |
30791 | 756 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
757 OCTAVE_API |
5164 | 758 T |
30791 | 759 Sparse<T, Alloc>::range_error (const char *fcn, octave_idx_type n) const |
5164 | 760 { |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
761 (*current_liboctave_error_handler) ("%s (%" OCTAVE_IDX_TYPE_FORMAT "): " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
762 "range error", fcn, n); |
5164 | 763 } |
764 | |
30791 | 765 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
766 OCTAVE_API |
5164 | 767 T& |
30791 | 768 Sparse<T, Alloc>::range_error (const char *fcn, octave_idx_type n) |
5164 | 769 { |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
770 (*current_liboctave_error_handler) ("%s (%" OCTAVE_IDX_TYPE_FORMAT "): " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
771 "range error", fcn, n); |
5164 | 772 } |
773 | |
30791 | 774 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
775 OCTAVE_API |
5164 | 776 T |
30791 | 777 Sparse<T, Alloc>::range_error (const char *fcn, octave_idx_type i, |
778 octave_idx_type j) const | |
5164 | 779 { |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
780 (*current_liboctave_error_handler) |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
781 ("%s (%" OCTAVE_IDX_TYPE_FORMAT ", %" OCTAVE_IDX_TYPE_FORMAT "): " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
782 "range error", fcn, i, j); |
5164 | 783 } |
784 | |
30791 | 785 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
786 OCTAVE_API |
5164 | 787 T& |
30791 | 788 Sparse<T, Alloc>::range_error (const char *fcn, octave_idx_type i, |
789 octave_idx_type j) | |
5164 | 790 { |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
791 (*current_liboctave_error_handler) |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
792 ("%s (%" OCTAVE_IDX_TYPE_FORMAT ", %" OCTAVE_IDX_TYPE_FORMAT "): " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
793 "range error", fcn, i, j); |
5164 | 794 } |
795 | |
30791 | 796 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
797 OCTAVE_API |
5164 | 798 T |
30791 | 799 Sparse<T, Alloc>::range_error (const char *fcn, |
800 const Array<octave_idx_type>& ra_idx) const | |
5164 | 801 { |
5765 | 802 std::ostringstream buf; |
5164 | 803 |
804 buf << fcn << " ("; | |
805 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
806 octave_idx_type n = ra_idx.numel (); |
5164 | 807 |
808 if (n > 0) | |
809 buf << ra_idx(0); | |
810 | |
5275 | 811 for (octave_idx_type i = 1; i < n; i++) |
5164 | 812 buf << ", " << ra_idx(i); |
813 | |
814 buf << "): range error"; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
815 |
5765 | 816 std::string buf_str = buf.str (); |
817 | |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
818 (*current_liboctave_error_handler) ("%s", buf_str.c_str ()); |
5164 | 819 } |
820 | |
30791 | 821 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
822 OCTAVE_API |
5164 | 823 T& |
30791 | 824 Sparse<T, Alloc>::range_error (const char *fcn, |
825 const Array<octave_idx_type>& ra_idx) | |
5164 | 826 { |
5765 | 827 std::ostringstream buf; |
5164 | 828 |
829 buf << fcn << " ("; | |
830 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
831 octave_idx_type n = ra_idx.numel (); |
5164 | 832 |
833 if (n > 0) | |
834 buf << ra_idx(0); | |
835 | |
5275 | 836 for (octave_idx_type i = 1; i < n; i++) |
5164 | 837 buf << ", " << ra_idx(i); |
838 | |
839 buf << "): range error"; | |
840 | |
5765 | 841 std::string buf_str = buf.str (); |
842 | |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
843 (*current_liboctave_error_handler) ("%s", buf_str.c_str ()); |
5164 | 844 } |
845 | |
30791 | 846 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
847 OCTAVE_API |
30791 | 848 Sparse<T, Alloc> |
849 Sparse<T, Alloc>::reshape (const dim_vector& new_dims) const | |
5164 | 850 { |
30791 | 851 Sparse<T, Alloc> retval; |
6689 | 852 dim_vector dims2 = new_dims; |
853 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
854 if (dims2.ndims () > 2) |
5164 | 855 { |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19381
diff
changeset
|
856 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19381
diff
changeset
|
857 ("Octave:reshape-smashes-dims", |
21014
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20673
diff
changeset
|
858 "reshape: sparse reshape to N-D array smashes dims"); |
6814 | 859 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
860 for (octave_idx_type i = 2; i < dims2.ndims (); i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
861 dims2(1) *= dims2(i); |
6814 | 862 |
6689 | 863 dims2.resize (2); |
864 } | |
865 | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
866 if (m_dimensions != dims2) |
6689 | 867 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
868 if (m_dimensions.numel () == dims2.numel ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
869 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
870 octave_idx_type new_nnz = nnz (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
871 octave_idx_type new_nr = dims2 (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
872 octave_idx_type new_nc = dims2 (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
873 octave_idx_type old_nr = rows (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
874 octave_idx_type old_nc = cols (); |
30791 | 875 retval = Sparse<T, Alloc> (new_nr, new_nc, new_nnz); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
876 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
877 octave_idx_type kk = 0; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
878 retval.xcidx (0) = 0; |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21337
diff
changeset
|
879 // Quotient and remainder of i * old_nr divided by new_nr. |
21256
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
880 // Track them individually to avoid overflow (bug #42850). |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
881 octave_idx_type i_old_qu = 0; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
882 octave_idx_type i_old_rm = static_cast<octave_idx_type> (-old_nr); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
883 for (octave_idx_type i = 0; i < old_nc; i++) |
21256
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
884 { |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
885 i_old_rm += old_nr; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
886 if (i_old_rm >= new_nr) |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
887 { |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
888 i_old_qu += i_old_rm / new_nr; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
889 i_old_rm = i_old_rm % new_nr; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
890 } |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
891 for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
892 { |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
893 octave_idx_type ii, jj; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
894 ii = (i_old_rm + ridx (j)) % new_nr; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
895 jj = i_old_qu + (i_old_rm + ridx (j)) / new_nr; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
896 |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
897 // Original calculation subject to overflow |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
898 // ii = (i*old_nr + ridx (j)) % new_nr |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
899 // jj = (i*old_nr + ridx (j)) / new_nr |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
900 for (octave_idx_type k = kk; k < jj; k++) |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
901 retval.xcidx (k+1) = j; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
902 kk = jj; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
903 retval.xdata (j) = data (j); |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
904 retval.xridx (j) = ii; |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
905 } |
a93fa1b0796e
Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21255
diff
changeset
|
906 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
907 for (octave_idx_type k = kk; k < new_nc; k++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
908 retval.xcidx (k+1) = new_nnz; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
909 } |
5164 | 910 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
911 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
912 std::string dimensions_str = m_dimensions.str (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
913 std::string new_dims_str = new_dims.str (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
914 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
915 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
916 ("reshape: can't reshape %s array to %s array", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
917 dimensions_str.c_str (), new_dims_str.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
918 } |
5164 | 919 } |
920 else | |
921 retval = *this; | |
922 | |
923 return retval; | |
924 } | |
925 | |
30791 | 926 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
927 OCTAVE_API |
30791 | 928 Sparse<T, Alloc> |
929 Sparse<T, Alloc>::permute (const Array<octave_idx_type>& perm_vec, bool) const | |
5164 | 930 { |
6813 | 931 // The only valid permutations of a sparse array are [1, 2] and [2, 1]. |
932 | |
933 bool fail = false; | |
6817 | 934 bool trans = false; |
6813 | 935 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
936 if (perm_vec.numel () == 2) |
5164 | 937 { |
6813 | 938 if (perm_vec(0) == 0 && perm_vec(1) == 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
939 /* do nothing */; |
6813 | 940 else if (perm_vec(0) == 1 && perm_vec(1) == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
941 trans = true; |
5164 | 942 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
943 fail = true; |
5164 | 944 } |
945 else | |
6813 | 946 fail = true; |
947 | |
948 if (fail) | |
949 (*current_liboctave_error_handler) | |
950 ("permutation vector contains an invalid element"); | |
951 | |
6817 | 952 return trans ? this->transpose () : *this; |
5164 | 953 } |
954 | |
30791 | 955 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
956 OCTAVE_API |
5164 | 957 void |
30791 | 958 Sparse<T, Alloc>::resize1 (octave_idx_type n) |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
959 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
960 octave_idx_type nr = rows (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
961 octave_idx_type nc = cols (); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
962 |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
963 if (nr == 0) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
964 resize (1, std::max (nc, n)); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
965 else if (nc == 0) |
10520
72c90e7132a9
fix failing sparse assignment tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10516
diff
changeset
|
966 resize (nr, (n + nr - 1) / nr); // Ain't it wicked? |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
967 else if (nr == 1) |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
968 resize (1, n); |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
969 else if (nc == 1) |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
970 resize (n, 1); |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
971 else |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
972 octave::err_invalid_resize (); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
973 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
974 |
30791 | 975 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
976 OCTAVE_API |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
977 void |
30791 | 978 Sparse<T, Alloc>::resize (const dim_vector& dv) |
5164 | 979 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
980 octave_idx_type n = dv.ndims (); |
5164 | 981 |
982 if (n != 2) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
983 (*current_liboctave_error_handler) ("sparse array must be 2-D"); |
5164 | 984 |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
985 resize (dv(0), dv(1)); |
5164 | 986 } |
987 | |
30791 | 988 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
989 OCTAVE_API |
5164 | 990 void |
30791 | 991 Sparse<T, Alloc>::resize (octave_idx_type r, octave_idx_type c) |
5164 | 992 { |
993 if (r < 0 || c < 0) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
994 (*current_liboctave_error_handler) ("can't resize to negative dimension"); |
5164 | 995 |
996 if (r == dim1 () && c == dim2 ()) | |
997 return; | |
998 | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
999 // This wouldn't be necessary for r >= rows () if m_nrows wasn't part of the |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1000 // Sparse rep. It is not good for anything in there. |
10499
fabed15083a4
optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
1001 make_unique (); |
fabed15083a4
optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
1002 |
fabed15083a4
optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
1003 if (r < rows ()) |
5164 | 1004 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1005 octave_idx_type i = 0; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1006 octave_idx_type k = 0; |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1007 for (octave_idx_type j = 1; j <= m_rep->m_ncols; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1008 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1009 octave_idx_type u = xcidx (j); |
21337
cfe11042fbc0
eliminate useless assignment in for loop
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
1010 for (; i < u; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1011 if (xridx (i) < r) |
10499
fabed15083a4
optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
1012 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1013 xdata (k) = xdata (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1014 xridx (k++) = xridx (i); |
10499
fabed15083a4
optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
1015 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1016 xcidx (j) = k; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1017 } |
5164 | 1018 } |
1019 | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1020 m_rep->m_nrows = m_dimensions(0) = r; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1021 |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1022 if (c != m_rep->m_ncols) |
10499
fabed15083a4
optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
1023 { |
30791 | 1024 octave_idx_type *new_cidx = m_rep->idx_type_allocate (c+1); |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
1025 std::copy_n (m_rep->m_cidx, std::min (c, m_rep->m_ncols) + 1, new_cidx); |
30883
7ad8385ff106
pass correct length to SparseRep idx_type_deallocate function
John W. Eaton <jwe@octave.org>
parents:
30791
diff
changeset
|
1026 m_rep->idx_type_deallocate (m_rep->m_cidx, m_rep->m_ncols + 1); |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
1027 m_rep->m_cidx = new_cidx; |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1028 |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1029 if (c > m_rep->m_ncols) |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
1030 std::fill_n (m_rep->m_cidx + m_rep->m_ncols + 1, c - m_rep->m_ncols, |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
1031 m_rep->m_cidx[m_rep->m_ncols]); |
10499
fabed15083a4
optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
1032 } |
fabed15083a4
optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents:
10497
diff
changeset
|
1033 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1034 m_rep->m_ncols = m_dimensions(1) = c; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1035 |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1036 m_rep->change_length (m_rep->nnz ()); |
5164 | 1037 } |
1038 | |
30791 | 1039 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1040 OCTAVE_API |
30791 | 1041 Sparse<T, Alloc>& |
1042 Sparse<T, Alloc>::insert (const Sparse<T, Alloc>& a, | |
1043 octave_idx_type r, octave_idx_type c) | |
5164 | 1044 { |
5275 | 1045 octave_idx_type a_rows = a.rows (); |
1046 octave_idx_type a_cols = a.cols (); | |
1047 octave_idx_type nr = rows (); | |
1048 octave_idx_type nc = cols (); | |
5164 | 1049 |
1050 if (r < 0 || r + a_rows > rows () || c < 0 || c + a_cols > cols ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
1051 (*current_liboctave_error_handler) ("range error for insert"); |
5164 | 1052 |
1053 // First count the number of elements in the final array | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1054 octave_idx_type nel = cidx (c) + a.nnz (); |
5164 | 1055 |
1056 if (c + a_cols < nc) | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1057 nel += cidx (nc) - cidx (c + a_cols); |
5164 | 1058 |
5275 | 1059 for (octave_idx_type i = c; i < c + a_cols; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1060 for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1061 if (ridx (j) < r || ridx (j) >= r + a_rows) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1062 nel++; |
5164 | 1063 |
30791 | 1064 Sparse<T, Alloc> tmp (*this); |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1065 --m_rep->m_count; |
30791 | 1066 m_rep = new typename Sparse<T, Alloc>::SparseRep (nr, nc, nel); |
5164 | 1067 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1068 for (octave_idx_type i = 0; i < tmp.cidx (c); i++) |
5164 | 1069 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1070 data (i) = tmp.data (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1071 ridx (i) = tmp.ridx (i); |
5164 | 1072 } |
5275 | 1073 for (octave_idx_type i = 0; i < c + 1; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1074 cidx (i) = tmp.cidx (i); |
5164 | 1075 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1076 octave_idx_type ii = cidx (c); |
5275 | 1077 |
1078 for (octave_idx_type i = c; i < c + a_cols; i++) | |
5164 | 1079 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
1080 octave_quit (); |
5164 | 1081 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1082 for (octave_idx_type j = tmp.cidx (i); j < tmp.cidx (i+1); j++) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1083 if (tmp.ridx (j) < r) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1084 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1085 data (ii) = tmp.data (j); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1086 ridx (ii++) = tmp.ridx (j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1087 } |
5164 | 1088 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
1089 octave_quit (); |
5164 | 1090 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1091 for (octave_idx_type j = a.cidx (i-c); j < a.cidx (i-c+1); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1092 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1093 data (ii) = a.data (j); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1094 ridx (ii++) = r + a.ridx (j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1095 } |
5164 | 1096 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
1097 octave_quit (); |
5164 | 1098 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1099 for (octave_idx_type j = tmp.cidx (i); j < tmp.cidx (i+1); j++) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1100 if (tmp.ridx (j) >= r + a_rows) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1101 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1102 data (ii) = tmp.data (j); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1103 ridx (ii++) = tmp.ridx (j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1104 } |
5164 | 1105 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1106 cidx (i+1) = ii; |
5164 | 1107 } |
1108 | |
5275 | 1109 for (octave_idx_type i = c + a_cols; i < nc; i++) |
5164 | 1110 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1111 for (octave_idx_type j = tmp.cidx (i); j < tmp.cidx (i+1); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1112 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1113 data (ii) = tmp.data (j); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1114 ridx (ii++) = tmp.ridx (j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1115 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1116 cidx (i+1) = ii; |
5164 | 1117 } |
1118 | |
1119 return *this; | |
1120 } | |
1121 | |
30791 | 1122 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1123 OCTAVE_API |
30791 | 1124 Sparse<T, Alloc>& |
1125 Sparse<T, Alloc>::insert (const Sparse<T, Alloc>& a, | |
1126 const Array<octave_idx_type>& ra_idx) | |
5164 | 1127 { |
1128 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
1129 if (ra_idx.numel () != 2) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
1130 (*current_liboctave_error_handler) ("range error for insert"); |
5164 | 1131 |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1132 return insert (a, ra_idx(0), ra_idx(1)); |
5164 | 1133 } |
1134 | |
30791 | 1135 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1136 OCTAVE_API |
30791 | 1137 Sparse<T, Alloc> |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
1138 Sparse<T, Alloc>::transpose () const |
5164 | 1139 { |
1140 assert (ndims () == 2); | |
1141 | |
5275 | 1142 octave_idx_type nr = rows (); |
1143 octave_idx_type nc = cols (); | |
5648 | 1144 octave_idx_type nz = nnz (); |
30791 | 1145 Sparse<T, Alloc> retval (nc, nr, nz); |
5164 | 1146 |
5648 | 1147 for (octave_idx_type i = 0; i < nz; i++) |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1148 retval.xcidx (ridx (i) + 1)++; |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1149 // retval.xcidx[1:nr] holds the row degrees for rows 0:(nr-1) |
5648 | 1150 nz = 0; |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1151 for (octave_idx_type i = 1; i <= nr; i++) |
5164 | 1152 { |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1153 const octave_idx_type tmp = retval.xcidx (i); |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1154 retval.xcidx (i) = nz; |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1155 nz += tmp; |
5164 | 1156 } |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1157 // retval.xcidx[1:nr] holds row entry *start* offsets for rows 0:(nr-1) |
5648 | 1158 |
1159 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
|
1160 for (octave_idx_type k = cidx (j); k < cidx (j+1); k++) |
5648 | 1161 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1162 octave_idx_type q = retval.xcidx (ridx (k) + 1)++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1163 retval.xridx (q) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1164 retval.xdata (q) = data (k); |
5648 | 1165 } |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1166 assert (nnz () == retval.xcidx (nr)); |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1167 // retval.xcidx[1:nr] holds row entry *end* offsets for rows 0:(nr-1) |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1168 // and retval.xcidx[0:(nr-1)] holds their row entry *start* offsets |
5164 | 1169 |
1170 return retval; | |
1171 } | |
1172 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1173 // Lower bound lookup. Could also use octave_sort, but that has upper bound |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1174 // semantics, so requires some manipulation to set right. Uses a plain loop |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1175 // for small columns. |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1176 static |
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1177 octave_idx_type |
10493
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1178 lblookup (const octave_idx_type *ridx, octave_idx_type nr, |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1179 octave_idx_type ri) |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1180 { |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1181 if (nr <= 8) |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1182 { |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1183 octave_idx_type l; |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1184 for (l = 0; l < nr; l++) |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1185 if (ridx[l] >= ri) |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1186 break; |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1187 return l; |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1188 } |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1189 else |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1190 return std::lower_bound (ridx, ridx + nr, ri) - ridx; |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1191 } |
2f8bacc2a57d
fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10490
diff
changeset
|
1192 |
30791 | 1193 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1194 OCTAVE_API |
5164 | 1195 void |
30791 | 1196 Sparse<T, Alloc>::delete_elements (const octave::idx_vector& idx) |
5164 | 1197 { |
30791 | 1198 Sparse<T, Alloc> retval; |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1199 |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1200 assert (ndims () == 2); |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1201 |
5275 | 1202 octave_idx_type nr = dim1 (); |
1203 octave_idx_type nc = dim2 (); | |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1204 octave_idx_type nz = nnz (); |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1205 |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1206 octave_idx_type nel = numel (); // Can throw. |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1207 |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1208 const dim_vector idx_dims = idx.orig_dimensions (); |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1209 |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1210 if (idx.extent (nel) > nel) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1211 octave::err_del_index_out_of_range (true, idx.extent (nel), nel); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
1212 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21118
diff
changeset
|
1213 if (nc == 1) |
5164 | 1214 { |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1215 // Sparse column vector. |
30791 | 1216 const Sparse<T, Alloc> tmp = *this; // constant copy to prevent COW. |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1217 |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1218 octave_idx_type lb, ub; |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1219 |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1220 if (idx.is_cont_range (nel, lb, ub)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1221 { |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1222 // Special-case a contiguous range. |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1223 // Look-up indices first. |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1224 octave_idx_type li = lblookup (tmp.ridx (), nz, lb); |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1225 octave_idx_type ui = lblookup (tmp.ridx (), nz, ub); |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1226 // Copy data and adjust indices. |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1227 octave_idx_type nz_new = nz - (ui - li); |
30791 | 1228 *this = Sparse<T, Alloc> (nr - (ub - lb), 1, nz_new); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1229 std::copy_n (tmp.data (), li, data ()); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1230 std::copy_n (tmp.ridx (), li, xridx ()); |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
1231 std::copy (tmp.data () + ui, tmp.data () + nz, xdata () + li); |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1232 mx_inline_sub (nz - ui, xridx () + li, tmp.ridx () + ui, ub - lb); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1233 xcidx (1) = nz_new; |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1234 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1235 else |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1236 { |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1237 OCTAVE_LOCAL_BUFFER (octave_idx_type, ridx_new, nz); |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1238 OCTAVE_LOCAL_BUFFER (T, data_new, nz); |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1239 octave::idx_vector sidx = idx.sorted (true); |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1240 const octave_idx_type *sj = sidx.raw (); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1241 octave_idx_type sl = sidx.length (nel); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1242 octave_idx_type nz_new = 0; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1243 octave_idx_type j = 0; |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1244 for (octave_idx_type i = 0; i < nz; i++) |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1245 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1246 octave_idx_type r = tmp.ridx (i); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1247 for (; j < sl && sj[j] < r; j++) ; |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1248 if (j == sl || sj[j] > r) |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1249 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1250 data_new[nz_new] = tmp.data (i); |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1251 ridx_new[nz_new++] = r - j; |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1252 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1253 } |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1254 |
30791 | 1255 *this = Sparse<T, Alloc> (nr - sl, 1, nz_new); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1256 std::copy_n (ridx_new, nz_new, ridx ()); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1257 std::copy_n (data_new, nz_new, xdata ()); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1258 xcidx (1) = nz_new; |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1259 } |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1260 } |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1261 else if (nr == 1) |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1262 { |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1263 // Sparse row vector. |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1264 octave_idx_type lb, ub; |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1265 if (idx.is_cont_range (nc, lb, ub)) |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1266 { |
30791 | 1267 const Sparse<T, Alloc> tmp = *this; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1268 octave_idx_type lbi = tmp.cidx (lb); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1269 octave_idx_type ubi = tmp.cidx (ub); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1270 octave_idx_type new_nz = nz - (ubi - lbi); |
30791 | 1271 *this = Sparse<T, Alloc> (1, nc - (ub - lb), new_nz); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1272 std::copy_n (tmp.data (), lbi, data ()); |
27933
863ae57eee69
maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
1273 std::copy (tmp.data () + ubi, tmp.data () + nz, xdata () + lbi); |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
1274 std::fill_n (ridx (), new_nz, static_cast<octave_idx_type> (0)); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1275 std::copy_n (tmp.cidx () + 1, lb, cidx () + 1); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1276 mx_inline_sub (nc - ub, xcidx () + 1, tmp.cidx () + ub + 1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1277 ubi - lbi); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1278 } |
5164 | 1279 else |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1280 *this = index (idx.complement (nc)); |
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1281 } |
17642
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1282 else if (idx.length (nel) != 0) |
10484
6a9571b57745
rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10480
diff
changeset
|
1283 { |
17642
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1284 if (idx.is_colon_equiv (nel)) |
30791 | 1285 *this = Sparse<T, Alloc> (); |
17642
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1286 else |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1287 { |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1288 *this = index (octave::idx_vector::colon); |
17642
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1289 delete_elements (idx); |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1290 *this = transpose (); // We want a row vector. |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1291 } |
5164 | 1292 } |
1293 } | |
1294 | |
30791 | 1295 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1296 OCTAVE_API |
5164 | 1297 void |
30791 | 1298 Sparse<T, Alloc>::delete_elements (const octave::idx_vector& idx_i, |
1299 const octave::idx_vector& idx_j) | |
5164 | 1300 { |
1301 assert (ndims () == 2); | |
1302 | |
5275 | 1303 octave_idx_type nr = dim1 (); |
1304 octave_idx_type nc = dim2 (); | |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1305 octave_idx_type nz = nnz (); |
5164 | 1306 |
1307 if (idx_i.is_colon ()) | |
1308 { | |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1309 // Deleting columns. |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1310 octave_idx_type lb, ub; |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1311 if (idx_j.extent (nc) > nc) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1312 octave::err_del_index_out_of_range (false, idx_j.extent (nc), nc); |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1313 else if (idx_j.is_cont_range (nc, lb, ub)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1314 { |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1315 if (lb == 0 && ub == nc) |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1316 { |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1317 // Delete all rows and columns. |
30791 | 1318 *this = Sparse<T, Alloc> (nr, 0); |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1319 } |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1320 else if (nz == 0) |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1321 { |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1322 // No elements to preserve; adjust dimensions. |
30791 | 1323 *this = Sparse<T, Alloc> (nr, nc - (ub - lb)); |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1324 } |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1325 else |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1326 { |
30791 | 1327 const Sparse<T, Alloc> tmp = *this; |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1328 octave_idx_type lbi = tmp.cidx (lb); |
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1329 octave_idx_type ubi = tmp.cidx (ub); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1330 octave_idx_type new_nz = nz - (ubi - lbi); |
14792
8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14791
diff
changeset
|
1331 |
30791 | 1332 *this = Sparse<T, Alloc> (nr, nc - (ub - lb), new_nz); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1333 std::copy_n (tmp.data (), lbi, data ()); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1334 std::copy_n (tmp.ridx (), lbi, ridx ()); |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
1335 std::copy (tmp.data () + ubi, tmp.data () + nz, xdata () + lbi); |
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
1336 std::copy (tmp.ridx () + ubi, tmp.ridx () + nz, xridx () + lbi); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1337 std::copy_n (tmp.cidx () + 1, lb, cidx () + 1); |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1338 mx_inline_sub (nc - ub, xcidx () + lb + 1, |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1339 tmp.cidx () + ub + 1, ubi - lbi); |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1340 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1341 } |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1342 else |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1343 *this = index (idx_i, idx_j.complement (nc)); |
5164 | 1344 } |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1345 else if (idx_j.is_colon ()) |
5164 | 1346 { |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1347 // Deleting rows. |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1348 octave_idx_type lb, ub; |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1349 if (idx_i.extent (nr) > nr) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1350 octave::err_del_index_out_of_range (false, idx_i.extent (nr), nr); |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1351 else if (idx_i.is_cont_range (nr, lb, ub)) |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1352 { |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1353 if (lb == 0 && ub == nr) |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1354 { |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1355 // Delete all rows and columns. |
30791 | 1356 *this = Sparse<T, Alloc> (0, nc); |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1357 } |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1358 else if (nz == 0) |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1359 { |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1360 // No elements to preserve; adjust dimensions. |
30791 | 1361 *this = Sparse<T, Alloc> (nr - (ub - lb), nc); |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1362 } |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1363 else |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1364 { |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1365 // This is more memory-efficient than the approach below. |
30791 | 1366 const Sparse<T, Alloc> tmpl = index (octave::idx_vector (0, lb), idx_j); |
1367 const Sparse<T, Alloc> tmpu = index (octave::idx_vector (ub, nr), idx_j); | |
1368 *this = Sparse<T, Alloc> (nr - (ub - lb), nc, | |
1369 tmpl.nnz () + tmpu.nnz ()); | |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1370 for (octave_idx_type j = 0, k = 0; j < nc; j++) |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1371 { |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1372 for (octave_idx_type i = tmpl.cidx (j); i < tmpl.cidx (j+1); |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1373 i++) |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1374 { |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1375 xdata (k) = tmpl.data (i); |
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1376 xridx (k++) = tmpl.ridx (i); |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1377 } |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1378 for (octave_idx_type i = tmpu.cidx (j); i < tmpu.cidx (j+1); |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1379 i++) |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1380 { |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1381 xdata (k) = tmpu.data (i); |
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1382 xridx (k++) = tmpu.ridx (i) + lb; |
14794
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1383 } |
41dcb2c5bb1a
Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents:
14792
diff
changeset
|
1384 |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17823
diff
changeset
|
1385 xcidx (j+1) = k; |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1386 } |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1387 } |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1388 } |
5164 | 1389 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1390 { |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1391 // This is done by transposing, deleting columns, then transposing |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1392 // again. |
30791 | 1393 Sparse<T, Alloc> tmp = transpose (); |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1394 tmp.delete_elements (idx_j, idx_i); |
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1395 *this = tmp.transpose (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1396 } |
5164 | 1397 } |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1398 else |
17642
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1399 { |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1400 // Empty assignment (no elements to delete) is OK if there is at |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1401 // least one zero-length index and at most one other index that is |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1402 // non-colon (or equivalent) index. Since we only have two |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1403 // indices, we just need to check that we have at least one zero |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1404 // length index. Matlab considers "[]" to be an empty index but |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1405 // not "false". We accept both. |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1406 |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1407 bool empty_assignment |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1408 = (idx_i.length (nr) == 0 || idx_j.length (nc) == 0); |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1409 |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1410 if (! empty_assignment) |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1411 (*current_liboctave_error_handler) |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1412 ("a null assignment can only have one non-colon index"); |
7ed397c8ca68
improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents:
17285
diff
changeset
|
1413 } |
5164 | 1414 } |
1415 | |
30791 | 1416 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1417 OCTAVE_API |
5164 | 1418 void |
30791 | 1419 Sparse<T, Alloc>::delete_elements (int dim, const octave::idx_vector& idx) |
5164 | 1420 { |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1421 if (dim == 0) |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1422 delete_elements (idx, octave::idx_vector::colon); |
10490
fdccd69d26bd
rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10484
diff
changeset
|
1423 else if (dim == 1) |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1424 delete_elements (octave::idx_vector::colon, idx); |
5164 | 1425 else |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
1426 (*current_liboctave_error_handler) ("invalid dimension in delete_elements"); |
5164 | 1427 } |
1428 | |
30791 | 1429 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1430 OCTAVE_API |
30791 | 1431 Sparse<T, Alloc> |
1432 Sparse<T, Alloc>::index (const octave::idx_vector& idx, bool resize_ok) const | |
5164 | 1433 { |
30791 | 1434 Sparse<T, Alloc> retval; |
5164 | 1435 |
1436 assert (ndims () == 2); | |
1437 | |
5275 | 1438 octave_idx_type nr = dim1 (); |
1439 octave_idx_type nc = dim2 (); | |
5681 | 1440 octave_idx_type nz = nnz (); |
5275 | 1441 |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1442 octave_idx_type nel = numel (); // Can throw. |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1443 |
19413
e354372e20f2
allow sparse arrays to be indexed by N-d arrays (bug #43855)
John W. Eaton <jwe@octave.org>
parents:
19410
diff
changeset
|
1444 const dim_vector idx_dims = idx.orig_dimensions ().redim (2); |
e354372e20f2
allow sparse arrays to be indexed by N-d arrays (bug #43855)
John W. Eaton <jwe@octave.org>
parents:
19410
diff
changeset
|
1445 |
e354372e20f2
allow sparse arrays to be indexed by N-d arrays (bug #43855)
John W. Eaton <jwe@octave.org>
parents:
19410
diff
changeset
|
1446 if (idx.is_colon ()) |
5164 | 1447 { |
10494
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1448 if (nc == 1) |
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1449 retval = *this; |
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1450 else |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1451 { |
10494
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1452 // Fast magic colon processing. |
30791 | 1453 retval = Sparse<T, Alloc> (nel, 1, nz); |
10494
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1454 |
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1455 for (octave_idx_type i = 0; i < nc; i++) |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1456 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1457 for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) |
10494
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1458 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1459 retval.xdata (j) = data (j); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1460 retval.xridx (j) = ridx (j) + i * nr; |
10494
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1461 } |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1462 } |
10494
e52f41fd82c7
optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
10493
diff
changeset
|
1463 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1464 retval.xcidx (0) = 0; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1465 retval.xcidx (1) = nz; |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1466 } |
5164 | 1467 } |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1468 else if (idx.extent (nel) > nel) |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10382
diff
changeset
|
1469 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1470 if (! resize_ok) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1471 octave::err_index_out_of_range (1, 1, idx.extent (nel), nel, dims ()); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1472 |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1473 // resize_ok is completely handled here. |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1474 octave_idx_type ext = idx.extent (nel); |
30791 | 1475 Sparse<T, Alloc> tmp = *this; |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1476 tmp.resize1 (ext); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1477 retval = tmp.index (idx); |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10382
diff
changeset
|
1478 } |
5164 | 1479 else if (nr == 1 && nc == 1) |
1480 { | |
1481 // You have to be pretty sick to get to this bit of code, | |
1482 // since you have a scalar stored as a sparse matrix, and | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1483 // then want to make a dense matrix with sparse representation. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1484 // Ok, we'll do it, but you deserve what you get!! |
30791 | 1485 retval = (Sparse<T, Alloc> (idx_dims(0), idx_dims(1), nz ? data (0) : T ())); |
5164 | 1486 } |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1487 else if (nc == 1) |
5164 | 1488 { |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1489 // Sparse column vector. |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1490 octave_idx_type lb, ub; |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1491 |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1492 if (idx.is_scalar ()) |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1493 { |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1494 // Scalar index - just a binary lookup. |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1495 octave_idx_type i = lblookup (ridx (), nz, idx(0)); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1496 if (i < nz && ridx (i) == idx(0)) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1497 retval = Sparse (1, 1, data (i)); |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1498 else |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1499 retval = Sparse (1, 1); |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1500 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1501 else if (idx.is_cont_range (nel, lb, ub)) |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1502 { |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1503 // Special-case a contiguous range. |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1504 // Look-up indices first. |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1505 octave_idx_type li = lblookup (ridx (), nz, lb); |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1506 octave_idx_type ui = lblookup (ridx (), nz, ub); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1507 // Copy data and adjust indices. |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1508 octave_idx_type nz_new = ui - li; |
30791 | 1509 retval = Sparse<T, Alloc> (ub - lb, 1, nz_new); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1510 std::copy_n (data () + li, nz_new, retval.data ()); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1511 mx_inline_sub (nz_new, retval.xridx (), ridx () + li, lb); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1512 retval.xcidx (1) = nz_new; |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1513 } |
23592
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1514 else if (idx.is_permutation (nel) && idx.isvector ()) |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1515 { |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1516 if (idx.is_range () && idx.increment () == -1) |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1517 { |
30791 | 1518 retval = Sparse<T, Alloc> (nr, 1, nz); |
14433
ec660526ae50
Fix sparse range indexing bug (bug #35570)
Marco Caliari <marco.caliari@univr.it>
parents:
14138
diff
changeset
|
1519 |
ec660526ae50
Fix sparse range indexing bug (bug #35570)
Marco Caliari <marco.caliari@univr.it>
parents:
14138
diff
changeset
|
1520 for (octave_idx_type j = 0; j < nz; j++) |
ec660526ae50
Fix sparse range indexing bug (bug #35570)
Marco Caliari <marco.caliari@univr.it>
parents:
14138
diff
changeset
|
1521 retval.ridx (j) = nr - ridx (nz - j - 1) - 1; |
ec660526ae50
Fix sparse range indexing bug (bug #35570)
Marco Caliari <marco.caliari@univr.it>
parents:
14138
diff
changeset
|
1522 |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1523 std::copy_n (cidx (), 2, retval.cidx ()); |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1524 std::reverse_copy (data (), data () + nz, retval.data ()); |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1525 } |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1526 else |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1527 { |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1528 Array<T> tmp = array_value (); |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1529 tmp = tmp.index (idx); |
30791 | 1530 retval = Sparse<T, Alloc> (tmp); |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1531 } |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1532 } |
5164 | 1533 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1534 { |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1535 // If indexing a sparse column vector by a vector, the result is a |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1536 // sparse column vector, otherwise it inherits the shape of index. |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1537 // Vector transpose is cheap, so do it right here. |
19416
06b23f224f52
fix problem with changeset e354372e20f2 (bug #43855)
John W. Eaton <jwe@octave.org>
parents:
19413
diff
changeset
|
1538 |
06b23f224f52
fix problem with changeset e354372e20f2 (bug #43855)
John W. Eaton <jwe@octave.org>
parents:
19413
diff
changeset
|
1539 Array<octave_idx_type> tmp_idx = idx.as_array ().as_matrix (); |
06b23f224f52
fix problem with changeset e354372e20f2 (bug #43855)
John W. Eaton <jwe@octave.org>
parents:
19413
diff
changeset
|
1540 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
1541 const Array<octave_idx_type> idxa = (idx_dims(0) == 1 |
19416
06b23f224f52
fix problem with changeset e354372e20f2 (bug #43855)
John W. Eaton <jwe@octave.org>
parents:
19413
diff
changeset
|
1542 ? tmp_idx.transpose () |
06b23f224f52
fix problem with changeset e354372e20f2 (bug #43855)
John W. Eaton <jwe@octave.org>
parents:
19413
diff
changeset
|
1543 : tmp_idx); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1544 |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1545 octave_idx_type new_nr = idxa.rows (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1546 octave_idx_type new_nc = idxa.cols (); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1547 |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1548 // Lookup. |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1549 // FIXME: Could specialize for sorted idx? |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27387
diff
changeset
|
1550 Array<octave_idx_type> lidx (dim_vector (new_nr, new_nc)); |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1551 for (octave_idx_type i = 0; i < new_nr*new_nc; i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27387
diff
changeset
|
1552 lidx.xelem (i) = lblookup (ridx (), nz, idxa(i)); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1553 |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1554 // Count matches. |
30791 | 1555 retval = Sparse<T, Alloc> (idxa.rows (), idxa.cols ()); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1556 for (octave_idx_type j = 0; j < new_nc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1557 { |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1558 octave_idx_type nzj = 0; |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1559 for (octave_idx_type i = 0; i < new_nr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1560 { |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27387
diff
changeset
|
1561 octave_idx_type l = lidx.xelem (i, j); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1562 if (l < nz && ridx (l) == idxa(i, j)) |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1563 nzj++; |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1564 else |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27387
diff
changeset
|
1565 lidx.xelem (i, j) = nz; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1566 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1567 retval.xcidx (j+1) = retval.xcidx (j) + nzj; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1568 } |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1569 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1570 retval.change_capacity (retval.xcidx (new_nc)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
1571 |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1572 // Copy data and set row indices. |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1573 octave_idx_type k = 0; |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1574 for (octave_idx_type j = 0; j < new_nc; j++) |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1575 for (octave_idx_type i = 0; i < new_nr; i++) |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1576 { |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27387
diff
changeset
|
1577 octave_idx_type l = lidx.xelem (i, j); |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1578 if (l < nz) |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1579 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1580 retval.data (k) = data (l); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1581 retval.xridx (k++) = i; |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1582 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1583 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1584 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1585 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1586 else if (nr == 1) |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1587 { |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1588 octave_idx_type lb, ub; |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1589 if (idx.is_scalar ()) |
30791 | 1590 retval = Sparse<T, Alloc> (1, 1, elem (0, idx(0))); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1591 else if (idx.is_cont_range (nel, lb, ub)) |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1592 { |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1593 // Special-case a contiguous range. |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1594 octave_idx_type lbi = cidx (lb); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1595 octave_idx_type ubi = cidx (ub); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1596 octave_idx_type new_nz = ubi - lbi; |
30791 | 1597 retval = Sparse<T, Alloc> (1, ub - lb, new_nz); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1598 std::copy_n (data () + lbi, new_nz, retval.data ()); |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
1599 std::fill_n (retval.ridx (), new_nz, static_cast<octave_idx_type> (0)); |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1600 mx_inline_sub (ub - lb + 1, retval.cidx (), cidx () + lb, lbi); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1601 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1602 else |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1603 { |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1604 // Sparse row vectors occupy O(nr) storage anyway, so let's just |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1605 // convert the matrix to full, index, and sparsify the result. |
30791 | 1606 retval = Sparse<T, Alloc> (array_value ().index (idx)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1607 } |
5164 | 1608 } |
1609 else | |
1610 { | |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1611 if (nr != 0 && idx.is_scalar ()) |
30791 | 1612 retval = Sparse<T, Alloc> (1, 1, elem (idx(0) % nr, idx(0) / nr)); |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10382
diff
changeset
|
1613 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1614 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
1615 // Indexing a non-vector sparse matrix by linear indexing. |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1616 // I suppose this is rare (and it may easily overflow), so let's take |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1617 // the easy way, and reshape first to column vector, which is already |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1618 // handled above. |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1619 retval = index (octave::idx_vector::colon).index (idx); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1620 // In this case we're supposed to always inherit the shape, but |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1621 // column(row) doesn't do it, so we'll do it instead. |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1622 if (idx_dims(0) == 1 && idx_dims(1) != 1) |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
1623 retval = retval.transpose (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1624 } |
5164 | 1625 } |
1626 | |
1627 return retval; | |
1628 } | |
1629 | |
30791 | 1630 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1631 OCTAVE_API |
30791 | 1632 Sparse<T, Alloc> |
1633 Sparse<T, Alloc>::index (const octave::idx_vector& idx_i, | |
1634 const octave::idx_vector& idx_j, | |
1635 bool resize_ok) const | |
5164 | 1636 { |
30791 | 1637 Sparse<T, Alloc> retval; |
5164 | 1638 |
1639 assert (ndims () == 2); | |
1640 | |
5275 | 1641 octave_idx_type nr = dim1 (); |
1642 octave_idx_type nc = dim2 (); | |
1643 | |
10421
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10382
diff
changeset
|
1644 octave_idx_type n = idx_i.length (nr); |
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10382
diff
changeset
|
1645 octave_idx_type m = idx_j.length (nc); |
99e9bae2d81e
improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10382
diff
changeset
|
1646 |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1647 octave_idx_type lb, ub; |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1648 |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1649 if (idx_i.extent (nr) > nr || idx_j.extent (nc) > nc) |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1650 { |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1651 // resize_ok is completely handled here. |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1652 if (resize_ok) |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1653 { |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1654 octave_idx_type ext_i = idx_i.extent (nr); |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1655 octave_idx_type ext_j = idx_j.extent (nc); |
30791 | 1656 Sparse<T, Alloc> tmp = *this; |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1657 tmp.resize (ext_i, ext_j); |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1658 retval = tmp.index (idx_i, idx_j); |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1659 } |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1660 else if (idx_i.extent (nr) > nr) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1661 octave::err_index_out_of_range (2, 1, idx_i.extent (nr), nr, dims ()); |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1662 else |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1663 octave::err_index_out_of_range (2, 2, idx_j.extent (nc), nc, dims ()); |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1664 } |
16803
f4eef73b6e90
When indexing scalars stored as sparse matrices, convert to an array, index and then resparsify (bug #37774)
David Bateman <dbateman@free.fr>
parents:
15358
diff
changeset
|
1665 else if (nr == 1 && nc == 1) |
f4eef73b6e90
When indexing scalars stored as sparse matrices, convert to an array, index and then resparsify (bug #37774)
David Bateman <dbateman@free.fr>
parents:
15358
diff
changeset
|
1666 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1667 // Scalars stored as sparse matrices occupy more memory than |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1668 // a scalar, so let's just convert the matrix to full, index, |
16803
f4eef73b6e90
When indexing scalars stored as sparse matrices, convert to an array, index and then resparsify (bug #37774)
David Bateman <dbateman@free.fr>
parents:
15358
diff
changeset
|
1669 // and sparsify the result. |
f4eef73b6e90
When indexing scalars stored as sparse matrices, convert to an array, index and then resparsify (bug #37774)
David Bateman <dbateman@free.fr>
parents:
15358
diff
changeset
|
1670 |
30791 | 1671 retval = Sparse<T, Alloc> (array_value ().index (idx_i, idx_j)); |
16803
f4eef73b6e90
When indexing scalars stored as sparse matrices, convert to an array, index and then resparsify (bug #37774)
David Bateman <dbateman@free.fr>
parents:
15358
diff
changeset
|
1672 } |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1673 else if (idx_i.is_colon ()) |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1674 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1675 // Great, we're just manipulating columns. This is going to be quite |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1676 // efficient, because the columns can stay compressed as they are. |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1677 if (idx_j.is_colon ()) |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1678 retval = *this; // Shallow copy. |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1679 else if (idx_j.is_cont_range (nc, lb, ub)) |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1680 { |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1681 // Special-case a contiguous range. |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1682 octave_idx_type lbi = cidx (lb); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1683 octave_idx_type ubi = cidx (ub); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1684 octave_idx_type new_nz = ubi - lbi; |
30791 | 1685 retval = Sparse<T, Alloc> (nr, ub - lb, new_nz); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1686 std::copy_n (data () + lbi, new_nz, retval.data ()); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1687 std::copy_n (ridx () + lbi, new_nz, retval.ridx ()); |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1688 mx_inline_sub (ub - lb + 1, retval.cidx (), cidx () + lb, lbi); |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1689 } |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1690 else |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1691 { |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1692 // Count new nonzero elements. |
30791 | 1693 retval = Sparse<T, Alloc> (nr, m); |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1694 for (octave_idx_type j = 0; j < m; j++) |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1695 { |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1696 octave_idx_type jj = idx_j(j); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1697 retval.xcidx (j+1) = retval.xcidx (j) + (cidx (jj+1) - cidx (jj)); |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1698 } |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1699 |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1700 retval.change_capacity (retval.xcidx (m)); |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1701 |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1702 // Copy data & indices. |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1703 for (octave_idx_type j = 0; j < m; j++) |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1704 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1705 octave_idx_type ljj = cidx (idx_j(j)); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1706 octave_idx_type lj = retval.xcidx (j); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1707 octave_idx_type nzj = retval.xcidx (j+1) - lj; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1708 |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1709 std::copy_n (data () + ljj, nzj, retval.data () + lj); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1710 std::copy_n (ridx () + ljj, nzj, retval.ridx () + lj); |
10432
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1711 } |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1712 } |
10207338603a
improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents:
10425
diff
changeset
|
1713 } |
23592
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1714 else if (nc == 1 && idx_j.is_colon_equiv (nc) && idx_i.isvector ()) |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1715 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1716 // It's actually vector indexing. The 1D index is specialized for that. |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1717 retval = index (idx_i); |
14790
b8041f48b0ff
Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents:
14789
diff
changeset
|
1718 |
b8041f48b0ff
Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents:
14789
diff
changeset
|
1719 // If nr == 1 then the vector indexing will return a column vector!! |
b8041f48b0ff
Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents:
14789
diff
changeset
|
1720 if (nr == 1) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
1721 retval.transpose (); |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1722 } |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1723 else if (idx_i.is_scalar ()) |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1724 { |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1725 octave_idx_type ii = idx_i(0); |
30791 | 1726 retval = Sparse<T, Alloc> (1, m); |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1727 OCTAVE_LOCAL_BUFFER (octave_idx_type, ij, m); |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1728 for (octave_idx_type j = 0; j < m; j++) |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1729 { |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1730 octave_quit (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1731 octave_idx_type jj = idx_j(j); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1732 octave_idx_type lj = cidx (jj); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1733 octave_idx_type nzj = cidx (jj+1) - cidx (jj); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1734 |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1735 // Scalar index - just a binary lookup. |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1736 octave_idx_type i = lblookup (ridx () + lj, nzj, ii); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1737 if (i < nzj && ridx (i+lj) == ii) |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1738 { |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1739 ij[j] = i + lj; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1740 retval.xcidx (j+1) = retval.xcidx (j) + 1; |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1741 } |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1742 else |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1743 retval.xcidx (j+1) = retval.xcidx (j); |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1744 } |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1745 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1746 retval.change_capacity (retval.xcidx (m)); |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1747 |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1748 // Copy data, adjust row indices. |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1749 for (octave_idx_type j = 0; j < m; j++) |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1750 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1751 octave_idx_type i = retval.xcidx (j); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1752 if (retval.xcidx (j+1) > i) |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1753 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1754 retval.xridx (i) = 0; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1755 retval.xdata (i) = data (ij[j]); |
10442
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1756 } |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1757 } |
3011d1765a6e
improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents:
10432
diff
changeset
|
1758 } |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1759 else if (idx_i.is_cont_range (nr, lb, ub)) |
5164 | 1760 { |
30791 | 1761 retval = Sparse<T, Alloc> (n, m); |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1762 OCTAVE_LOCAL_BUFFER (octave_idx_type, li, m); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1763 OCTAVE_LOCAL_BUFFER (octave_idx_type, ui, m); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1764 for (octave_idx_type j = 0; j < m; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1765 { |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1766 octave_quit (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1767 octave_idx_type jj = idx_j(j); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1768 octave_idx_type lj = cidx (jj); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1769 octave_idx_type nzj = cidx (jj+1) - cidx (jj); |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1770 octave_idx_type lij, uij; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1771 |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1772 // Lookup indices. |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1773 li[j] = lij = lblookup (ridx () + lj, nzj, lb) + lj; |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1774 ui[j] = uij = lblookup (ridx () + lj, nzj, ub) + lj; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1775 retval.xcidx (j+1) = retval.xcidx (j) + ui[j] - li[j]; |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1776 } |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1777 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1778 retval.change_capacity (retval.xcidx (m)); |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1779 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1780 // Copy data, adjust row indices. |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1781 for (octave_idx_type j = 0, k = 0; j < m; j++) |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1782 { |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1783 octave_quit (); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1784 for (octave_idx_type i = li[j]; i < ui[j]; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1785 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1786 retval.xdata (k) = data (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1787 retval.xridx (k++) = ridx (i) - lb; |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1788 } |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1789 } |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1790 } |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1791 else if (idx_i.is_permutation (nr)) |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1792 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1793 // The columns preserve their length, just need to renumber and sort them. |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1794 // Count new nonzero elements. |
30791 | 1795 retval = Sparse<T, Alloc> (nr, m); |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1796 for (octave_idx_type j = 0; j < m; j++) |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1797 { |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1798 octave_idx_type jj = idx_j(j); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1799 retval.xcidx (j+1) = retval.xcidx (j) + (cidx (jj+1) - cidx (jj)); |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1800 } |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1801 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1802 retval.change_capacity (retval.xcidx (m)); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1803 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1804 octave_quit (); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1805 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1806 if (idx_i.is_range () && idx_i.increment () == -1) |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1807 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1808 // It's nr:-1:1. Just flip all columns. |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1809 for (octave_idx_type j = 0; j < m; j++) |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1810 { |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1811 octave_quit (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1812 octave_idx_type jj = idx_j(j); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1813 octave_idx_type lj = cidx (jj); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1814 octave_idx_type nzj = cidx (jj+1) - cidx (jj); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1815 octave_idx_type li = retval.xcidx (j); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1816 octave_idx_type uj = lj + nzj - 1; |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1817 for (octave_idx_type i = 0; i < nzj; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1818 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1819 retval.xdata (li + i) = data (uj - i); // Copy in reverse order. |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1820 retval.xridx (li + i) = nr - 1 - ridx (uj - i); // Ditto with transform. |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1821 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1822 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1823 } |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1824 else |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1825 { |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1826 // Get inverse permutation. |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1827 octave::idx_vector idx_iinv = idx_i.inverse_permutation (nr); |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1828 const octave_idx_type *iinv = idx_iinv.raw (); |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1829 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1830 // Scatter buffer. |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1831 OCTAVE_LOCAL_BUFFER (T, scb, nr); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1832 octave_idx_type *rri = retval.ridx (); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1833 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1834 for (octave_idx_type j = 0; j < m; j++) |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1835 { |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1836 octave_quit (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1837 octave_idx_type jj = idx_j(j); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1838 octave_idx_type lj = cidx (jj); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1839 octave_idx_type nzj = cidx (jj+1) - cidx (jj); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1840 octave_idx_type li = retval.xcidx (j); |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1841 // Scatter the column, transform indices. |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1842 for (octave_idx_type i = 0; i < nzj; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1843 scb[rri[li + i] = iinv[ridx (lj + i)]] = data (lj + i); |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1844 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1845 octave_quit (); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1846 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1847 // Sort them. |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1848 std::sort (rri + li, rri + li + nzj); |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1849 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1850 // Gather. |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1851 for (octave_idx_type i = 0; i < nzj; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1852 retval.xdata (li + i) = scb[rri[li + i]]; |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1853 } |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1854 } |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1855 |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1856 } |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1857 else if (idx_j.is_colon ()) |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1858 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21337
diff
changeset
|
1859 // This requires uncompressing columns, which is generally costly, |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1860 // so we rely on the efficient transpose to handle this. |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1861 // It may still make sense to optimize some cases here. |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1862 retval = transpose (); |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1863 retval = retval.index (octave::idx_vector::colon, idx_i); |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1864 retval = retval.transpose (); |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1865 } |
10468
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1866 else |
197b096001b7
improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents:
10442
diff
changeset
|
1867 { |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
1868 // A(I, J) is decomposed into A(:, J)(I, :). |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1869 retval = index (octave::idx_vector::colon, idx_j); |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1870 retval = retval.index (idx_i, octave::idx_vector::colon); |
5164 | 1871 } |
1872 | |
1873 return retval; | |
1874 } | |
1875 | |
30791 | 1876 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
1877 OCTAVE_API |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1878 void |
30791 | 1879 Sparse<T, Alloc>::assign (const octave::idx_vector& idx, |
1880 const Sparse<T, Alloc>& rhs) | |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1881 { |
30791 | 1882 Sparse<T, Alloc> retval; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1883 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1884 assert (ndims () == 2); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1885 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1886 octave_idx_type nr = dim1 (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1887 octave_idx_type nc = dim2 (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1888 octave_idx_type nz = nnz (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1889 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1890 octave_idx_type n = numel (); // Can throw. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1891 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1892 octave_idx_type rhl = rhs.numel (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1893 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1894 if (idx.length (n) == rhl) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1895 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1896 if (rhl == 0) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1897 return; |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1898 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1899 octave_idx_type nx = idx.extent (n); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
1900 // Try to resize first if necessary. |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1901 if (nx != n) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1902 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1903 resize1 (nx); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1904 n = numel (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1905 nr = rows (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1906 nc = cols (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1907 // nz is preserved. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1908 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1909 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1910 if (idx.is_colon ()) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1911 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
1912 *this = rhs.reshape (m_dimensions); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1913 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1914 else if (nc == 1 && rhs.cols () == 1) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1915 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1916 // Sparse column vector to sparse column vector assignment. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1917 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1918 octave_idx_type lb, ub; |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1919 if (idx.is_cont_range (nr, lb, ub)) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1920 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1921 // Special-case a contiguous range. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1922 // Look-up indices first. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1923 octave_idx_type li = lblookup (ridx (), nz, lb); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1924 octave_idx_type ui = lblookup (ridx (), nz, ub); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1925 octave_idx_type rnz = rhs.nnz (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
1926 octave_idx_type new_nz = nz - (ui - li) + rnz; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1927 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
1928 if (new_nz >= nz && new_nz <= nzmax ()) |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1929 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1930 // Adding/overwriting elements, enough capacity allocated. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1931 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1932 if (new_nz > nz) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1933 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1934 // Make room first. |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1935 std::copy_backward (data () + ui, data () + nz, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1936 data () + nz + rnz); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1937 std::copy_backward (ridx () + ui, ridx () + nz, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1938 ridx () + nz + rnz); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1939 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
1940 |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1941 // Copy data and adjust indices from rhs. |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1942 std::copy_n (rhs.data (), rnz, data () + li); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1943 mx_inline_add (rnz, ridx () + li, rhs.ridx (), lb); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1944 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1945 else |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1946 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1947 // Clearing elements or exceeding capacity, allocate afresh |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1948 // and paste pieces. |
30791 | 1949 const Sparse<T, Alloc> tmp = *this; |
1950 *this = Sparse<T, Alloc> (nr, 1, new_nz); | |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1951 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1952 // Head ... |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1953 std::copy_n (tmp.data (), li, data ()); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1954 std::copy_n (tmp.ridx (), li, ridx ()); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1955 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1956 // new stuff ... |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1957 std::copy_n (rhs.data (), rnz, data () + li); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1958 mx_inline_add (rnz, ridx () + li, rhs.ridx (), lb); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1959 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1960 // ...tail |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
1961 std::copy (tmp.data () + ui, tmp.data () + nz, |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1962 data () + li + rnz); |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
1963 std::copy (tmp.ridx () + ui, tmp.ridx () + nz, |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1964 ridx () + li + rnz); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1965 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1966 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1967 cidx (1) = new_nz; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1968 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1969 else if (idx.is_range () && idx.increment () == -1) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1970 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
1971 // It's s(u:-1:l) = r. Reverse the assignment. |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
1972 assign (idx.sorted (), rhs.index (octave::idx_vector (rhl - 1, 0, -1))); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1973 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1974 else if (idx.is_permutation (n)) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1975 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1976 *this = rhs.index (idx.inverse_permutation (n)); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1977 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1978 else if (rhs.nnz () == 0) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1979 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1980 // Elements are being zeroed. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1981 octave_idx_type *ri = ridx (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1982 for (octave_idx_type i = 0; i < rhl; i++) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1983 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1984 octave_idx_type iidx = idx(i); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1985 octave_idx_type li = lblookup (ri, nz, iidx); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1986 if (li != nz && ri[li] == iidx) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1987 xdata (li) = T (); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1988 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1989 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1990 maybe_compress (true); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1991 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1992 else |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1993 { |
30791 | 1994 const Sparse<T, Alloc> tmp = *this; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1995 octave_idx_type new_nz = nz + rhl; |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
1996 // Disassembly our matrix... |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1997 Array<octave_idx_type> new_ri (dim_vector (new_nz, 1)); |
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1998 Array<T> new_data (dim_vector (new_nz, 1)); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1999 std::copy_n (tmp.ridx (), nz, new_ri.fortran_vec ()); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2000 std::copy_n (tmp.data (), nz, new_data.fortran_vec ()); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2001 // ... insert new data (densified) ... |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2002 idx.copy_data (new_ri.fortran_vec () + nz); |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2003 new_data.assign (octave::idx_vector (nz, new_nz), rhs.array_value ()); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2004 // ... reassembly. |
30791 | 2005 *this = Sparse<T, Alloc> (new_data, new_ri, 0, nr, nc, false); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2006 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2007 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2008 else |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2009 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
2010 dim_vector save_dims = m_dimensions; |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2011 *this = index (octave::idx_vector::colon); |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2012 assign (idx, rhs.index (octave::idx_vector::colon)); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2013 *this = reshape (save_dims); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2014 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2015 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2016 else if (rhl == 1) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2017 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2018 rhl = idx.length (n); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2019 if (rhs.nnz () != 0) |
30791 | 2020 assign (idx, Sparse<T, Alloc> (rhl, 1, rhs.data (0))); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2021 else |
30791 | 2022 assign (idx, Sparse<T, Alloc> (rhl, 1)); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2023 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2024 else |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30099
diff
changeset
|
2025 octave::err_nonconformant ("=", dim_vector(idx.length (n), 1), rhs.dims()); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2026 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2027 |
30791 | 2028 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2029 OCTAVE_API |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2030 void |
30791 | 2031 Sparse<T, Alloc>::assign (const octave::idx_vector& idx, |
2032 const T& rhs) | |
29845
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2033 { |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2034 // FIXME: Converting the RHS and forwarding to the sparse matrix |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2035 // assignment function is simpler, but it might be good to have a |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2036 // specialization... |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2037 |
30791 | 2038 assign (idx, Sparse<T, Alloc> (1, 1, rhs)); |
29845
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2039 } |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2040 |
30791 | 2041 template <typename T, typename Alloc> |
29845
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2042 OCTAVE_API |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2043 void |
30791 | 2044 Sparse<T, Alloc>::assign (const octave::idx_vector& idx_i, |
2045 const octave::idx_vector& idx_j, | |
2046 const Sparse<T, Alloc>& rhs) | |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2047 { |
30791 | 2048 Sparse<T, Alloc> retval; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2049 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2050 assert (ndims () == 2); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2051 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2052 octave_idx_type nr = dim1 (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2053 octave_idx_type nc = dim2 (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2054 octave_idx_type nz = nnz (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2055 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2056 octave_idx_type n = rhs.rows (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2057 octave_idx_type m = rhs.columns (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2058 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2059 // FIXME: this should probably be written more like the |
12184
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2060 // Array<T>::assign function... |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2061 |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2062 bool orig_zero_by_zero = (nr == 0 && nc == 0); |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2063 |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2064 if (orig_zero_by_zero || (idx_i.length (nr) == n && idx_j.length (nc) == m)) |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2065 { |
12184
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2066 octave_idx_type nrx; |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2067 octave_idx_type ncx; |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2068 |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2069 if (orig_zero_by_zero) |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2070 { |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2071 if (idx_i.is_colon ()) |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2072 { |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2073 nrx = n; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2074 |
12184
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2075 if (idx_j.is_colon ()) |
12318
211f8c905a4f
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
12184
diff
changeset
|
2076 ncx = m; |
12184
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2077 else |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2078 ncx = idx_j.extent (nc); |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2079 } |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2080 else if (idx_j.is_colon ()) |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2081 { |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2082 nrx = idx_i.extent (nr); |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2083 ncx = m; |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2084 } |
12318
211f8c905a4f
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
12184
diff
changeset
|
2085 else |
211f8c905a4f
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
12184
diff
changeset
|
2086 { |
211f8c905a4f
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
12184
diff
changeset
|
2087 nrx = idx_i.extent (nr); |
211f8c905a4f
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
12184
diff
changeset
|
2088 ncx = idx_j.extent (nc); |
211f8c905a4f
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
12184
diff
changeset
|
2089 } |
12184
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2090 } |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2091 else |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2092 { |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2093 nrx = idx_i.extent (nr); |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2094 ncx = idx_j.extent (nc); |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2095 } |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2096 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2097 // Try to resize first if necessary. |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2098 if (nrx != nr || ncx != nc) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2099 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2100 resize (nrx, ncx); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2101 nr = rows (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2102 nc = cols (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2103 // nz is preserved. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2104 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2105 |
12184
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2106 if (n == 0 || m == 0) |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2107 return; |
d8de1a28274c
sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents:
11590
diff
changeset
|
2108 |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2109 if (idx_i.is_colon ()) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2110 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2111 octave_idx_type lb, ub; |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
2112 // Great, we're just manipulating columns. This is going to be quite |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2113 // efficient, because the columns can stay compressed as they are. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2114 if (idx_j.is_colon ()) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2115 *this = rhs; // Shallow copy. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2116 else if (idx_j.is_cont_range (nc, lb, ub)) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2117 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2118 // Special-case a contiguous range. |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2119 octave_idx_type li = cidx (lb); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2120 octave_idx_type ui = cidx (ub); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2121 octave_idx_type rnz = rhs.nnz (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2122 octave_idx_type new_nz = nz - (ui - li) + rnz; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2123 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
2124 if (new_nz >= nz && new_nz <= nzmax ()) |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2125 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2126 // Adding/overwriting elements, enough capacity allocated. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2127 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2128 if (new_nz > nz) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2129 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2130 // Make room first. |
21255
6209f428426c
Fix memory corruption allocating to sparse arrays (bug #42825).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19861
diff
changeset
|
2131 std::copy_backward (data () + ui, data () + nz, |
6209f428426c
Fix memory corruption allocating to sparse arrays (bug #42825).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19861
diff
changeset
|
2132 data () + new_nz); |
6209f428426c
Fix memory corruption allocating to sparse arrays (bug #42825).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19861
diff
changeset
|
2133 std::copy_backward (ridx () + ui, ridx () + nz, |
6209f428426c
Fix memory corruption allocating to sparse arrays (bug #42825).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19861
diff
changeset
|
2134 ridx () + new_nz); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2135 mx_inline_add2 (nc - ub, cidx () + ub + 1, new_nz - nz); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2136 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2137 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2138 // Copy data and indices from rhs. |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2139 std::copy_n (rhs.data (), rnz, data () + li); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2140 std::copy_n (rhs.ridx (), rnz, ridx () + li); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2141 mx_inline_add (ub - lb, cidx () + lb + 1, rhs.cidx () + 1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2142 li); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2143 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2144 assert (nnz () == new_nz); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2145 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2146 else |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2147 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2148 // Clearing elements or exceeding capacity, allocate afresh |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2149 // and paste pieces. |
30791 | 2150 const Sparse<T, Alloc> tmp = *this; |
2151 *this = Sparse<T, Alloc> (nr, nc, new_nz); | |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2152 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2153 // Head... |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2154 std::copy_n (tmp.data (), li, data ()); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2155 std::copy_n (tmp.ridx (), li, ridx ()); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2156 std::copy_n (tmp.cidx () + 1, lb, cidx () + 1); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2157 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2158 // new stuff... |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2159 std::copy_n (rhs.data (), rnz, data () + li); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2160 std::copy_n (rhs.ridx (), rnz, ridx () + li); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2161 mx_inline_add (ub - lb, cidx () + lb + 1, rhs.cidx () + 1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2162 li); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2163 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2164 // ...tail. |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
2165 std::copy (tmp.data () + ui, tmp.data () + nz, |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2166 data () + li + rnz); |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19078
diff
changeset
|
2167 std::copy (tmp.ridx () + ui, tmp.ridx () + nz, |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2168 ridx () + li + rnz); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2169 mx_inline_add (nc - ub, cidx () + ub + 1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2170 tmp.cidx () + ub + 1, new_nz - nz); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2171 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2172 assert (nnz () == new_nz); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2173 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2174 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2175 else if (idx_j.is_range () && idx_j.increment () == -1) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2176 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
2177 // It's s(:,u:-1:l) = r. Reverse the assignment. |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2178 assign (idx_i, idx_j.sorted (), |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2179 rhs.index (idx_i, octave::idx_vector (m - 1, 0, -1))); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2180 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2181 else if (idx_j.is_permutation (nc)) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2182 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2183 *this = rhs.index (idx_i, idx_j.inverse_permutation (nc)); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2184 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2185 else |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2186 { |
30791 | 2187 const Sparse<T, Alloc> tmp = *this; |
2188 *this = Sparse<T, Alloc> (nr, nc); | |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2189 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, jsav, nc, -1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2190 |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2191 // Assemble column lengths. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2192 for (octave_idx_type i = 0; i < nc; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2193 xcidx (i+1) = tmp.cidx (i+1) - tmp.cidx (i); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2194 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2195 for (octave_idx_type i = 0; i < m; i++) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2196 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2197 octave_idx_type j =idx_j(i); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2198 jsav[j] = i; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2199 xcidx (j+1) = rhs.cidx (i+1) - rhs.cidx (i); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2200 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2201 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2202 // Make cumulative. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2203 for (octave_idx_type i = 0; i < nc; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2204 xcidx (i+1) += xcidx (i); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2205 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2206 change_capacity (nnz ()); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2207 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2208 // Merge columns. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2209 for (octave_idx_type i = 0; i < nc; i++) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2210 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2211 octave_idx_type l = xcidx (i); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2212 octave_idx_type u = xcidx (i+1); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2213 octave_idx_type j = jsav[i]; |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2214 if (j >= 0) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2215 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2216 // from rhs |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2217 octave_idx_type k = rhs.cidx (j); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2218 std::copy_n (rhs.data () + k, u - l, xdata () + l); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2219 std::copy_n (rhs.ridx () + k, u - l, xridx () + l); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2220 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2221 else |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2222 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2223 // original |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2224 octave_idx_type k = tmp.cidx (i); |
23420
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2225 std::copy_n (tmp.data () + k, u - l, xdata () + l); |
1fee389bd04b
Use std::copy_n rather than std::copy for clarity in liboctave/array.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
2226 std::copy_n (tmp.ridx () + k, u - l, xridx () + l); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2227 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2228 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2229 |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2230 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2231 } |
23592
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
2232 else if (nc == 1 && idx_j.is_colon_equiv (nc) && idx_i.isvector ()) |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
2233 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2234 // It's just vector indexing. The 1D assign is specialized for that. |
10516
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
2235 assign (idx_i, rhs); |
f0266ee4aabe
optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents:
10512
diff
changeset
|
2236 } |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2237 else if (idx_j.is_colon ()) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2238 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2239 if (idx_i.is_permutation (nr)) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2240 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2241 *this = rhs.index (idx_i.inverse_permutation (nr), idx_j); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2242 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2243 else |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2244 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2245 // FIXME: optimize more special cases? |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2246 // In general this requires unpacking the columns, which is slow, |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
2247 // especially for many small columns. OTOH, transpose is an |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2248 // efficient O(nr+nc+nnz) operation. |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2249 *this = transpose (); |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2250 assign (octave::idx_vector::colon, idx_i, rhs.transpose ()); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2251 *this = transpose (); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2252 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2253 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2254 else |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2255 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2256 // Split it into 2 assignments and one indexing. |
30791 | 2257 Sparse<T, Alloc> tmp = index (octave::idx_vector::colon, idx_j); |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2258 tmp.assign (idx_i, octave::idx_vector::colon, rhs); |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2259 assign (octave::idx_vector::colon, idx_j, tmp); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2260 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2261 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2262 else if (m == 1 && n == 1) |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2263 { |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2264 n = idx_i.length (nr); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2265 m = idx_j.length (nc); |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2266 if (rhs.nnz () != 0) |
30791 | 2267 assign (idx_i, idx_j, Sparse<T, Alloc> (n, m, rhs.data (0))); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2268 else |
30791 | 2269 assign (idx_i, idx_j, Sparse<T, Alloc> (n, m)); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2270 } |
22600
dd80fb1ef949
maint: minor style fixes for C++ code.
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
2271 else if (idx_i.length (nr) == m && idx_j.length (nc) == n |
dd80fb1ef949
maint: minor style fixes for C++ code.
John W. Eaton <jwe@octave.org>
parents:
22489
diff
changeset
|
2272 && (n == 1 || m == 1)) |
20673
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
2273 { |
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
2274 assign (idx_i, idx_j, rhs.transpose ()); |
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
2275 } |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2276 else |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2277 octave::err_nonconformant ("=", idx_i.length (nr), idx_j.length (nc), n, m); |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2278 } |
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
2279 |
30791 | 2280 template <typename T, typename Alloc> |
29845
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2281 OCTAVE_API |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2282 void |
30791 | 2283 Sparse<T, Alloc>::assign (const octave::idx_vector& idx_i, |
2284 const octave::idx_vector& idx_j, | |
2285 const T& rhs) | |
29845
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2286 { |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2287 // FIXME: Converting the RHS and forwarding to the sparse matrix |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2288 // assignment function is simpler, but it might be good to have a |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2289 // specialization... |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2290 |
30791 | 2291 assign (idx_i, idx_j, Sparse<T, Alloc> (1, 1, rhs)); |
29845
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2292 } |
2ef9080ca017
allow more mixed-type assignments to work for sparse matrices (bug #60859)
John W. Eaton <jwe@octave.org>
parents:
29688
diff
changeset
|
2293 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2294 // Can't use versions of these in Array.cc due to duplication of the |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2295 // instantiations for Array<double and Sparse<double>, etc. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
2296 template <typename T> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2297 OCTAVE_API |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2298 bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2299 sparse_ascending_compare (typename ref_param<T>::type a, |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2300 typename ref_param<T>::type b) |
7433 | 2301 { |
2302 return (a < b); | |
2303 } | |
2304 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
2305 template <typename T> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2306 OCTAVE_API |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2307 bool |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2308 sparse_descending_compare (typename ref_param<T>::type a, |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2309 typename ref_param<T>::type b) |
7433 | 2310 { |
2311 return (a > b); | |
2312 } | |
2313 | |
30791 | 2314 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2315 OCTAVE_API |
30791 | 2316 Sparse<T, Alloc> |
2317 Sparse<T, Alloc>::sort (octave_idx_type dim, sortmode mode) const | |
7433 | 2318 { |
30791 | 2319 Sparse<T, Alloc> m = *this; |
7433 | 2320 |
2321 octave_idx_type nr = m.rows (); | |
2322 octave_idx_type nc = m.columns (); | |
2323 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
2324 if (m.numel () < 1 || dim > 1) |
7433 | 2325 return m; |
2326 | |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2327 bool sort_by_column = (dim > 0); |
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2328 if (sort_by_column) |
7433 | 2329 { |
2330 m = m.transpose (); | |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2331 std::swap (nr, nc); |
7433 | 2332 } |
2333 | |
2334 octave_sort<T> lsort; | |
2335 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2336 if (mode == ASCENDING) |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2337 lsort.set_compare (sparse_ascending_compare<T>); |
7433 | 2338 else if (mode == DESCENDING) |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2339 lsort.set_compare (sparse_descending_compare<T>); |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2340 else |
23448
e1c02e7126a9
avoid calling abort if possible; include cstdlib for declaration if needed
John W. Eaton <jwe@octave.org>
parents:
23432
diff
changeset
|
2341 (*current_liboctave_error_handler) |
30791 | 2342 ("Sparse<T, Alloc>::sort: invalid MODE"); |
7433 | 2343 |
2344 T *v = m.data (); | |
2345 octave_idx_type *mcidx = m.cidx (); | |
2346 octave_idx_type *mridx = m.ridx (); | |
2347 | |
2348 for (octave_idx_type j = 0; j < nc; j++) | |
2349 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2350 octave_idx_type ns = mcidx[j + 1] - mcidx[j]; |
7433 | 2351 lsort.sort (v, ns); |
2352 | |
2353 octave_idx_type i; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2354 if (mode == ASCENDING) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2355 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2356 for (i = 0; i < ns; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2357 if (sparse_ascending_compare<T> (static_cast<T> (0), v[i])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2358 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2359 } |
7433 | 2360 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2361 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2362 for (i = 0; i < ns; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2363 if (sparse_descending_compare<T> (static_cast<T> (0), v[i])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2364 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2365 } |
7433 | 2366 for (octave_idx_type k = 0; k < i; k++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2367 mridx[k] = k; |
7433 | 2368 for (octave_idx_type k = i; k < ns; k++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2369 mridx[k] = k - ns + nr; |
7433 | 2370 |
2371 v += ns; | |
2372 mridx += ns; | |
2373 } | |
2374 | |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2375 if (sort_by_column) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2376 m = m.transpose (); |
7433 | 2377 |
2378 return m; | |
2379 } | |
2380 | |
30791 | 2381 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2382 OCTAVE_API |
30791 | 2383 Sparse<T, Alloc> |
2384 Sparse<T, Alloc>::sort (Array<octave_idx_type>& sidx, | |
2385 octave_idx_type dim, sortmode mode) const | |
7433 | 2386 { |
30791 | 2387 Sparse<T, Alloc> m = *this; |
7433 | 2388 |
2389 octave_idx_type nr = m.rows (); | |
2390 octave_idx_type nc = m.columns (); | |
2391 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
2392 if (m.numel () < 1 || dim > 1) |
7433 | 2393 { |
10703
5eb420d92307
fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
2394 sidx = Array<octave_idx_type> (dim_vector (nr, nc), 1); |
7433 | 2395 return m; |
2396 } | |
2397 | |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2398 bool sort_by_column = (dim > 0); |
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2399 if (sort_by_column) |
7433 | 2400 { |
2401 m = m.transpose (); | |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2402 std::swap (nr, nc); |
7433 | 2403 } |
2404 | |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2405 octave_sort<T> indexed_sort; |
7433 | 2406 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2407 if (mode == ASCENDING) |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2408 indexed_sort.set_compare (sparse_ascending_compare<T>); |
7433 | 2409 else if (mode == DESCENDING) |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2410 indexed_sort.set_compare (sparse_descending_compare<T>); |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2411 else |
23448
e1c02e7126a9
avoid calling abort if possible; include cstdlib for declaration if needed
John W. Eaton <jwe@octave.org>
parents:
23432
diff
changeset
|
2412 (*current_liboctave_error_handler) |
30791 | 2413 ("Sparse<T, Alloc>::sort: invalid MODE"); |
7433 | 2414 |
2415 T *v = m.data (); | |
2416 octave_idx_type *mcidx = m.cidx (); | |
2417 octave_idx_type *mridx = m.ridx (); | |
2418 | |
2419 sidx = Array<octave_idx_type> (dim_vector (nr, nc)); | |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2420 OCTAVE_LOCAL_BUFFER (octave_idx_type, vi, nr); |
7433 | 2421 |
2422 for (octave_idx_type j = 0; j < nc; j++) | |
2423 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2424 octave_idx_type ns = mcidx[j + 1] - mcidx[j]; |
7433 | 2425 octave_idx_type offset = j * nr; |
2426 | |
2427 if (ns == 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2428 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2429 for (octave_idx_type k = 0; k < nr; k++) |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2430 sidx(offset + k) = k; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2431 } |
7433 | 2432 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2433 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2434 for (octave_idx_type i = 0; i < ns; i++) |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2435 vi[i] = mridx[i]; |
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2436 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2437 indexed_sort.sort (v, vi, ns); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2438 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2439 octave_idx_type i; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2440 if (mode == ASCENDING) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2441 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2442 for (i = 0; i < ns; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2443 if (sparse_ascending_compare<T> (static_cast<T> (0), v[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2444 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2445 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2446 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2447 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2448 for (i = 0; i < ns; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2449 if (sparse_descending_compare<T> (static_cast<T> (0), v[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2450 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2451 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2452 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2453 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2454 octave_idx_type jj = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2455 for (octave_idx_type k = 0; k < nr; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2456 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2457 if (ii < ns && mridx[ii] == k) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2458 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2459 else |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2460 sidx(offset + jj++) = k; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2461 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2462 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2463 for (octave_idx_type k = 0; k < i; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2464 { |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2465 sidx(k + offset) = vi[k]; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2466 mridx[k] = k; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2467 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2468 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2469 for (octave_idx_type k = i; k < ns; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2470 { |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2471 sidx(k - ns + nr + offset) = vi[k]; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2472 mridx[k] = k - ns + nr; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2473 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2474 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2475 v += ns; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2476 mridx += ns; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2477 } |
7433 | 2478 } |
2479 | |
29981
0c3d248a3b44
maint: Code cleanup in Sparse::sort routines.
Rik <rik@octave.org>
parents:
29927
diff
changeset
|
2480 if (sort_by_column) |
7433 | 2481 { |
2482 m = m.transpose (); | |
2483 sidx = sidx.transpose (); | |
2484 } | |
2485 | |
2486 return m; | |
2487 } | |
2488 | |
30791 | 2489 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2490 OCTAVE_API |
30791 | 2491 Sparse<T, Alloc> |
2492 Sparse<T, Alloc>::diag (octave_idx_type k) const | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2493 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2494 octave_idx_type nnr = rows (); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2495 octave_idx_type nnc = cols (); |
30791 | 2496 Sparse<T, Alloc> d; |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2497 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2498 if (nnr == 0 || nnc == 0) |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2499 ; // do nothing |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2500 else if (nnr != 1 && nnc != 1) |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2501 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2502 if (k > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2503 nnc -= k; |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2504 else if (k < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2505 nnr += k; |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2506 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2507 if (nnr > 0 && nnc > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2508 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2509 octave_idx_type ndiag = (nnr < nnc) ? nnr : nnc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2510 |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
2511 // Count the number of nonzero elements |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2512 octave_idx_type nel = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2513 if (k > 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2514 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2515 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2516 if (elem (i, i+k) != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2517 nel++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2518 } |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18278
diff
changeset
|
2519 else if (k < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2520 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2521 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2522 if (elem (i-k, i) != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2523 nel++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2524 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2525 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2526 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2527 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2528 if (elem (i, i) != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2529 nel++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2530 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2531 |
30791 | 2532 d = Sparse<T, Alloc> (ndiag, 1, nel); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2533 d.xcidx (0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2534 d.xcidx (1) = nel; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2535 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2536 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2537 if (k > 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2538 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2539 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2540 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2541 T tmp = elem (i, i+k); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2542 if (tmp != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2543 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2544 d.xdata (ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2545 d.xridx (ii++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2546 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2547 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2548 } |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18278
diff
changeset
|
2549 else if (k < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2550 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2551 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2552 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2553 T tmp = elem (i-k, i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2554 if (tmp != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2555 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2556 d.xdata (ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2557 d.xridx (ii++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2558 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2559 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2560 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2561 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2562 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2563 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2564 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2565 T tmp = elem (i, i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2566 if (tmp != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2567 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2568 d.xdata (ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2569 d.xridx (ii++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2570 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2571 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2572 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2573 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2574 else |
18278
00539b673cd4
Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents:
18146
diff
changeset
|
2575 { |
00539b673cd4
Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents:
18146
diff
changeset
|
2576 // Matlab returns [] 0x1 for out-of-range diagonal |
00539b673cd4
Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents:
18146
diff
changeset
|
2577 |
00539b673cd4
Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents:
18146
diff
changeset
|
2578 octave_idx_type nr = 0; |
00539b673cd4
Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents:
18146
diff
changeset
|
2579 octave_idx_type nc = 1; |
00539b673cd4
Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents:
18146
diff
changeset
|
2580 octave_idx_type nz = 0; |
00539b673cd4
Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents:
18146
diff
changeset
|
2581 |
30791 | 2582 d = Sparse<T, Alloc> (nr, nc, nz); |
18278
00539b673cd4
Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents:
18146
diff
changeset
|
2583 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2584 } |
26448
5f402dfe8179
Sparse.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2585 else // one of dimensions == 1 (vector) |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2586 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2587 octave_idx_type roff = 0; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2588 octave_idx_type coff = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2589 if (k > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2590 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2591 roff = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2592 coff = k; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2593 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2594 else if (k < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2595 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2596 roff = -k; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2597 coff = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2598 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2599 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2600 if (nnr == 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2601 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2602 octave_idx_type n = nnc + std::abs (k); |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10499
diff
changeset
|
2603 octave_idx_type nz = nnz (); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2604 |
30791 | 2605 d = Sparse<T, Alloc> (n, n, nz); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2606 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2607 if (nnz () > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2608 { |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2609 for (octave_idx_type i = 0; i < coff+1; i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2610 d.xcidx (i) = 0; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2611 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2612 for (octave_idx_type j = 0; j < nnc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2613 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2614 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++) |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2615 { |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2616 d.xdata (i) = data (i); |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2617 d.xridx (i) = j + roff; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2618 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2619 d.xcidx (j + coff + 1) = cidx (j+1); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2620 } |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2621 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2622 for (octave_idx_type i = nnc + coff + 1; i < n + 1; i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2623 d.xcidx (i) = nz; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2624 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2625 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2626 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2627 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2628 octave_idx_type n = nnr + std::abs (k); |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10499
diff
changeset
|
2629 octave_idx_type nz = nnz (); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2630 |
30791 | 2631 d = Sparse<T, Alloc> (n, n, nz); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2632 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2633 if (nnz () > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2634 { |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2635 octave_idx_type ii = 0; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2636 octave_idx_type ir = ridx (0); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2637 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2638 for (octave_idx_type i = 0; i < coff+1; i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2639 d.xcidx (i) = 0; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2640 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2641 for (octave_idx_type i = 0; i < nnr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2642 { |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2643 if (ir == i) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2644 { |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2645 d.xdata (ii) = data (ii); |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2646 d.xridx (ii++) = ir + roff; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2647 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2648 if (ii != nz) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2649 ir = ridx (ii); |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2650 } |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2651 d.xcidx (i + coff + 1) = ii; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2652 } |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2653 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2654 for (octave_idx_type i = nnr + coff + 1; i < n+1; i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2655 d.xcidx (i) = nz; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2656 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2657 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2658 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2659 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2660 return d; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2661 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2662 |
30791 | 2663 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2664 OCTAVE_API |
30791 | 2665 Sparse<T, Alloc> |
2666 Sparse<T, Alloc>::cat (int dim, octave_idx_type n, | |
2667 const Sparse<T, Alloc> *sparse_list) | |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2668 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2669 // Default concatenation. |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2670 bool (dim_vector::*concat_rule) (const dim_vector&, int) = &dim_vector::concat; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2671 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2672 if (dim == -1 || dim == -2) |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2673 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2674 concat_rule = &dim_vector::hvcat; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2675 dim = -dim - 1; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2676 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2677 else if (dim < 0) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2678 (*current_liboctave_error_handler) ("cat: invalid dimension"); |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2679 |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2680 dim_vector dv; |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2681 octave_idx_type total_nz = 0; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2682 if (dim != 0 && dim != 1) |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
2683 (*current_liboctave_error_handler) |
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
2684 ("cat: invalid dimension for sparse concatenation"); |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2685 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2686 if (n == 1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2687 return sparse_list[0]; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2688 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2689 for (octave_idx_type i = 0; i < n; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2690 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2691 if (! (dv.*concat_rule) (sparse_list[i].dims (), dim)) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2692 (*current_liboctave_error_handler) ("cat: dimension mismatch"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2693 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2694 total_nz += sparse_list[i].nnz (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2695 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2696 |
30791 | 2697 Sparse<T, Alloc> retval (dv, total_nz); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11571
diff
changeset
|
2698 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
2699 if (retval.isempty ()) |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2700 return retval; |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2701 |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2702 switch (dim) |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2703 { |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2704 case 0: |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2705 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2706 // sparse vertcat. This is not efficiently handled by assignment, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2707 // so we'll do it directly. |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2708 octave_idx_type l = 0; |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2709 for (octave_idx_type j = 0; j < dv(1); j++) |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2710 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2711 octave_quit (); |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2712 |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2713 octave_idx_type rcum = 0; |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2714 for (octave_idx_type i = 0; i < n; i++) |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2715 { |
30791 | 2716 const Sparse<T, Alloc>& spi = sparse_list[i]; |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
2717 // Skipping empty matrices. See the comment in Array.cc. |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
2718 if (spi.isempty ()) |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2719 continue; |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2720 |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2721 octave_idx_type kl = spi.cidx (j); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
2722 octave_idx_type ku = spi.cidx (j+1); |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2723 for (octave_idx_type k = kl; k < ku; k++, l++) |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2724 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2725 retval.xridx (l) = spi.ridx (k) + rcum; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2726 retval.xdata (l) = spi.data (k); |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2727 } |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2728 |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2729 rcum += spi.rows (); |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2730 } |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2731 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2732 retval.xcidx (j+1) = l; |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2733 } |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2734 |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2735 break; |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2736 } |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2737 case 1: |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2738 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2739 octave_idx_type l = 0; |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2740 for (octave_idx_type i = 0; i < n; i++) |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2741 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2742 octave_quit (); |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2743 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21704
diff
changeset
|
2744 // Skipping empty matrices. See the comment in Array.cc. |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
2745 if (sparse_list[i].isempty ()) |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2746 continue; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
2747 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2748 octave_idx_type u = l + sparse_list[i].columns (); |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
2749 retval.assign (octave::idx_vector::colon, octave::idx_vector (l, u), |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2750 sparse_list[i]); |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10531
diff
changeset
|
2751 l = u; |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2752 } |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2753 |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2754 break; |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2755 } |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2756 default: |
10535
3f973f6c841c
improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
2757 assert (false); |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2758 } |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2759 |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2760 return retval; |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2761 } |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10527
diff
changeset
|
2762 |
30791 | 2763 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2764 OCTAVE_API |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2765 Array<T> |
30791 | 2766 Sparse<T, Alloc>::array_value () const |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2767 { |
27387
e1968e40e43f
Remove use of NoAlias in construction of array_value from Sparse object (bug #56752).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27081
diff
changeset
|
2768 Array<T> retval (dims (), T ()); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2769 if (rows () == 1) |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2770 { |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2771 octave_idx_type i = 0; |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2772 for (octave_idx_type j = 0, nc = cols (); j < nc; j++) |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2773 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2774 if (cidx (j+1) > i) |
27387
e1968e40e43f
Remove use of NoAlias in construction of array_value from Sparse object (bug #56752).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27081
diff
changeset
|
2775 retval.xelem (j) = data (i++); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2776 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2777 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2778 else |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2779 { |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2780 for (octave_idx_type j = 0, nc = cols (); j < nc; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2781 for (octave_idx_type i = cidx (j), iu = cidx (j+1); i < iu; i++) |
27387
e1968e40e43f
Remove use of NoAlias in construction of array_value from Sparse object (bug #56752).
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27081
diff
changeset
|
2782 retval.xelem (ridx (i), j) = data (i); |
10425
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2783 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2784 |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2785 return retval; |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2786 } |
0677c5d80b77
rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
10421
diff
changeset
|
2787 |
21704
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2788 template <typename T> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
2789 OCTAVE_API |
21704
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2790 std::istream& |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2791 read_sparse_matrix (std::istream& is, Sparse<T>& a, |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2792 T (*read_fcn) (std::istream&)) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2793 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2794 octave_idx_type nr = a.rows (); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2795 octave_idx_type nc = a.cols (); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2796 octave_idx_type nz = a.nzmax (); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2797 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2798 if (nr > 0 && nc > 0) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2799 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2800 octave_idx_type itmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2801 octave_idx_type jtmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2802 octave_idx_type iold = 0; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2803 octave_idx_type jold = 0; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2804 octave_idx_type ii = 0; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2805 T tmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2806 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2807 a.cidx (0) = 0; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2808 for (octave_idx_type i = 0; i < nz; i++) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2809 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2810 itmp = 0; jtmp = 0; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2811 is >> itmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2812 itmp--; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2813 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2814 is >> jtmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2815 jtmp--; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2816 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2817 if (is.fail ()) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2818 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2819 is.clear(); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2820 std::string err_field; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2821 is >> err_field; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2822 (*current_liboctave_error_handler) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2823 ("invalid sparse matrix: element %" OCTAVE_IDX_TYPE_FORMAT ": " |
21704
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2824 "Symbols '%s' is not an integer format", |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2825 i+1, err_field.c_str ()); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2826 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2827 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2828 if (itmp < 0 || itmp >= nr) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2829 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2830 is.setstate (std::ios::failbit); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2831 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2832 (*current_liboctave_error_handler) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2833 ("invalid sparse matrix: element %" OCTAVE_IDX_TYPE_FORMAT ": " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2834 "row index = %" OCTAVE_IDX_TYPE_FORMAT " out of range", |
21704
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2835 i+1, itmp + 1); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2836 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2837 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2838 if (jtmp < 0 || jtmp >= nc) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2839 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2840 is.setstate (std::ios::failbit); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2841 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2842 (*current_liboctave_error_handler) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2843 ("invalid sparse matrix: element %" OCTAVE_IDX_TYPE_FORMAT ": " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2844 "column index = %" OCTAVE_IDX_TYPE_FORMAT " out of range", |
21704
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2845 i+1, jtmp + 1); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2846 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2847 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2848 if (jtmp < jold) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2849 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2850 is.setstate (std::ios::failbit); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2851 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2852 (*current_liboctave_error_handler) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2853 ("invalid sparse matrix: element %" OCTAVE_IDX_TYPE_FORMAT ":" |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2854 "column indices must appear in ascending order " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2855 "(%" OCTAVE_IDX_TYPE_FORMAT " < %" OCTAVE_IDX_TYPE_FORMAT ")", |
21704
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2856 i+1, jtmp, jold); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2857 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2858 else if (jtmp > jold) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2859 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2860 for (octave_idx_type j = jold; j < jtmp; j++) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2861 a.cidx (j+1) = ii; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2862 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2863 else if (itmp < iold) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2864 { |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2865 is.setstate (std::ios::failbit); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2866 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2867 (*current_liboctave_error_handler) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2868 ("invalid sparse matrix: element %" OCTAVE_IDX_TYPE_FORMAT ": " |
21704
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2869 "row indices must appear in ascending order in each column " |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26448
diff
changeset
|
2870 "(%" OCTAVE_IDX_TYPE_FORMAT " < %" OCTAVE_IDX_TYPE_FORMAT ")", |
21704
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2871 i+1, iold, itmp); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2872 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2873 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2874 iold = itmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2875 jold = jtmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2876 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2877 tmp = read_fcn (is); |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2878 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2879 if (! is) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2880 return is; // Problem, return is in error state |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2881 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2882 a.data (ii) = tmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2883 a.ridx (ii++) = itmp; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2884 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2885 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2886 for (octave_idx_type j = jold; j < nc; j++) |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2887 a.cidx (j+1) = ii; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2888 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2889 |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2890 return is; |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2891 } |
ac59b72712fd
Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21690
diff
changeset
|
2892 |
7356 | 2893 /* |
2894 * Tests | |
2895 * | |
2896 | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2897 %!function x = set_slice (x, dim, slice, arg) |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16803
diff
changeset
|
2898 %! switch (dim) |
7356 | 2899 %! case 11 |
2900 %! x(slice) = 2; | |
2901 %! case 21 | |
2902 %! x(slice, :) = 2; | |
2903 %! case 22 | |
2904 %! x(:, slice) = 2; | |
2905 %! otherwise | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2906 %! error ("invalid dim, '%d'", dim); |
7356 | 2907 %! endswitch |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2908 %!endfunction |
7356 | 2909 |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2910 %!function x = set_slice2 (x, dim, slice) |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16803
diff
changeset
|
2911 %! switch (dim) |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
2912 %! case 11 |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2913 %! x(slice) = 2 * ones (size (slice)); |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
2914 %! case 21 |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2915 %! x(slice, :) = 2 * ones (length (slice), columns (x)); |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
2916 %! case 22 |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2917 %! x(:, slice) = 2 * ones (rows (x), length (slice)); |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
2918 %! otherwise |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2919 %! error ("invalid dim, '%d'", dim); |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
2920 %! endswitch |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2921 %!endfunction |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
2922 |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2923 %!function test_sparse_slice (size, dim, slice) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2924 %! x = ones (size); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2925 %! s = set_slice (sparse (x), dim, slice); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2926 %! f = set_slice (x, dim, slice); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2927 %! assert (nnz (s), nnz (f)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2928 %! assert (full (s), f); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2929 %! s = set_slice2 (sparse (x), dim, slice); |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2930 %! f = set_slice2 (x, dim, slice); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2931 %! assert (nnz (s), nnz (f)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2932 %! assert (full (s), f); |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2933 %!endfunction |
7356 | 2934 |
2935 #### 1d indexing | |
2936 | |
2937 ## size = [2 0] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2938 %!test test_sparse_slice ([2 0], 11, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2939 %!assert (set_slice (sparse (ones ([2 0])), 11, 1), sparse ([2 0]')) # sparse different from full |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2940 %!assert (set_slice (sparse (ones ([2 0])), 11, 2), sparse ([0 2]')) # sparse different from full |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2941 %!assert (set_slice (sparse (ones ([2 0])), 11, 3), sparse ([0 0; 2 0]')) # sparse different from full |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2942 %!assert (set_slice (sparse (ones ([2 0])), 11, 4), sparse ([0 0; 0 2]')) # sparse different from full |
7356 | 2943 |
2944 ## size = [0 2] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2945 %!test test_sparse_slice ([0 2], 11, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2946 %!assert (set_slice (sparse (ones ([0 2])), 11, 1), sparse ([2 0])) # sparse different from full |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2947 %!test test_sparse_slice ([0 2], 11, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2948 %!test test_sparse_slice ([0 2], 11, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2949 %!test test_sparse_slice ([0 2], 11, 4); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2950 %!test test_sparse_slice ([0 2], 11, [4, 4]); |
7356 | 2951 |
2952 ## size = [2 1] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2953 %!test test_sparse_slice ([2 1], 11, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2954 %!test test_sparse_slice ([2 1], 11, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2955 %!test test_sparse_slice ([2 1], 11, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2956 %!test test_sparse_slice ([2 1], 11, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2957 %!test test_sparse_slice ([2 1], 11, 4); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2958 %!test test_sparse_slice ([2 1], 11, [4, 4]); |
7356 | 2959 |
2960 ## size = [1 2] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2961 %!test test_sparse_slice ([1 2], 11, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2962 %!test test_sparse_slice ([1 2], 11, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2963 %!test test_sparse_slice ([1 2], 11, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2964 %!test test_sparse_slice ([1 2], 11, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2965 %!test test_sparse_slice ([1 2], 11, 4); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2966 %!test test_sparse_slice ([1 2], 11, [4, 4]); |
7356 | 2967 |
2968 ## size = [2 2] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2969 %!test test_sparse_slice ([2 2], 11, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2970 %!test test_sparse_slice ([2 2], 11, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2971 %!test test_sparse_slice ([2 2], 11, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2972 %!test test_sparse_slice ([2 2], 11, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2973 %!test test_sparse_slice ([2 2], 11, 4); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2974 %!test test_sparse_slice ([2 2], 11, [4, 4]); |
7356 | 2975 # These 2 errors are the same as in the full case |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2976 %!error id=Octave:invalid-resize set_slice (sparse (ones ([2 2])), 11, 5) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2977 %!error id=Octave:invalid-resize set_slice (sparse (ones ([2 2])), 11, 6) |
7356 | 2978 |
2979 #### 2d indexing | |
2980 | |
2981 ## size = [2 0] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2982 %!test test_sparse_slice ([2 0], 21, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2983 %!test test_sparse_slice ([2 0], 21, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2984 %!test test_sparse_slice ([2 0], 21, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2985 %!test test_sparse_slice ([2 0], 21, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2986 %!assert (set_slice (sparse (ones ([2 0])), 21, 3), sparse (3,0)) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2987 %!assert (set_slice (sparse (ones ([2 0])), 21, 4), sparse (4,0)) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2988 %!test test_sparse_slice ([2 0], 22, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2989 %!test test_sparse_slice ([2 0], 22, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2990 %!test test_sparse_slice ([2 0], 22, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2991 %!test test_sparse_slice ([2 0], 22, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2992 %!assert (set_slice (sparse (ones ([2 0])), 22, 3), sparse ([0 0 2;0 0 2])) # sparse different from full |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2993 %!assert (set_slice (sparse (ones ([2 0])), 22, 4), sparse ([0 0 0 2;0 0 0 2])) # sparse different from full |
7356 | 2994 |
2995 ## size = [0 2] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2996 %!test test_sparse_slice ([0 2], 21, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2997 %!test test_sparse_slice ([0 2], 21, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2998 %!test test_sparse_slice ([0 2], 21, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
2999 %!test test_sparse_slice ([0 2], 21, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3000 %!assert (set_slice (sparse (ones ([0 2])), 21, 3), sparse ([0 0;0 0;2 2])) # sparse different from full |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3001 %!assert (set_slice (sparse (ones ([0 2])), 21, 4), sparse ([0 0;0 0;0 0;2 2])) # sparse different from full |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3002 %!test test_sparse_slice ([0 2], 22, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3003 %!test test_sparse_slice ([0 2], 22, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3004 %!test test_sparse_slice ([0 2], 22, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3005 %!test test_sparse_slice ([0 2], 22, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3006 %!assert (set_slice (sparse (ones ([0 2])), 22, 3), sparse (0,3)) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3007 %!assert (set_slice (sparse (ones ([0 2])), 22, 4), sparse (0,4)) |
7356 | 3008 |
3009 ## size = [2 1] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3010 %!test test_sparse_slice ([2 1], 21, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3011 %!test test_sparse_slice ([2 1], 21, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3012 %!test test_sparse_slice ([2 1], 21, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3013 %!test test_sparse_slice ([2 1], 21, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3014 %!test test_sparse_slice ([2 1], 21, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3015 %!test test_sparse_slice ([2 1], 21, 4); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3016 %!test test_sparse_slice ([2 1], 22, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3017 %!test test_sparse_slice ([2 1], 22, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3018 %!test test_sparse_slice ([2 1], 22, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3019 %!test test_sparse_slice ([2 1], 22, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3020 %!test test_sparse_slice ([2 1], 22, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3021 %!test test_sparse_slice ([2 1], 22, 4); |
7356 | 3022 |
3023 ## size = [1 2] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3024 %!test test_sparse_slice ([1 2], 21, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3025 %!test test_sparse_slice ([1 2], 21, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3026 %!test test_sparse_slice ([1 2], 21, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3027 %!test test_sparse_slice ([1 2], 21, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3028 %!test test_sparse_slice ([1 2], 21, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3029 %!test test_sparse_slice ([1 2], 21, 4); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3030 %!test test_sparse_slice ([1 2], 22, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3031 %!test test_sparse_slice ([1 2], 22, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3032 %!test test_sparse_slice ([1 2], 22, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3033 %!test test_sparse_slice ([1 2], 22, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3034 %!test test_sparse_slice ([1 2], 22, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3035 %!test test_sparse_slice ([1 2], 22, 4); |
7356 | 3036 |
3037 ## size = [2 2] | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3038 %!test test_sparse_slice ([2 2], 21, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3039 %!test test_sparse_slice ([2 2], 21, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3040 %!test test_sparse_slice ([2 2], 21, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3041 %!test test_sparse_slice ([2 2], 21, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3042 %!test test_sparse_slice ([2 2], 21, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3043 %!test test_sparse_slice ([2 2], 21, 4); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3044 %!test test_sparse_slice ([2 2], 22, []); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3045 %!test test_sparse_slice ([2 2], 22, 1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3046 %!test test_sparse_slice ([2 2], 22, 2); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3047 %!test test_sparse_slice ([2 2], 22, [2,2]); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3048 %!test test_sparse_slice ([2 2], 22, 3); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3049 %!test test_sparse_slice ([2 2], 22, 4); |
7356 | 3050 |
28579
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3051 %!assert <*35570> (speye (3,1)(3:-1:1), sparse ([0; 0; 1])) |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
3052 |
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
3053 ## Test removing columns |
28579
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3054 %!test <*36656> |
14789
62219ea36f05
Assign the sparse column index when deleting contiguous columns (bug #36656)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14433
diff
changeset
|
3055 %! s = sparse (magic (5)); |
62219ea36f05
Assign the sparse column index when deleting contiguous columns (bug #36656)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14433
diff
changeset
|
3056 %! s(:,2:4) = []; |
62219ea36f05
Assign the sparse column index when deleting contiguous columns (bug #36656)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14433
diff
changeset
|
3057 %! assert (s, sparse (magic (5)(:, [1,5]))); |
62219ea36f05
Assign the sparse column index when deleting contiguous columns (bug #36656)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14433
diff
changeset
|
3058 |
14790
b8041f48b0ff
Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents:
14789
diff
changeset
|
3059 %!test |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
3060 %! s = sparse ([], [], [], 1, 1); |
14790
b8041f48b0ff
Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents:
14789
diff
changeset
|
3061 %! s(1,:) = []; |
b8041f48b0ff
Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents:
14789
diff
changeset
|
3062 %! assert (s, sparse ([], [], [], 0, 1)); |
b8041f48b0ff
Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents:
14789
diff
changeset
|
3063 |
17278
79d4b6089968
Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents:
16933
diff
changeset
|
3064 ## Test (bug #37321) |
28579
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3065 %!test <*37321> a=sparse (0,0); assert (all (a) == sparse ([1])); |
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3066 %!test <*37321> a=sparse (0,1); assert (all (a) == sparse ([1])); |
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3067 %!test <*37321> a=sparse (1,0); assert (all (a) == sparse ([1])); |
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3068 %!test <*37321> a=sparse (1,0); assert (all (a,2) == sparse ([1])); |
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3069 %!test <*37321> a=sparse (1,0); assert (size (all (a,1)), [1 0]); |
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3070 %!test <*37321> a=sparse (1,1); |
17285
f519560bfcb4
maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents:
17278
diff
changeset
|
3071 %! assert (all (a) == sparse ([0])); |
f519560bfcb4
maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents:
17278
diff
changeset
|
3072 %! assert (size (all (a)), [1 1]); |
28579
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3073 %!test <*37321> a=sparse (2,1); |
17285
f519560bfcb4
maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents:
17278
diff
changeset
|
3074 %! assert (all (a) == sparse ([0])); |
f519560bfcb4
maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents:
17278
diff
changeset
|
3075 %! assert (size (all (a)), [1 1]); |
28579
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3076 %!test <*37321> a=sparse (1,2); |
17285
f519560bfcb4
maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents:
17278
diff
changeset
|
3077 %! assert (all (a) == sparse ([0])); |
f519560bfcb4
maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents:
17278
diff
changeset
|
3078 %! assert (size (all (a)), [1 1]); |
28579
713398d4a3c3
update bug status of tests marked with bug numbers
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3079 %!test <*37321> a=sparse (2,2); assert (isequal (all (a), sparse ([0 0]))); |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
3080 |
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
3081 ## Test assigning row to a column slice |
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
3082 %!test <45589> |
20673
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
3083 %! a = sparse (magic (3)); |
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
3084 %! b = a; |
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
3085 %! a(1,:) = 1:3; |
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
3086 %! b(1,:) = (1:3)'; |
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
3087 %! assert (a, b); |
3d8aee0b7415
Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20542
diff
changeset
|
3088 |
7356 | 3089 */ |
3090 | |
30791 | 3091 template <typename T, typename Alloc> |
29227
a009cb8ef68f
Set API tags in files in liboctave/array (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28579
diff
changeset
|
3092 OCTAVE_API |
5164 | 3093 void |
30791 | 3094 Sparse<T, Alloc>::print_info (std::ostream& os, const std::string& prefix) const |
5164 | 3095 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
3096 os << prefix << "m_rep address: " << m_rep << "\n" |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
3097 << prefix << "m_rep->m_nzmax: " << m_rep->m_nzmax << "\n" |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
3098 << prefix << "m_rep->m_nrows: " << m_rep->m_nrows << "\n" |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
3099 << prefix << "m_rep->m_ncols: " << m_rep->m_ncols << "\n" |
29927
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
3100 << prefix << "m_rep->m_data: " << m_rep->m_data << "\n" |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
3101 << prefix << "m_rep->m_ridx: " << m_rep->m_ridx << "\n" |
6a8642d310c8
style fixes for Sparse<T> class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
3102 << prefix << "m_rep->m_cidx: " << m_rep->m_cidx << "\n" |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29845
diff
changeset
|
3103 << prefix << "m_rep->m_count: " << m_rep->m_count << "\n"; |
5164 | 3104 } |
10512
aac9f4265048
rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10509
diff
changeset
|
3105 |
29247
d83ae0145030
Export template class instantiations with clang (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29227
diff
changeset
|
3106 #if defined (__clang__) |
30791 | 3107 # define INSTANTIATE_SPARSE(T) \ |
3108 template class OCTAVE_API Sparse<T>; \ | |
3109 template OCTAVE_API std::istream& \ | |
3110 read_sparse_matrix<T> (std::istream& is, Sparse<T>& a, \ | |
3111 T (*read_fcn) (std::istream&)); | |
29247
d83ae0145030
Export template class instantiations with clang (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29227
diff
changeset
|
3112 #else |
30791 | 3113 # define INSTANTIATE_SPARSE(T) \ |
3114 template class Sparse<T>; \ | |
3115 template OCTAVE_API std::istream& \ | |
3116 read_sparse_matrix<T> (std::istream& is, Sparse<T>& a, \ | |
3117 T (*read_fcn) (std::istream&)); | |
29247
d83ae0145030
Export template class instantiations with clang (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29227
diff
changeset
|
3118 #endif |