Mercurial > octave
annotate liboctave/array/dim-vector.h @ 29949:f254c302bb9c
remove JIT compiler from Octave sources
As stated in the NEWS file entry added with this changeset, no one
has ever seriously taken on further development of the JIT compiler in
Octave since it was first added as part of a Google Summer of Code
project in 2012 and it still does nothing significant. It is out of
date with the default interpreter that walks the parse tree. Even
though we have fixed the configure script to disable it by default,
people still ask questions about how to build it, but it doesn’t seem
that they are doing that to work on it but because they think it will
make Octave code run faster (it never did, except for some extremely
simple bits of code as examples for demonstration purposes only).
* NEWS: Note change.
* configure.ac, acinclude.m4: Eliminate checks and macros related to
the JIT compiler and LLVM.
* basics.txi, install.txi, octave.texi, vectorize.txi: Remove mention
of JIT compiler and LLVM.
* jit-ir.cc, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc,
jit-util.h, pt-jit.cc, pt-jit.h: Delete.
* libinterp/parse-tree/module.mk: Update.
* Array-jit.cc: Delete.
* libinterp/template-inst/module.mk: Update.
* test/jit.tst: Delete.
* test/module.mk: Update.
* interpreter.cc (interpreter::interpreter): Don't check options for
debug_jit or jit_compiler.
* toplev.cc (F__octave_config_info__): Remove JIT compiler and LLVM
info from struct.
* ov-base.h (octave_base_value::grab, octave_base_value::release):
Delete.
* ov-builtin.h, ov-builtin.cc (octave_builtin::to_jit,
octave_builtin::stash_jit): Delete.
(octave_builtin::m_jtype): Delete data member and all uses.
* ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_function::m_jit_info):
Delete data member and all uses.
(octave_user_function::get_info, octave_user_function::stash_info): Delete.
* options.h (DEBUG_JIT_OPTION, JIT_COMPILER_OPTION): Delete macro
definitions and all uses.
* octave.h, octave.cc (cmdline_options::cmdline_options): Don't handle
DEBUG_JIT_OPTION, JIT_COMPILER_OPTION): Delete.
(cmdline_options::debug_jit, cmdline_options::jit_compiler): Delete
functions and all uses.
(cmdline_options::m_debug_jit, cmdline_options::m_jit_compiler): Delete
data members and all uses.
(octave_getopt_options long_opts): Remove "debug-jit" and
"jit-compiler" from the list.
* pt-eval.cc (tree_evaluator::visit_simple_for_command,
tree_evaluator::visit_complex_for_command,
tree_evaluator::visit_while_command,
tree_evaluator::execute_user_function): Eliminate JIT compiler code.
* pt-loop.h, pt-loop.cc (tree_while_command::get_info,
tree_while_command::stash_info, tree_simple_for_command::get_info,
tree_simple_for_command::stash_info): Delete functions and all uses.
(tree_while_command::m_compiled, tree_simple_for_command::m_compiled):
Delete member variable and all uses.
* usage.h (usage_string, octave_print_verbose_usage_and_exit): Remove
[--debug-jit] and [--jit-compiler] from the message.
* Array.h (Array<T>::Array): Remove constructor that was only intended
to be used by the JIT compiler.
(Array<T>::jit_ref_count, Array<T>::jit_slice_data,
Array<T>::jit_dimensions, Array<T>::jit_array_rep): Delete.
* Marray.h (MArray<T>::MArray): Remove constructor that was only
intended to be used by the JIT compiler.
* NDArray.h (NDArray::NDarray): Remove constructor that was only
intended to be used by the JIT compiler.
* dim-vector.h (dim_vector::to_jit): Delete.
(dim_vector::dim_vector): Remove constructor that was only intended to
be used by the JIT compiler.
* codeql-analysis.yaml, make.yaml: Don't require llvm-dev.
* subst-config-vals.in.sh, subst-cross-config-vals.in.sh: Don't
substitute OCTAVE_CONF_LLVM_CPPFLAGS, OCTAVE_CONF_LLVM_LDFLAGS, or
OCTAVE_CONF_LLVM_LIBS.
* Doxyfile.in: Don't define HAVE_LLVM.
* aspell-octave.en.pws: Eliminate jit, JIT, and LLVM from the list of
spelling exceptions.
* build-env.h, build-env.in.cc (LLVM_CPPFLAGS, LLVM_LDFLAGS,
LLVM_LIBS): Delete variables and all uses.
* libinterp/corefcn/module.mk (%canon_reldir%_libcorefcn_la_CPPFLAGS):
Remove $(LLVM_CPPFLAGS) from the list.
* libinterp/parse-tree/module.mk (%canon_reldir%_libparse_tree_la_CPPFLAGS):
Remove $(LLVM_CPPFLAGS) from the list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 10 Aug 2021 16:42:29 -0400 |
parents | 13e9e244284e |
children | e38202d3628d |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27933
diff
changeset
|
3 // Copyright (C) 2003-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // Copyirght (C) 2009, 2010 VZLU Prague |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
25 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
26 //////////////////////////////////////////////////////////////////////// |
4513 | 27 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20236
diff
changeset
|
28 #if ! defined (octave_dim_vector_h) |
4513 | 29 #define octave_dim_vector_h 1 |
30 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
31 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
32 |
4513 | 33 #include <cassert> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
34 |
23408
0af9a1ae0912
maint: Use std::copy_n and std::fill_n for dim_vectors and idx_vectors.
Rik <rik@octave.org>
parents:
23396
diff
changeset
|
35 #include <algorithm> |
22277
7a6279f4018f
dim_vector: fix type deduction in constructor with parameter pack (patch #9030)
Carnë Draug <carandraug@octave.org>
parents:
22222
diff
changeset
|
36 #include <initializer_list> |
4543 | 37 #include <string> |
38 | |
27447
396996f1dad0
use std::atomic to implement refcount class
John W. Eaton <jwe@octave.org>
parents:
27352
diff
changeset
|
39 #include "oct-atomic.h" |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11586
diff
changeset
|
40 #include "oct-refcount.h" |
4513 | 41 |
23679
ece6f43304e5
new function to convert dim_vector to Array<octave_idx_type>
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
42 template <typename T> class Array; |
ece6f43304e5
new function to convert dim_vector to Array<octave_idx_type>
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
43 |
20236
a3bf35bd5b44
doc: doxygen documentation for dim_vector header.
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
44 //! Vector representing the dimensions (size) of an Array. |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
45 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
46 //! A dim_vector is used to represent dimensions of an Array. It is used |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
47 //! on its constructor to specify its size, or when reshaping it. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
48 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
49 //! @code{.cc} |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
50 //! // Matrix with 10 rows and 20 columns. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
51 //! Matrix m Matrix (dim_vector (10, 20)); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
52 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
53 //! // Change its size to 5 rows and 40 columns. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
54 //! Matrix m2 = m.reshape (dim_vector (5, 40)); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
55 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
56 //! // Five dimensional Array of length 10, 20, 3, 8, 7 on each dimension. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
57 //! NDArray a (dim_vector (10, 20, 3, 8, 7)); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
58 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
59 //! // Uninitialized array of same size as other. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
60 //! NDArray b (a.dims ()); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
61 //! @endcode |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
62 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
63 //! The main thing to understand about this class, is that methods such as |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
64 //! ndims() and numel(), return the value for an Array of these dimensions, |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
65 //! not the actual number of elements in the dim_vector. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
66 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
67 //! @code{.cc} |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
68 //! dim_vector d (10, 5, 3); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
69 //! octave_idx_type n = d.numel (); // returns 150 |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
70 //! octave_idx_type nd = d.ndims (); // returns 3 |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
71 //! @endcode |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
72 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
73 //! ## Implementation details ## |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
74 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
75 //! This implementation is more tricky than Array, but the big plus is that |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
76 //! dim_vector requires only one allocation instead of two. It is (slightly) |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
77 //! patterned after GCC's basic_string implementation. rep is a pointer to an |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
78 //! array of memory, comprising count, length, and the data: |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
79 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
80 //! @verbatim |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
81 //! <count> |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
82 //! <ndims> |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
83 //! rep --> <dims[0]> |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
84 //! <dims[1]> |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
85 //! ... |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
86 //! @endverbatim |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
87 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
88 //! The inlines count(), ndims() recover this data from the rep. Note |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
89 //! that rep points to the beginning of dims to grant faster access |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
90 //! (reinterpret_cast is assumed to be an inexpensive operation). |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
91 |
4513 | 92 class |
11173
298a75c128ad
Additional exported symbols [MSVC]
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10830
diff
changeset
|
93 OCTAVE_API |
4513 | 94 dim_vector |
95 { | |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
96 private: |
4513 | 97 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
98 octave_idx_type m_num_dims; |
10150 | 99 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
100 octave_idx_type *m_dims; |
4548 | 101 |
102 public: | |
103 | |
22059
b1256fb38777
dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
104 //! Construct dim_vector for a N dimensional array. |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
105 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
106 //! Each argument to constructor defines the length of an additional |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
107 //! dimension. A dim_vector always represents a minimum of 2 dimensions |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
108 //! (just like an Array has at least 2 dimensions) and there is no |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
109 //! upper limit on the number of dimensions. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
110 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
111 //! @code{.cc} |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
112 //! dim_vector dv (7, 5); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
113 //! Matrix mat (dv); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
114 //! @endcode |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
115 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
116 //! The constructed dim_vector @c dv will have two elements, @f$[7, 5]@f$, |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
117 //! one for each dimension. It can then be used to construct a Matrix |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
118 //! with such dimensions, i.e., 7 rows and 5 columns. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
119 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
120 //! @code{.cc} |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
121 //! NDArray x (dim_vector (7, 5, 10)); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
122 //! @endcode |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
123 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
124 //! This will construct a 3 dimensional NDArray of lengths 7, 5, and 10, |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
125 //! on the first, second, and third dimension (rows, columns, and pages) |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
126 //! respectively. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
127 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
128 //! Note that that there is no constructor that accepts only one |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
129 //! dimension length to avoid confusion. The source for such confusion |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
130 //! is that constructor could mean: |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
131 //! - a column vector, i.e., assume @f$[N, 1]@f$; |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
132 //! - a square matrix, i.e., as is common in Octave interpreter; |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
133 //! - support for a 1 dimensional Array (does not exist); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
134 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
135 //! Using r, c, and lengths... as arguments, allow us to check at compile |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
136 //! time that there's at least 2 dimensions specified, while maintaining |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
137 //! type safety. |
20208
f638a61af5a8
doxygen: improve dim_vector constructor documentation (bug #45105)
Piotr Held <pjheld@gmail.com>
parents:
19861
diff
changeset
|
138 |
22059
b1256fb38777
dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
139 template <typename... Ints> |
b1256fb38777
dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
140 dim_vector (const octave_idx_type r, const octave_idx_type c, |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
141 Ints... lengths) |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
142 : m_num_dims (2 + sizeof... (Ints)), m_dims (new octave_idx_type [m_num_dims]) |
22059
b1256fb38777
dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
143 { |
22277
7a6279f4018f
dim_vector: fix type deduction in constructor with parameter pack (patch #9030)
Carnë Draug <carandraug@octave.org>
parents:
22222
diff
changeset
|
144 std::initializer_list<octave_idx_type> all_lengths = {r, c, lengths...}; |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
145 octave_idx_type *ptr = m_dims; |
22277
7a6279f4018f
dim_vector: fix type deduction in constructor with parameter pack (patch #9030)
Carnë Draug <carandraug@octave.org>
parents:
22222
diff
changeset
|
146 for (const octave_idx_type l: all_lengths) |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
147 *ptr++ = l; |
22059
b1256fb38777
dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
148 } |
10419
afe44ee90cbd
implement generic macro magic for repeated decls
Jaroslav Hajek <highegg@gmail.com>
parents:
10418
diff
changeset
|
149 |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
150 // Fast access with absolutely no checking |
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
151 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
152 octave_idx_type& xelem (int i) { return m_dims[i]; } |
23396
945b53af4655
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23392
diff
changeset
|
153 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
154 octave_idx_type xelem (int i) const { return m_dims[i]; } |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
155 |
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
156 // Safe access to to elements |
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
157 |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
158 octave_idx_type& elem (int i) |
10150 | 159 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
160 return xelem (i); |
10150 | 161 } |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
162 |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23449
diff
changeset
|
163 octave_idx_type elem (int i) const { return xelem (i); } |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
164 |
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
165 void chop_trailing_singletons (void) |
10150 | 166 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
167 while (m_num_dims > 2 && xelem(m_num_dims-1) == 1) |
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
168 m_num_dims--; |
10150 | 169 } |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
170 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
171 OCTAVE_API void chop_all_singletons (void); |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
172 |
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
173 private: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
174 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
175 explicit dim_vector (octave_idx_type ndims) |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
176 : m_num_dims (ndims < 2 ? 2 : ndims), m_dims (new octave_idx_type [m_num_dims]) |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
177 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
178 std::fill_n (m_dims, m_num_dims, 0); |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
179 } |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
180 |
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
181 public: |
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
182 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
183 static OCTAVE_API octave_idx_type dim_max (void); |
10810
6683f0c9d742
make the maximum extent externally accessible
Jaroslav Hajek <highegg@gmail.com>
parents:
10715
diff
changeset
|
184 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
185 explicit dim_vector (void) |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
186 : m_num_dims (2), m_dims (new octave_idx_type [m_num_dims]) |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
187 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
188 std::fill_n (m_dims, m_num_dims, 0); |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
189 } |
4548 | 190 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
191 dim_vector (const dim_vector& dv) |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
192 : m_num_dims (dv.m_num_dims), m_dims (new octave_idx_type [m_num_dims]) |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
193 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
194 std::copy_n (dv.m_dims, m_num_dims, m_dims); |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
195 } |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
196 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
197 dim_vector (dim_vector&& dv) |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
198 : m_num_dims (0), m_dims (nullptr) |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
199 { |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
200 *this = std::move (dv); |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
201 } |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14625
diff
changeset
|
202 |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
203 static dim_vector alloc (int n) |
10150 | 204 { |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
205 return dim_vector (n); |
10150 | 206 } |
4548 | 207 |
208 dim_vector& operator = (const dim_vector& dv) | |
209 { | |
210 if (&dv != this) | |
211 { | |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
212 delete [] m_dims; |
4548 | 213 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
214 m_num_dims = dv.m_num_dims; |
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
215 m_dims = new octave_idx_type [m_num_dims]; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
216 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
217 std::copy_n (dv.m_dims, m_num_dims, m_dims); |
4548 | 218 } |
219 | |
220 return *this; | |
221 } | |
222 | |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
223 dim_vector& operator = (dim_vector&& dv) |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
224 { |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
225 if (&dv != this) |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
226 { |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
227 // Because we define a move constructor and a move assignment |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
228 // operator, m_dims may be a nullptr here. We should only need to |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
229 // protect the destructor in a similar way. |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
230 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
231 delete [] m_dims; |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
232 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
233 m_num_dims = dv.m_num_dims; |
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
234 m_dims = dv.m_dims; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
235 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
236 dv.m_num_dims = 0; |
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
237 dv.m_dims = nullptr; |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
238 } |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
239 |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
240 return *this; |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
241 } |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
242 |
4548 | 243 ~dim_vector (void) |
244 { | |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
245 // Because we define a move constructor and a move assignment |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
246 // operator, m_dims may be a nullptr here. We should only need to |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
247 // protect the move assignment operator in a similar way. |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
248 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
249 delete [] m_dims; |
4548 | 250 } |
251 | |
21509
dcee67d28570
doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents:
21244
diff
changeset
|
252 //! Number of dimensions. |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
253 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
254 //! Returns the number of dimensions of the dim_vector. This is number of |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
255 //! elements in the dim_vector including trailing singletons. It is also |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
256 //! the number of dimensions an Array with this dim_vector would have. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
257 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
258 octave_idx_type ndims (void) const { return m_num_dims; } |
21509
dcee67d28570
doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents:
21244
diff
changeset
|
259 |
dcee67d28570
doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents:
21244
diff
changeset
|
260 //! Number of dimensions. |
dcee67d28570
doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents:
21244
diff
changeset
|
261 //! Synonymous with ndims(). |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
262 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
263 //! While this method is not officially deprecated, consider using ndims() |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
264 //! instead to avoid confusion. Array does not have length because of its |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
265 //! odd definition as length of the longest dimension. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
266 |
10150 | 267 int length (void) const { return ndims (); } |
4513 | 268 |
5275 | 269 octave_idx_type& operator () (int i) { return elem (i); } |
4513 | 270 |
5275 | 271 octave_idx_type operator () (int i) const { return elem (i); } |
4513 | 272 |
4887 | 273 void resize (int n, int fill_value = 0) |
4548 | 274 { |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
275 if (n < 2) |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
276 n = 2; |
4513 | 277 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
278 if (n == m_num_dims) |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
279 return; |
4513 | 280 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
281 if (n < m_num_dims) |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
282 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
283 m_num_dims = n; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
284 return; |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
285 } |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
286 |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
287 octave_idx_type *new_rep = new octave_idx_type [n]; |
4513 | 288 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
289 std::copy_n (m_dims, m_num_dims, new_rep); |
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
290 std::fill_n (new_rep + m_num_dims, n - m_num_dims, fill_value); |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
291 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
292 delete [] m_dims; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
293 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
294 m_dims = new_rep; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
295 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
296 m_num_dims = n; |
4548 | 297 } |
4513 | 298 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
299 OCTAVE_API std::string str (char sep = 'x') const; |
4543 | 300 |
301 bool all_zero (void) const | |
4548 | 302 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
303 return std::all_of (m_dims, m_dims + ndims (), |
23422
206a7eb1561b
Use more std:: routines in liboctave/array header files.
Rik <rik@octave.org>
parents:
23408
diff
changeset
|
304 [] (octave_idx_type dim) { return dim == 0; }); |
4548 | 305 } |
4559 | 306 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
307 bool empty_2d (void) const |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
308 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
309 return ndims () == 2 && (xelem (0) == 0 || xelem (1) == 0); |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
310 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
311 |
9886
cddd5c3d5f04
fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
312 bool zero_by_zero (void) const |
cddd5c3d5f04
fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
313 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
314 return ndims () == 2 && xelem (0) == 0 && xelem (1) == 0; |
9886
cddd5c3d5f04
fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
315 } |
cddd5c3d5f04
fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
316 |
4559 | 317 bool any_zero (void) const |
318 { | |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
319 return std::any_of (m_dims, m_dims + ndims (), |
23422
206a7eb1561b
Use more std:: routines in liboctave/array header files.
Rik <rik@octave.org>
parents:
23408
diff
changeset
|
320 [] (octave_idx_type dim) { return dim == 0; }); |
4559 | 321 } |
4567 | 322 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
323 OCTAVE_API int num_ones (void) const; |
4635 | 324 |
10150 | 325 bool all_ones (void) const |
4655 | 326 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
327 return (num_ones () == ndims ()); |
4655 | 328 } |
329 | |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
330 //! Number of elements that a matrix with this dimensions would have. |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
331 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
332 //! Return the number of elements that a matrix with this dimension |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
333 //! vector would have, NOT the number of dimensions (elements in the |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
334 //! dimension vector). |
4567 | 335 |
9027
9a46ba093db4
generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
336 octave_idx_type numel (int n = 0) const |
4567 | 337 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
338 int n_dims = ndims (); |
4567 | 339 |
9027
9a46ba093db4
generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
340 octave_idx_type retval = 1; |
4567 | 341 |
9027
9a46ba093db4
generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
342 for (int i = n; i < n_dims; i++) |
4567 | 343 retval *= elem (i); |
344 | |
345 return retval; | |
346 } | |
4673 | 347 |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
348 //! The following function will throw a std::bad_alloc () |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
349 //! exception if the requested size is larger than can be indexed by |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
350 //! octave_idx_type. This may be smaller than the actual amount of |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
351 //! memory that can be safely allocated on a system. However, if we |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
352 //! don't fail here, we can end up with a mysterious crash inside a |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
353 //! function that is iterating over an array using octave_idx_type |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
354 //! indices. |
9840
c0b54271904b
improve safe numel() calculation for arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9743
diff
changeset
|
355 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
356 OCTAVE_API octave_idx_type safe_numel (void) const; |
9840
c0b54271904b
improve safe numel() calculation for arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9743
diff
changeset
|
357 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
358 bool any_neg (void) const |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
359 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
360 return std::any_of (m_dims, m_dims + ndims (), |
23422
206a7eb1561b
Use more std:: routines in liboctave/array header files.
Rik <rik@octave.org>
parents:
23408
diff
changeset
|
361 [] (octave_idx_type dim) { return dim < 0; }); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
362 } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
363 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
364 OCTAVE_API dim_vector squeeze (void) const; |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10420
diff
changeset
|
365 |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
366 //! This corresponds to cat(). |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
367 OCTAVE_API bool concat (const dim_vector& dvb, int dim); |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
368 |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
369 //! This corresponds to [,] (horzcat, dim = 0) and [;] (vertcat, dim = 1). |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
370 // The rules are more relaxed here. |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
371 OCTAVE_API bool hvcat (const dim_vector& dvb, int dim); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
372 |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
373 //! Force certain dimensionality, preserving numel (). Missing |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
374 //! dimensions are set to 1, redundant are folded into the trailing |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
375 //! one. If n = 1, the result is 2d and the second dim is 1 |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
376 //! (dim_vectors are always at least 2D). |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
377 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
378 OCTAVE_API dim_vector redim (int n) const; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
379 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10150
diff
changeset
|
380 dim_vector as_column (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
381 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
382 if (ndims () == 2 && xelem (1) == 1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
383 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
384 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
385 return dim_vector (numel (), 1); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
386 } |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10150
diff
changeset
|
387 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10150
diff
changeset
|
388 dim_vector as_row (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
389 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
390 if (ndims () == 2 && xelem (0) == 1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
391 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
392 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
393 return dim_vector (1, numel ()); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
394 } |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10150
diff
changeset
|
395 |
23592
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23487
diff
changeset
|
396 bool isvector (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
397 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
398 return (ndims () == 2 && (xelem (0) == 1 || xelem (1) == 1)); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
399 } |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
400 |
23386
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
401 bool is_nd_vector (void) const |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
402 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
403 int num_non_one = 0; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
404 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
405 for (int i = 0; i < ndims (); i++) |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
406 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
407 if (xelem (i) != 1) |
23386
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
408 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
409 num_non_one++; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
410 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
411 if (num_non_one > 1) |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
412 break; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
413 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
414 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
415 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
416 return num_non_one == 1; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
417 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
418 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
419 // Create a vector with length N. If this object is a vector, |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
420 // preserve the orientation, otherwise, create a column vector. |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
421 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
422 dim_vector make_nd_vector (octave_idx_type n) const |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
423 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
424 dim_vector orig_dims; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
425 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
426 if (is_nd_vector ()) |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
427 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
428 orig_dims = *this; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
429 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
430 for (int i = 0; i < orig_dims.ndims (); i++) |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
431 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
432 if (orig_dims(i) != 1) |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
433 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
434 orig_dims(i) = n; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
435 break; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
436 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
437 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
438 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
439 else |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
440 orig_dims = dim_vector (n, 1); |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
441 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
442 return orig_dims; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
443 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
444 |
9511
cc1fd3084cb2
implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents:
9507
diff
changeset
|
445 int first_non_singleton (int def = 0) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
446 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
447 for (int i = 0; i < ndims (); i++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
448 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
449 if (xelem (i) != 1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
450 return i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
451 } |
9511
cc1fd3084cb2
implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents:
9507
diff
changeset
|
452 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
453 return def; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
454 } |
9511
cc1fd3084cb2
implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents:
9507
diff
changeset
|
455 |
22222
8a50ab960ae6
dim-vector.h: remove duplicated code.
Carnë Draug <carandraug@octave.org>
parents:
22213
diff
changeset
|
456 //! Linear index from an index tuple. |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
457 octave_idx_type compute_index (const octave_idx_type *idx) const |
22222
8a50ab960ae6
dim-vector.h: remove duplicated code.
Carnë Draug <carandraug@octave.org>
parents:
22213
diff
changeset
|
458 { return compute_index (idx, ndims ()); } |
10150 | 459 |
22222
8a50ab960ae6
dim-vector.h: remove duplicated code.
Carnë Draug <carandraug@octave.org>
parents:
22213
diff
changeset
|
460 //! Linear index from an incomplete index tuple (nidx < length ()). |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
461 octave_idx_type compute_index (const octave_idx_type *idx, int nidx) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
462 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
463 octave_idx_type k = 0; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
464 for (int i = nidx - 1; i >= 0; i--) |
29944
029880dbbebb
prefer xelem over indexing m_rep in dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29943
diff
changeset
|
465 k = xelem(i) * k + idx[i]; |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
466 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
467 return k; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
468 } |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
469 |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
470 //! Increment a multi-dimensional index tuple, optionally starting |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
471 //! from an offset position and return the index of the last index |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
472 //! position that was changed, or length () if just cycled over. |
10150 | 473 |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
474 int increment_index (octave_idx_type *idx, int start = 0) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
475 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
476 int i; |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
477 for (i = start; i < ndims (); i++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
478 { |
29944
029880dbbebb
prefer xelem over indexing m_rep in dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29943
diff
changeset
|
479 if (++(*idx) == xelem(i)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
480 *idx++ = 0; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
481 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
482 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
483 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
484 return i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
485 } |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
486 |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
487 //! Return cumulative dimensions. |
10150 | 488 |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
489 dim_vector cumulative (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
490 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
491 int nd = ndims (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
492 dim_vector retval = alloc (nd); |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
493 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
494 octave_idx_type k = 1; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
495 for (int i = 0; i < nd; i++) |
29944
029880dbbebb
prefer xelem over indexing m_rep in dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29943
diff
changeset
|
496 retval.xelem(i) = (k *= xelem(i)); |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
497 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
498 return retval; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
499 } |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
500 |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
501 //! Compute a linear index from an index tuple. Dimensions are |
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
502 //! required to be cumulative. |
10150 | 503 |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
504 octave_idx_type cum_compute_index (const octave_idx_type *idx) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
505 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
506 octave_idx_type k = idx[0]; |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
507 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
508 for (int i = 1; i < ndims (); i++) |
29944
029880dbbebb
prefer xelem over indexing m_rep in dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29943
diff
changeset
|
509 k += xelem(i-1) * idx[i]; |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
510 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
511 return k; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
512 } |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
513 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
514 friend OCTAVE_API bool |
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
515 operator == (const dim_vector& a, const dim_vector& b); |
23679
ece6f43304e5
new function to convert dim_vector to Array<octave_idx_type>
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
516 |
29646
3e8bc8bee8e9
liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29358
diff
changeset
|
517 OCTAVE_API Array<octave_idx_type> as_array (void) const; |
4513 | 518 }; |
519 | |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
520 inline bool |
4543 | 521 operator == (const dim_vector& a, const dim_vector& b) |
522 { | |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
523 // Fast case. |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
524 if (a.m_dims == b.m_dims) |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
525 return true; |
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
526 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
527 int a_len = a.ndims (); |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
528 int b_len = b.ndims (); |
4543 | 529 |
530 if (a_len != b_len) | |
23422
206a7eb1561b
Use more std:: routines in liboctave/array header files.
Rik <rik@octave.org>
parents:
23408
diff
changeset
|
531 return false; |
4543 | 532 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
533 return std::equal (a.m_dims, a.m_dims + a_len, b.m_dims); |
4543 | 534 } |
535 | |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
536 inline bool |
4543 | 537 operator != (const dim_vector& a, const dim_vector& b) |
538 { | |
539 return ! operator == (a, b); | |
540 } | |
541 | |
4513 | 542 #endif |