annotate liboctave/array/Sparse.cc @ 22755:3a2b891d0b33

maint: Standardize Copyright formatting. * Makefile.am, README, build-aux/check-subst-vars.in.sh, build-aux/find-files-with-tests.sh, build-aux/mk-builtins.sh, build-aux/mk-default-qt-settings.in.sh, build-aux/mk-f77-def.in.sh, build-aux/mk-hg-id.sh, build-aux/mk-mxarray-h.in.sh, build-aux/mk-octave-config-h.sh, build-aux/mk-opts.pl, build-aux/mk-version-h.in.sh, build-aux/subst-config-vals.in.sh, build-aux/subst-cross-config-vals.in.sh, build-aux/subst-default-vals.in.sh, build-aux/subst-f77-isnan-macro.in.sh, build-aux/subst-script-vals.in.sh, configure.ac, doc/interpreter/arith.txi, doc/interpreter/audio.txi, doc/interpreter/basics.txi, doc/interpreter/bugs.txi, doc/interpreter/container.txi, doc/interpreter/cp-idx.txi, doc/interpreter/data.txi, doc/interpreter/debug.txi, doc/interpreter/diagperm.txi, doc/interpreter/diffeq.txi, doc/interpreter/errors.txi, doc/interpreter/eval.txi, doc/interpreter/expr.txi, doc/interpreter/external.txi, doc/interpreter/fn-idx.txi, doc/interpreter/func.txi, doc/interpreter/genpropdoc.m, doc/interpreter/geometry.txi, doc/interpreter/geometryimages.m, doc/interpreter/grammar.txi, doc/interpreter/gui.txi, doc/interpreter/image.txi, doc/interpreter/install.txi, doc/interpreter/interp.txi, doc/interpreter/interpimages.m, doc/interpreter/intro.txi, doc/interpreter/io.txi, doc/interpreter/linalg.txi, doc/interpreter/macros.texi, doc/interpreter/matrix.txi, doc/interpreter/mk-doc-cache.pl, doc/interpreter/mkoctfile.1, doc/interpreter/nonlin.txi, doc/interpreter/numbers.txi, doc/interpreter/obsolete.txi, doc/interpreter/octave-cli.1, doc/interpreter/octave-config.1, doc/interpreter/octave.1, doc/interpreter/octave.css, doc/interpreter/octave.texi, doc/interpreter/oop.txi, doc/interpreter/op-idx.txi, doc/interpreter/optim.txi, doc/interpreter/package.txi, doc/interpreter/plot.txi, doc/interpreter/plotimages.m, doc/interpreter/poly.txi, doc/interpreter/preface.txi, doc/interpreter/quad.txi, doc/interpreter/set.txi, doc/interpreter/signal.txi, doc/interpreter/sparse.txi, doc/interpreter/sparseimages.m, doc/interpreter/splineimages.m, doc/interpreter/stats.txi, doc/interpreter/stmt.txi, doc/interpreter/strings.txi, doc/interpreter/system.txi, doc/interpreter/testfun.txi, doc/interpreter/var.txi, doc/interpreter/vectorize.txi, doc/liboctave/array.texi, doc/liboctave/bugs.texi, doc/liboctave/cp-idx.texi, doc/liboctave/dae.texi, doc/liboctave/diffeq.texi, doc/liboctave/error.texi, doc/liboctave/factor.texi, doc/liboctave/fn-idx.texi, doc/liboctave/gpl.texi, doc/liboctave/install.texi, doc/liboctave/intro.texi, doc/liboctave/liboctave.texi, doc/liboctave/matvec.texi, doc/liboctave/nleqn.texi, doc/liboctave/nlfunc.texi, doc/liboctave/ode.texi, doc/liboctave/optim.texi, doc/liboctave/preface.texi, doc/liboctave/quad.texi, doc/liboctave/range.texi, doc/refcard/refcard-a4.tex, doc/refcard/refcard-legal.tex, doc/refcard/refcard-letter.tex, doc/refcard/refcard.tex, etc/HACKING, etc/icons/octave.appdata.xml.in, libgui/graphics/Backend.cc, libgui/graphics/Backend.h, libgui/graphics/BaseControl.cc, libgui/graphics/BaseControl.h, libgui/graphics/ButtonControl.cc, libgui/graphics/ButtonControl.h, libgui/graphics/ButtonGroup.cc, libgui/graphics/ButtonGroup.h, libgui/graphics/Canvas.cc, libgui/graphics/Canvas.h, libgui/graphics/CheckBoxControl.cc, libgui/graphics/CheckBoxControl.h, libgui/graphics/Container.cc, libgui/graphics/Container.h, libgui/graphics/ContextMenu.cc, libgui/graphics/ContextMenu.h, libgui/graphics/EditControl.cc, libgui/graphics/EditControl.h, libgui/graphics/Figure.cc, libgui/graphics/Figure.h, libgui/graphics/FigureWindow.cc, libgui/graphics/FigureWindow.h, libgui/graphics/GLCanvas.cc, libgui/graphics/GLCanvas.h, libgui/graphics/GenericEventNotify.h, libgui/graphics/KeyMap.cc, libgui/graphics/KeyMap.h, libgui/graphics/ListBoxControl.cc, libgui/graphics/ListBoxControl.h, libgui/graphics/Logger.cc, libgui/graphics/Logger.h, libgui/graphics/Menu.cc, libgui/graphics/Menu.h, libgui/graphics/MenuContainer.h, libgui/graphics/MouseModeActionGroup.cc, libgui/graphics/MouseModeActionGroup.h, libgui/graphics/Object.cc, libgui/graphics/Object.h, libgui/graphics/ObjectFactory.cc, libgui/graphics/ObjectFactory.h, libgui/graphics/ObjectProxy.cc, libgui/graphics/ObjectProxy.h, libgui/graphics/Panel.cc, libgui/graphics/Panel.h, libgui/graphics/PopupMenuControl.cc, libgui/graphics/PopupMenuControl.h, libgui/graphics/PushButtonControl.cc, libgui/graphics/PushButtonControl.h, libgui/graphics/PushTool.cc, libgui/graphics/PushTool.h, libgui/graphics/QtHandlesUtils.cc, libgui/graphics/QtHandlesUtils.h, libgui/graphics/RadioButtonControl.cc, libgui/graphics/RadioButtonControl.h, libgui/graphics/SliderControl.cc, libgui/graphics/SliderControl.h, libgui/graphics/TextControl.cc, libgui/graphics/TextControl.h, libgui/graphics/TextEdit.cc, libgui/graphics/TextEdit.h, libgui/graphics/ToggleButtonControl.cc, libgui/graphics/ToggleButtonControl.h, libgui/graphics/ToggleTool.cc, libgui/graphics/ToggleTool.h, libgui/graphics/ToolBar.cc, libgui/graphics/ToolBar.h, libgui/graphics/ToolBarButton.cc, libgui/graphics/ToolBarButton.h, libgui/graphics/__init_qt__.cc, libgui/graphics/__init_qt__.h, libgui/graphics/annotation-dialog.cc, libgui/graphics/annotation-dialog.h, libgui/graphics/gl-select.cc, libgui/graphics/gl-select.h, libgui/src/color-picker.cc, libgui/src/color-picker.h, libgui/src/dialog.cc, libgui/src/dialog.h, libgui/src/documentation-dock-widget.cc, libgui/src/documentation-dock-widget.h, libgui/src/files-dock-widget.cc, libgui/src/files-dock-widget.h, libgui/src/find-files-dialog.cc, libgui/src/find-files-dialog.h, libgui/src/find-files-model.cc, libgui/src/find-files-model.h, libgui/src/history-dock-widget.cc, libgui/src/history-dock-widget.h, libgui/src/liboctgui-build-info.h, libgui/src/liboctgui-build-info.in.cc, libgui/src/m-editor/file-editor-interface.h, libgui/src/m-editor/file-editor-tab.cc, libgui/src/m-editor/file-editor-tab.h, libgui/src/m-editor/file-editor.cc, libgui/src/m-editor/file-editor.h, libgui/src/m-editor/find-dialog.cc, libgui/src/m-editor/find-dialog.h, libgui/src/m-editor/marker.cc, libgui/src/m-editor/marker.h, libgui/src/m-editor/octave-qscintilla.cc, libgui/src/m-editor/octave-qscintilla.h, libgui/src/m-editor/octave-txt-lexer.cc, libgui/src/m-editor/octave-txt-lexer.h, libgui/src/main-window.cc, libgui/src/main-window.h, libgui/src/octave-cmd.cc, libgui/src/octave-cmd.h, libgui/src/octave-dock-widget.cc, libgui/src/octave-dock-widget.h, libgui/src/octave-gui.cc, libgui/src/octave-gui.h, libgui/src/octave-interpreter.cc, libgui/src/octave-interpreter.h, libgui/src/octave-qt-link.cc, libgui/src/octave-qt-link.h, libgui/src/qtinfo/parser.cc, libgui/src/qtinfo/parser.h, libgui/src/qtinfo/webinfo.cc, libgui/src/qtinfo/webinfo.h, libgui/src/resource-manager.cc, libgui/src/resource-manager.h, libgui/src/settings-dialog.cc, libgui/src/settings-dialog.h, libgui/src/shortcut-manager.cc, libgui/src/shortcut-manager.h, libgui/src/terminal-dock-widget.cc, libgui/src/terminal-dock-widget.h, libgui/src/thread-manager.cc, libgui/src/thread-manager.h, libgui/src/welcome-wizard.cc, libgui/src/welcome-wizard.h, libgui/src/workspace-model.cc, libgui/src/workspace-model.h, libgui/src/workspace-view.cc, libgui/src/workspace-view.h, libinterp/build-env.h, libinterp/build-env.in.cc, libinterp/builtins.h, libinterp/corefcn/Cell.cc, libinterp/corefcn/Cell.h, libinterp/corefcn/__contourc__.cc, libinterp/corefcn/__dsearchn__.cc, libinterp/corefcn/__ichol__.cc, libinterp/corefcn/__ilu__.cc, libinterp/corefcn/__lin_interpn__.cc, libinterp/corefcn/__luinc__.cc, libinterp/corefcn/__magick_read__.cc, libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc, libinterp/corefcn/balance.cc, libinterp/corefcn/base-text-renderer.h, libinterp/corefcn/besselj.cc, libinterp/corefcn/betainc.cc, libinterp/corefcn/bitfcns.cc, libinterp/corefcn/bsxfun.cc, libinterp/corefcn/c-file-ptr-stream.cc, libinterp/corefcn/c-file-ptr-stream.h, libinterp/corefcn/call-stack.cc, libinterp/corefcn/call-stack.h, libinterp/corefcn/cdisplay.c, libinterp/corefcn/cdisplay.h, libinterp/corefcn/cellfun.cc, libinterp/corefcn/coct-hdf5-types.c, libinterp/corefcn/colloc.cc, libinterp/corefcn/comment-list.cc, libinterp/corefcn/comment-list.h, libinterp/corefcn/conv2.cc, libinterp/corefcn/daspk.cc, libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc, libinterp/corefcn/data.cc, libinterp/corefcn/data.h, libinterp/corefcn/debug.cc, libinterp/corefcn/debug.h, libinterp/corefcn/defaults.cc, libinterp/corefcn/defaults.in.h, libinterp/corefcn/defun-dld.h, libinterp/corefcn/defun-int.h, libinterp/corefcn/defun.cc, libinterp/corefcn/defun.h, libinterp/corefcn/det.cc, libinterp/corefcn/dirfns.cc, libinterp/corefcn/dirfns.h, libinterp/corefcn/display.cc, libinterp/corefcn/display.h, libinterp/corefcn/dlmread.cc, libinterp/corefcn/dot.cc, libinterp/corefcn/dynamic-ld.cc, libinterp/corefcn/dynamic-ld.h, libinterp/corefcn/eig.cc, libinterp/corefcn/ellipj.cc, libinterp/corefcn/error.cc, libinterp/corefcn/error.h, libinterp/corefcn/errwarn.cc, libinterp/corefcn/errwarn.h, libinterp/corefcn/event-queue.cc, libinterp/corefcn/event-queue.h, libinterp/corefcn/fft.cc, libinterp/corefcn/fft2.cc, libinterp/corefcn/fftn.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/file-io.h, libinterp/corefcn/filter.cc, libinterp/corefcn/find.cc, libinterp/corefcn/ft-text-renderer.cc, libinterp/corefcn/ft-text-renderer.h, libinterp/corefcn/gammainc.cc, libinterp/corefcn/gcd.cc, libinterp/corefcn/getgrent.cc, libinterp/corefcn/getpwent.cc, libinterp/corefcn/getrusage.cc, libinterp/corefcn/givens.cc, libinterp/corefcn/gl-render.cc, libinterp/corefcn/gl-render.h, libinterp/corefcn/gl2ps-print.cc, libinterp/corefcn/gl2ps-print.h, libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h, libinterp/corefcn/gripes.cc, libinterp/corefcn/gripes.h, libinterp/corefcn/gsvd.cc, libinterp/corefcn/hash.cc, libinterp/corefcn/help.cc, libinterp/corefcn/help.h, libinterp/corefcn/hess.cc, libinterp/corefcn/hex2num.cc, libinterp/corefcn/hook-fcn.cc, libinterp/corefcn/hook-fcn.h, libinterp/corefcn/input.cc, libinterp/corefcn/input.h, libinterp/corefcn/interpreter.cc, libinterp/corefcn/interpreter.h, libinterp/corefcn/inv.cc, libinterp/corefcn/jit-ir.cc, libinterp/corefcn/jit-ir.h, libinterp/corefcn/jit-typeinfo.cc, libinterp/corefcn/jit-typeinfo.h, libinterp/corefcn/jit-util.cc, libinterp/corefcn/jit-util.h, libinterp/corefcn/kron.cc, libinterp/corefcn/load-path.cc, libinterp/corefcn/load-path.h, libinterp/corefcn/load-save.cc, libinterp/corefcn/load-save.h, libinterp/corefcn/lookup.cc, libinterp/corefcn/ls-ascii-helper.cc, libinterp/corefcn/ls-ascii-helper.h, libinterp/corefcn/ls-hdf5.cc, libinterp/corefcn/ls-hdf5.h, libinterp/corefcn/ls-mat-ascii.cc, libinterp/corefcn/ls-mat-ascii.h, libinterp/corefcn/ls-mat4.cc, libinterp/corefcn/ls-mat4.h, libinterp/corefcn/ls-mat5.cc, libinterp/corefcn/ls-mat5.h, libinterp/corefcn/ls-oct-binary.cc, libinterp/corefcn/ls-oct-binary.h, libinterp/corefcn/ls-oct-text.cc, libinterp/corefcn/ls-oct-text.h, libinterp/corefcn/ls-utils.cc, libinterp/corefcn/ls-utils.h, libinterp/corefcn/lsode.cc, libinterp/corefcn/lu.cc, libinterp/corefcn/mappers.cc, libinterp/corefcn/matrix_type.cc, libinterp/corefcn/max.cc, libinterp/corefcn/mex.cc, libinterp/corefcn/mex.h, libinterp/corefcn/mexproto.h, libinterp/corefcn/mgorth.cc, libinterp/corefcn/mxarray.in.h, libinterp/corefcn/nproc.cc, libinterp/corefcn/oct-errno.h, libinterp/corefcn/oct-errno.in.cc, libinterp/corefcn/oct-fstrm.cc, libinterp/corefcn/oct-fstrm.h, libinterp/corefcn/oct-handle.h, libinterp/corefcn/oct-hdf5-types.cc, libinterp/corefcn/oct-hdf5-types.h, libinterp/corefcn/oct-hdf5.h, libinterp/corefcn/oct-hist.cc, libinterp/corefcn/oct-hist.h, libinterp/corefcn/oct-iostrm.cc, libinterp/corefcn/oct-iostrm.h, libinterp/corefcn/oct-lvalue.cc, libinterp/corefcn/oct-lvalue.h, libinterp/corefcn/oct-map.cc, libinterp/corefcn/oct-map.h, libinterp/corefcn/oct-obj.h, libinterp/corefcn/oct-opengl.h, libinterp/corefcn/oct-prcstrm.cc, libinterp/corefcn/oct-prcstrm.h, libinterp/corefcn/oct-procbuf.cc, libinterp/corefcn/oct-procbuf.h, libinterp/corefcn/oct-stdstrm.h, libinterp/corefcn/oct-stream.cc, libinterp/corefcn/oct-stream.h, libinterp/corefcn/oct-strstrm.cc, libinterp/corefcn/oct-strstrm.h, libinterp/corefcn/oct-tex-lexer.in.ll, libinterp/corefcn/oct-tex-parser.in.yy, libinterp/corefcn/oct.h, libinterp/corefcn/octave-default-image.h, libinterp/corefcn/octave-link.cc, libinterp/corefcn/octave-link.h, libinterp/corefcn/octave-preserve-stream-state.h, libinterp/corefcn/ordschur.cc, libinterp/corefcn/pager.cc, libinterp/corefcn/pager.h, libinterp/corefcn/pinv.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/pr-output.h, libinterp/corefcn/procstream.cc, libinterp/corefcn/procstream.h, libinterp/corefcn/profiler.cc, libinterp/corefcn/profiler.h, libinterp/corefcn/psi.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/pt-jit.h, libinterp/corefcn/quad.cc, libinterp/corefcn/quadcc.cc, libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/rcond.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc, libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sighandlers.h, libinterp/corefcn/sparse-xdiv.cc, libinterp/corefcn/sparse-xdiv.h, libinterp/corefcn/sparse-xpow.cc, libinterp/corefcn/sparse-xpow.h, libinterp/corefcn/sparse.cc, libinterp/corefcn/spparms.cc, libinterp/corefcn/sqrtm.cc, libinterp/corefcn/str2double.cc, libinterp/corefcn/strfind.cc, libinterp/corefcn/strfns.cc, libinterp/corefcn/sub2ind.cc, libinterp/corefcn/svd.cc, libinterp/corefcn/sylvester.cc, libinterp/corefcn/symtab.cc, libinterp/corefcn/symtab.h, libinterp/corefcn/syscalls.cc, libinterp/corefcn/sysdep.cc, libinterp/corefcn/sysdep.h, libinterp/corefcn/text-renderer.cc, libinterp/corefcn/text-renderer.h, libinterp/corefcn/time.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h, libinterp/corefcn/tril.cc, libinterp/corefcn/tsearch.cc, libinterp/corefcn/txt-eng.cc, libinterp/corefcn/txt-eng.h, libinterp/corefcn/typecast.cc, libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc, libinterp/corefcn/utils.h, libinterp/corefcn/variables.cc, libinterp/corefcn/variables.h, libinterp/corefcn/workspace-element.h, libinterp/corefcn/xdiv.cc, libinterp/corefcn/xdiv.h, libinterp/corefcn/xnorm.cc, libinterp/corefcn/xnorm.h, libinterp/corefcn/xpow.cc, libinterp/corefcn/xpow.h, libinterp/corefcn/zfstream.cc, libinterp/corefcn/zfstream.h, libinterp/deprecated-config.h, libinterp/dldfcn/__delaunayn__.cc, libinterp/dldfcn/__eigs__.cc, libinterp/dldfcn/__fltk_uigetfile__.cc, libinterp/dldfcn/__glpk__.cc, libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__init_gnuplot__.cc, libinterp/dldfcn/__osmesa_print__.cc, libinterp/dldfcn/__voronoi__.cc, libinterp/dldfcn/amd.cc, libinterp/dldfcn/audiodevinfo.cc, libinterp/dldfcn/audioread.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/chol.cc, libinterp/dldfcn/colamd.cc, libinterp/dldfcn/convhulln.cc, libinterp/dldfcn/dmperm.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/gzip.cc, libinterp/dldfcn/oct-qhull.h, libinterp/dldfcn/qr.cc, libinterp/dldfcn/symbfact.cc, libinterp/dldfcn/symrcm.cc, libinterp/gendoc.pl, libinterp/genprops.awk, libinterp/liboctinterp-build-info.h, libinterp/liboctinterp-build-info.in.cc, libinterp/mk-errno-list, libinterp/mk-pkg-add, libinterp/mkops, libinterp/octave-value/ov-base-diag.cc, libinterp/octave-value/ov-base-diag.h, libinterp/octave-value/ov-base-int.cc, libinterp/octave-value/ov-base-int.h, libinterp/octave-value/ov-base-mat.cc, libinterp/octave-value/ov-base-mat.h, libinterp/octave-value/ov-base-scalar.cc, libinterp/octave-value/ov-base-scalar.h, libinterp/octave-value/ov-base-sparse.cc, libinterp/octave-value/ov-base-sparse.h, libinterp/octave-value/ov-base.cc, libinterp/octave-value/ov-base.h, libinterp/octave-value/ov-bool-mat.cc, libinterp/octave-value/ov-bool-mat.h, libinterp/octave-value/ov-bool-sparse.cc, libinterp/octave-value/ov-bool-sparse.h, libinterp/octave-value/ov-bool.cc, libinterp/octave-value/ov-bool.h, libinterp/octave-value/ov-builtin.cc, libinterp/octave-value/ov-builtin.h, libinterp/octave-value/ov-cell.cc, libinterp/octave-value/ov-cell.h, libinterp/octave-value/ov-ch-mat.cc, libinterp/octave-value/ov-ch-mat.h, libinterp/octave-value/ov-class.cc, libinterp/octave-value/ov-class.h, libinterp/octave-value/ov-classdef.cc, libinterp/octave-value/ov-classdef.h, libinterp/octave-value/ov-colon.cc, libinterp/octave-value/ov-colon.h, libinterp/octave-value/ov-complex.cc, libinterp/octave-value/ov-complex.h, libinterp/octave-value/ov-cs-list.cc, libinterp/octave-value/ov-cs-list.h, libinterp/octave-value/ov-cx-diag.cc, libinterp/octave-value/ov-cx-diag.h, libinterp/octave-value/ov-cx-mat.cc, libinterp/octave-value/ov-cx-mat.h, libinterp/octave-value/ov-cx-sparse.cc, libinterp/octave-value/ov-cx-sparse.h, libinterp/octave-value/ov-dld-fcn.cc, libinterp/octave-value/ov-dld-fcn.h, libinterp/octave-value/ov-fcn-handle.cc, libinterp/octave-value/ov-fcn-handle.h, libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-fcn-inline.h, libinterp/octave-value/ov-fcn.cc, libinterp/octave-value/ov-fcn.h, libinterp/octave-value/ov-float.cc, libinterp/octave-value/ov-float.h, libinterp/octave-value/ov-flt-complex.cc, libinterp/octave-value/ov-flt-complex.h, libinterp/octave-value/ov-flt-cx-diag.cc, libinterp/octave-value/ov-flt-cx-diag.h, libinterp/octave-value/ov-flt-cx-mat.cc, libinterp/octave-value/ov-flt-cx-mat.h, libinterp/octave-value/ov-flt-re-diag.cc, libinterp/octave-value/ov-flt-re-diag.h, libinterp/octave-value/ov-flt-re-mat.cc, libinterp/octave-value/ov-flt-re-mat.h, libinterp/octave-value/ov-int-traits.h, libinterp/octave-value/ov-int16.cc, libinterp/octave-value/ov-int16.h, libinterp/octave-value/ov-int32.cc, libinterp/octave-value/ov-int32.h, libinterp/octave-value/ov-int64.cc, libinterp/octave-value/ov-int64.h, libinterp/octave-value/ov-int8.cc, libinterp/octave-value/ov-int8.h, libinterp/octave-value/ov-intx.h, libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-java.h, libinterp/octave-value/ov-lazy-idx.cc, libinterp/octave-value/ov-lazy-idx.h, libinterp/octave-value/ov-mex-fcn.cc, libinterp/octave-value/ov-mex-fcn.h, libinterp/octave-value/ov-null-mat.cc, libinterp/octave-value/ov-null-mat.h, libinterp/octave-value/ov-oncleanup.cc, libinterp/octave-value/ov-oncleanup.h, libinterp/octave-value/ov-perm.cc, libinterp/octave-value/ov-perm.h, libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-range.h, libinterp/octave-value/ov-re-diag.cc, libinterp/octave-value/ov-re-diag.h, libinterp/octave-value/ov-re-mat.cc, libinterp/octave-value/ov-re-mat.h, libinterp/octave-value/ov-re-sparse.cc, libinterp/octave-value/ov-re-sparse.h, libinterp/octave-value/ov-scalar.cc, libinterp/octave-value/ov-scalar.h, libinterp/octave-value/ov-str-mat.cc, libinterp/octave-value/ov-str-mat.h, libinterp/octave-value/ov-struct.cc, libinterp/octave-value/ov-struct.h, libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov-typeinfo.h, libinterp/octave-value/ov-uint16.cc, libinterp/octave-value/ov-uint16.h, libinterp/octave-value/ov-uint32.cc, libinterp/octave-value/ov-uint32.h, libinterp/octave-value/ov-uint64.cc, libinterp/octave-value/ov-uint64.h, libinterp/octave-value/ov-uint8.cc, libinterp/octave-value/ov-uint8.h, libinterp/octave-value/ov-usr-fcn.cc, libinterp/octave-value/ov-usr-fcn.h, libinterp/octave-value/ov.cc, libinterp/octave-value/ov.h, libinterp/octave-value/ovl.cc, libinterp/octave-value/ovl.h, libinterp/octave.cc, libinterp/octave.h, libinterp/op-kw-docs, libinterp/operators/op-b-b.cc, libinterp/operators/op-b-bm.cc, libinterp/operators/op-b-sbm.cc, libinterp/operators/op-bm-b.cc, libinterp/operators/op-bm-bm.cc, libinterp/operators/op-bm-sbm.cc, libinterp/operators/op-cdm-cdm.cc, libinterp/operators/op-cdm-cm.cc, libinterp/operators/op-cdm-cs.cc, libinterp/operators/op-cdm-dm.cc, libinterp/operators/op-cdm-m.cc, libinterp/operators/op-cdm-s.cc, libinterp/operators/op-cell.cc, libinterp/operators/op-chm.cc, libinterp/operators/op-class.cc, libinterp/operators/op-cm-cdm.cc, libinterp/operators/op-cm-cm.cc, libinterp/operators/op-cm-cs.cc, libinterp/operators/op-cm-dm.cc, libinterp/operators/op-cm-m.cc, libinterp/operators/op-cm-pm.cc, libinterp/operators/op-cm-s.cc, libinterp/operators/op-cm-scm.cc, libinterp/operators/op-cm-sm.cc, libinterp/operators/op-cs-cm.cc, libinterp/operators/op-cs-cs.cc, libinterp/operators/op-cs-m.cc, libinterp/operators/op-cs-s.cc, libinterp/operators/op-cs-scm.cc, libinterp/operators/op-cs-sm.cc, libinterp/operators/op-dm-cdm.cc, libinterp/operators/op-dm-cm.cc, libinterp/operators/op-dm-cs.cc, libinterp/operators/op-dm-dm.cc, libinterp/operators/op-dm-m.cc, libinterp/operators/op-dm-s.cc, libinterp/operators/op-dm-scm.cc, libinterp/operators/op-dm-sm.cc, libinterp/operators/op-dm-template.cc, libinterp/operators/op-dms-template.cc, libinterp/operators/op-fcdm-fcdm.cc, libinterp/operators/op-fcdm-fcm.cc, libinterp/operators/op-fcdm-fcs.cc, libinterp/operators/op-fcdm-fdm.cc, libinterp/operators/op-fcdm-fm.cc, libinterp/operators/op-fcdm-fs.cc, libinterp/operators/op-fcm-fcdm.cc, libinterp/operators/op-fcm-fcm.cc, libinterp/operators/op-fcm-fcs.cc, libinterp/operators/op-fcm-fdm.cc, libinterp/operators/op-fcm-fm.cc, libinterp/operators/op-fcm-fs.cc, libinterp/operators/op-fcm-pm.cc, libinterp/operators/op-fcn.cc, libinterp/operators/op-fcs-fcm.cc, libinterp/operators/op-fcs-fcs.cc, libinterp/operators/op-fcs-fm.cc, libinterp/operators/op-fcs-fs.cc, libinterp/operators/op-fdm-fcdm.cc, libinterp/operators/op-fdm-fcm.cc, libinterp/operators/op-fdm-fcs.cc, libinterp/operators/op-fdm-fdm.cc, libinterp/operators/op-fdm-fm.cc, libinterp/operators/op-fdm-fs.cc, libinterp/operators/op-fm-fcdm.cc, libinterp/operators/op-fm-fcm.cc, libinterp/operators/op-fm-fcs.cc, libinterp/operators/op-fm-fdm.cc, libinterp/operators/op-fm-fm.cc, libinterp/operators/op-fm-fs.cc, libinterp/operators/op-fm-pm.cc, libinterp/operators/op-fs-fcm.cc, libinterp/operators/op-fs-fcs.cc, libinterp/operators/op-fs-fm.cc, libinterp/operators/op-fs-fs.cc, libinterp/operators/op-i16-i16.cc, libinterp/operators/op-i32-i32.cc, libinterp/operators/op-i64-i64.cc, libinterp/operators/op-i8-i8.cc, libinterp/operators/op-int-concat.cc, libinterp/operators/op-int.h, libinterp/operators/op-m-cdm.cc, libinterp/operators/op-m-cm.cc, libinterp/operators/op-m-cs.cc, libinterp/operators/op-m-dm.cc, libinterp/operators/op-m-m.cc, libinterp/operators/op-m-pm.cc, libinterp/operators/op-m-s.cc, libinterp/operators/op-m-scm.cc, libinterp/operators/op-m-sm.cc, libinterp/operators/op-pm-cm.cc, libinterp/operators/op-pm-fcm.cc, libinterp/operators/op-pm-fm.cc, libinterp/operators/op-pm-m.cc, libinterp/operators/op-pm-pm.cc, libinterp/operators/op-pm-scm.cc, libinterp/operators/op-pm-sm.cc, libinterp/operators/op-pm-template.cc, libinterp/operators/op-range.cc, libinterp/operators/op-s-cm.cc, libinterp/operators/op-s-cs.cc, libinterp/operators/op-s-m.cc, libinterp/operators/op-s-s.cc, libinterp/operators/op-s-scm.cc, libinterp/operators/op-s-sm.cc, libinterp/operators/op-sbm-b.cc, libinterp/operators/op-sbm-bm.cc, libinterp/operators/op-sbm-sbm.cc, libinterp/operators/op-scm-cm.cc, libinterp/operators/op-scm-cs.cc, libinterp/operators/op-scm-m.cc, libinterp/operators/op-scm-s.cc, libinterp/operators/op-scm-scm.cc, libinterp/operators/op-scm-sm.cc, libinterp/operators/op-sm-cm.cc, libinterp/operators/op-sm-cs.cc, libinterp/operators/op-sm-m.cc, libinterp/operators/op-sm-s.cc, libinterp/operators/op-sm-scm.cc, libinterp/operators/op-sm-sm.cc, libinterp/operators/op-str-m.cc, libinterp/operators/op-str-s.cc, libinterp/operators/op-str-str.cc, libinterp/operators/op-struct.cc, libinterp/operators/op-ui16-ui16.cc, libinterp/operators/op-ui32-ui32.cc, libinterp/operators/op-ui64-ui64.cc, libinterp/operators/op-ui8-ui8.cc, libinterp/operators/ops.h, libinterp/options-usage.h, libinterp/parse-tree/lex.h, libinterp/parse-tree/lex.ll, libinterp/parse-tree/oct-parse.in.yy, libinterp/parse-tree/octave.gperf, libinterp/parse-tree/parse.h, libinterp/parse-tree/pt-all.h, libinterp/parse-tree/pt-arg-list.cc, libinterp/parse-tree/pt-arg-list.h, libinterp/parse-tree/pt-array-list.cc, libinterp/parse-tree/pt-array-list.h, libinterp/parse-tree/pt-assign.cc, libinterp/parse-tree/pt-assign.h, libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-binop.h, libinterp/parse-tree/pt-bp.cc, libinterp/parse-tree/pt-bp.h, libinterp/parse-tree/pt-cbinop.cc, libinterp/parse-tree/pt-cbinop.h, libinterp/parse-tree/pt-cell.cc, libinterp/parse-tree/pt-cell.h, libinterp/parse-tree/pt-check.cc, libinterp/parse-tree/pt-check.h, libinterp/parse-tree/pt-classdef.cc, libinterp/parse-tree/pt-classdef.h, libinterp/parse-tree/pt-cmd.cc, libinterp/parse-tree/pt-cmd.h, libinterp/parse-tree/pt-colon.cc, libinterp/parse-tree/pt-colon.h, libinterp/parse-tree/pt-const.cc, libinterp/parse-tree/pt-const.h, libinterp/parse-tree/pt-decl.cc, libinterp/parse-tree/pt-decl.h, libinterp/parse-tree/pt-eval.cc, libinterp/parse-tree/pt-eval.h, libinterp/parse-tree/pt-except.cc, libinterp/parse-tree/pt-except.h, libinterp/parse-tree/pt-exp.cc, libinterp/parse-tree/pt-exp.h, libinterp/parse-tree/pt-fcn-handle.cc, libinterp/parse-tree/pt-fcn-handle.h, libinterp/parse-tree/pt-funcall.cc, libinterp/parse-tree/pt-funcall.h, libinterp/parse-tree/pt-id.cc, libinterp/parse-tree/pt-id.h, libinterp/parse-tree/pt-idx.cc, libinterp/parse-tree/pt-idx.h, libinterp/parse-tree/pt-jump.cc, libinterp/parse-tree/pt-jump.h, libinterp/parse-tree/pt-loop.cc, libinterp/parse-tree/pt-loop.h, libinterp/parse-tree/pt-mat.cc, libinterp/parse-tree/pt-mat.h, libinterp/parse-tree/pt-misc.cc, libinterp/parse-tree/pt-misc.h, libinterp/parse-tree/pt-pr-code.cc, libinterp/parse-tree/pt-pr-code.h, libinterp/parse-tree/pt-select.cc, libinterp/parse-tree/pt-select.h, libinterp/parse-tree/pt-stmt.cc, libinterp/parse-tree/pt-stmt.h, libinterp/parse-tree/pt-unop.cc, libinterp/parse-tree/pt-unop.h, libinterp/parse-tree/pt-walk.h, libinterp/parse-tree/pt.cc, libinterp/parse-tree/pt.h, libinterp/parse-tree/token.cc, libinterp/parse-tree/token.h, libinterp/template-inst/Array-jit.cc, libinterp/template-inst/Array-tc.cc, libinterp/version.cc, libinterp/version.in.h, liboctave/array/Array-C.cc, liboctave/array/Array-b.cc, liboctave/array/Array-ch.cc, liboctave/array/Array-d.cc, liboctave/array/Array-f.cc, liboctave/array/Array-fC.cc, liboctave/array/Array-i.cc, liboctave/array/Array-idx-vec.cc, liboctave/array/Array-s.cc, liboctave/array/Array-str.cc, liboctave/array/Array-util.cc, liboctave/array/Array-util.h, liboctave/array/Array-voidp.cc, liboctave/array/Array.cc, liboctave/array/Array.h, liboctave/array/CColVector.cc, liboctave/array/CColVector.h, liboctave/array/CDiagMatrix.cc, liboctave/array/CDiagMatrix.h, liboctave/array/CMatrix.cc, liboctave/array/CMatrix.h, liboctave/array/CNDArray.cc, liboctave/array/CNDArray.h, liboctave/array/CRowVector.cc, liboctave/array/CRowVector.h, liboctave/array/CSparse.cc, liboctave/array/CSparse.h, liboctave/array/DiagArray2.cc, liboctave/array/DiagArray2.h, liboctave/array/MArray-C.cc, liboctave/array/MArray-d.cc, liboctave/array/MArray-f.cc, liboctave/array/MArray-fC.cc, liboctave/array/MArray-i.cc, liboctave/array/MArray-s.cc, liboctave/array/MArray.cc, liboctave/array/MArray.h, liboctave/array/MDiagArray2.cc, liboctave/array/MDiagArray2.h, liboctave/array/MSparse-C.cc, liboctave/array/MSparse-d.cc, liboctave/array/MSparse.cc, liboctave/array/MSparse.h, liboctave/array/Matrix.h, liboctave/array/MatrixType.cc, liboctave/array/MatrixType.h, liboctave/array/PermMatrix.cc, liboctave/array/PermMatrix.h, liboctave/array/Range.cc, liboctave/array/Range.h, liboctave/array/Sparse-C.cc, liboctave/array/Sparse-b.cc, liboctave/array/Sparse-d.cc, liboctave/array/Sparse.cc, liboctave/array/Sparse.h, liboctave/array/boolMatrix.cc, liboctave/array/boolMatrix.h, liboctave/array/boolNDArray.cc, liboctave/array/boolNDArray.h, liboctave/array/boolSparse.cc, liboctave/array/boolSparse.h, liboctave/array/chMatrix.cc, liboctave/array/chMatrix.h, liboctave/array/chNDArray.cc, liboctave/array/chNDArray.h, liboctave/array/dColVector.cc, liboctave/array/dColVector.h, liboctave/array/dDiagMatrix.cc, liboctave/array/dDiagMatrix.h, liboctave/array/dMatrix.cc, liboctave/array/dMatrix.h, liboctave/array/dNDArray.cc, liboctave/array/dNDArray.h, liboctave/array/dRowVector.cc, liboctave/array/dRowVector.h, liboctave/array/dSparse.cc, liboctave/array/dSparse.h, liboctave/array/dim-vector.cc, liboctave/array/dim-vector.h, liboctave/array/fCColVector.cc, liboctave/array/fCColVector.h, liboctave/array/fCDiagMatrix.cc, liboctave/array/fCDiagMatrix.h, liboctave/array/fCMatrix.cc, liboctave/array/fCMatrix.h, liboctave/array/fCNDArray.cc, liboctave/array/fCNDArray.h, liboctave/array/fCRowVector.cc, liboctave/array/fCRowVector.h, liboctave/array/fColVector.cc, liboctave/array/fColVector.h, liboctave/array/fDiagMatrix.cc, liboctave/array/fDiagMatrix.h, liboctave/array/fMatrix.cc, liboctave/array/fMatrix.h, liboctave/array/fNDArray.cc, liboctave/array/fNDArray.h, liboctave/array/fRowVector.cc, liboctave/array/fRowVector.h, liboctave/array/idx-vector.cc, liboctave/array/idx-vector.h, liboctave/array/int16NDArray.cc, liboctave/array/int16NDArray.h, liboctave/array/int32NDArray.cc, liboctave/array/int32NDArray.h, liboctave/array/int64NDArray.cc, liboctave/array/int64NDArray.h, liboctave/array/int8NDArray.cc, liboctave/array/int8NDArray.h, liboctave/array/intNDArray.cc, liboctave/array/intNDArray.h, liboctave/array/uint16NDArray.cc, liboctave/array/uint16NDArray.h, liboctave/array/uint32NDArray.cc, liboctave/array/uint32NDArray.h, liboctave/array/uint64NDArray.cc, liboctave/array/uint64NDArray.h, liboctave/array/uint8NDArray.cc, liboctave/array/uint8NDArray.h, liboctave/cruft/misc/blaswrap.c, liboctave/cruft/misc/cquit.c, liboctave/cruft/misc/f77-extern.cc, liboctave/cruft/misc/f77-fcn.c, liboctave/cruft/misc/f77-fcn.h, liboctave/cruft/misc/lo-error.c, liboctave/cruft/misc/lo-error.h, liboctave/cruft/misc/quit.cc, liboctave/cruft/misc/quit.h, liboctave/liboctave-build-info.h, liboctave/liboctave-build-info.in.cc, liboctave/numeric/CollocWt.cc, liboctave/numeric/CollocWt.h, liboctave/numeric/DAE.h, liboctave/numeric/DAEFunc.h, liboctave/numeric/DAERT.h, liboctave/numeric/DAERTFunc.h, liboctave/numeric/DASPK-opts.in, liboctave/numeric/DASPK.cc, liboctave/numeric/DASPK.h, liboctave/numeric/DASRT-opts.in, liboctave/numeric/DASRT.cc, liboctave/numeric/DASRT.h, liboctave/numeric/DASSL-opts.in, liboctave/numeric/DASSL.cc, liboctave/numeric/DASSL.h, liboctave/numeric/DET.h, liboctave/numeric/EIG.cc, liboctave/numeric/EIG.h, liboctave/numeric/LSODE-opts.in, liboctave/numeric/LSODE.cc, liboctave/numeric/LSODE.h, liboctave/numeric/ODE.h, liboctave/numeric/ODEFunc.h, liboctave/numeric/ODES.cc, liboctave/numeric/ODES.h, liboctave/numeric/ODESFunc.h, liboctave/numeric/Quad-opts.in, liboctave/numeric/Quad.cc, liboctave/numeric/Quad.h, liboctave/numeric/aepbalance.cc, liboctave/numeric/aepbalance.h, liboctave/numeric/base-dae.h, liboctave/numeric/base-de.h, liboctave/numeric/base-min.h, liboctave/numeric/bsxfun-decl.h, liboctave/numeric/bsxfun-defs.cc, liboctave/numeric/bsxfun.h, liboctave/numeric/chol.cc, liboctave/numeric/chol.h, liboctave/numeric/eigs-base.cc, liboctave/numeric/eigs-base.h, liboctave/numeric/fEIG.cc, liboctave/numeric/fEIG.h, liboctave/numeric/gepbalance.cc, liboctave/numeric/gepbalance.h, liboctave/numeric/gsvd.cc, liboctave/numeric/gsvd.h, liboctave/numeric/hess.cc, liboctave/numeric/hess.h, liboctave/numeric/lo-amos-proto.h, liboctave/numeric/lo-arpack-proto.h, liboctave/numeric/lo-blas-proto.h, liboctave/numeric/lo-fftpack-proto.h, liboctave/numeric/lo-lapack-proto.h, liboctave/numeric/lo-mappers.cc, liboctave/numeric/lo-mappers.h, liboctave/numeric/lo-qrupdate-proto.h, liboctave/numeric/lo-ranlib-proto.h, liboctave/numeric/lo-slatec-proto.h, liboctave/numeric/lo-specfun.cc, liboctave/numeric/lo-specfun.h, liboctave/numeric/lu.cc, liboctave/numeric/lu.h, liboctave/numeric/oct-convn.cc, liboctave/numeric/oct-convn.h, liboctave/numeric/oct-fftw.cc, liboctave/numeric/oct-fftw.h, liboctave/numeric/oct-norm.cc, liboctave/numeric/oct-norm.h, liboctave/numeric/oct-rand.cc, liboctave/numeric/oct-rand.h, liboctave/numeric/oct-spparms.cc, liboctave/numeric/oct-spparms.h, liboctave/numeric/qr.cc, liboctave/numeric/qr.h, liboctave/numeric/qrp.cc, liboctave/numeric/qrp.h, liboctave/numeric/randgamma.cc, liboctave/numeric/randgamma.h, liboctave/numeric/randmtzig.cc, liboctave/numeric/randmtzig.h, liboctave/numeric/randpoisson.cc, liboctave/numeric/randpoisson.h, liboctave/numeric/schur.cc, liboctave/numeric/schur.h, liboctave/numeric/sparse-chol.cc, liboctave/numeric/sparse-chol.h, liboctave/numeric/sparse-dmsolve.cc, liboctave/numeric/sparse-dmsolve.h, liboctave/numeric/sparse-lu.cc, liboctave/numeric/sparse-lu.h, liboctave/numeric/sparse-qr.cc, liboctave/numeric/sparse-qr.h, liboctave/numeric/svd.cc, liboctave/numeric/svd.h, liboctave/operators/Sparse-diag-op-defs.h, liboctave/operators/Sparse-op-decls.h, liboctave/operators/Sparse-op-defs.h, liboctave/operators/Sparse-perm-op-defs.h, liboctave/operators/mk-ops.awk, liboctave/operators/mx-base.h, liboctave/operators/mx-defs.h, liboctave/operators/mx-ext.h, liboctave/operators/mx-inlines.cc, liboctave/operators/mx-op-decl.h, liboctave/operators/mx-op-defs.h, liboctave/operators/mx-ops, liboctave/operators/smx-ops, liboctave/operators/vx-ops, liboctave/system/child-list.cc, liboctave/system/child-list.h, liboctave/system/dir-ops.cc, liboctave/system/dir-ops.h, liboctave/system/file-ops.cc, liboctave/system/file-ops.h, liboctave/system/file-stat.cc, liboctave/system/file-stat.h, liboctave/system/lo-sysdep.cc, liboctave/system/lo-sysdep.h, liboctave/system/mach-info.cc, liboctave/system/mach-info.h, liboctave/system/oct-env.cc, liboctave/system/oct-env.h, liboctave/system/oct-group.cc, liboctave/system/oct-group.h, liboctave/system/oct-passwd.cc, liboctave/system/oct-passwd.h, liboctave/system/oct-syscalls.cc, liboctave/system/oct-syscalls.h, liboctave/system/oct-time.cc, liboctave/system/oct-time.h, liboctave/system/oct-uname.cc, liboctave/system/oct-uname.h, liboctave/util/action-container.h, liboctave/util/base-list.h, liboctave/util/byte-swap.h, liboctave/util/caseless-str.h, liboctave/util/cmd-edit.cc, liboctave/util/cmd-edit.h, liboctave/util/cmd-hist.cc, liboctave/util/cmd-hist.h, liboctave/util/data-conv.cc, liboctave/util/data-conv.h, liboctave/util/f2c-main.c, liboctave/util/functor.h, liboctave/util/glob-match.cc, liboctave/util/glob-match.h, liboctave/util/kpse.cc, liboctave/util/kpse.h, liboctave/util/lo-array-errwarn.cc, liboctave/util/lo-array-errwarn.h, liboctave/util/lo-array-gripes.cc, liboctave/util/lo-array-gripes.h, liboctave/util/lo-cutils.c, liboctave/util/lo-cutils.h, liboctave/util/lo-hash.cc, liboctave/util/lo-hash.h, liboctave/util/lo-ieee.cc, liboctave/util/lo-ieee.h, liboctave/util/lo-macros.h, liboctave/util/lo-math.h, liboctave/util/lo-regexp.cc, liboctave/util/lo-regexp.h, liboctave/util/lo-traits.h, liboctave/util/lo-utils.cc, liboctave/util/lo-utils.h, liboctave/util/oct-alloc.h, liboctave/util/oct-base64.cc, liboctave/util/oct-base64.h, liboctave/util/oct-binmap.h, liboctave/util/oct-cmplx.h, liboctave/util/oct-glob.cc, liboctave/util/oct-glob.h, liboctave/util/oct-inttypes-fwd.h, liboctave/util/oct-inttypes.cc, liboctave/util/oct-inttypes.h, liboctave/util/oct-locbuf.cc, liboctave/util/oct-locbuf.h, liboctave/util/oct-mutex.cc, liboctave/util/oct-mutex.h, liboctave/util/oct-refcount.h, liboctave/util/oct-rl-edit.c, liboctave/util/oct-rl-edit.h, liboctave/util/oct-rl-hist.c, liboctave/util/oct-rl-hist.h, liboctave/util/oct-shlib.cc, liboctave/util/oct-shlib.h, liboctave/util/oct-sort.cc, liboctave/util/oct-sort.h, liboctave/util/oct-sparse.h, liboctave/util/oct-string.cc, liboctave/util/oct-string.h, liboctave/util/pathsearch.cc, liboctave/util/pathsearch.h, liboctave/util/singleton-cleanup.cc, liboctave/util/sparse-sort.cc, liboctave/util/sparse-sort.h, liboctave/util/sparse-util.cc, liboctave/util/sparse-util.h, liboctave/util/str-vec.cc, liboctave/util/str-vec.h, liboctave/util/sun-utils.h, liboctave/util/unwind-prot.cc, liboctave/util/unwind-prot.h, liboctave/util/url-transfer.cc, liboctave/util/url-transfer.h, liboctave/wrappers/areadlink-wrapper.c, liboctave/wrappers/areadlink-wrapper.h, liboctave/wrappers/async-system-wrapper.c, liboctave/wrappers/async-system-wrapper.h, liboctave/wrappers/base64-wrappers.c, liboctave/wrappers/base64-wrappers.h, liboctave/wrappers/canonicalize-file-name-wrapper.c, liboctave/wrappers/canonicalize-file-name-wrapper.h, liboctave/wrappers/dirent-wrappers.c, liboctave/wrappers/dirent-wrappers.h, liboctave/wrappers/fcntl-wrappers.c, liboctave/wrappers/fcntl-wrappers.h, liboctave/wrappers/filepos-wrappers.c, liboctave/wrappers/filepos-wrappers.h, liboctave/wrappers/fpucw-wrappers.c, liboctave/wrappers/fpucw-wrappers.h, liboctave/wrappers/gen-tempname-wrapper.c, liboctave/wrappers/gen-tempname-wrapper.h, liboctave/wrappers/getopt-wrapper.c, liboctave/wrappers/getopt-wrapper.h, liboctave/wrappers/glob-wrappers.c, liboctave/wrappers/glob-wrappers.h, liboctave/wrappers/hash-wrappers.c, liboctave/wrappers/hash-wrappers.h, liboctave/wrappers/math-wrappers.c, liboctave/wrappers/math-wrappers.h, liboctave/wrappers/mkostemp-wrapper.c, liboctave/wrappers/mkostemp-wrapper.h, liboctave/wrappers/nanosleep-wrapper.c, liboctave/wrappers/nanosleep-wrapper.h, liboctave/wrappers/nproc-wrapper.c, liboctave/wrappers/nproc-wrapper.h, liboctave/wrappers/octave-popen2.c, liboctave/wrappers/octave-popen2.h, liboctave/wrappers/putenv-wrapper.c, liboctave/wrappers/putenv-wrapper.h, liboctave/wrappers/set-program-name-wrapper.c, liboctave/wrappers/set-program-name-wrapper.h, liboctave/wrappers/signal-wrappers.c, liboctave/wrappers/signal-wrappers.h, liboctave/wrappers/stat-wrappers.c, liboctave/wrappers/stat-wrappers.h, liboctave/wrappers/strdup-wrapper.c, liboctave/wrappers/strdup-wrapper.h, liboctave/wrappers/strftime-wrapper.c, liboctave/wrappers/strftime-wrapper.h, liboctave/wrappers/strmode-wrapper.c, liboctave/wrappers/strmode-wrapper.h, liboctave/wrappers/strptime-wrapper.c, liboctave/wrappers/strptime-wrapper.h, liboctave/wrappers/time-wrappers.c, liboctave/wrappers/time-wrappers.h, liboctave/wrappers/tmpfile-wrapper.c, liboctave/wrappers/tmpfile-wrapper.h, liboctave/wrappers/uname-wrapper.c, liboctave/wrappers/uname-wrapper.h, liboctave/wrappers/unistd-wrappers.c, liboctave/wrappers/unistd-wrappers.h, liboctave/wrappers/unsetenv-wrapper.c, liboctave/wrappers/unsetenv-wrapper.h, liboctave/wrappers/vasprintf-wrapper.c, liboctave/wrappers/vasprintf-wrapper.h, liboctave/wrappers/wait-for-input.c, liboctave/wrappers/wait-for-input.h, liboctave/wrappers/wait-wrappers.c, liboctave/wrappers/wait-wrappers.h, m4/acinclude.m4, oct-conf-post.in.h, run-octave.in, scripts/@ftp/ascii.m, scripts/@ftp/binary.m, scripts/@ftp/cd.m, scripts/@ftp/close.m, scripts/@ftp/delete.m, scripts/@ftp/dir.m, scripts/@ftp/display.m, scripts/@ftp/ftp.m, scripts/@ftp/loadobj.m, scripts/@ftp/mget.m, scripts/@ftp/mkdir.m, scripts/@ftp/mput.m, scripts/@ftp/rename.m, scripts/@ftp/rmdir.m, scripts/@ftp/saveobj.m, scripts/audio/@audioplayer/__get_properties__.m, scripts/audio/@audioplayer/audioplayer.m, scripts/audio/@audioplayer/display.m, scripts/audio/@audioplayer/get.m, scripts/audio/@audioplayer/isplaying.m, scripts/audio/@audioplayer/pause.m, scripts/audio/@audioplayer/play.m, scripts/audio/@audioplayer/playblocking.m, scripts/audio/@audioplayer/resume.m, scripts/audio/@audioplayer/set.m, scripts/audio/@audioplayer/stop.m, scripts/audio/@audioplayer/subsasgn.m, scripts/audio/@audioplayer/subsref.m, scripts/audio/@audiorecorder/__get_properties__.m, scripts/audio/@audiorecorder/audiorecorder.m, scripts/audio/@audiorecorder/display.m, scripts/audio/@audiorecorder/get.m, scripts/audio/@audiorecorder/getaudiodata.m, scripts/audio/@audiorecorder/getplayer.m, scripts/audio/@audiorecorder/isrecording.m, scripts/audio/@audiorecorder/pause.m, scripts/audio/@audiorecorder/play.m, scripts/audio/@audiorecorder/record.m, scripts/audio/@audiorecorder/recordblocking.m, scripts/audio/@audiorecorder/resume.m, scripts/audio/@audiorecorder/set.m, scripts/audio/@audiorecorder/stop.m, scripts/audio/@audiorecorder/subsasgn.m, scripts/audio/@audiorecorder/subsref.m, scripts/audio/lin2mu.m, scripts/audio/mu2lin.m, scripts/audio/record.m, scripts/audio/sound.m, scripts/audio/soundsc.m, scripts/deprecated/bitmax.m, scripts/deprecated/comma.m, scripts/deprecated/isstr.m, scripts/deprecated/mahalanobis.m, scripts/deprecated/md5sum.m, scripts/deprecated/octave_config_info.m, scripts/deprecated/onenormest.m, scripts/deprecated/paren.m, scripts/deprecated/semicolon.m, scripts/deprecated/sleep.m, scripts/deprecated/usleep.m, scripts/deprecated/wavread.m, scripts/deprecated/wavwrite.m, scripts/elfun/acosd.m, scripts/elfun/acot.m, scripts/elfun/acotd.m, scripts/elfun/acoth.m, scripts/elfun/acsc.m, scripts/elfun/acscd.m, scripts/elfun/acsch.m, scripts/elfun/asec.m, scripts/elfun/asecd.m, scripts/elfun/asech.m, scripts/elfun/asind.m, scripts/elfun/atan2d.m, scripts/elfun/atand.m, scripts/elfun/cosd.m, scripts/elfun/cot.m, scripts/elfun/cotd.m, scripts/elfun/coth.m, scripts/elfun/csc.m, scripts/elfun/cscd.m, scripts/elfun/csch.m, scripts/elfun/sec.m, scripts/elfun/secd.m, scripts/elfun/sech.m, scripts/elfun/sind.m, scripts/elfun/tand.m, scripts/general/accumarray.m, scripts/general/accumdim.m, scripts/general/bincoeff.m, scripts/general/bitcmp.m, scripts/general/bitget.m, scripts/general/bitset.m, scripts/general/blkdiag.m, scripts/general/cart2pol.m, scripts/general/cart2sph.m, scripts/general/cell2mat.m, scripts/general/celldisp.m, scripts/general/chop.m, scripts/general/circshift.m, scripts/general/common_size.m, scripts/general/cplxpair.m, scripts/general/cumtrapz.m, scripts/general/curl.m, scripts/general/dblquad.m, scripts/general/deal.m, scripts/general/deg2rad.m, scripts/general/del2.m, scripts/general/display.m, scripts/general/divergence.m, scripts/general/fieldnames.m, scripts/general/flip.m, scripts/general/flipdim.m, scripts/general/fliplr.m, scripts/general/flipud.m, scripts/general/grabcode.m, scripts/general/gradient.m, scripts/general/idivide.m, scripts/general/inputParser.m, scripts/general/int2str.m, scripts/general/interp1.m, scripts/general/interp2.m, scripts/general/interp3.m, scripts/general/interpft.m, scripts/general/interpn.m, scripts/general/isdir.m, scripts/general/isequal.m, scripts/general/isequaln.m, scripts/general/loadobj.m, scripts/general/logspace.m, scripts/general/methods.m, scripts/general/nargchk.m, scripts/general/narginchk.m, scripts/general/nargoutchk.m, scripts/general/nextpow2.m, scripts/general/nthargout.m, scripts/general/num2str.m, scripts/general/pol2cart.m, scripts/general/polyarea.m, scripts/general/postpad.m, scripts/general/prepad.m, scripts/general/private/__isequal__.m, scripts/general/private/__splinen__.m, scripts/general/publish.m, scripts/general/quadgk.m, scripts/general/quadl.m, scripts/general/quadv.m, scripts/general/rad2deg.m, scripts/general/randi.m, scripts/general/rat.m, scripts/general/repmat.m, scripts/general/rot90.m, scripts/general/rotdim.m, scripts/general/saveobj.m, scripts/general/shift.m, scripts/general/shiftdim.m, scripts/general/sortrows.m, scripts/general/sph2cart.m, scripts/general/structfun.m, scripts/general/subsindex.m, scripts/general/trapz.m, scripts/general/triplequad.m, scripts/general/validateattributes.m, scripts/geometry/convhull.m, scripts/geometry/delaunay.m, scripts/geometry/delaunayn.m, scripts/geometry/dsearch.m, scripts/geometry/dsearchn.m, scripts/geometry/griddata.m, scripts/geometry/griddata3.m, scripts/geometry/griddatan.m, scripts/geometry/inpolygon.m, scripts/geometry/rectint.m, scripts/geometry/tsearchn.m, scripts/geometry/voronoi.m, scripts/geometry/voronoin.m, scripts/gui/dialog.m, scripts/gui/errordlg.m, scripts/gui/guidata.m, scripts/gui/guihandles.m, scripts/gui/helpdlg.m, scripts/gui/inputdlg.m, scripts/gui/listdlg.m, scripts/gui/msgbox.m, scripts/gui/private/__file_filter__.m, scripts/gui/private/__fltk_file_filter__.m, scripts/gui/private/__get_funcname__.m, scripts/gui/private/__is_function__.m, scripts/gui/private/__uigetdir_fltk__.m, scripts/gui/private/__uigetfile_fltk__.m, scripts/gui/private/__uiobject_split_args__.m, scripts/gui/private/__uiputfile_fltk__.m, scripts/gui/questdlg.m, scripts/gui/uibuttongroup.m, scripts/gui/uicontextmenu.m, scripts/gui/uicontrol.m, scripts/gui/uigetdir.m, scripts/gui/uigetfile.m, scripts/gui/uimenu.m, scripts/gui/uipanel.m, scripts/gui/uipushtool.m, scripts/gui/uiputfile.m, scripts/gui/uiresume.m, scripts/gui/uitoggletool.m, scripts/gui/uitoolbar.m, scripts/gui/uiwait.m, scripts/gui/waitbar.m, scripts/gui/waitforbuttonpress.m, scripts/gui/warndlg.m, scripts/help/__gripe_missing_component__.m, scripts/help/__makeinfo__.m, scripts/help/__unimplemented__.m, scripts/help/ans.m, scripts/help/doc.m, scripts/help/doc_cache_create.m, scripts/help/error_ids.m, scripts/help/get_first_help_sentence.m, scripts/help/help.m, scripts/help/lookfor.m, scripts/help/print_usage.m, scripts/help/private/__additional_help_message__.m, scripts/help/private/__strip_html_tags__.m, scripts/help/type.m, scripts/help/warning_ids.m, scripts/help/which.m, scripts/image/autumn.m, scripts/image/bone.m, scripts/image/brighten.m, scripts/image/cmpermute.m, scripts/image/cmunique.m, scripts/image/colorcube.m, scripts/image/colormap.m, scripts/image/contrast.m, scripts/image/cool.m, scripts/image/copper.m, scripts/image/cubehelix.m, scripts/image/flag.m, scripts/image/gray.m, scripts/image/gray2ind.m, scripts/image/hot.m, scripts/image/hsv.m, scripts/image/hsv2rgb.m, scripts/image/im2double.m, scripts/image/image.m, scripts/image/imagesc.m, scripts/image/imfinfo.m, scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imshow.m, scripts/image/imwrite.m, scripts/image/ind2gray.m, scripts/image/ind2rgb.m, scripts/image/iscolormap.m, scripts/image/jet.m, scripts/image/lines.m, scripts/image/ntsc2rgb.m, scripts/image/ocean.m, scripts/image/pink.m, scripts/image/prism.m, scripts/image/private/__imfinfo__.m, scripts/image/private/__imread__.m, scripts/image/private/__imwrite__.m, scripts/image/private/colorspace_conversion_input_check.m, scripts/image/private/colorspace_conversion_revert.m, scripts/image/private/imageIO.m, scripts/image/private/imwrite_filename.m, scripts/image/private/ind2x.m, scripts/image/rainbow.m, scripts/image/rgb2hsv.m, scripts/image/rgb2ind.m, scripts/image/rgb2ntsc.m, scripts/image/rgbplot.m, scripts/image/spinmap.m, scripts/image/spring.m, scripts/image/summer.m, scripts/image/viridis.m, scripts/image/white.m, scripts/image/winter.m, scripts/io/beep.m, scripts/io/csvread.m, scripts/io/csvwrite.m, scripts/io/dlmwrite.m, scripts/io/fileread.m, scripts/io/importdata.m, scripts/io/is_valid_file_id.m, scripts/io/strread.m, scripts/io/textread.m, scripts/java/javaArray.m, scripts/java/java_get.m, scripts/java/java_set.m, scripts/java/javaaddpath.m, scripts/java/javachk.m, scripts/java/javaclasspath.m, scripts/java/javamem.m, scripts/java/javarmpath.m, scripts/java/org/octave/ClassHelper.java, scripts/java/org/octave/Matrix.java, scripts/java/org/octave/OctClassLoader.java, scripts/java/org/octave/Octave.java, scripts/java/org/octave/OctaveReference.java, scripts/java/usejava.m, scripts/linear-algebra/bandwidth.m, scripts/linear-algebra/commutation_matrix.m, scripts/linear-algebra/cond.m, scripts/linear-algebra/condeig.m, scripts/linear-algebra/condest.m, scripts/linear-algebra/cross.m, scripts/linear-algebra/duplication_matrix.m, scripts/linear-algebra/expm.m, scripts/linear-algebra/housh.m, scripts/linear-algebra/isbanded.m, scripts/linear-algebra/isdefinite.m, scripts/linear-algebra/isdiag.m, scripts/linear-algebra/ishermitian.m, scripts/linear-algebra/issymmetric.m, scripts/linear-algebra/istril.m, scripts/linear-algebra/istriu.m, scripts/linear-algebra/krylov.m, scripts/linear-algebra/linsolve.m, scripts/linear-algebra/logm.m, scripts/linear-algebra/normest.m, scripts/linear-algebra/normest1.m, scripts/linear-algebra/null.m, scripts/linear-algebra/orth.m, scripts/linear-algebra/planerot.m, scripts/linear-algebra/qzhess.m, scripts/linear-algebra/rank.m, scripts/linear-algebra/rref.m, scripts/linear-algebra/subspace.m, scripts/linear-algebra/trace.m, scripts/linear-algebra/vech.m, scripts/miscellaneous/bug_report.m, scripts/miscellaneous/bunzip2.m, scripts/miscellaneous/cast.m, scripts/miscellaneous/citation.m, scripts/miscellaneous/compare_versions.m, scripts/miscellaneous/computer.m, scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m, scripts/miscellaneous/delete.m, scripts/miscellaneous/desktop.m, scripts/miscellaneous/dir.m, scripts/miscellaneous/dos.m, scripts/miscellaneous/edit.m, scripts/miscellaneous/fact.m, scripts/miscellaneous/fileattrib.m, scripts/miscellaneous/fileparts.m, scripts/miscellaneous/fullfile.m, scripts/miscellaneous/genvarname.m, scripts/miscellaneous/getappdata.m, scripts/miscellaneous/getfield.m, scripts/miscellaneous/gunzip.m, scripts/miscellaneous/info.m, scripts/miscellaneous/inputname.m, scripts/miscellaneous/isappdata.m, scripts/miscellaneous/isdeployed.m, scripts/miscellaneous/ismac.m, scripts/miscellaneous/ispc.m, scripts/miscellaneous/isunix.m, scripts/miscellaneous/license.m, scripts/miscellaneous/list_primes.m, scripts/miscellaneous/ls.m, scripts/miscellaneous/ls_command.m, scripts/miscellaneous/menu.m, scripts/miscellaneous/mex.m, scripts/miscellaneous/mexext.m, scripts/miscellaneous/mkdir.m, scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m, scripts/miscellaneous/namelengthmax.m, scripts/miscellaneous/news.m, scripts/miscellaneous/open.m, scripts/miscellaneous/orderfields.m, scripts/miscellaneous/pack.m, scripts/miscellaneous/parseparams.m, scripts/miscellaneous/perl.m, scripts/miscellaneous/private/__w2mpth__.m, scripts/miscellaneous/private/display_info_file.m, scripts/miscellaneous/python.m, scripts/miscellaneous/recycle.m, scripts/miscellaneous/rmappdata.m, scripts/miscellaneous/run.m, scripts/miscellaneous/setappdata.m, scripts/miscellaneous/setfield.m, scripts/miscellaneous/substruct.m, scripts/miscellaneous/swapbytes.m, scripts/miscellaneous/symvar.m, scripts/miscellaneous/tar.m, scripts/miscellaneous/tempdir.m, scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unix.m, scripts/miscellaneous/unpack.m, scripts/miscellaneous/untar.m, scripts/miscellaneous/unzip.m, scripts/miscellaneous/ver.m, scripts/miscellaneous/version.m, scripts/miscellaneous/what.m, scripts/miscellaneous/xor.m, scripts/miscellaneous/zip.m, scripts/mk-pkg-add, scripts/mkdoc.pl, scripts/ode/ode23.m, scripts/ode/ode45.m, scripts/ode/odeget.m, scripts/ode/odeplot.m, scripts/ode/odeset.m, scripts/ode/private/AbsRel_norm.m, scripts/ode/private/integrate_adaptive.m, scripts/ode/private/kahan.m, scripts/ode/private/ode_event_handler.m, scripts/ode/private/odedefaults.m, scripts/ode/private/odemergeopts.m, scripts/ode/private/runge_kutta_23.m, scripts/ode/private/runge_kutta_45_dorpri.m, scripts/ode/private/runge_kutta_interpolate.m, scripts/ode/private/starting_stepsize.m, scripts/optimization/__all_opts__.m, scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m, scripts/optimization/fminunc.m, scripts/optimization/fsolve.m, scripts/optimization/fzero.m, scripts/optimization/glpk.m, scripts/optimization/lsqnonneg.m, scripts/optimization/optimget.m, scripts/optimization/optimset.m, scripts/optimization/pqpnonneg.m, scripts/optimization/private/__fdjac__.m, scripts/optimization/qp.m, scripts/optimization/sqp.m, scripts/path/matlabroot.m, scripts/path/pathdef.m, scripts/path/private/getsavepath.m, scripts/path/savepath.m, scripts/pkg/pkg.m, scripts/pkg/private/build.m, scripts/pkg/private/configure_make.m, scripts/pkg/private/default_prefix.m, scripts/pkg/private/describe.m, scripts/pkg/private/dirempty.m, scripts/pkg/private/get_description.m, scripts/pkg/private/get_forge_download.m, scripts/pkg/private/get_forge_pkg.m, scripts/pkg/private/get_unsatisfied_deps.m, scripts/pkg/private/getarch.m, scripts/pkg/private/getarchdir.m, scripts/pkg/private/install.m, scripts/pkg/private/installed_packages.m, scripts/pkg/private/list_forge_packages.m, scripts/pkg/private/load_packages.m, scripts/pkg/private/load_packages_and_dependencies.m, scripts/pkg/private/rebuild.m, scripts/pkg/private/save_order.m, scripts/pkg/private/uninstall.m, scripts/pkg/private/unload_packages.m, scripts/plot/appearance/__clabel__.m, scripts/plot/appearance/__getlegenddata__.m, scripts/plot/appearance/annotation.m, scripts/plot/appearance/axis.m, scripts/plot/appearance/box.m, scripts/plot/appearance/caxis.m, scripts/plot/appearance/clabel.m, scripts/plot/appearance/daspect.m, scripts/plot/appearance/datetick.m, scripts/plot/appearance/diffuse.m, scripts/plot/appearance/grid.m, scripts/plot/appearance/gtext.m, scripts/plot/appearance/hidden.m, scripts/plot/appearance/legend.m, scripts/plot/appearance/lighting.m, scripts/plot/appearance/material.m, scripts/plot/appearance/orient.m, scripts/plot/appearance/pbaspect.m, scripts/plot/appearance/private/__axis_label__.m, scripts/plot/appearance/private/__axis_limits__.m, scripts/plot/appearance/shading.m, scripts/plot/appearance/specular.m, scripts/plot/appearance/text.m, scripts/plot/appearance/title.m, scripts/plot/appearance/view.m, scripts/plot/appearance/whitebg.m, scripts/plot/appearance/xlabel.m, scripts/plot/appearance/xlim.m, scripts/plot/appearance/ylabel.m, scripts/plot/appearance/ylim.m, scripts/plot/appearance/zlabel.m, scripts/plot/appearance/zlim.m, scripts/plot/draw/area.m, scripts/plot/draw/bar.m, scripts/plot/draw/barh.m, scripts/plot/draw/camlight.m, scripts/plot/draw/colorbar.m, scripts/plot/draw/comet.m, scripts/plot/draw/comet3.m, scripts/plot/draw/compass.m, scripts/plot/draw/contour.m, scripts/plot/draw/contour3.m, scripts/plot/draw/contourc.m, scripts/plot/draw/contourf.m, scripts/plot/draw/cylinder.m, scripts/plot/draw/ellipsoid.m, scripts/plot/draw/errorbar.m, scripts/plot/draw/ezcontour.m, scripts/plot/draw/ezcontourf.m, scripts/plot/draw/ezmesh.m, scripts/plot/draw/ezmeshc.m, scripts/plot/draw/ezplot.m, scripts/plot/draw/ezplot3.m, scripts/plot/draw/ezpolar.m, scripts/plot/draw/ezsurf.m, scripts/plot/draw/ezsurfc.m, scripts/plot/draw/feather.m, scripts/plot/draw/fill.m, scripts/plot/draw/fplot.m, scripts/plot/draw/hist.m, scripts/plot/draw/isocaps.m, scripts/plot/draw/isocolors.m, scripts/plot/draw/isonormals.m, scripts/plot/draw/isosurface.m, scripts/plot/draw/light.m, scripts/plot/draw/line.m, scripts/plot/draw/loglog.m, scripts/plot/draw/loglogerr.m, scripts/plot/draw/mesh.m, scripts/plot/draw/meshc.m, scripts/plot/draw/meshz.m, scripts/plot/draw/pareto.m, scripts/plot/draw/patch.m, scripts/plot/draw/pcolor.m, scripts/plot/draw/peaks.m, scripts/plot/draw/pie.m, scripts/plot/draw/pie3.m, scripts/plot/draw/plot.m, scripts/plot/draw/plot3.m, scripts/plot/draw/plotmatrix.m, scripts/plot/draw/plotyy.m, scripts/plot/draw/polar.m, scripts/plot/draw/private/__add_datasource__.m, scripts/plot/draw/private/__bar__.m, scripts/plot/draw/private/__calc_isovalue_from_data__.m, scripts/plot/draw/private/__contour__.m, scripts/plot/draw/private/__errplot__.m, scripts/plot/draw/private/__ezplot__.m, scripts/plot/draw/private/__interp_cube__.m, scripts/plot/draw/private/__line__.m, scripts/plot/draw/private/__marching_cube__.m, scripts/plot/draw/private/__patch__.m, scripts/plot/draw/private/__pie__.m, scripts/plot/draw/private/__plt__.m, scripts/plot/draw/private/__quiver__.m, scripts/plot/draw/private/__rotate_around_axis__.m, scripts/plot/draw/private/__scatter__.m, scripts/plot/draw/private/__stem__.m, scripts/plot/draw/private/__unite_shared_vertices__.m, scripts/plot/draw/quiver.m, scripts/plot/draw/quiver3.m, scripts/plot/draw/rectangle.m, scripts/plot/draw/reducepatch.m, scripts/plot/draw/reducevolume.m, scripts/plot/draw/ribbon.m, scripts/plot/draw/rose.m, scripts/plot/draw/scatter.m, scripts/plot/draw/scatter3.m, scripts/plot/draw/semilogx.m, scripts/plot/draw/semilogxerr.m, scripts/plot/draw/semilogy.m, scripts/plot/draw/semilogyerr.m, scripts/plot/draw/shrinkfaces.m, scripts/plot/draw/slice.m, scripts/plot/draw/smooth3.m, scripts/plot/draw/sombrero.m, scripts/plot/draw/sphere.m, scripts/plot/draw/stairs.m, scripts/plot/draw/stem.m, scripts/plot/draw/stem3.m, scripts/plot/draw/stemleaf.m, scripts/plot/draw/surf.m, scripts/plot/draw/surface.m, scripts/plot/draw/surfc.m, scripts/plot/draw/surfl.m, scripts/plot/draw/surfnorm.m, scripts/plot/draw/tetramesh.m, scripts/plot/draw/trimesh.m, scripts/plot/draw/triplot.m, scripts/plot/draw/trisurf.m, scripts/plot/draw/waterfall.m, scripts/plot/util/__actual_axis_position__.m, scripts/plot/util/__default_plot_options__.m, scripts/plot/util/__gnuplot_drawnow__.m, scripts/plot/util/__next_line_color__.m, scripts/plot/util/__next_line_style__.m, scripts/plot/util/__opengl_info__.m, scripts/plot/util/__plt_get_axis_arg__.m, scripts/plot/util/__pltopt__.m, scripts/plot/util/allchild.m, scripts/plot/util/ancestor.m, scripts/plot/util/axes.m, scripts/plot/util/cla.m, scripts/plot/util/clf.m, scripts/plot/util/close.m, scripts/plot/util/closereq.m, scripts/plot/util/colstyle.m, scripts/plot/util/copyobj.m, scripts/plot/util/figure.m, scripts/plot/util/findall.m, scripts/plot/util/findfigs.m, scripts/plot/util/findobj.m, scripts/plot/util/frame2im.m, scripts/plot/util/gca.m, scripts/plot/util/gcbf.m, scripts/plot/util/gcbo.m, scripts/plot/util/gcf.m, scripts/plot/util/gco.m, scripts/plot/util/ginput.m, scripts/plot/util/gnuplot_binary.in.m, scripts/plot/util/graphics_toolkit.m, scripts/plot/util/hdl2struct.m, scripts/plot/util/hggroup.m, scripts/plot/util/hgload.m, scripts/plot/util/hgsave.m, scripts/plot/util/hold.m, scripts/plot/util/im2frame.m, scripts/plot/util/isaxes.m, scripts/plot/util/isfigure.m, scripts/plot/util/ishghandle.m, scripts/plot/util/ishold.m, scripts/plot/util/isprop.m, scripts/plot/util/linkaxes.m, scripts/plot/util/linkprop.m, scripts/plot/util/meshgrid.m, scripts/plot/util/ndgrid.m, scripts/plot/util/newplot.m, scripts/plot/util/pan.m, scripts/plot/util/print.m, scripts/plot/util/printd.m, scripts/plot/util/private/__add_default_menu__.m, scripts/plot/util/private/__ghostscript__.m, scripts/plot/util/private/__gnuplot_draw_axes__.m, scripts/plot/util/private/__gnuplot_draw_figure__.m, scripts/plot/util/private/__gnuplot_get_var__.m, scripts/plot/util/private/__gnuplot_ginput__.m, scripts/plot/util/private/__gnuplot_has_feature__.m, scripts/plot/util/private/__gnuplot_has_terminal__.m, scripts/plot/util/private/__gnuplot_open_stream__.m, scripts/plot/util/private/__gnuplot_print__.m, scripts/plot/util/private/__gnuplot_version__.m, scripts/plot/util/private/__opengl_print__.m, scripts/plot/util/private/__print_parse_opts__.m, scripts/plot/util/refresh.m, scripts/plot/util/refreshdata.m, scripts/plot/util/rotate.m, scripts/plot/util/rotate3d.m, scripts/plot/util/saveas.m, scripts/plot/util/shg.m, scripts/plot/util/struct2hdl.m, scripts/plot/util/subplot.m, scripts/plot/util/zoom.m, scripts/polynomial/compan.m, scripts/polynomial/conv.m, scripts/polynomial/deconv.m, scripts/polynomial/mkpp.m, scripts/polynomial/mpoles.m, scripts/polynomial/padecoef.m, scripts/polynomial/pchip.m, scripts/polynomial/poly.m, scripts/polynomial/polyaffine.m, scripts/polynomial/polyder.m, scripts/polynomial/polyeig.m, scripts/polynomial/polyfit.m, scripts/polynomial/polygcd.m, scripts/polynomial/polyint.m, scripts/polynomial/polyout.m, scripts/polynomial/polyreduce.m, scripts/polynomial/polyval.m, scripts/polynomial/polyvalm.m, scripts/polynomial/ppder.m, scripts/polynomial/ppint.m, scripts/polynomial/ppjumps.m, scripts/polynomial/ppval.m, scripts/polynomial/residue.m, scripts/polynomial/roots.m, scripts/polynomial/spline.m, scripts/polynomial/splinefit.m, scripts/polynomial/unmkpp.m, scripts/prefs/addpref.m, scripts/prefs/getpref.m, scripts/prefs/ispref.m, scripts/prefs/prefdir.m, scripts/prefs/preferences.m, scripts/prefs/private/loadprefs.m, scripts/prefs/private/prefsfile.m, scripts/prefs/private/saveprefs.m, scripts/prefs/rmpref.m, scripts/prefs/setpref.m, scripts/profiler/html/style.css, scripts/profiler/profexplore.m, scripts/profiler/profexport.m, scripts/profiler/profile.m, scripts/profiler/profshow.m, scripts/set/intersect.m, scripts/set/ismember.m, scripts/set/powerset.m, scripts/set/private/validsetargs.m, scripts/set/setdiff.m, scripts/set/setxor.m, scripts/set/union.m, scripts/set/unique.m, scripts/signal/arch_fit.m, scripts/signal/arch_rnd.m, scripts/signal/arch_test.m, scripts/signal/arma_rnd.m, scripts/signal/autoreg_matrix.m, scripts/signal/bartlett.m, scripts/signal/blackman.m, scripts/signal/detrend.m, scripts/signal/diffpara.m, scripts/signal/durbinlevinson.m, scripts/signal/fftconv.m, scripts/signal/fftfilt.m, scripts/signal/fftshift.m, scripts/signal/filter2.m, scripts/signal/fractdiff.m, scripts/signal/freqz.m, scripts/signal/freqz_plot.m, scripts/signal/hamming.m, scripts/signal/hanning.m, scripts/signal/hurst.m, scripts/signal/ifftshift.m, scripts/signal/periodogram.m, scripts/signal/private/rectangle_lw.m, scripts/signal/private/rectangle_sw.m, scripts/signal/private/triangle_lw.m, scripts/signal/private/triangle_sw.m, scripts/signal/sinc.m, scripts/signal/sinetone.m, scripts/signal/sinewave.m, scripts/signal/spectral_adf.m, scripts/signal/spectral_xdf.m, scripts/signal/spencer.m, scripts/signal/stft.m, scripts/signal/synthesis.m, scripts/signal/unwrap.m, scripts/signal/yulewalker.m, scripts/sparse/bicg.m, scripts/sparse/bicgstab.m, scripts/sparse/cgs.m, scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m, scripts/sparse/gmres.m, scripts/sparse/gplot.m, scripts/sparse/ichol.m, scripts/sparse/ilu.m, scripts/sparse/nonzeros.m, scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/sparse/private/__sprand__.m, scripts/sparse/qmr.m, scripts/sparse/spaugment.m, scripts/sparse/spconvert.m, scripts/sparse/spdiags.m, scripts/sparse/speye.m, scripts/sparse/spfun.m, scripts/sparse/spones.m, scripts/sparse/sprand.m, scripts/sparse/sprandn.m, scripts/sparse/sprandsym.m, scripts/sparse/spstats.m, scripts/sparse/spy.m, scripts/sparse/svds.m, scripts/sparse/treelayout.m, scripts/sparse/treeplot.m, scripts/specfun/bessel.m, scripts/specfun/beta.m, scripts/specfun/betaln.m, scripts/specfun/ellipke.m, scripts/specfun/expint.m, scripts/specfun/factor.m, scripts/specfun/factorial.m, scripts/specfun/isprime.m, scripts/specfun/lcm.m, scripts/specfun/legendre.m, scripts/specfun/nchoosek.m, scripts/specfun/nthroot.m, scripts/specfun/perms.m, scripts/specfun/pow2.m, scripts/specfun/primes.m, scripts/specfun/reallog.m, scripts/specfun/realpow.m, scripts/specfun/realsqrt.m, scripts/special-matrix/gallery.m, scripts/special-matrix/hadamard.m, scripts/special-matrix/hankel.m, scripts/special-matrix/hilb.m, scripts/special-matrix/invhilb.m, scripts/special-matrix/magic.m, scripts/special-matrix/pascal.m, scripts/special-matrix/rosser.m, scripts/special-matrix/toeplitz.m, scripts/special-matrix/vander.m, scripts/special-matrix/wilkinson.m, scripts/startup/__finish__.m, scripts/statistics/base/center.m, scripts/statistics/base/cloglog.m, scripts/statistics/base/corr.m, scripts/statistics/base/cov.m, scripts/statistics/base/gls.m, scripts/statistics/base/histc.m, scripts/statistics/base/iqr.m, scripts/statistics/base/kendall.m, scripts/statistics/base/kurtosis.m, scripts/statistics/base/logit.m, scripts/statistics/base/lscov.m, scripts/statistics/base/mean.m, scripts/statistics/base/meansq.m, scripts/statistics/base/median.m, scripts/statistics/base/mode.m, scripts/statistics/base/moment.m, scripts/statistics/base/ols.m, scripts/statistics/base/ppplot.m, scripts/statistics/base/prctile.m, scripts/statistics/base/probit.m, scripts/statistics/base/qqplot.m, scripts/statistics/base/quantile.m, scripts/statistics/base/range.m, scripts/statistics/base/ranks.m, scripts/statistics/base/run_count.m, scripts/statistics/base/runlength.m, scripts/statistics/base/skewness.m, scripts/statistics/base/spearman.m, scripts/statistics/base/statistics.m, scripts/statistics/base/std.m, scripts/statistics/base/table.m, scripts/statistics/base/var.m, scripts/statistics/base/zscore.m, scripts/statistics/distributions/betacdf.m, scripts/statistics/distributions/betainv.m, scripts/statistics/distributions/betapdf.m, scripts/statistics/distributions/betarnd.m, scripts/statistics/distributions/binocdf.m, scripts/statistics/distributions/binoinv.m, scripts/statistics/distributions/binopdf.m, scripts/statistics/distributions/binornd.m, scripts/statistics/distributions/cauchy_cdf.m, scripts/statistics/distributions/cauchy_inv.m, scripts/statistics/distributions/cauchy_pdf.m, scripts/statistics/distributions/cauchy_rnd.m, scripts/statistics/distributions/chi2cdf.m, scripts/statistics/distributions/chi2inv.m, scripts/statistics/distributions/chi2pdf.m, scripts/statistics/distributions/chi2rnd.m, scripts/statistics/distributions/discrete_cdf.m, scripts/statistics/distributions/discrete_inv.m, scripts/statistics/distributions/discrete_pdf.m, scripts/statistics/distributions/discrete_rnd.m, scripts/statistics/distributions/empirical_cdf.m, scripts/statistics/distributions/empirical_inv.m, scripts/statistics/distributions/empirical_pdf.m, scripts/statistics/distributions/empirical_rnd.m, scripts/statistics/distributions/expcdf.m, scripts/statistics/distributions/expinv.m, scripts/statistics/distributions/exppdf.m, scripts/statistics/distributions/exprnd.m, scripts/statistics/distributions/fcdf.m, scripts/statistics/distributions/finv.m, scripts/statistics/distributions/fpdf.m, scripts/statistics/distributions/frnd.m, scripts/statistics/distributions/gamcdf.m, scripts/statistics/distributions/gaminv.m, scripts/statistics/distributions/gampdf.m, scripts/statistics/distributions/gamrnd.m, scripts/statistics/distributions/geocdf.m, scripts/statistics/distributions/geoinv.m, scripts/statistics/distributions/geopdf.m, scripts/statistics/distributions/geornd.m, scripts/statistics/distributions/hygecdf.m, scripts/statistics/distributions/hygeinv.m, scripts/statistics/distributions/hygepdf.m, scripts/statistics/distributions/hygernd.m, scripts/statistics/distributions/kolmogorov_smirnov_cdf.m, scripts/statistics/distributions/laplace_cdf.m, scripts/statistics/distributions/laplace_inv.m, scripts/statistics/distributions/laplace_pdf.m, scripts/statistics/distributions/laplace_rnd.m, scripts/statistics/distributions/logistic_cdf.m, scripts/statistics/distributions/logistic_inv.m, scripts/statistics/distributions/logistic_pdf.m, scripts/statistics/distributions/logistic_rnd.m, scripts/statistics/distributions/logncdf.m, scripts/statistics/distributions/logninv.m, scripts/statistics/distributions/lognpdf.m, scripts/statistics/distributions/lognrnd.m, scripts/statistics/distributions/nbincdf.m, scripts/statistics/distributions/nbininv.m, scripts/statistics/distributions/nbinpdf.m, scripts/statistics/distributions/nbinrnd.m, scripts/statistics/distributions/normcdf.m, scripts/statistics/distributions/norminv.m, scripts/statistics/distributions/normpdf.m, scripts/statistics/distributions/normrnd.m, scripts/statistics/distributions/poisscdf.m, scripts/statistics/distributions/poissinv.m, scripts/statistics/distributions/poisspdf.m, scripts/statistics/distributions/poissrnd.m, scripts/statistics/distributions/stdnormal_cdf.m, scripts/statistics/distributions/stdnormal_inv.m, scripts/statistics/distributions/stdnormal_pdf.m, scripts/statistics/distributions/stdnormal_rnd.m, scripts/statistics/distributions/tcdf.m, scripts/statistics/distributions/tinv.m, scripts/statistics/distributions/tpdf.m, scripts/statistics/distributions/trnd.m, scripts/statistics/distributions/unidcdf.m, scripts/statistics/distributions/unidinv.m, scripts/statistics/distributions/unidpdf.m, scripts/statistics/distributions/unidrnd.m, scripts/statistics/distributions/unifcdf.m, scripts/statistics/distributions/unifinv.m, scripts/statistics/distributions/unifpdf.m, scripts/statistics/distributions/unifrnd.m, scripts/statistics/distributions/wblcdf.m, scripts/statistics/distributions/wblinv.m, scripts/statistics/distributions/wblpdf.m, scripts/statistics/distributions/wblrnd.m, scripts/statistics/distributions/wienrnd.m, scripts/statistics/models/logistic_regression.m, scripts/statistics/models/private/logistic_regression_derivatives.m, scripts/statistics/models/private/logistic_regression_likelihood.m, scripts/statistics/tests/anova.m, scripts/statistics/tests/bartlett_test.m, scripts/statistics/tests/chisquare_test_homogeneity.m, scripts/statistics/tests/chisquare_test_independence.m, scripts/statistics/tests/cor_test.m, scripts/statistics/tests/f_test_regression.m, scripts/statistics/tests/hotelling_test.m, scripts/statistics/tests/hotelling_test_2.m, scripts/statistics/tests/kolmogorov_smirnov_test.m, scripts/statistics/tests/kolmogorov_smirnov_test_2.m, scripts/statistics/tests/kruskal_wallis_test.m, scripts/statistics/tests/manova.m, scripts/statistics/tests/mcnemar_test.m, scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/run_test.m, scripts/statistics/tests/sign_test.m, scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m, scripts/statistics/tests/t_test_regression.m, scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m, scripts/statistics/tests/welch_test.m, scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m, scripts/statistics/tests/z_test_2.m, scripts/strings/base2dec.m, scripts/strings/bin2dec.m, scripts/strings/blanks.m, scripts/strings/cstrcat.m, scripts/strings/deblank.m, scripts/strings/dec2base.m, scripts/strings/dec2bin.m, scripts/strings/dec2hex.m, scripts/strings/findstr.m, scripts/strings/hex2dec.m, scripts/strings/index.m, scripts/strings/isletter.m, scripts/strings/isstrprop.m, scripts/strings/mat2str.m, scripts/strings/ostrsplit.m, scripts/strings/regexptranslate.m, scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m, scripts/strings/strchr.m, scripts/strings/strjoin.m, scripts/strings/strjust.m, scripts/strings/strmatch.m, scripts/strings/strsplit.m, scripts/strings/strtok.m, scripts/strings/strtrim.m, scripts/strings/strtrunc.m, scripts/strings/substr.m, scripts/strings/untabify.m, scripts/strings/validatestring.m, scripts/testfun/__have_feature__.m, scripts/testfun/__printf_assert__.m, scripts/testfun/__prog_output_assert__.m, scripts/testfun/__run_test_suite__.m, scripts/testfun/assert.m, scripts/testfun/demo.m, scripts/testfun/example.m, scripts/testfun/fail.m, scripts/testfun/private/compare_plot_demos.m, scripts/testfun/private/dump_demos.m, scripts/testfun/private/html_compare_plot_demos.m, scripts/testfun/rundemos.m, scripts/testfun/runtests.m, scripts/testfun/speed.m, scripts/testfun/test.m, scripts/time/addtodate.m, scripts/time/asctime.m, scripts/time/calendar.m, scripts/time/clock.m, scripts/time/ctime.m, scripts/time/date.m, scripts/time/datenum.m, scripts/time/datestr.m, scripts/time/datevec.m, scripts/time/eomday.m, scripts/time/etime.m, scripts/time/is_leap_year.m, scripts/time/now.m, scripts/time/weekday.m, src/display-available.c, src/display-available.h, src/main-cli.cc, src/main-gui.cc, src/main.in.cc, src/mkoctfile.in.cc, src/octave-build-info.h, src/octave-build-info.in.cc, src/octave-config.in.cc, src/shared-fcns.h, test/args.tst, test/classdef/classdef.tst, test/classes/classes.tst, test/colormaps.tst, test/complex.tst, test/ctor-vs-method/ctor-vs-method.tst, test/diag-perm.tst, test/error.tst, test/eval-catch.tst, test/fcn-handle-derived-resolution/fcn-handle-derived-resolution.tst, test/fntests.m, test/for.tst, test/func.tst, test/global.tst, test/if.tst, test/index.tst, test/io.tst, test/jit.tst, test/line-continue.tst, test/logical-index.tst, test/nest/nest.tst, test/null-assign.tst, test/parser.tst, test/prefer.tst, test/range.tst, test/recursion.tst, test/return.tst, test/slice.tst, test/struct.tst, test/switch.tst, test/system.tst, test/transpose.tst, test/try.tst, test/unwind.tst, test/while.tst: Use the same Copyright formatting throughout Octave.
author Rik <rik@octave.org>
date Sun, 13 Nov 2016 20:33:47 -0800
parents dd80fb1ef949
children ef4d915df748
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1 // Template sparse array class
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2 /*
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3
22323
bac0d6f07a3e maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
4 Copyright (C) 2004-2016 David Bateman
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11508
diff changeset
5 Copyright (C) 1998-2004 Andy Adler
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10520
diff changeset
6 Copyright (C) 2010 VZLU Prague
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6988
diff changeset
7
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6988
diff changeset
8 This file is part of Octave.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
9
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
10 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
11 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
12 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
13 (at your option) any later version.
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
14
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
15 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
16 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22600
diff changeset
18 GNU General Public License for more details.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
19
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6988
diff changeset
21 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6988
diff changeset
22 <http://www.gnu.org/licenses/>.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
23
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
24 */
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
25
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
29
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
30 #include <cassert>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
31
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
32 #include <algorithm>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
33 #include <iostream>
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
34 #include <limits>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
35 #include <sstream>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
36 #include <vector>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
37
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
38 #include "Array.h"
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
39 #include "MArray.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
40 #include "Array-util.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41 #include "Range.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
42 #include "idx-vector.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
43 #include "lo-error.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
44 #include "quit.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
45 #include "oct-locbuf.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
47 #include "Sparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
48 #include "sparse-sort.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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
55 template <typename T>
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21256
diff changeset
56 typename Sparse<T>::SparseRep *
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21256
diff changeset
57 Sparse<T>::nil_rep (void)
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21256
diff changeset
58 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21256
diff changeset
59 static typename Sparse<T>::SparseRep nr;
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
21574
ae4d7dfea337 maint: merge stable to default.
John W. Eaton <jwe@octave.org>
parents: 21562 21573
diff changeset
63 template <typename T>
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
64 Sparse<T>::Sparse (const PermMatrix& a)
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
65 : rep (new typename Sparse<T>::SparseRep (a.rows (), a.cols (), a.rows ())),
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
66 dimensions (dim_vector (a.rows (), a.cols ()))
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
67 {
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
68 octave_idx_type n = a.rows ();
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
69 for (octave_idx_type i = 0; i <= n; i++)
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
70 cidx (i) = i;
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
71
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18812
diff changeset
72 const Array<octave_idx_type> pv = a.col_perm_vec ();
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18812
diff changeset
73
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18812
diff changeset
74 for (octave_idx_type i = 0; i < n; i++)
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18812
diff changeset
75 ridx (i) = pv(i);
13030
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
76
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
77 for (octave_idx_type i = 0; i < n; i++)
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
78 data (i) = 1.0;
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
79 }
b646413c3d0e Make operators do smarter sparse conversions on permutation matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12511
diff changeset
80
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
81 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
82 T&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
83 Sparse<T>::SparseRep::elem (octave_idx_type _r, octave_idx_type _c)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
84 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
85 octave_idx_type i;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
86
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
87 if (nzmx <= 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
88 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
89 ("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
90
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
91 for (i = c[_c]; i < c[_c + 1]; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
92 if (r[i] == _r)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
93 return d[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
94 else if (r[i] > _r)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
95 break;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
96
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
97 // 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
98 // new element in the sparse array. This' gonna be slow!!!
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
99 if (c[ncols] == nzmx)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
100 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
101 ("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
102
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
103 octave_idx_type to_move = c[ncols] - i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
104 if (to_move != 0)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
105 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
106 for (octave_idx_type j = c[ncols]; j > i; j--)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
107 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
108 d[j] = d[j-1];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
109 r[j] = r[j-1];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
110 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
111 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
112
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
113 for (octave_idx_type j = _c + 1; j < ncols + 1; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
114 c[j] = c[j] + 1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
115
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
116 d[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
117 r[i] = _r;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
118
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
119 return d[i];
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
120 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
121
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
122 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
123 T
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
124 Sparse<T>::SparseRep::celem (octave_idx_type _r, octave_idx_type _c) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125 {
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5603
diff changeset
126 if (nzmx > 0)
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
127 for (octave_idx_type i = c[_c]; i < c[_c + 1]; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
128 if (r[i] == _r)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
129 return d[i];
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
130 return T ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
131 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
132
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
133 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
134 void
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
135 Sparse<T>::SparseRep::maybe_compress (bool remove_zeros)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
136 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
137 if (remove_zeros)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
138 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
139 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
140 octave_idx_type k = 0;
10497
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
141 for (octave_idx_type j = 1; j <= ncols; j++)
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
142 {
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
143 octave_idx_type u = c[j];
21337
cfe11042fbc0 eliminate useless assignment in for loop
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
144 for (; i < u; i++)
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
145 if (d[i] != T ())
10497
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
146 {
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
147 d[k] = d[i];
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
148 r[k++] = r[i];
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
149 }
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
150 c[j] = k;
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
151 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
152 }
10497
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
153
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
154 change_length (c[ncols]);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
155 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
156
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
157 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
158 void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
159 Sparse<T>::SparseRep::change_length (octave_idx_type nz)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
160 {
10497
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
161 for (octave_idx_type j = ncols; j > 0 && c[j] > nz; j--)
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
162 c[j] = nz;
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
163
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
164 // We shall skip reallocation if we have less than 1/frac extra elements to
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
165 // discard.
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
166 static const int frac = 5;
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
167 if (nz > nzmx || nz < nzmx - nzmx/frac)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
168 {
10497
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
169 // Reallocate.
cb7ffe7288f0 improve & fix SparseRep reallocation and compression
Jaroslav Hajek <highegg@gmail.com>
parents: 10494
diff changeset
170 octave_idx_type min_nzmx = std::min (nz, nzmx);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
171
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 15018
diff changeset
172 octave_idx_type * new_ridx = new octave_idx_type [nz];
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
173 std::copy (r, r + min_nzmx, new_ridx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
174
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
175 delete [] r;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
176 r = new_ridx;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
177
15020
560317fd5977 maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents: 15018
diff changeset
178 T * new_data = new T [nz];
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
179 std::copy (d, d + min_nzmx, new_data);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
180
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
181 delete [] d;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
182 d = new_data;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
183
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5603
diff changeset
184 nzmx = nz;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
185 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
186 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
187
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
188 template <typename T>
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 9177
diff changeset
189 bool
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 9177
diff changeset
190 Sparse<T>::SparseRep::indices_ok (void) const
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 9177
diff changeset
191 {
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 9177
diff changeset
192 return sparse_indices_ok (r, c, nrows, ncols, nnz ());
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 9177
diff changeset
193 }
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 9177
diff changeset
194
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
195 template <typename T>
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
196 bool
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 Sparse<T>::SparseRep::any_element_is_nan (void) const
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
198 {
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
199 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
200
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
201 for (octave_idx_type i = 0; i < nz; i++)
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
202 if (octave::math::isnan (d[i]))
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
203 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
204
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
205 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
206 }
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
207
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
208 template <typename T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
209 Sparse<T>::Sparse (octave_idx_type nr, octave_idx_type nc, T val)
11508
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
210 : rep (0), dimensions (dim_vector (nr, nc))
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
211 {
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
212 if (val != T ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
213 {
17823
eaf5c3ef3e8d avoid crash in sparse constructor (bug #)
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
214 rep = new typename Sparse<T>::SparseRep (nr, nc, dimensions.safe_numel ());
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
215
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
216 octave_idx_type ii = 0;
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
217 xcidx (0) = 0;
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
218 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
219 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
220 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
221 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
222 xdata (ii) = val;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
223 xridx (ii++) = i;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
224 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
225 xcidx (j+1) = ii;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
226 }
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
227 }
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
228 else
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
229 {
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
230 rep = new typename Sparse<T>::SparseRep (nr, nc, 0);
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5604
diff changeset
231 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
232 xcidx (j) = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
233 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
234 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
235
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
236 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
237 Sparse<T>::Sparse (const dim_vector& dv)
11508
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
238 : rep (0), dimensions (dv)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
239 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
240 if (dv.ndims () != 2)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
241 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
242 ("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
243
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
244 rep = new typename Sparse<T>::SparseRep (dv(0), dv(1), 0);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
245 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
246
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
247 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
248 Sparse<T>::Sparse (const Sparse<T>& a, const dim_vector& dv)
11508
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
249 : rep (0), dimensions (dv)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
250 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
251
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
252 // Work in unsigned long long to avoid overflow issues with numel
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
253 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
254 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
255 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
256 static_cast<unsigned long long>(dv(1));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
257
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
258 if (a_nel != dv_nel)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
259 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
260 ("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
261
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
262 dim_vector old_dims = a.dims ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
263 octave_idx_type new_nzmx = a.nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
264 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
265 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
266 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
267 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
268
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
269 rep = new typename Sparse<T>::SparseRep (new_nr, new_nc, new_nzmx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
270
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
271 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
272 xcidx (0) = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
273 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
274 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
275 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
276 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
277 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
278 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
279 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
280 xcidx (k+1) = j;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
281 kk = jj;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
282 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
283 xridx (j) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
284 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
285 for (octave_idx_type k = kk; k < new_nc; k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
286 xcidx (k+1) = new_nzmx;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
287 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
288
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
289 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
290 Sparse<T>::Sparse (const Array<T>& a, const idx_vector& r,
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
291 const idx_vector& c, octave_idx_type nr,
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
292 octave_idx_type nc, bool sum_terms,
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
293 octave_idx_type nzm)
11508
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
294 : rep (0), dimensions ()
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
295 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
296 if (nr < 0)
11508
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
297 nr = r.extent (0);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
298 else if (r.extent (nr) > nr)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
299 (*current_liboctave_error_handler) ("sparse: row index %d out of bound %d",
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
300 r.extent (nr), nr);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
301
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
302 if (nc < 0)
11508
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
303 nc = c.extent (0);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
304 else if (c.extent (nc) > nc)
11508
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
305 (*current_liboctave_error_handler)
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
306 ("sparse: column index %d out of bound %d", r.extent (nc), nc);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
307
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
308 dimensions = dim_vector (nr, nc);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
309
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
310 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
311 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
312 octave_idx_type cl = c.length (nc);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
313 bool a_scalar = n == 1;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
314 if (a_scalar)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
315 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
316 if (rl != 1)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
317 n = rl;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
318 else if (cl != 1)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
319 n = cl;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
320 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
321
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
322 if ((rl != 1 && rl != n) || (cl != 1 && cl != n))
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
323 (*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
324
17664
f4b0430fa5fd Avoid memory leak in Sparse constructor.
Rik <rik@octave.org>
parents: 17642
diff changeset
325 // Only create rep after input validation to avoid memory leak.
f4b0430fa5fd Avoid memory leak in Sparse constructor.
Rik <rik@octave.org>
parents: 17642
diff changeset
326 rep = new typename Sparse<T>::SparseRep (nr, nc, (nzm > 0 ? nzm : 0));
f4b0430fa5fd Avoid memory leak in Sparse constructor.
Rik <rik@octave.org>
parents: 17642
diff changeset
327
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
328 if (rl <= 1 && cl <= 1)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
329 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
330 if (n == 1 && a(0) != T ())
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
331 {
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
332 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
333 xcidx (0) = 0;
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 17823
diff changeset
334 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
335 xdata (0) = a(0);
15358
b135f013679e maint: periodic merge of stable to default
John W. Eaton <jwe@octave.org>
parents: 15304 15271
diff changeset
336
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
337 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
338 xcidx (j+1) = j >= c(0);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
339 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
340 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
341 else if (a_scalar)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
342 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
343 // This is completely specialized, because the sorts can be simplified.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
344 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
345 if (a0 == T ())
10509
ddbd812d09aa properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10506
diff changeset
346 {
ddbd812d09aa properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10506
diff changeset
347 // Do nothing, it's an empty matrix.
ddbd812d09aa properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10506
diff changeset
348 }
ddbd812d09aa properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10506
diff changeset
349 else if (cl == 1)
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
350 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
351 // Sparse column vector. Sort row indices.
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
352 idx_vector rs = r.sorted ();
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 octave_quit ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
355
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
356 const octave_idx_type *rd = rs.raw ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
357 // Count unique indices.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
358 octave_idx_type new_nz = 1;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
359 for (octave_idx_type i = 1; i < n; i++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
360 new_nz += rd[i-1] != rd[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
361 // Allocate result.
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
362 change_capacity (nzm > new_nz ? nzm : new_nz);
14656
8d2ce821e38a Ensure sparse constructors have valid ridx and data indices even if they are zero matrices (bug #36104)
David Bateman <dbateman@free.fr>
parents: 14446
diff changeset
363 xcidx (0) = 0;
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
364 xcidx (1) = new_nz;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
365 octave_idx_type *rri = ridx ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
366 T *rrd = data ();
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
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
370 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
371 octave_idx_type l = -1;
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
372
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
373 if (sum_terms)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
374 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
375 // Sum repeated indices.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
376 for (octave_idx_type i = 0; i < n; i++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
377 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
378 if (rd[i] != l)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
379 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
380 l = rd[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
381 rri[++k] = rd[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
382 rrd[k] = a0;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
383 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
384 else
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
385 rrd[k] += a0;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
386 }
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 else
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 // Pick the last one.
11571
0e414f837c58 Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents: 11570
diff changeset
391 for (octave_idx_type i = 0; i < n; i++)
10479
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];
11571
0e414f837c58 Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents: 11570
diff changeset
396 rri[++k] = rd[i];
0e414f837c58 Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents: 11570
diff changeset
397 rrd[k] = a0;
10479
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 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
400 }
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 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
405 idx_vector rr = r;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
406 idx_vector cc = c;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
407 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
408 const octave_idx_type *cd = cc.raw ();
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
409 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
410 ci[0] = 0;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
411 // Bin counts of column indices.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
412 for (octave_idx_type i = 0; i < n; i++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
413 ci[cd[i]+1]++;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
414 // Make them cumulative, shifted one to right.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
415 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
416 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
417 octave_idx_type s1 = s + ci[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
418 ci[i] = s;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
419 s = s1;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
420 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
421
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
422 octave_quit ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
423
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
424 // Bucket sort.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
425 OCTAVE_LOCAL_BUFFER (octave_idx_type, sidx, n);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
426 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
427 if (rl == 1)
0e414f837c58 Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents: 11570
diff changeset
428 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
429 else
0e414f837c58 Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents: 11570
diff changeset
430 sidx[ci[cd[i]+1]++] = rd[i];
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
431
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
432 // 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
433 xcidx (0) = 0;
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
434 for (octave_idx_type j = 0; j < nc; j++)
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 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
437 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
438 octave_idx_type nzj = 0;
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
439 // Count.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
440 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
441 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
442 octave_idx_type k = sidx[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
443 if (k != l)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
444 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
445 l = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
446 nzj++;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
447 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
448 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
449 // Set column pointer.
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
450 xcidx (j+1) = xcidx (j) + nzj;
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
451 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
452
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
453 change_capacity (nzm > xcidx (nc) ? nzm : xcidx (nc));
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
454 octave_idx_type *rri = ridx ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
455 T *rrd = data ();
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 // Fill-in data.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
458 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
459 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
460 octave_quit ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
461 octave_idx_type l = -1;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
462 if (sum_terms)
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 // Sum adjacent terms.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
465 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
466 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
467 octave_idx_type k = sidx[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
468 if (k != l)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
469 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
470 l = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
471 rrd[++jj] = a0;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
472 rri[jj] = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
473 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
474 else
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
475 rrd[jj] += a0;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
476 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
477 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
478 else
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
479 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
480 // Use the last one.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
481 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
482 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
483 octave_idx_type k = sidx[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
484 if (k != l)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
485 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
486 l = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
487 rrd[++jj] = a0;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
488 rri[jj] = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
489 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
490 }
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 }
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 else if (cl == 1)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
496 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
497 // Sparse column vector. Sort row indices.
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
498 Array<octave_idx_type> rsi;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
499 idx_vector rs = r.sorted (rsi);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
500
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
501 octave_quit ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
502
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
503 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
504 const octave_idx_type *rdi = rsi.data ();
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
505 // Count unique indices.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
506 octave_idx_type new_nz = 1;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
507 for (octave_idx_type i = 1; i < n; i++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
508 new_nz += rd[i-1] != rd[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
509 // Allocate result.
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
510 change_capacity (nzm > new_nz ? nzm : new_nz);
18083
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 17823
diff changeset
511 xcidx (0) = 0;
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 17823
diff changeset
512 xcidx (1) = new_nz;
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
513 octave_idx_type *rri = ridx ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
514 T *rrd = data ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
515
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
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
518 octave_idx_type k = 0;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
519 rri[k] = rd[0];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
520 rrd[k] = a(rdi[0]);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
521
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
522 if (sum_terms)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
523 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
524 // Sum repeated indices.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
525 for (octave_idx_type i = 1; i < n; i++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
526 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
527 if (rd[i] != rd[i-1])
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
528 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
529 rri[++k] = rd[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
530 rrd[k] = a(rdi[i]);
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 else
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
533 rrd[k] += a(rdi[i]);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
534 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
535 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
536 else
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 // Pick the last one.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
539 for (octave_idx_type i = 1; i < n; i++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
540 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
541 if (rd[i] != rd[i-1])
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
542 rri[++k] = rd[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
543 rrd[k] = a(rdi[i]);
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 }
10509
ddbd812d09aa properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10506
diff changeset
546
ddbd812d09aa properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10506
diff changeset
547 maybe_compress (true);
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
548 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
549 else
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
550 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
551 idx_vector rr = r;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
552 idx_vector cc = c;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
553 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
554 const octave_idx_type *cd = cc.raw ();
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
555 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
556 ci[0] = 0;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
557 // Bin counts of column indices.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
558 for (octave_idx_type i = 0; i < n; i++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
559 ci[cd[i]+1]++;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
560 // Make them cumulative, shifted one to right.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
561 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
562 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
563 octave_idx_type s1 = s + ci[i];
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
564 ci[i] = s;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
565 s = s1;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
566 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
567
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
568 octave_quit ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
569
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
570 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
571 // Bucket sort.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
572 OCTAVE_LOCAL_BUFFER (idx_pair, spairs, n);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
573 for (octave_idx_type i = 0; i < n; i++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
574 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
575 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
576 if (rl == 1)
0e414f837c58 Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents: 11570
diff changeset
577 p.first = rd[0];
0e414f837c58 Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents: 11570
diff changeset
578 else
0e414f837c58 Fix indexing error in the construction of sparse matrices
David Bateman <dbateman@free.fr>
parents: 11570
diff changeset
579 p.first = rd[i];
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
580 p.second = i;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
581 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
582
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
583 // 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
584 xcidx (0) = 0;
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
585 for (octave_idx_type j = 0; j < nc; j++)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
586 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
587 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
588 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
589 octave_idx_type nzj = 0;
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
590 // Count.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
591 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
592 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
593 octave_idx_type k = spairs[i].first;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
594 if (k != l)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
595 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
596 l = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
597 nzj++;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
598 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
599 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
600 // Set column pointer.
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
601 xcidx (j+1) = xcidx (j) + nzj;
10479
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
10527
b4d2080b6df7 Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents: 10521
diff changeset
604 change_capacity (nzm > xcidx (nc) ? nzm : xcidx (nc));
10479
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
605 octave_idx_type *rri = ridx ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
606 T *rrd = data ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
607
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
608 // Fill-in data.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
609 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
610 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
611 octave_quit ();
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
612 octave_idx_type l = -1;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
613 if (sum_terms)
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 // Sum adjacent terms.
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
616 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
617 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
618 octave_idx_type k = spairs[i].first;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
619 if (k != l)
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
620 {
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
621 l = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
622 rrd[++jj] = a(spairs[i].second);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
623 rri[jj] = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
624 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
625 else
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
626 rrd[jj] += a(spairs[i].second);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
627 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
628 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
629 else
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 // Use the last one.
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 rri[++jj] = k;
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
639 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
640 rrd[jj] = a(spairs[i].second);
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
641 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
642 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
643 }
10509
ddbd812d09aa properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10506
diff changeset
644
ddbd812d09aa properly compress sparse matrices after assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10506
diff changeset
645 maybe_compress (true);
10479
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 }
ded9beac7582 optimize sparse matrix assembly
Jaroslav Hajek <highegg@gmail.com>
parents: 10468
diff changeset
648
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
649 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
650 Sparse<T>::Sparse (const Array<T>& a)
11508
41866901ec62 Sparse.cc: more constructor fixes
John W. Eaton <jwe@octave.org>
parents: 11311
diff changeset
651 : rep (0), dimensions (a.dims ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
652 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
653 if (dimensions.ndims () > 2)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
654 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
655 ("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
656
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
657 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
658 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
659 octave_idx_type len = a.numel ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
660 octave_idx_type new_nzmx = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
661
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
662 // 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
663 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
664 if (a(i) != T ())
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
665 new_nzmx++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
666
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
667 rep = new typename Sparse<T>::SparseRep (nr, nc, new_nzmx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
668
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
669 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
670 xcidx (0) = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
671 for (octave_idx_type j = 0; j < nc; j++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
672 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
673 for (octave_idx_type i = 0; i < nr; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
674 if (a.elem (i,j) != T ())
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
675 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
676 xdata (ii) = a.elem (i,j);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
677 xridx (ii++) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
678 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
679 xcidx (j+1) = ii;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
680 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
681 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
682
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
683 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
684 Sparse<T>::~Sparse (void)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
685 {
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13841
diff changeset
686 if (--rep->count == 0)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
687 delete rep;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
688 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
689
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
690 template <typename T>
7717
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
691 Sparse<T>&
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
692 Sparse<T>::operator = (const Sparse<T>& a)
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
693 {
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
694 if (this != &a)
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
695 {
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13841
diff changeset
696 if (--rep->count == 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
697 delete rep;
7717
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
698
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
699 rep = a.rep;
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
700 rep->count++;
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
701
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
702 dimensions = a.dimensions;
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
703 }
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
704
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
705 return *this;
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
706 }
ff918ee1a983 Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
707
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
708 template <typename T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
709 octave_idx_type
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
710 Sparse<T>::compute_index (const Array<octave_idx_type>& ra_idx) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
711 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
712 octave_idx_type n = dimensions.ndims ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
713
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
714 if (n <= 0 || n != ra_idx.numel ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
715 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
716 ("Sparse<T>::compute_index: invalid ra_idxing operation");
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
717
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
718 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
719
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
720 retval = ra_idx(--n);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
721
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
722 while (--n >= 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
723 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
724 retval *= dimensions(n);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
725 retval += ra_idx(n);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
726 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
727
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
728 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
729 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
730
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
731 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
732 T
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
733 Sparse<T>::range_error (const char *fcn, octave_idx_type n) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
734 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
735 (*current_liboctave_error_handler) ("%s (%d): range error", fcn, n);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
736 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
737
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
738 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
739 T&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
740 Sparse<T>::range_error (const char *fcn, octave_idx_type n)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
741 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
742 (*current_liboctave_error_handler) ("%s (%d): range error", fcn, n);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
743 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
744
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
745 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
746 T
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
747 Sparse<T>::range_error (const char *fcn, octave_idx_type i,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
748 octave_idx_type j) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
749 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
750 (*current_liboctave_error_handler) ("%s (%d, %d): range error", fcn, i, j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
751 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
752
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
753 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
754 T&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
755 Sparse<T>::range_error (const char *fcn, octave_idx_type i, octave_idx_type j)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
756 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
757 (*current_liboctave_error_handler) ("%s (%d, %d): range error", fcn, i, j);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
758 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
759
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
760 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
761 T
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
762 Sparse<T>::range_error (const char *fcn,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
763 const Array<octave_idx_type>& ra_idx) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
764 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
765 std::ostringstream buf;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
766
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
767 buf << fcn << " (";
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
768
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20229
diff changeset
769 octave_idx_type n = ra_idx.numel ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
770
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
771 if (n > 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
772 buf << ra_idx(0);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
773
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
774 for (octave_idx_type i = 1; i < n; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
775 buf << ", " << ra_idx(i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
776
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
777 buf << "): range error";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
778
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
779 std::string buf_str = buf.str ();
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
780
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
781 (*current_liboctave_error_handler) (buf_str.c_str ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
782 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
783
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
784 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
785 T&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
786 Sparse<T>::range_error (const char *fcn, const Array<octave_idx_type>& ra_idx)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
787 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
788 std::ostringstream buf;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
789
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
790 buf << fcn << " (";
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
791
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20229
diff changeset
792 octave_idx_type n = ra_idx.numel ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
793
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
794 if (n > 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
795 buf << ra_idx(0);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
796
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
797 for (octave_idx_type i = 1; i < n; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
798 buf << ", " << ra_idx(i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
799
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
800 buf << "): range error";
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
801
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
802 std::string buf_str = buf.str ();
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
803
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
804 (*current_liboctave_error_handler) (buf_str.c_str ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
805 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
806
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
807 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
808 Sparse<T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
809 Sparse<T>::reshape (const dim_vector& new_dims) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
810 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
811 Sparse<T> retval;
6689
8e0444d90050 [project @ 2007-06-04 22:28:19 by dbateman]
dbateman
parents: 6101
diff changeset
812 dim_vector dims2 = new_dims;
8e0444d90050 [project @ 2007-06-04 22:28:19 by dbateman]
dbateman
parents: 6101
diff changeset
813
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
814 if (dims2.ndims () > 2)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
815 {
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 19381
diff changeset
816 (*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
817 ("Octave:reshape-smashes-dims",
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20673
diff changeset
818 "reshape: sparse reshape to N-D array smashes dims");
6814
8c89a644df8a [project @ 2007-08-14 17:30:59 by jwe]
jwe
parents: 6813
diff changeset
819
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
820 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
821 dims2(1) *= dims2(i);
6814
8c89a644df8a [project @ 2007-08-14 17:30:59 by jwe]
jwe
parents: 6813
diff changeset
822
6689
8e0444d90050 [project @ 2007-06-04 22:28:19 by dbateman]
dbateman
parents: 6101
diff changeset
823 dims2.resize (2);
8e0444d90050 [project @ 2007-06-04 22:28:19 by dbateman]
dbateman
parents: 6101
diff changeset
824 }
8e0444d90050 [project @ 2007-06-04 22:28:19 by dbateman]
dbateman
parents: 6101
diff changeset
825
8e0444d90050 [project @ 2007-06-04 22:28:19 by dbateman]
dbateman
parents: 6101
diff changeset
826 if (dimensions != dims2)
8e0444d90050 [project @ 2007-06-04 22:28:19 by dbateman]
dbateman
parents: 6101
diff changeset
827 {
8e0444d90050 [project @ 2007-06-04 22:28:19 by dbateman]
dbateman
parents: 6101
diff changeset
828 if (dimensions.numel () == dims2.numel ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
829 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
830 octave_idx_type new_nnz = nnz ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
831 octave_idx_type new_nr = dims2 (0);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
832 octave_idx_type new_nc = dims2 (1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
833 octave_idx_type old_nr = rows ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
834 octave_idx_type old_nc = cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
835 retval = Sparse<T> (new_nr, new_nc, new_nnz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
836
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
837 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
838 retval.xcidx (0) = 0;
21562
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21337
diff changeset
839 // 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
840 // 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
841 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
842 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
843 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
844 {
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
845 i_old_rm += old_nr;
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
846 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
847 {
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
848 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
849 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
850 }
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
851 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
852 {
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
853 octave_idx_type ii, jj;
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
854 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
855 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
856
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
857 // Original calculation subject to overflow
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
858 // 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
859 // 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
860
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
861 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
862 retval.xcidx (k+1) = j;
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
863 kk = jj;
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
864 retval.xdata (j) = data (j);
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
865 retval.xridx (j) = ii;
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
866 }
a93fa1b0796e Avoid overflow while reshaping large sparse matrices (bug #42850).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21255
diff changeset
867 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
868 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
869 retval.xcidx (k+1) = new_nnz;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
870 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
871 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
872 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
873 std::string dimensions_str = dimensions.str ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
874 std::string new_dims_str = new_dims.str ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
875
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
876 (*current_liboctave_error_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
877 ("reshape: can't reshape %s array to %s array",
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
878 dimensions_str.c_str (), new_dims_str.c_str ());
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
879 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
880 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
881 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
882 retval = *this;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
883
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
884 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
885 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
886
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
887 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
888 Sparse<T>
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
889 Sparse<T>::permute (const Array<octave_idx_type>& perm_vec, bool) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
890 {
6813
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
891 // The only valid permutations of a sparse array are [1, 2] and [2, 1].
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
892
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
893 bool fail = false;
6817
2e7f62e52c13 [project @ 2007-08-19 19:36:40 by dbateman]
dbateman
parents: 6814
diff changeset
894 bool trans = false;
6813
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
895
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20229
diff changeset
896 if (perm_vec.numel () == 2)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
897 {
6813
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
898 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
899 /* do nothing */;
6813
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
900 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
901 trans = true;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
902 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
903 fail = true;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
904 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
905 else
6813
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
906 fail = true;
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
907
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
908 if (fail)
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
909 (*current_liboctave_error_handler)
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
910 ("permutation vector contains an invalid element");
75d99621f850 [project @ 2007-08-14 17:14:18 by jwe]
jwe
parents: 6689
diff changeset
911
6817
2e7f62e52c13 [project @ 2007-08-19 19:36:40 by dbateman]
dbateman
parents: 6814
diff changeset
912 return trans ? this->transpose () : *this;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
913 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
914
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
915 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
916 void
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
917 Sparse<T>::resize1 (octave_idx_type n)
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
918 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
919 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
920 octave_idx_type nc = cols ();
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
921
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
922 if (nr == 0)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
923 resize (1, std::max (nc, n));
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
924 else if (nc == 0)
10520
72c90e7132a9 fix failing sparse assignment tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10516
diff changeset
925 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
926 else if (nr == 1)
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
927 resize (1, n);
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
928 else if (nc == 1)
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
929 resize (n, 1);
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
930 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
931 octave::err_invalid_resize ();
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
932 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
933
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
934 template <typename T>
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
935 void
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
936 Sparse<T>::resize (const dim_vector& dv)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
937 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
938 octave_idx_type n = dv.ndims ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
939
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
940 if (n != 2)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
941 (*current_liboctave_error_handler) ("sparse array must be 2-D");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
942
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
943 resize (dv(0), dv(1));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
944 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
945
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
946 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
947 void
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
948 Sparse<T>::resize (octave_idx_type r, octave_idx_type c)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
949 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
950 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
951 (*current_liboctave_error_handler) ("can't resize to negative dimension");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
952
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
953 if (r == dim1 () && c == dim2 ())
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
954 return;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
955
10499
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
956 // This wouldn't be necessary for r >= rows () if 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
957 // Sparse rep. It is not good for anything in there.
10499
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
958 make_unique ();
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
959
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
960 if (r < rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
961 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
962 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
963 octave_idx_type k = 0;
10499
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
964 for (octave_idx_type j = 1; j <= rep->ncols; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
965 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
966 octave_idx_type u = xcidx (j);
21337
cfe11042fbc0 eliminate useless assignment in for loop
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
967 for (; i < u; i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
968 if (xridx (i) < r)
10499
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
969 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
970 xdata (k) = xdata (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
971 xridx (k++) = xridx (i);
10499
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
972 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
973 xcidx (j) = k;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
974 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
975 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
976
10499
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
977 rep->nrows = dimensions(0) = r;
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
978
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
979 if (c != rep->ncols)
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
980 {
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
981 octave_idx_type *new_cidx = new octave_idx_type [c+1];
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
982 std::copy (rep->c, rep->c + std::min (c, rep->ncols) + 1, new_cidx);
10499
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
983 delete [] rep->c;
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
984 rep->c = new_cidx;
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
985
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
986 if (c > rep->ncols)
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
987 std::fill_n (rep->c + rep->ncols + 1, c - rep->ncols,
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
988 rep->c[rep->ncols]);
10499
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
989 }
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
990
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
991 rep->ncols = dimensions(1) = c;
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
992
fabed15083a4 optimize sparse resize
Jaroslav Hajek <highegg@gmail.com>
parents: 10497
diff changeset
993 rep->change_length (rep->nnz ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
994 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
995
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
996 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
997 Sparse<T>&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
998 Sparse<T>::insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
999 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1000 octave_idx_type a_rows = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1001 octave_idx_type a_cols = a.cols ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1002 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1003 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1004
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1005 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
1006 (*current_liboctave_error_handler) ("range error for insert");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1007
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1008 // 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
1009 octave_idx_type nel = cidx (c) + a.nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1010
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1011 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
1012 nel += cidx (nc) - cidx (c + a_cols);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1013
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1014 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
1015 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
1016 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
1017 nel++;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1018
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1019 Sparse<T> tmp (*this);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1020 --rep->count;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1021 rep = new typename Sparse<T>::SparseRep (nr, nc, nel);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1022
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1023 for (octave_idx_type i = 0; i < tmp.cidx (c); i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1024 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1025 data (i) = tmp.data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1026 ridx (i) = tmp.ridx (i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1027 }
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1028 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
1029 cidx (i) = tmp.cidx (i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1030
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1031 octave_idx_type ii = cidx (c);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1032
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1033 for (octave_idx_type i = c; i < c + a_cols; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1034 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
1035 octave_quit ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1036
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1037 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
1038 if (tmp.ridx (j) < r)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1039 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1040 data (ii) = tmp.data (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1041 ridx (ii++) = tmp.ridx (j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1042 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1043
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
1044 octave_quit ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1045
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1046 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
1047 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1048 data (ii) = a.data (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1049 ridx (ii++) = r + a.ridx (j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1050 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1051
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
1052 octave_quit ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1053
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1054 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
1055 if (tmp.ridx (j) >= r + a_rows)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1056 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1057 data (ii) = tmp.data (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1058 ridx (ii++) = tmp.ridx (j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1059 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1060
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1061 cidx (i+1) = ii;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1062 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1063
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1064 for (octave_idx_type i = c + a_cols; i < nc; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1065 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1066 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
1067 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1068 data (ii) = tmp.data (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1069 ridx (ii++) = tmp.ridx (j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1070 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1071 cidx (i+1) = ii;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1072 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1073
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1074 return *this;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1075 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1076
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1077 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1078 Sparse<T>&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1079 Sparse<T>::insert (const Sparse<T>& a, const Array<octave_idx_type>& ra_idx)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1080 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1081
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20229
diff changeset
1082 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
1083 (*current_liboctave_error_handler) ("range error for insert");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1084
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19861
diff changeset
1085 return insert (a, ra_idx(0), ra_idx(1));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1086 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1087
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1088 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1089 Sparse<T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1090 Sparse<T>::transpose (void) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1091 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1092 assert (ndims () == 2);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1093
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1094 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1095 octave_idx_type nc = cols ();
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
1096 octave_idx_type nz = nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1097 Sparse<T> retval (nc, nr, nz);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1098
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
1099 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
1100 retval.xcidx (ridx (i) + 1)++;
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
1101 // retval.xcidx[1:nr] holds the row degrees for rows 0:(nr-1)
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
1102 nz = 0;
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
1103 for (octave_idx_type i = 1; i <= nr; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1104 {
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
1105 const octave_idx_type tmp = retval.xcidx (i);
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
1106 retval.xcidx (i) = nz;
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
1107 nz += tmp;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1108 }
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
1109 // retval.xcidx[1:nr] holds row entry *start* offsets for rows 0:(nr-1)
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
1110
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
1111 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
1112 for (octave_idx_type k = cidx (j); k < cidx (j+1); k++)
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
1113 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1114 octave_idx_type q = retval.xcidx (ridx (k) + 1)++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1115 retval.xridx (q) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1116 retval.xdata (q) = data (k);
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
1117 }
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
1118 assert (nnz () == retval.xcidx (nr));
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
1119 // 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
1120 // and retval.xcidx[0:(nr-1)] holds their row entry *start* offsets
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1121
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1122 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1123 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1124
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
1125 // 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
1126 // 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
1127 // for small columns.
10493
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1128 static octave_idx_type
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1129 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
1130 octave_idx_type ri)
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1131 {
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1132 if (nr <= 8)
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1133 {
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1134 octave_idx_type l;
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1135 for (l = 0; l < nr; l++)
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1136 if (ridx[l] >= ri)
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1137 break;
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1138 return l;
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1139 }
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1140 else
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1141 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
1142 }
2f8bacc2a57d fix order of func defs in Sparse.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10490
diff changeset
1143
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1144 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1145 void
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1146 Sparse<T>::delete_elements (const idx_vector& idx)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1147 {
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1148 Sparse<T> retval;
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1149
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1150 assert (ndims () == 2);
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1151
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1152 octave_idx_type nr = dim1 ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1153 octave_idx_type nc = dim2 ();
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1154 octave_idx_type nz = nnz ();
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1155
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1156 octave_idx_type nel = numel (); // Can throw.
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1157
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1158 const dim_vector idx_dims = idx.orig_dimensions ();
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1159
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1160 if (idx.extent (nel) > nel)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1161 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
1162
499b851fbfae Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents: 21118
diff changeset
1163 if (nc == 1)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1164 {
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1165 // Sparse column vector.
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1166 const Sparse<T> tmp = *this; // constant copy to prevent COW.
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1167
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1168 octave_idx_type lb, ub;
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1169
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1170 if (idx.is_cont_range (nel, lb, ub))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1171 {
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1172 // Special-case a contiguous range.
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1173 // Look-up indices first.
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1174 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
1175 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
1176 // Copy data and adjust indices.
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1177 octave_idx_type nz_new = nz - (ui - li);
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1178 *this = Sparse<T> (nr - (ub - lb), 1, nz_new);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1179 std::copy (tmp.data (), tmp.data () + li, data ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1180 std::copy (tmp.ridx (), tmp.ridx () + li, xridx ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1181 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
1182 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
1183 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
1184 }
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
1185 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
1186 {
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1187 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
1188 OCTAVE_LOCAL_BUFFER (T, data_new, nz);
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1189 idx_vector sidx = idx.sorted (true);
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1190 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
1191 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
1192 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
1193 octave_idx_type j = 0;
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1194 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
1195 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1196 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
1197 for (; j < sl && sj[j] < r; j++) ;
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1198 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
1199 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1200 data_new[nz_new] = tmp.data (i);
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1201 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
1202 }
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
1203 }
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1204
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1205 *this = Sparse<T> (nr - sl, 1, nz_new);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1206 std::copy (ridx_new, ridx_new + nz_new, ridx ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1207 std::copy (data_new, 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
1208 xcidx (1) = nz_new;
10484
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 }
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1211 else if (nr == 1)
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1212 {
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1213 // Sparse row vector.
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1214 octave_idx_type lb, ub;
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1215 if (idx.is_cont_range (nc, lb, ub))
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1216 {
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1217 const Sparse<T> tmp = *this;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1218 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
1219 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
1220 octave_idx_type new_nz = nz - (ubi - lbi);
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1221 *this = Sparse<T> (1, nc - (ub - lb), new_nz);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1222 std::copy (tmp.data (), tmp.data () + lbi, data ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1223 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
1224 std::fill_n (ridx (), new_nz, static_cast<octave_idx_type> (0));
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1225 std::copy (tmp.cidx () + 1, 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
1226 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
1227 ubi - lbi);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1228 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1229 else
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1230 *this = index (idx.complement (nc));
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1231 }
17642
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1232 else if (idx.length (nel) != 0)
10484
6a9571b57745 rewrite sparse null assignment (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10480
diff changeset
1233 {
17642
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1234 if (idx.is_colon_equiv (nel))
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1235 *this = Sparse<T> ();
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1236 else
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1237 {
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1238 *this = index (idx_vector::colon);
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1239 delete_elements (idx);
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1240 *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
1241 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1242 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1243 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1244
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1245 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1246 void
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1247 Sparse<T>::delete_elements (const idx_vector& idx_i, const idx_vector& idx_j)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1248 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1249 assert (ndims () == 2);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1250
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1251 octave_idx_type nr = dim1 ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1252 octave_idx_type nc = dim2 ();
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1253 octave_idx_type nz = nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1254
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1255 if (idx_i.is_colon ())
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1256 {
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1257 // Deleting columns.
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1258 octave_idx_type lb, ub;
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1259 if (idx_j.extent (nc) > nc)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1260 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
1261 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
1262 {
14794
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1263 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
1264 {
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1265 // Delete all rows and columns.
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1266 *this = Sparse<T> (nr, 0);
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1267 }
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1268 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
1269 {
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1270 // No elements to preserve; adjust dimensions.
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1271 *this = Sparse<T> (nr, nc - (ub - lb));
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1272 }
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1273 else
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1274 {
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1275 const Sparse<T> 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
1276 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
1277 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
1278 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
1279
14794
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1280 *this = Sparse<T> (nr, nc - (ub - lb), new_nz);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1281 std::copy (tmp.data (), tmp.data () + lbi, data ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1282 std::copy (tmp.ridx (), tmp.ridx () + lbi, ridx ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1283 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
1284 std::copy (tmp.ridx () + ubi, tmp.ridx () + nz, xridx () + lbi);
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1285 std::copy (tmp.cidx () + 1, 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
1286 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
1287 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
1288 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1289 }
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1290 else
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1291 *this = index (idx_i, idx_j.complement (nc));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1292 }
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1293 else if (idx_j.is_colon ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1294 {
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1295 // Deleting rows.
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1296 octave_idx_type lb, ub;
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1297 if (idx_i.extent (nr) > nr)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1298 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
1299 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
1300 {
14794
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1301 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
1302 {
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1303 // Delete all rows and columns.
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1304 *this = Sparse<T> (0, nc);
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1305 }
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1306 else if (nz == 0)
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1307 {
14794
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1308 // No elements to preserve; adjust dimensions.
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1309 *this = Sparse<T> (nr - (ub - lb), nc);
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1310 }
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1311 else
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1312 {
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1313 // This is more memory-efficient than the approach below.
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1314 const Sparse<T> tmpl = index (idx_vector (0, lb), idx_j);
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1315 const Sparse<T> tmpu = index (idx_vector (ub, nr), idx_j);
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1316 *this = Sparse<T> (nr - (ub - lb), nc,
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1317 tmpl.nnz () + tmpu.nnz ());
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1318 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
1319 {
18083
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 17823
diff changeset
1320 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
1321 i++)
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1322 {
18083
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 17823
diff changeset
1323 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
1324 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
1325 }
18083
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 17823
diff changeset
1326 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
1327 i++)
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1328 {
18083
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 17823
diff changeset
1329 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
1330 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
1331 }
41dcb2c5bb1a Special-case removing rows or columns from empty sparse matrices
John W. Eaton <jwe@octave.org>
parents: 14792
diff changeset
1332
18083
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 17823
diff changeset
1333 xcidx (j+1) = k;
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1334 }
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1335 }
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1336 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1337 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1338 {
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1339 // 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
1340 // again.
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1341 Sparse<T> tmp = transpose ();
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1342 tmp.delete_elements (idx_j, idx_i);
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1343 *this = tmp.transpose ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1344 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1345 }
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1346 else
17642
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1347 {
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1348 // 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
1349 // 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
1350 // 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
1351 // 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
1352 // 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
1353 // not "false". We accept both.
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1354
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1355 bool empty_assignment
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1356 = (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
1357
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1358 if (! empty_assignment)
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1359 (*current_liboctave_error_handler)
7ed397c8ca68 improve compatibility of null assignment (bug #31287)
John W. Eaton <jwe@octave.org>
parents: 17285
diff changeset
1360 ("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
1361 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1362 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1363
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1364 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1365 void
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1366 Sparse<T>::delete_elements (int dim, const idx_vector& idx)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1367 {
10490
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1368 if (dim == 0)
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1369 delete_elements (idx, idx_vector::colon);
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1370 else if (dim == 1)
fdccd69d26bd rewrite sparse null assignment (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10484
diff changeset
1371 delete_elements (idx_vector::colon, idx);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1372 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
1373 (*current_liboctave_error_handler) ("invalid dimension in delete_elements");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1374 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1375
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1376 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1377 Sparse<T>
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1378 Sparse<T>::index (const idx_vector& idx, bool resize_ok) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1379 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1380 Sparse<T> retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1381
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1382 assert (ndims () == 2);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1383
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1384 octave_idx_type nr = dim1 ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1385 octave_idx_type nc = dim2 ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
1386 octave_idx_type nz = nnz ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1387
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1388 octave_idx_type nel = numel (); // Can throw.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1389
19413
e354372e20f2 allow sparse arrays to be indexed by N-d arrays (bug #43855)
John W. Eaton <jwe@octave.org>
parents: 19410
diff changeset
1390 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
1391
e354372e20f2 allow sparse arrays to be indexed by N-d arrays (bug #43855)
John W. Eaton <jwe@octave.org>
parents: 19410
diff changeset
1392 if (idx.is_colon ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1393 {
10494
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1394 if (nc == 1)
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1395 retval = *this;
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1396 else
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1397 {
10494
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1398 // Fast magic colon processing.
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1399 retval = Sparse<T> (nel, 1, nz);
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1400
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1401 for (octave_idx_type i = 0; i < nc; i++)
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1402 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1403 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
1404 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1405 retval.xdata (j) = data (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1406 retval.xridx (j) = ridx (j) + i * nr;
10494
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1407 }
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1408 }
10494
e52f41fd82c7 optimize (:) indexing of sparse column vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 10493
diff changeset
1409
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1410 retval.xcidx (0) = 0;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1411 retval.xcidx (1) = nz;
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1412 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1413 }
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1414 else if (idx.extent (nel) > nel)
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10382
diff changeset
1415 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
1416 if (! resize_ok)
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1417 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
1418
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1419 // 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
1420 octave_idx_type ext = idx.extent (nel);
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
1421 Sparse<T> tmp = *this;
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
1422 tmp.resize1 (ext);
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
1423 retval = tmp.index (idx);
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10382
diff changeset
1424 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1425 else if (nr == 1 && nc == 1)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1426 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1427 // You have to be pretty sick to get to this bit of code,
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1428 // 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
1429 // 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
1430 // Ok, we'll do it, but you deserve what you get!!
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1431 retval = Sparse<T> (idx_dims(0), idx_dims(1), nz ? data (0) : T ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1432 }
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1433 else if (nc == 1)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1434 {
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1435 // Sparse column vector.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1436 octave_idx_type lb, ub;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1437
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1438 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
1439 {
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1440 // Scalar index - just a binary lookup.
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1441 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
1442 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
1443 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
1444 else
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1445 retval = Sparse (1, 1);
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1446 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1447 else if (idx.is_cont_range (nel, lb, ub))
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1448 {
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1449 // Special-case a contiguous range.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1450 // Look-up indices first.
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1451 octave_idx_type li = lblookup (ridx (), nz, lb);
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1452 octave_idx_type ui = lblookup (ridx (), nz, ub);
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1453 // Copy data and adjust indices.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1454 octave_idx_type nz_new = ui - li;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1455 retval = Sparse<T> (ub - lb, 1, nz_new);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1456 std::copy (data () + li, data () + li + nz_new, retval.data ());
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1457 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
1458 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
1459 }
10516
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1460 else if (idx.is_permutation (nel) && idx.is_vector ())
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1461 {
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1462 if (idx.is_range () && idx.increment () == -1)
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1463 {
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1464 retval = Sparse<T> (nr, 1, nz);
14433
ec660526ae50 Fix sparse range indexing bug (bug #35570)
Marco Caliari <marco.caliari@univr.it>
parents: 14138
diff changeset
1465
ec660526ae50 Fix sparse range indexing bug (bug #35570)
Marco Caliari <marco.caliari@univr.it>
parents: 14138
diff changeset
1466 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
1467 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
1468
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1469 std::copy (cidx (), cidx () + 2, retval.cidx ());
10516
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1470 std::reverse_copy (data (), data () + nz, retval.data ());
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1471 }
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1472 else
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1473 {
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1474 Array<T> tmp = array_value ();
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1475 tmp = tmp.index (idx);
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1476 retval = Sparse<T> (tmp);
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1477 }
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1478 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1479 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1480 {
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1481 // 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
1482 // sparse column vector, otherwise it inherits the shape of index.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1483 // 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
1484
06b23f224f52 fix problem with changeset e354372e20f2 (bug #43855)
John W. Eaton <jwe@octave.org>
parents: 19413
diff changeset
1485 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
1486
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
1487 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
1488 ? tmp_idx.transpose ()
06b23f224f52 fix problem with changeset e354372e20f2 (bug #43855)
John W. Eaton <jwe@octave.org>
parents: 19413
diff changeset
1489 : tmp_idx);
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1490
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
1491 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
1492 octave_idx_type new_nc = idxa.cols ();
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1493
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1494 // Lookup.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1495 // FIXME: Could specialize for sorted idx?
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1496 NoAlias< 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
1497 for (octave_idx_type i = 0; i < new_nr*new_nc; i++)
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1498 lidx(i) = lblookup (ridx (), nz, idxa(i));
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1499
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1500 // Count matches.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1501 retval = Sparse<T> (idxa.rows (), idxa.cols ());
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1502 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
1503 {
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1504 octave_idx_type nzj = 0;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1505 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
1506 {
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1507 octave_idx_type l = lidx(i, j);
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1508 if (l < nz && ridx (l) == idxa(i, j))
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1509 nzj++;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1510 else
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1511 lidx(i, j) = nz;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1512 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1513 retval.xcidx (j+1) = retval.xcidx (j) + nzj;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1514 }
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1515
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1516 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
1517
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1518 // Copy data and set row indices.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1519 octave_idx_type k = 0;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1520 for (octave_idx_type j = 0; j < new_nc; j++)
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1521 for (octave_idx_type i = 0; i < new_nr; i++)
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1522 {
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1523 octave_idx_type l = lidx(i, j);
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1524 if (l < nz)
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1525 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1526 retval.data (k) = data (l);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1527 retval.xridx (k++) = i;
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1528 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1529 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1530 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1531 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1532 else if (nr == 1)
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1533 {
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1534 octave_idx_type lb, ub;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1535 if (idx.is_scalar ())
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1536 retval = Sparse<T> (1, 1, elem (0, idx(0)));
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1537 else if (idx.is_cont_range (nel, lb, ub))
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1538 {
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1539 // 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
1540 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
1541 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
1542 octave_idx_type new_nz = ubi - lbi;
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1543 retval = Sparse<T> (1, ub - lb, new_nz);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1544 std::copy (data () + lbi, data () + lbi + new_nz, retval.data ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1545 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
1546 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
1547 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1548 else
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1549 {
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1550 // 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
1551 // convert the matrix to full, index, and sparsify the result.
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1552 retval = Sparse<T> (array_value ().index (idx));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1553 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1554 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1555 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1556 {
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1557 if (nr != 0 && idx.is_scalar ())
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1558 retval = Sparse<T> (1, 1, elem (idx(0) % nr, idx(0) / nr));
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10382
diff changeset
1559 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1560 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
1561 // 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
1562 // 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
1563 // 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
1564 // handled above.
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1565 retval = index (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
1566 // 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
1567 // 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
1568 if (idx_dims(0) == 1 && idx_dims(1) != 1)
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
1569 retval = retval.transpose ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1570 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1571 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1572
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1573 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1574 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1575
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1576 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1577 Sparse<T>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1578 Sparse<T>::index (const idx_vector& idx_i, const idx_vector& idx_j,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1579 bool resize_ok) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1580 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1581 Sparse<T> retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1582
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1583 assert (ndims () == 2);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1584
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1585 octave_idx_type nr = dim1 ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1586 octave_idx_type nc = dim2 ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5166
diff changeset
1587
10421
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10382
diff changeset
1588 octave_idx_type n = idx_i.length (nr);
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10382
diff changeset
1589 octave_idx_type m = idx_j.length (nc);
99e9bae2d81e improve sparse indexing interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10382
diff changeset
1590
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1591 octave_idx_type lb, ub;
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1592
10432
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1593 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
1594 {
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1595 // resize_ok is completely handled here.
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1596 if (resize_ok)
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1597 {
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1598 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
1599 octave_idx_type ext_j = idx_j.extent (nc);
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1600 Sparse<T> tmp = *this;
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1601 tmp.resize (ext_i, ext_j);
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1602 retval = tmp.index (idx_i, idx_j);
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1603 }
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1604 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
1605 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
1606 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1607 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
1608 }
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
1609 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
1610 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1611 // 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
1612 // 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
1613 // 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
1614
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
1615 retval = Sparse<T> (array_value ().index (idx_i, idx_j));
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
1616 }
10432
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1617 else if (idx_i.is_colon ())
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1618 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
1619 // 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
1620 // 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
1621 if (idx_j.is_colon ())
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1622 retval = *this; // Shallow copy.
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1623 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
1624 {
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1625 // 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
1626 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
1627 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
1628 octave_idx_type new_nz = ubi - lbi;
10432
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1629 retval = Sparse<T> (nr, ub - lb, new_nz);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1630 std::copy (data () + lbi, data () + lbi + new_nz, retval.data ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1631 std::copy (ridx () + lbi, ridx () + lbi + new_nz, retval.ridx ());
10432
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1632 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
1633 }
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1634 else
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1635 {
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1636 // Count new nonzero elements.
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1637 retval = Sparse<T> (nr, m);
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1638 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
1639 {
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1640 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
1641 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
1642 }
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1643
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1644 retval.change_capacity (retval.xcidx (m));
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1645
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1646 // Copy data & indices.
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1647 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
1648 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1649 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
1650 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
1651 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
1652
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1653 std::copy (data () + ljj, data () + ljj + nzj, retval.data () + lj);
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1654 std::copy (ridx () + ljj, ridx () + ljj + nzj, retval.ridx () + lj);
10432
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1655 }
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1656 }
10207338603a improve sparse 2D indexing (part 1)
Jaroslav Hajek <highegg@gmail.com>
parents: 10425
diff changeset
1657 }
10516
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1658 else if (nc == 1 && idx_j.is_colon_equiv (nc) && idx_i.is_vector ())
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1659 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
1660 // 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
1661 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
1662
b8041f48b0ff Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents: 14789
diff changeset
1663 // 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
1664 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
1665 retval.transpose ();
10516
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1666 }
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1667 else if (idx_i.is_scalar ())
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1668 {
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1669 octave_idx_type ii = idx_i(0);
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1670 retval = Sparse<T> (1, m);
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1671 OCTAVE_LOCAL_BUFFER (octave_idx_type, ij, m);
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1672 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
1673 {
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1674 octave_quit ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1675 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
1676 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
1677 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
1678
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1679 // Scalar index - just a binary lookup.
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1680 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
1681 if (i < nzj && ridx (i+lj) == ii)
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1682 {
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1683 ij[j] = i + lj;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1684 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
1685 }
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1686 else
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1687 retval.xcidx (j+1) = retval.xcidx (j);
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1688 }
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1689
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1690 retval.change_capacity (retval.xcidx (m));
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1691
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1692 // Copy data, adjust row indices.
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1693 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
1694 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1695 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
1696 if (retval.xcidx (j+1) > i)
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1697 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1698 retval.xridx (i) = 0;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1699 retval.xdata (i) = data (ij[j]);
10442
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1700 }
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1701 }
3011d1765a6e improve sparse 2d indexing (part 2)
Jaroslav Hajek <highegg@gmail.com>
parents: 10432
diff changeset
1702 }
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1703 else if (idx_i.is_cont_range (nr, lb, ub))
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1704 {
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1705 retval = Sparse<T> (n, m);
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1706 OCTAVE_LOCAL_BUFFER (octave_idx_type, li, m);
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1707 OCTAVE_LOCAL_BUFFER (octave_idx_type, ui, m);
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1708 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
1709 {
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1710 octave_quit ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1711 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
1712 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
1713 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
1714 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
1715
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1716 // Lookup indices.
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1717 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
1718 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
1719 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
1720 }
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1721
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1722 retval.change_capacity (retval.xcidx (m));
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1723
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1724 // Copy data, adjust row indices.
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1725 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
1726 {
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1727 octave_quit ();
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1728 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
1729 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1730 retval.xdata (k) = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1731 retval.xridx (k++) = ridx (i) - lb;
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1732 }
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1733 }
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1734 }
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1735 else if (idx_i.is_permutation (nr))
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1736 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1737 // 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
1738 // Count new nonzero elements.
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1739 retval = Sparse<T> (nr, m);
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1740 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
1741 {
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1742 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
1743 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
1744 }
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1745
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1746 retval.change_capacity (retval.xcidx (m));
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1747
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1748 octave_quit ();
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1749
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1750 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
1751 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
1752 // 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
1753 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
1754 {
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1755 octave_quit ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1756 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
1757 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
1758 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
1759 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
1760 octave_idx_type uj = lj + nzj - 1;
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1761 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
1762 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1763 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
1764 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
1765 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1766 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1767 }
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1768 else
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1769 {
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1770 // Get inverse permutation.
10516
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1771 idx_vector idx_iinv = idx_i.inverse_permutation (nr);
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1772 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
1773
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1774 // Scatter buffer.
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1775 OCTAVE_LOCAL_BUFFER (T, scb, nr);
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1776 octave_idx_type *rri = retval.ridx ();
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1777
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1778 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
1779 {
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1780 octave_quit ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1781 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
1782 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
1783 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
1784 octave_idx_type li = retval.xcidx (j);
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1785 // Scatter the column, transform indices.
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1786 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
1787 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
1788
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1789 octave_quit ();
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 // Sort them.
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1792 std::sort (rri + li, rri + li + nzj);
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1793
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1794 // Gather.
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1795 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
1796 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
1797 }
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1798 }
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1799
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1800 }
10516
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1801 else if (idx_j.is_colon ())
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1802 {
21562
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21337
diff changeset
1803 // 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
1804 // 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
1805 // 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
1806 retval = transpose ();
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1807 retval = retval.index (idx_vector::colon, idx_i);
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1808 retval = retval.transpose ();
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1809 }
10468
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1810 else
197b096001b7 improve sparse 2d indexing (part 3)
Jaroslav Hajek <highegg@gmail.com>
parents: 10442
diff changeset
1811 {
10516
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1812 // A(I, J) is decomposed into A(:, J)(I, :).
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1813 retval = index (idx_vector::colon, idx_j);
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
1814 retval = retval.index (idx_i, idx_vector::colon);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1815 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1816
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1817 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1818 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1819
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1820 template <typename T>
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1821 void
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1822 Sparse<T>::assign (const idx_vector& idx, const Sparse<T>& rhs)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1823 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1824 Sparse<T> retval;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1825
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1826 assert (ndims () == 2);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1827
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1828 octave_idx_type nr = dim1 ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1829 octave_idx_type nc = dim2 ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1830 octave_idx_type nz = nnz ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1831
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1832 octave_idx_type n = numel (); // Can throw.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1833
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1834 octave_idx_type rhl = rhs.numel ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1835
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1836 if (idx.length (n) == rhl)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1837 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1838 if (rhl == 0)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1839 return;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1840
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1841 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
1842 // Try to resize first if necessary.
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1843 if (nx != n)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1844 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1845 resize1 (nx);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1846 n = numel ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1847 nr = rows ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1848 nc = cols ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1849 // nz is preserved.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1850 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1851
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1852 if (idx.is_colon ())
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1853 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1854 *this = rhs.reshape (dimensions);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1855 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1856 else if (nc == 1 && rhs.cols () == 1)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1857 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1858 // Sparse column vector to sparse column vector assignment.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1859
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1860 octave_idx_type lb, ub;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1861 if (idx.is_cont_range (nr, lb, ub))
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1862 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1863 // Special-case a contiguous range.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1864 // Look-up indices first.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1865 octave_idx_type li = lblookup (ridx (), nz, lb);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1866 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
1867 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
1868 octave_idx_type new_nz = nz - (ui - li) + rnz;
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1869
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
1870 if (new_nz >= nz && new_nz <= nzmax ())
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1871 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1872 // Adding/overwriting elements, enough capacity allocated.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1873
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1874 if (new_nz > nz)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1875 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1876 // Make room first.
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1877 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
1878 data () + nz + rnz);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1879 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
1880 ridx () + nz + rnz);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1881 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
1882
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1883 // Copy data and adjust indices from rhs.
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1884 std::copy (rhs.data (), rhs.data () + rnz, data () + li);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1885 mx_inline_add (rnz, ridx () + li, rhs.ridx (), lb);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1886 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1887 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1888 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1889 // Clearing elements or exceeding capacity, allocate afresh
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1890 // and paste pieces.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1891 const Sparse<T> tmp = *this;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1892 *this = Sparse<T> (nr, 1, new_nz);
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 // Head ...
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1895 std::copy (tmp.data (), tmp.data () + li, data ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1896 std::copy (tmp.ridx (), tmp.ridx () + li, ridx ());
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1897
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1898 // new stuff ...
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1899 std::copy (rhs.data (), rhs.data () + rnz, data () + li);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1900 mx_inline_add (rnz, ridx () + li, rhs.ridx (), lb);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1901
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1902 // ...tail
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1903 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
1904 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
1905 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
1906 ridx () + li + rnz);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1907 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1908
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1909 cidx (1) = new_nz;
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1910 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1911 else if (idx.is_range () && idx.increment () == -1)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1912 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
1913 // It's s(u:-1:l) = r. Reverse the assignment.
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1914 assign (idx.sorted (), rhs.index (idx_vector (rhl - 1, 0, -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 else if (idx.is_permutation (n))
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 *this = rhs.index (idx.inverse_permutation (n));
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1919 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1920 else if (rhs.nnz () == 0)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1921 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1922 // Elements are being zeroed.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1923 octave_idx_type *ri = ridx ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1924 for (octave_idx_type i = 0; i < rhl; i++)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1925 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1926 octave_idx_type iidx = idx(i);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1927 octave_idx_type li = lblookup (ri, nz, iidx);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1928 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
1929 xdata (li) = T ();
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1930 }
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 maybe_compress (true);
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 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1935 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1936 const Sparse<T> tmp = *this;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1937 octave_idx_type new_nz = nz + rhl;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1938 // Disassembly our matrix...
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1939 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
1940 Array<T> new_data (dim_vector (new_nz, 1));
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1941 std::copy (tmp.ridx (), tmp.ridx () + nz, new_ri.fortran_vec ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
1942 std::copy (tmp.data (), tmp.data () + nz, new_data.fortran_vec ());
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1943 // ... insert new data (densified) ...
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1944 idx.copy_data (new_ri.fortran_vec () + nz);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1945 new_data.assign (idx_vector (nz, new_nz), rhs.array_value ());
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1946 // ... reassembly.
10586
ec3cec8277df fixes for --enable-64
John W. Eaton <jwe@octave.org>
parents: 10543
diff changeset
1947 *this = Sparse<T> (new_data, new_ri,
ec3cec8277df fixes for --enable-64
John W. Eaton <jwe@octave.org>
parents: 10543
diff changeset
1948 static_cast<octave_idx_type> (0),
ec3cec8277df fixes for --enable-64
John W. Eaton <jwe@octave.org>
parents: 10543
diff changeset
1949 nr, nc, false);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1950 }
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 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1953 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1954 dim_vector save_dims = dimensions;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1955 *this = index (idx_vector::colon);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1956 assign (idx, rhs.index (idx_vector::colon));
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1957 *this = reshape (save_dims);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1958 }
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 else if (rhl == 1)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1961 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1962 rhl = idx.length (n);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1963 if (rhs.nnz () != 0)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1964 assign (idx, Sparse<T> (rhl, 1, rhs.data (0)));
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1965 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1966 assign (idx, Sparse<T> (rhl, 1));
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1967 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1968 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1969 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
1970 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1971
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
1972 template <typename T>
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1973 void
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1974 Sparse<T>::assign (const idx_vector& idx_i,
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1975 const idx_vector& idx_j, const Sparse<T>& rhs)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1976 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1977 Sparse<T> retval;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1978
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1979 assert (ndims () == 2);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1980
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1981 octave_idx_type nr = dim1 ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1982 octave_idx_type nc = dim2 ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1983 octave_idx_type nz = nnz ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1984
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1985 octave_idx_type n = rhs.rows ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1986 octave_idx_type m = rhs.columns ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
1987
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1988 // 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
1989 // Array<T>::assign function...
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
1990
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
1991 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
1992
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
1993 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
1994 {
12184
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
1995 octave_idx_type nrx;
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
1996 octave_idx_type ncx;
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
1997
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
1998 if (orig_zero_by_zero)
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
1999 {
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2000 if (idx_i.is_colon ())
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2001 {
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2002 nrx = n;
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2003
12184
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2004 if (idx_j.is_colon ())
12318
211f8c905a4f sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 12184
diff changeset
2005 ncx = m;
12184
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2006 else
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2007 ncx = idx_j.extent (nc);
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2008 }
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2009 else if (idx_j.is_colon ())
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2010 {
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2011 nrx = idx_i.extent (nr);
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2012 ncx = m;
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2013 }
12318
211f8c905a4f sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 12184
diff changeset
2014 else
211f8c905a4f sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 12184
diff changeset
2015 {
211f8c905a4f sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 12184
diff changeset
2016 nrx = idx_i.extent (nr);
211f8c905a4f sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 12184
diff changeset
2017 ncx = idx_j.extent (nc);
211f8c905a4f sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 12184
diff changeset
2018 }
12184
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2019 }
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2020 else
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2021 {
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2022 nrx = idx_i.extent (nr);
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2023 ncx = idx_j.extent (nc);
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2024 }
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2025
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2026 // Try to resize first if necessary.
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2027 if (nrx != nr || ncx != nc)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2028 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2029 resize (nrx, ncx);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2030 nr = rows ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2031 nc = cols ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2032 // nz is preserved.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2033 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2034
12184
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2035 if (n == 0 || m == 0)
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2036 return;
d8de1a28274c sparse matrix indexed assignment bug
John W. Eaton <jwe@octave.org>
parents: 11590
diff changeset
2037
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2038 if (idx_i.is_colon ())
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2039 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2040 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
2041 // 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
2042 // efficient, because the columns can stay compressed as they are.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2043 if (idx_j.is_colon ())
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2044 *this = rhs; // Shallow copy.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2045 else if (idx_j.is_cont_range (nc, lb, ub))
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2046 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2047 // 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
2048 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
2049 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
2050 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
2051 octave_idx_type new_nz = nz - (ui - li) + rnz;
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2052
20229
5dfaaaae784f Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
2053 if (new_nz >= nz && new_nz <= nzmax ())
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2054 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2055 // Adding/overwriting elements, enough capacity allocated.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2056
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2057 if (new_nz > nz)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2058 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2059 // Make room first.
21255
6209f428426c Fix memory corruption allocating to sparse arrays (bug #42825).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19861
diff changeset
2060 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
2061 data () + new_nz);
6209f428426c Fix memory corruption allocating to sparse arrays (bug #42825).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19861
diff changeset
2062 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
2063 ridx () + new_nz);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2064 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
2065 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2066
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2067 // Copy data and indices from rhs.
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2068 std::copy (rhs.data (), rhs.data () + rnz, data () + li);
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2069 std::copy (rhs.ridx (), 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
2070 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
2071 li);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2072
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2073 assert (nnz () == new_nz);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2074 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2075 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2076 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2077 // Clearing elements or exceeding capacity, allocate afresh
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2078 // and paste pieces.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2079 const Sparse<T> tmp = *this;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2080 *this = Sparse<T> (nr, nc, new_nz);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2081
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2082 // Head...
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2083 std::copy (tmp.data (), tmp.data () + li, data ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2084 std::copy (tmp.ridx (), tmp.ridx () + li, ridx ());
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2085 std::copy (tmp.cidx () + 1, tmp.cidx () + 1 + lb, cidx () + 1);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2086
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2087 // new stuff...
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2088 std::copy (rhs.data (), rhs.data () + rnz, data () + li);
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2089 std::copy (rhs.ridx (), 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
2090 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
2091 li);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2092
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2093 // ...tail.
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2094 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
2095 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
2096 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
2097 ridx () + li + rnz);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2098 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
2099 tmp.cidx () + ub + 1, new_nz - nz);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2100
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2101 assert (nnz () == new_nz);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2102 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2103 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2104 else if (idx_j.is_range () && idx_j.increment () == -1)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2105 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
2106 // 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
2107 assign (idx_i, idx_j.sorted (),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2108 rhs.index (idx_i, idx_vector (m - 1, 0, -1)));
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2109 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2110 else if (idx_j.is_permutation (nc))
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2111 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2112 *this = rhs.index (idx_i, idx_j.inverse_permutation (nc));
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2113 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2114 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2115 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2116 const Sparse<T> tmp = *this;
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2117 *this = Sparse<T> (nr, nc);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2118 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
2119
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2120 // Assemble column lengths.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2121 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
2122 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
2123
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2124 for (octave_idx_type i = 0; i < m; i++)
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 octave_idx_type j =idx_j(i);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2127 jsav[j] = i;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2128 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
2129 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2130
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2131 // Make cumulative.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2132 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
2133 xcidx (i+1) += xcidx (i);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2134
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2135 change_capacity (nnz ());
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 // Merge columns.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2138 for (octave_idx_type i = 0; i < nc; i++)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2139 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
2140 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
2141 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
2142 octave_idx_type j = jsav[i];
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2143 if (j >= 0)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2144 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2145 // from rhs
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2146 octave_idx_type k = rhs.cidx (j);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2147 std::copy (rhs.data () + k, rhs.data () + k + u - l,
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2148 xdata () + l);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2149 std::copy (rhs.ridx () + k, rhs.ridx () + k + u - l,
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2150 xridx () + l);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2151 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2152 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2153 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2154 // original
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2155 octave_idx_type k = tmp.cidx (i);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2156 std::copy (tmp.data () + k, tmp.data () + k + u - l,
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2157 xdata () + l);
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19078
diff changeset
2158 std::copy (tmp.ridx () + k, tmp.ridx () + k + u - l,
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2159 xridx () + l);
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2160 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2161 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2162
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 }
10516
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
2165 else if (nc == 1 && idx_j.is_colon_equiv (nc) && idx_i.is_vector ())
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
2166 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2167 // 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
2168 assign (idx_i, rhs);
f0266ee4aabe optimize some special indexing & assignment cases
Jaroslav Hajek <highegg@gmail.com>
parents: 10512
diff changeset
2169 }
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2170 else if (idx_j.is_colon ())
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 if (idx_i.is_permutation (nr))
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 *this = rhs.index (idx_i.inverse_permutation (nr), idx_j);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2175 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2176 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2177 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2178 // FIXME: optimize more special cases?
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2179 // 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
2180 // especially for many small columns. OTOH, transpose is an
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2181 // efficient O(nr+nc+nnz) operation.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2182 *this = transpose ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2183 assign (idx_vector::colon, idx_i, rhs.transpose ());
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2184 *this = transpose ();
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2185 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2186 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2187 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2188 {
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2189 // Split it into 2 assignments and one indexing.
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2190 Sparse<T> tmp = index (idx_vector::colon, idx_j);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2191 tmp.assign (idx_i, idx_vector::colon, rhs);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2192 assign (idx_vector::colon, idx_j, tmp);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2193 }
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 else if (m == 1 && n == 1)
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 n = idx_i.length (nr);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2198 m = idx_j.length (nc);
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2199 if (rhs.nnz () != 0)
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2200 assign (idx_i, idx_j, Sparse<T> (n, m, rhs.data (0)));
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2201 else
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2202 assign (idx_i, idx_j, Sparse<T> (n, m));
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2203 }
22600
dd80fb1ef949 maint: minor style fixes for C++ code.
John W. Eaton <jwe@octave.org>
parents: 22489
diff changeset
2204 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
2205 && (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
2206 {
3d8aee0b7415 Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20542
diff changeset
2207 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
2208 }
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2209 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2210 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
2211 }
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
2212
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2213 // Can't use versions of these in Array.cc due to duplication of the
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2214 // 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
2215 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2216 bool
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2217 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
2218 typename ref_param<T>::type b)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2219 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2220 return (a < b);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2221 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2222
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
2223 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2224 bool
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2225 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
2226 typename ref_param<T>::type b)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2227 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2228 return (a > b);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2229 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2230
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
2231 template <typename T>
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2232 Sparse<T>
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2233 Sparse<T>::sort (octave_idx_type dim, sortmode mode) const
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2234 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2235 Sparse<T> m = *this;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2236
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2237 octave_idx_type nr = m.rows ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2238 octave_idx_type nc = m.columns ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2239
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20229
diff changeset
2240 if (m.numel () < 1 || dim > 1)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2241 return m;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2242
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2243 if (dim > 0)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2244 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2245 m = m.transpose ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2246 nr = m.rows ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2247 nc = m.columns ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2248 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2249
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2250 octave_sort<T> lsort;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2251
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2252 if (mode == ASCENDING)
8752
06b9903a029b fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents: 8677
diff changeset
2253 lsort.set_compare (sparse_ascending_compare<T>);
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2254 else if (mode == DESCENDING)
8752
06b9903a029b fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents: 8677
diff changeset
2255 lsort.set_compare (sparse_descending_compare<T>);
7463
2467639bd8c0 eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents: 7433
diff changeset
2256 else
2467639bd8c0 eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents: 7433
diff changeset
2257 abort ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2258
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2259 T *v = m.data ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2260 octave_idx_type *mcidx = m.cidx ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2261 octave_idx_type *mridx = m.ridx ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2262
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2263 for (octave_idx_type j = 0; j < nc; j++)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2264 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2265 octave_idx_type ns = mcidx[j + 1] - mcidx[j];
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2266 lsort.sort (v, ns);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2267
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2268 octave_idx_type i;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2269 if (mode == ASCENDING)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2270 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2271 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
2272 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
2273 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2274 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2275 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2276 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2277 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
2278 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
2279 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2280 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2281 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
2282 mridx[k] = k;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2283 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
2284 mridx[k] = k - ns + nr;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2285
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2286 v += ns;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2287 mridx += ns;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2288 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2289
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2290 if (dim > 0)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2291 m = m.transpose ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2292
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2293 return m;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2294 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2295
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>
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2297 Sparse<T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2298 Sparse<T>::sort (Array<octave_idx_type> &sidx, octave_idx_type dim,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2299 sortmode mode) const
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2300 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2301 Sparse<T> m = *this;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2302
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2303 octave_idx_type nr = m.rows ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2304 octave_idx_type nc = m.columns ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2305
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20229
diff changeset
2306 if (m.numel () < 1 || dim > 1)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2307 {
10703
5eb420d92307 fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents: 10586
diff changeset
2308 sidx = Array<octave_idx_type> (dim_vector (nr, nc), 1);
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2309 return m;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2310 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2311
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2312 if (dim > 0)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2313 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2314 m = m.transpose ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2315 nr = m.rows ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2316 nc = m.columns ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2317 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2318
8752
06b9903a029b fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents: 8677
diff changeset
2319 octave_sort<T> indexed_sort;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2320
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2321 if (mode == ASCENDING)
8752
06b9903a029b fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents: 8677
diff changeset
2322 indexed_sort.set_compare (sparse_ascending_compare<T>);
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2323 else if (mode == DESCENDING)
8752
06b9903a029b fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents: 8677
diff changeset
2324 indexed_sort.set_compare (sparse_descending_compare<T>);
7463
2467639bd8c0 eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents: 7433
diff changeset
2325 else
2467639bd8c0 eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents: 7433
diff changeset
2326 abort ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2327
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2328 T *v = m.data ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2329 octave_idx_type *mcidx = m.cidx ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2330 octave_idx_type *mridx = m.ridx ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2331
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2332 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
2333 OCTAVE_LOCAL_BUFFER (octave_idx_type, vi, nr);
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2334
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2335 for (octave_idx_type j = 0; j < nc; j++)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2336 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2337 octave_idx_type ns = mcidx[j + 1] - mcidx[j];
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2338 octave_idx_type offset = j * nr;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2339
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2340 if (ns == 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2341 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2342 for (octave_idx_type k = 0; k < nr; k++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2343 sidx (offset + k) = k;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2344 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2345 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2346 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2347 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
2348 vi[i] = mridx[i];
06b9903a029b fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents: 8677
diff changeset
2349
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2350 indexed_sort.sort (v, vi, ns);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2351
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2352 octave_idx_type i;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2353 if (mode == ASCENDING)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2354 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2355 for (i = 0; i < ns; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2356 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
2357 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2358 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2359 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2360 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2361 for (i = 0; i < ns; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2362 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
2363 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2364 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2365
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2366 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2367 octave_idx_type jj = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2368 for (octave_idx_type k = 0; k < nr; k++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2369 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2370 if (ii < ns && mridx[ii] == k)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2371 ii++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2372 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2373 sidx (offset + jj++) = k;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2374 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2375
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2376 for (octave_idx_type k = 0; k < i; k++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2377 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2378 sidx (k + offset) = vi[k];
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2379 mridx[k] = k;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2380 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2381
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2382 for (octave_idx_type k = i; k < ns; k++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2383 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2384 sidx (k - ns + nr + offset) = vi[k];
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2385 mridx[k] = k - ns + nr;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2386 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2387
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2388 v += ns;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2389 mridx += ns;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2390 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2391 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2392
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2393 if (dim > 0)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2394 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2395 m = m.transpose ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2396 sidx = sidx.transpose ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2397 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2398
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2399 return m;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2400 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7356
diff changeset
2401
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
2402 template <typename T>
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2403 Sparse<T>
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2404 Sparse<T>::diag (octave_idx_type k) const
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2405 {
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2406 octave_idx_type nnr = rows ();
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2407 octave_idx_type nnc = cols ();
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2408 Sparse<T> d;
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2409
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2410 if (nnr == 0 || nnc == 0)
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2411 ; // do nothing
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2412 else if (nnr != 1 && nnc != 1)
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2413 {
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2414 if (k > 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2415 nnc -= k;
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2416 else if (k < 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2417 nnr += k;
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2418
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2419 if (nnr > 0 && nnc > 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2420 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2421 octave_idx_type ndiag = (nnr < nnc) ? nnr : nnc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2422
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
2423 // Count the number of nonzero elements
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2424 octave_idx_type nel = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2425 if (k > 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2426 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2427 for (octave_idx_type i = 0; i < ndiag; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2428 if (elem (i, i+k) != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2429 nel++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2430 }
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18278
diff changeset
2431 else if (k < 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2432 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2433 for (octave_idx_type i = 0; i < ndiag; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2434 if (elem (i-k, i) != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2435 nel++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2436 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2437 else
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 for (octave_idx_type i = 0; i < ndiag; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2440 if (elem (i, i) != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2441 nel++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2442 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2443
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2444 d = Sparse<T> (ndiag, 1, nel);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2445 d.xcidx (0) = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2446 d.xcidx (1) = nel;
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 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2449 if (k > 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2450 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2451 for (octave_idx_type i = 0; i < ndiag; i++)
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 T tmp = elem (i, i+k);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2454 if (tmp != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2455 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2456 d.xdata (ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2457 d.xridx (ii++) = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2458 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2459 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2460 }
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18278
diff changeset
2461 else if (k < 0)
10314
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 i = 0; i < ndiag; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2464 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2465 T tmp = elem (i-k, i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2466 if (tmp != 0.)
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 d.xdata (ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2469 d.xridx (ii++) = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2470 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2471 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2472 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2473 else
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 for (octave_idx_type i = 0; i < ndiag; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2476 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2477 T tmp = elem (i, i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2478 if (tmp != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2479 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2480 d.xdata (ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2481 d.xridx (ii++) = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2482 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2483 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2484 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2485 }
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2486 else
18278
00539b673cd4 Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
2487 {
00539b673cd4 Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
2488 // 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
2489
00539b673cd4 Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
2490 octave_idx_type nr = 0;
00539b673cd4 Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
2491 octave_idx_type nc = 1;
00539b673cd4 Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
2492 octave_idx_type nz = 0;
00539b673cd4 Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
2493
00539b673cd4 Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
2494 d = Sparse<T> (nr, nc, nz);
00539b673cd4 Sparse.cc: Fix C++ function ambiguity (bug #41145).
John W. Eaton <jwe@octave.org>
parents: 18146
diff changeset
2495 }
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2496 }
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2497 else if (nnr != 0 && nnc != 0)
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2498 {
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2499 octave_idx_type roff = 0;
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2500 octave_idx_type coff = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2501 if (k > 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2502 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2503 roff = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2504 coff = k;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2505 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2506 else if (k < 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2507 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2508 roff = -k;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2509 coff = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2510 }
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2511
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2512 if (nnr == 1)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2513 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2514 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
2515 octave_idx_type nz = nnz ();
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2516
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2517 d = Sparse<T> (n, n, nz);
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2518
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2519 if (nnz () > 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2520 {
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2521 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
2522 d.xcidx (i) = 0;
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2523
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2524 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
2525 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2526 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
2527 {
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2528 d.xdata (i) = data (i);
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2529 d.xridx (i) = j + roff;
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2530 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2531 d.xcidx (j + coff + 1) = cidx (j+1);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2532 }
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2533
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2534 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
2535 d.xcidx (i) = nz;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2536 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2537 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2538 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2539 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2540 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
2541 octave_idx_type nz = nnz ();
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2542
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2543 d = Sparse<T> (n, n, nz);
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2544
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2545 if (nnz () > 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2546 {
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2547 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
2548 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
2549
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2550 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
2551 d.xcidx (i) = 0;
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2552
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2553 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
2554 {
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2555 if (ir == i)
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2556 {
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2557 d.xdata (ii) = data (ii);
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2558 d.xridx (ii++) = ir + roff;
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2559
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2560 if (ii != nz)
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2561 ir = ridx (ii);
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2562 }
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2563 d.xcidx (i + coff + 1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2564 }
10367
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2565
173e10268080 avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents: 10352
diff changeset
2566 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
2567 d.xcidx (i) = nz;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2568 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2569 }
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2570 }
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2571
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2572 return d;
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2573 }
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7573
diff changeset
2574
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
2575 template <typename T>
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2576 Sparse<T>
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2577 Sparse<T>::cat (int dim, octave_idx_type n, const Sparse<T> *sparse_list)
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2578 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2579 // 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
2580 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
2581
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2582 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
2583 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2584 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
2585 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
2586 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2587 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
2588 (*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
2589
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2590 dim_vector dv;
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2591 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
2592 if (dim != 0 && dim != 1)
10535
3f973f6c841c improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
2593 (*current_liboctave_error_handler)
3f973f6c841c improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
2594 ("cat: invalid dimension for sparse concatenation");
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2595
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
2596 if (n == 1)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
2597 return sparse_list[0];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
2598
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
2599 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
2600 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
2601 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
2602 (*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
2603
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
2604 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
2605 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21120
diff changeset
2606
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2607 Sparse<T> retval (dv, total_nz);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11571
diff changeset
2608
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2609 if (retval.is_empty ())
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2610 return retval;
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2611
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2612 switch (dim)
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2613 {
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2614 case 0:
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2615 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2616 // 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
2617 // so we'll do it directly.
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2618 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
2619 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
2620 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10531
diff changeset
2621 octave_quit ();
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10531
diff changeset
2622
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2623 octave_idx_type rcum = 0;
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2624 for (octave_idx_type i = 0; i < n; i++)
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2625 {
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2626 const Sparse<T>& spi = sparse_list[i];
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
2627 // Skipping empty matrices. See the comment in Array.cc.
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2628 if (spi.is_empty ())
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10531
diff changeset
2629 continue;
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10531
diff changeset
2630
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
2631 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
2632 octave_idx_type ku = spi.cidx (j+1);
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2633 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
2634 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2635 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
2636 retval.xdata (l) = spi.data (k);
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2637 }
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2638
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2639 rcum += spi.rows ();
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2640 }
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2641
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2642 retval.xcidx (j+1) = l;
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2643 }
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2644
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2645 break;
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2646 }
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2647 case 1:
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2648 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10531
diff changeset
2649 octave_idx_type l = 0;
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2650 for (octave_idx_type i = 0; i < n; i++)
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2651 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10531
diff changeset
2652 octave_quit ();
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10531
diff changeset
2653
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21704
diff changeset
2654 // Skipping empty matrices. See the comment in Array.cc.
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2655 if (sparse_list[i].is_empty ())
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2656 continue;
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
2657
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10531
diff changeset
2658 octave_idx_type u = l + sparse_list[i].columns ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2659 retval.assign (idx_vector::colon, idx_vector (l, u),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
2660 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
2661 l = u;
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2662 }
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2663
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2664 break;
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2665 }
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2666 default:
10535
3f973f6c841c improve sparse concatenation operator
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
2667 assert (false);
10531
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2668 }
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2669
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2670 return retval;
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2671 }
2dd8ea8bfd71 basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10527
diff changeset
2672
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
2673 template <typename T>
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2674 Array<T>
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2675 Sparse<T>::array_value () const
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2676 {
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
2677 NoAlias< Array<T> > retval (dims (), T ());
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2678 if (rows () == 1)
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2679 {
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2680 octave_idx_type i = 0;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2681 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
2682 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2683 if (cidx (j+1) > i)
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2684 retval(j) = data (i++);
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2685 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2686 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2687 else
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2688 {
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2689 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
2690 for (octave_idx_type i = cidx (j), iu = cidx (j+1); i < iu; i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2691 retval(ridx (i), j) = data (i);
10425
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2692 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2693
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2694 return retval;
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2695 }
0677c5d80b77 rewrite 1D sparse indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
2696
21704
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2697 template <typename T>
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2698 std::istream&
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2699 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
2700 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
2701 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2702 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
2703 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
2704 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
2705
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2706 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
2707 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2708 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
2709 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
2710 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
2711 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
2712 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
2713 T tmp;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2714
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2715 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
2716 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
2717 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2718 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
2719 is >> itmp;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2720 itmp--;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2721
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2722 is >> jtmp;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2723 jtmp--;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2724
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2725 if (is.fail ())
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2726 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2727 is.clear();
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2728 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
2729 is >> err_field;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2730 (*current_liboctave_error_handler)
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2731 ("invalid sparse matrix: element %d: "
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2732 "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
2733 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
2734 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2735
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2736 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
2737 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2738 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
2739
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2740 (*current_liboctave_error_handler)
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2741 ("invalid sparse matrix: element %d: "
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2742 "row index = %d out of range",
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2743 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
2744 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2745
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2746 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
2747 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2748 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
2749
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2750 (*current_liboctave_error_handler)
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2751 ("invalid sparse matrix: element %d: "
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2752 "column index = %d out of range",
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2753 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
2754 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2755
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2756 if (jtmp < jold)
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2757 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2758 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
2759
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2760 (*current_liboctave_error_handler)
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2761 ("invalid sparse matrix: element %d:"
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2762 "column indices must appear in ascending order (%d < %d)",
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2763 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
2764 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2765 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
2766 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2767 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
2768 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
2769 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2770 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
2771 {
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2772 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
2773
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2774 (*current_liboctave_error_handler)
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2775 ("invalid sparse matrix: element %d: "
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2776 "row indices must appear in ascending order in each column "
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2777 "(%d < %d)",
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2778 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
2779 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2780
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2781 iold = itmp;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2782 jold = jtmp;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2783
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2784 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
2785
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2786 if (! is)
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2787 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
2788
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2789 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
2790 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
2791 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2792
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2793 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
2794 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
2795 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2796
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2797 return is;
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2798 }
ac59b72712fd Clearer error messages when loading buggy sparse matrix files (bug #38414)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21690
diff changeset
2799
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2800 /*
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2801 * Tests
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2802 *
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2803
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2804 %!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
2805 %! switch (dim)
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2806 %! case 11
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2807 %! x(slice) = 2;
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2808 %! case 21
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2809 %! x(slice, :) = 2;
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2810 %! case 22
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2811 %! x(:, slice) = 2;
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2812 %! otherwise
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2813 %! error ("invalid dim, '%d'", dim);
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2814 %! endswitch
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2815 %!endfunction
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2816
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2817 %!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
2818 %! switch (dim)
7546
4249c6fb6e09 Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
2819 %! case 11
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2820 %! x(slice) = 2 * ones (size (slice));
7546
4249c6fb6e09 Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
2821 %! case 21
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2822 %! 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
2823 %! case 22
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2824 %! 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
2825 %! otherwise
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2826 %! error ("invalid dim, '%d'", dim);
7546
4249c6fb6e09 Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
2827 %! endswitch
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2828 %!endfunction
7546
4249c6fb6e09 Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents: 7463
diff changeset
2829
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2830 %!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
2831 %! x = ones (size);
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2832 %! 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
2833 %! 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
2834 %! assert (nnz (s), nnz (f));
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2835 %! assert (full (s), f);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2836 %! 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
2837 %! 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
2838 %! assert (nnz (s), nnz (f));
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2839 %! assert (full (s), f);
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2840 %!endfunction
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2841
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2842 #### 1d indexing
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2843
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2844 ## size = [2 0]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2845 %!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
2846 %!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
2847 %!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
2848 %!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
2849 %!assert (set_slice (sparse (ones ([2 0])), 11, 4), sparse ([0 0; 0 2]')) # sparse different from full
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2850
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2851 ## size = [0 2]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2852 %!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
2853 %!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
2854 %!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
2855 %!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
2856 %!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
2857 %!test test_sparse_slice ([0 2], 11, [4, 4]);
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2858
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2859 ## size = [2 1]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2860 %!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
2861 %!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
2862 %!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
2863 %!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
2864 %!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
2865 %!test test_sparse_slice ([2 1], 11, [4, 4]);
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2866
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2867 ## size = [1 2]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2868 %!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
2869 %!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
2870 %!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
2871 %!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
2872 %!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
2873 %!test test_sparse_slice ([1 2], 11, [4, 4]);
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2874
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2875 ## size = [2 2]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2876 %!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
2877 %!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
2878 %!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
2879 %!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
2880 %!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
2881 %!test test_sparse_slice ([2 2], 11, [4, 4]);
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2882 # 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
2883 %!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
2884 %!error id=Octave:invalid-resize set_slice (sparse (ones ([2 2])), 11, 6)
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2885
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2886 #### 2d indexing
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2887
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2888 ## size = [2 0]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2889 %!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
2890 %!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
2891 %!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
2892 %!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
2893 %!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
2894 %!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
2895 %!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
2896 %!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
2897 %!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
2898 %!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
2899 %!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
2900 %!assert (set_slice (sparse (ones ([2 0])), 22, 4), sparse ([0 0 0 2;0 0 0 2])) # sparse different from full
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2901
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2902 ## size = [0 2]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2903 %!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
2904 %!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
2905 %!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
2906 %!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
2907 %!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
2908 %!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
2909 %!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
2910 %!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
2911 %!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
2912 %!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
2913 %!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
2914 %!assert (set_slice (sparse (ones ([0 2])), 22, 4), sparse (0,4))
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2915
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2916 ## size = [2 1]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2917 %!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
2918 %!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
2919 %!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
2920 %!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
2921 %!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
2922 %!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
2923 %!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
2924 %!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
2925 %!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
2926 %!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
2927 %!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
2928 %!test test_sparse_slice ([2 1], 22, 4);
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2929
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2930 ## size = [1 2]
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2931 %!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
2932 %!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
2933 %!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
2934 %!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
2935 %!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
2936 %!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
2937 %!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
2938 %!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
2939 %!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
2940 %!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
2941 %!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
2942 %!test test_sparse_slice ([1 2], 22, 4);
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2943
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2944 ## size = [2 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 ([2 2], 21, []);
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2946 %!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
2947 %!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
2948 %!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
2949 %!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
2950 %!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
2951 %!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
2952 %!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
2953 %!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
2954 %!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
2955 %!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
2956 %!test test_sparse_slice ([2 2], 22, 4);
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2957
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2958 %!assert <35570> (speye (3,1)(3:-1:1), sparse ([0; 0; 1]))
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2959
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2960 ## Test removing columns
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2961 %!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
2962 %! 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
2963 %! 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
2964 %! 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
2965
14790
b8041f48b0ff Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents: 14789
diff changeset
2966 %!test
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2967 %! 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
2968 %! s(1,:) = [];
b8041f48b0ff Return sparse column vectors when the indexing allows it (bug #36656)
David Bateman <dbateman@free.fr>
parents: 14789
diff changeset
2969 %! 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
2970
17278
79d4b6089968 Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents: 16933
diff changeset
2971 ## Test (bug #37321)
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2972 %!test <37321> a=sparse (0,0); assert (all (a) == sparse ([1]));
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2973 %!test <37321> a=sparse (0,1); assert (all (a) == sparse ([1]));
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2974 %!test <37321> a=sparse (1,0); assert (all (a) == sparse ([1]));
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2975 %!test <37321> a=sparse (1,0); assert (all (a,2) == sparse ([1]));
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2976 %!test <37321> a=sparse (1,0); assert (size (all (a,1)), [1 0]);
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2977 %!test <37321> a=sparse (1,1);
17285
f519560bfcb4 maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents: 17278
diff changeset
2978 %! assert (all (a) == sparse ([0]));
f519560bfcb4 maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents: 17278
diff changeset
2979 %! assert (size (all (a)), [1 1]);
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2980 %!test <37321> a=sparse (2,1);
17285
f519560bfcb4 maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents: 17278
diff changeset
2981 %! assert (all (a) == sparse ([0]));
f519560bfcb4 maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents: 17278
diff changeset
2982 %! assert (size (all (a)), [1 1]);
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2983 %!test <37321> a=sparse (1,2);
17285
f519560bfcb4 maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents: 17278
diff changeset
2984 %! assert (all (a) == sparse ([0]));
f519560bfcb4 maint: Use Octave spacing conventions in cset 79d4b6089968.
Rik <rik@octave.org>
parents: 17278
diff changeset
2985 %! assert (size (all (a)), [1 1]);
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2986 %!test <37321> a=sparse (2,2); assert (isequal (all (a), sparse ([0 0])));
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2987
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2988 ## Test assigning row to a column slice
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22402
diff changeset
2989 %!test <45589>
20673
3d8aee0b7415 Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20542
diff changeset
2990 %! 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
2991 %! b = a;
3d8aee0b7415 Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20542
diff changeset
2992 %! 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
2993 %! 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
2994 %! assert (a, b);
3d8aee0b7415 Allow assigning row vector to column of Sparse array (bug #45589).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20542
diff changeset
2995
7356
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2996 */
164e98cdee8b [project @ 2008-01-10 09:23:45 by jwe]
jwe
parents: 7326
diff changeset
2997
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
2998 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2999 void
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3000 Sparse<T>::print_info (std::ostream& os, const std::string& prefix) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3001 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3002 os << prefix << "rep address: " << rep << "\n"
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5603
diff changeset
3003 << prefix << "rep->nzmx: " << rep->nzmx << "\n"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3004 << prefix << "rep->nrows: " << rep->nrows << "\n"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3005 << prefix << "rep->ncols: " << rep->ncols << "\n"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3006 << prefix << "rep->data: " << static_cast<void *> (rep->d) << "\n"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3007 << prefix << "rep->ridx: " << static_cast<void *> (rep->r) << "\n"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3008 << prefix << "rep->cidx: " << static_cast<void *> (rep->c) << "\n"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3009 << prefix << "rep->count: " << rep->count << "\n";
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3010 }
10512
aac9f4265048 rewrite sparse indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10509
diff changeset
3011
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3012 #define INSTANTIATE_SPARSE(T, API) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3013 template class API Sparse<T>; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3014 template std::istream& \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3015 read_sparse_matrix<T> (std::istream& is, Sparse<T>& a, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3016 T (*read_fcn) (std::istream&));
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
3017