Mercurial > octave
annotate liboctave/array/dim-vector.h @ 29945:13e9e244284e
rename dim_vector data members for clarity
* dim-vector.h, dim-vector.cc (dim_vector::m_dims): Rename from m_rep.
(dim_vector::m_num_dims): Rename from m_ndims to avoid possible
confusion with m_dims.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 05 Aug 2021 11:47:53 -0400 |
parents | 029880dbbebb |
children | f254c302bb9c |
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 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14625
diff
changeset
|
173 // WARNING: Only call by jit |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
174 octave_idx_type * to_jit (void) const |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14625
diff
changeset
|
175 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
176 return m_dims; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14625
diff
changeset
|
177 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14625
diff
changeset
|
178 |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
179 private: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
180 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
181 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
|
182 : 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
|
183 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
184 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
|
185 } |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
186 |
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
187 public: |
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
188 |
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
|
189 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
|
190 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
191 explicit dim_vector (void) |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
192 : 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
|
193 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
194 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
|
195 } |
4548 | 196 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
197 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
|
198 : 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
|
199 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
200 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
|
201 } |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
202 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
203 // FIXME: Should be private, but required by array constructor for jit |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
204 explicit dim_vector (octave_idx_type *r) : m_dims (r) { } |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
205 |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
206 dim_vector (dim_vector&& dv) |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
207 : 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
|
208 { |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
209 *this = std::move (dv); |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
210 } |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14625
diff
changeset
|
211 |
9507
b096d11237be
dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9420
diff
changeset
|
212 static dim_vector alloc (int n) |
10150 | 213 { |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
214 return dim_vector (n); |
10150 | 215 } |
4548 | 216 |
217 dim_vector& operator = (const dim_vector& dv) | |
218 { | |
219 if (&dv != this) | |
220 { | |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
221 delete [] m_dims; |
4548 | 222 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
223 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
|
224 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
|
225 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
226 std::copy_n (dv.m_dims, m_num_dims, m_dims); |
4548 | 227 } |
228 | |
229 return *this; | |
230 } | |
231 | |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
232 dim_vector& operator = (dim_vector&& dv) |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
233 { |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
234 if (&dv != this) |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
235 { |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
236 // 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
|
237 // 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
|
238 // 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
|
239 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
240 delete [] m_dims; |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
241 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
242 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
|
243 m_dims = dv.m_dims; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
244 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
245 dv.m_num_dims = 0; |
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
246 dv.m_dims = nullptr; |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
247 } |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
248 |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
249 return *this; |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
250 } |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
251 |
4548 | 252 ~dim_vector (void) |
253 { | |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
254 // 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
|
255 // 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
|
256 // 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
|
257 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
258 delete [] m_dims; |
4548 | 259 } |
260 | |
21509
dcee67d28570
doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents:
21244
diff
changeset
|
261 //! Number of dimensions. |
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 //! 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
|
264 //! 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
|
265 //! 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
|
266 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
267 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
|
268 |
dcee67d28570
doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents:
21244
diff
changeset
|
269 //! Number of dimensions. |
dcee67d28570
doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents:
21244
diff
changeset
|
270 //! Synonymous with ndims(). |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
271 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
272 //! 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
|
273 //! 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
|
274 //! 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
|
275 |
10150 | 276 int length (void) const { return ndims (); } |
4513 | 277 |
5275 | 278 octave_idx_type& operator () (int i) { return elem (i); } |
4513 | 279 |
5275 | 280 octave_idx_type operator () (int i) const { return elem (i); } |
4513 | 281 |
4887 | 282 void resize (int n, int fill_value = 0) |
4548 | 283 { |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
284 if (n < 2) |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
285 n = 2; |
4513 | 286 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
287 if (n == m_num_dims) |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
288 return; |
4513 | 289 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
290 if (n < m_num_dims) |
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 m_num_dims = n; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
293 return; |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
294 } |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
295 |
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
296 octave_idx_type *new_rep = new octave_idx_type [n]; |
4513 | 297 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
298 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
|
299 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
|
300 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
301 delete [] m_dims; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
302 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
303 m_dims = new_rep; |
29943
513c4fd440b1
simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
304 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
305 m_num_dims = n; |
4548 | 306 } |
4513 | 307 |
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
|
308 OCTAVE_API std::string str (char sep = 'x') const; |
4543 | 309 |
310 bool all_zero (void) const | |
4548 | 311 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
312 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
|
313 [] (octave_idx_type dim) { return dim == 0; }); |
4548 | 314 } |
4559 | 315 |
10715
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
316 bool empty_2d (void) const |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
317 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
318 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
|
319 } |
53253f796351
make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10681
diff
changeset
|
320 |
9886
cddd5c3d5f04
fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
321 bool zero_by_zero (void) const |
cddd5c3d5f04
fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
322 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
323 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
|
324 } |
cddd5c3d5f04
fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
325 |
4559 | 326 bool any_zero (void) const |
327 { | |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
328 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
|
329 [] (octave_idx_type dim) { return dim == 0; }); |
4559 | 330 } |
4567 | 331 |
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
|
332 OCTAVE_API int num_ones (void) const; |
4635 | 333 |
10150 | 334 bool all_ones (void) const |
4655 | 335 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
336 return (num_ones () == ndims ()); |
4655 | 337 } |
338 | |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
339 //! 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
|
340 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
341 //! 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
|
342 //! 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
|
343 //! dimension vector). |
4567 | 344 |
9027
9a46ba093db4
generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
345 octave_idx_type numel (int n = 0) const |
4567 | 346 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
347 int n_dims = ndims (); |
4567 | 348 |
9027
9a46ba093db4
generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
349 octave_idx_type retval = 1; |
4567 | 350 |
9027
9a46ba093db4
generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
351 for (int i = n; i < n_dims; i++) |
4567 | 352 retval *= elem (i); |
353 | |
354 return retval; | |
355 } | |
4673 | 356 |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
357 //! 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
|
358 //! 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
|
359 //! 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
|
360 //! 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
|
361 //! 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
|
362 //! 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
|
363 //! indices. |
9840
c0b54271904b
improve safe numel() calculation for arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9743
diff
changeset
|
364 |
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
|
365 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
|
366 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
367 bool any_neg (void) const |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
368 { |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
369 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
|
370 [] (octave_idx_type dim) { return dim < 0; }); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
371 } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
372 |
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
|
373 OCTAVE_API dim_vector squeeze (void) const; |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10420
diff
changeset
|
374 |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
375 //! 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
|
376 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
|
377 |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
378 //! 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
|
379 // 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
|
380 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
|
381 |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
382 //! Force certain dimensionality, preserving numel (). Missing |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
383 //! 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
|
384 //! 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
|
385 //! (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
|
386 |
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
|
387 OCTAVE_API dim_vector redim (int n) const; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
388 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10150
diff
changeset
|
389 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
|
390 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
391 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
|
392 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
393 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
394 return dim_vector (numel (), 1); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
395 } |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10150
diff
changeset
|
396 |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10150
diff
changeset
|
397 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
|
398 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
399 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
|
400 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
401 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
402 return dim_vector (1, numel ()); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
403 } |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10150
diff
changeset
|
404 |
23592
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23487
diff
changeset
|
405 bool isvector (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
406 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
407 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
|
408 } |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
409 |
23386
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
410 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
|
411 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
412 int num_non_one = 0; |
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 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
|
415 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
416 if (xelem (i) != 1) |
23386
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 num_non_one++; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
419 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
420 if (num_non_one > 1) |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
421 break; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
422 } |
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 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
425 return num_non_one == 1; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
426 } |
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 // 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
|
429 // 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
|
430 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
431 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
|
432 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
433 dim_vector orig_dims; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
434 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
435 if (is_nd_vector ()) |
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 orig_dims = *this; |
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 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
|
440 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
441 if (orig_dims(i) != 1) |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
442 { |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
443 orig_dims(i) = n; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
444 break; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
445 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
446 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
447 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
448 else |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
449 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
|
450 |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
451 return orig_dims; |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
452 } |
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
453 |
9511
cc1fd3084cb2
implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents:
9507
diff
changeset
|
454 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
|
455 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
456 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
|
457 { |
23392
77a7f2fecd74
New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents:
23386
diff
changeset
|
458 if (xelem (i) != 1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
459 return i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
460 } |
9511
cc1fd3084cb2
implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents:
9507
diff
changeset
|
461 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
462 return def; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
463 } |
9511
cc1fd3084cb2
implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents:
9507
diff
changeset
|
464 |
22222
8a50ab960ae6
dim-vector.h: remove duplicated code.
Carnë Draug <carandraug@octave.org>
parents:
22213
diff
changeset
|
465 //! Linear index from an index tuple. |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
466 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
|
467 { return compute_index (idx, ndims ()); } |
10150 | 468 |
22222
8a50ab960ae6
dim-vector.h: remove duplicated code.
Carnë Draug <carandraug@octave.org>
parents:
22213
diff
changeset
|
469 //! 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
|
470 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
|
471 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
472 octave_idx_type k = 0; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
473 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
|
474 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
|
475 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
476 return k; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
477 } |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
478 |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
479 //! 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
|
480 //! 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
|
481 //! position that was changed, or length () if just cycled over. |
10150 | 482 |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
483 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
|
484 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
485 int i; |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
486 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
|
487 { |
29944
029880dbbebb
prefer xelem over indexing m_rep in dim_vector class
John W. Eaton <jwe@octave.org>
parents:
29943
diff
changeset
|
488 if (++(*idx) == xelem(i)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
489 *idx++ = 0; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
490 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
491 break; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
492 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
493 return i; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
494 } |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
495 |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
496 //! Return cumulative dimensions. |
10150 | 497 |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
498 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
|
499 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
500 int nd = ndims (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
501 dim_vector retval = alloc (nd); |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
502 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
503 octave_idx_type k = 1; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
504 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
|
505 retval.xelem(i) = (k *= xelem(i)); |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
506 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
507 return retval; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
508 } |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
509 |
19199
3a6fd52e1458
liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents:
17769
diff
changeset
|
510 //! 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
|
511 //! required to be cumulative. |
10150 | 512 |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10586
diff
changeset
|
513 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
|
514 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
515 octave_idx_type k = idx[0]; |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
516 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
517 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
|
518 k += xelem(i-1) * idx[i]; |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
519 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
520 return k; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
521 } |
9739
13b57eec9440
a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
9694
diff
changeset
|
522 |
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
|
523 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
|
524 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
|
525 |
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
|
526 OCTAVE_API Array<octave_idx_type> as_array (void) const; |
4513 | 527 }; |
528 | |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
529 inline bool |
4543 | 530 operator == (const dim_vector& a, const dim_vector& b) |
531 { | |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
532 // Fast case. |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
533 if (a.m_dims == b.m_dims) |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
534 return true; |
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
535 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
536 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
|
537 int b_len = b.ndims (); |
4543 | 538 |
539 if (a_len != b_len) | |
23422
206a7eb1561b
Use more std:: routines in liboctave/array header files.
Rik <rik@octave.org>
parents:
23408
diff
changeset
|
540 return false; |
4543 | 541 |
29945
13e9e244284e
rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents:
29944
diff
changeset
|
542 return std::equal (a.m_dims, a.m_dims + a_len, b.m_dims); |
4543 | 543 } |
544 | |
9694
50db3c5175b5
allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents:
9666
diff
changeset
|
545 inline bool |
4543 | 546 operator != (const dim_vector& a, const dim_vector& b) |
547 { | |
548 return ! operator == (a, b); | |
549 } | |
550 | |
4513 | 551 #endif |