annotate liboctave/array/dim-vector.h @ 31706:597f3ee61a48 stable

update Octave Project Developers copyright for the new year
author John W. Eaton <jwe@octave.org>
date Fri, 06 Jan 2023 13:11:27 -0500
parents 796f54d4ddbf
children 21f9b34eb893
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
31706
597f3ee61a48 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
3 // Copyright (C) 2003-2023 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // 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
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
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
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
29 #define octave_dim_vector_h 1
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
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
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
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
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
37 #include <string>
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
38
30429
e38202d3628d provide header file for forward declaration of Array<T> template
John W. Eaton <jwe@octave.org>
parents: 29949
diff changeset
39 #include "Array-fwd.h"
27447
396996f1dad0 use std::atomic to implement refcount class
John W. Eaton <jwe@octave.org>
parents: 27352
diff changeset
40 #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
41 #include "oct-refcount.h"
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
42
20236
a3bf35bd5b44 doc: doxygen documentation for dim_vector header.
Carnë Draug <carandraug@octave.org>
parents: 20230
diff changeset
43 //! 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
44 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
45 //! 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
46 //! 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
47 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
48 //! @code{.cc}
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
49 //! // 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
50 //! 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
51 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
52 //! // 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
53 //! 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
54 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
55 //! // 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
56 //! 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
57 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
58 //! // 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
59 //! NDArray b (a.dims ());
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
60 //! @endcode
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
61 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
62 //! 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
63 //! 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
64 //! 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
65 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
66 //! @code{.cc}
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
67 //! dim_vector d (10, 5, 3);
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
68 //! 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
69 //! 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
70 //! @endcode
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
71 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
72 //! ## Implementation details ##
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
73 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
74 //! 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
75 //! 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
76 //! 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
77 //! 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
78 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
79 //! @verbatim
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
80 //! <count>
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
81 //! <ndims>
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
82 //! rep --> <dims[0]>
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
83 //! <dims[1]>
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
84 //! ...
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
85 //! @endverbatim
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
86 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
87 //! 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
88 //! 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
89 //! (reinterpret_cast is assumed to be an inexpensive operation).
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
90
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
91 class
11173
298a75c128ad Additional exported symbols [MSVC]
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10830
diff changeset
92 OCTAVE_API
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
93 dim_vector
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
94 {
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
95 private:
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
96
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
97 octave_idx_type m_num_dims;
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
98
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
99 octave_idx_type *m_dims;
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
100
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
101 public:
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
102
22059
b1256fb38777 dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
103 //! 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
104 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
105 //! 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
106 //! 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
107 //! (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
108 //! 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
109 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
110 //! @code{.cc}
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
111 //! dim_vector dv (7, 5);
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
112 //! Matrix mat (dv);
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
113 //! @endcode
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
114 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
115 //! 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
116 //! 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
117 //! 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
118 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
119 //! @code{.cc}
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
120 //! 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
121 //! @endcode
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
122 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
123 //! 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
124 //! 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
125 //! respectively.
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
126 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
127 //! 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
128 //! 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
129 //! is that constructor could mean:
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
130 //! - 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
131 //! - 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
132 //! - 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
133 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
134 //! 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
135 //! 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
136 //! type safety.
20208
f638a61af5a8 doxygen: improve dim_vector constructor documentation (bug #45105)
Piotr Held <pjheld@gmail.com>
parents: 19861
diff changeset
137
22059
b1256fb38777 dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
138 template <typename... Ints>
b1256fb38777 dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
139 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
140 Ints... lengths)
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
141 : 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
142 {
22277
7a6279f4018f dim_vector: fix type deduction in constructor with parameter pack (patch #9030)
Carnë Draug <carandraug@octave.org>
parents: 22222
diff changeset
143 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
144 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
145 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
146 *ptr++ = l;
22059
b1256fb38777 dim_vector: replace 7 constructors with single variadic template (patch #9030).
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
147 }
10419
afe44ee90cbd implement generic macro magic for repeated decls
Jaroslav Hajek <highegg@gmail.com>
parents: 10418
diff changeset
148
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
149 // 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
150
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
151 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
152
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
153 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
154
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
155 // Safe access to to elements
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
156
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
157 octave_idx_type& elem (int i)
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
158 {
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
159 return xelem (i);
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
160 }
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
161
23487
af2f1f3dbe06 eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents: 23449
diff changeset
162 octave_idx_type elem (int i) const { return xelem (i); }
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
163
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
164 void chop_trailing_singletons (void)
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
165 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
166 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
167 m_num_dims--;
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
168 }
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
169
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
170 OCTAVE_API void chop_all_singletons (void);
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
171
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
172 private:
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
173
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
174 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
175 : 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
176 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
177 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
178 }
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
179
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
180 public:
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
181
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
182 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
183
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
184 explicit dim_vector (void)
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
185 : 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
186 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
187 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
188 }
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
189
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
190 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
191 : 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
192 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
193 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
194 }
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
195
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
196 dim_vector (dim_vector&& dv)
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
197 : 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
198 {
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
199 *this = std::move (dv);
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
200 }
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14625
diff changeset
201
9507
b096d11237be dim_vector improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9420
diff changeset
202 static dim_vector alloc (int n)
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
203 {
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
204 return dim_vector (n);
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
205 }
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
206
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
207 dim_vector& operator = (const dim_vector& dv)
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
208 {
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
209 if (&dv != this)
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
210 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
211 delete [] m_dims;
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
212
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
213 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
214 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
215
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
216 std::copy_n (dv.m_dims, m_num_dims, m_dims);
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
217 }
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
218
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
219 return *this;
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
220 }
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
221
27352
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
222 dim_vector& operator = (dim_vector&& dv)
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
223 {
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
224 if (&dv != this)
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
225 {
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
226 // 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
227 // 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
228 // 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
229
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
230 delete [] m_dims;
27352
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
231
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
232 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
233 m_dims = dv.m_dims;
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
234
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
235 dv.m_num_dims = 0;
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
236 dv.m_dims = nullptr;
27352
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
237 }
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 return *this;
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
240 }
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
241
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
242 ~dim_vector (void)
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
243 {
27352
7335ebd4c798 define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
244 // 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
245 // 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
246 // 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
247
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
248 delete [] m_dims;
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
249 }
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
250
21509
dcee67d28570 doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents: 21244
diff changeset
251 //! Number of dimensions.
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
252 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
253 //! 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
254 //! 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
255 //! 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
256
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
257 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
258
dcee67d28570 doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents: 21244
diff changeset
259 //! Number of dimensions.
dcee67d28570 doc: doxygen documentation for dim_vector::ndims and dim_vector::length.
Carnë Draug <carandraug@octave.org>
parents: 21244
diff changeset
260 //! Synonymous with ndims().
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
261 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
262 //! 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
263 //! 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
264 //! 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
265
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
266 int length (void) const { return ndims (); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
267
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
268 octave_idx_type& operator () (int i) { return elem (i); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
269
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
270 octave_idx_type operator () (int i) const { return elem (i); }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
271
4887
bbddd4339cf2 [project @ 2004-04-30 17:08:55 by jwe]
jwe
parents: 4735
diff changeset
272 void resize (int n, int fill_value = 0)
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
273 {
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
274 if (n < 2)
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
275 n = 2;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
276
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
277 if (n == m_num_dims)
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
278 return;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
279
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
280 if (n < m_num_dims)
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
281 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
282 m_num_dims = n;
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
283 return;
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
284 }
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 octave_idx_type *new_rep = new octave_idx_type [n];
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
287
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
288 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
289 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
290
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
291 delete [] m_dims;
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
292
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
293 m_dims = new_rep;
29943
513c4fd440b1 simplify implementation of dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29887
diff changeset
294
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
295 m_num_dims = n;
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
296 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
297
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
298 OCTAVE_API std::string str (char sep = 'x') const;
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
299
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
300 bool all_zero (void) const
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
301 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
302 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
303 [] (octave_idx_type dim) { return dim == 0; });
4548
820323598f4f [project @ 2003-10-26 03:16:42 by jwe]
jwe
parents: 4543
diff changeset
304 }
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4548
diff changeset
305
10715
53253f796351 make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10681
diff changeset
306 bool empty_2d (void) const
53253f796351 make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10681
diff changeset
307 {
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
308 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
309 }
53253f796351 make [] (hopefully) more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10681
diff changeset
310
9886
cddd5c3d5f04 fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9840
diff changeset
311 bool zero_by_zero (void) const
cddd5c3d5f04 fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9840
diff changeset
312 {
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
313 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
314 }
cddd5c3d5f04 fix & extend special-case optimizations for indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9840
diff changeset
315
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4548
diff changeset
316 bool any_zero (void) const
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4548
diff changeset
317 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
318 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
319 [] (octave_idx_type dim) { return dim == 0; });
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4548
diff changeset
320 }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
321
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
322 OCTAVE_API int num_ones (void) const;
4635
f2cd320cbf6e [project @ 2003-11-20 01:48:23 by jwe]
jwe
parents: 4567
diff changeset
323
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
324 bool all_ones (void) const
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4635
diff changeset
325 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
326 return (num_ones () == ndims ());
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4635
diff changeset
327 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4635
diff changeset
328
19199
3a6fd52e1458 liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents: 17769
diff changeset
329 //! 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
330 //!
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
331 //! 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
332 //! 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
333 //! dimension vector).
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
334
9027
9a46ba093db4 generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
335 octave_idx_type numel (int n = 0) const
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
336 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
337 int n_dims = ndims ();
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
338
9027
9a46ba093db4 generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
339 octave_idx_type retval = 1;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
340
9027
9a46ba093db4 generalize dim_vector::numel
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
341 for (int i = n; i < n_dims; i++)
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
342 retval *= elem (i);
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
343
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
344 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
345 }
4673
6639c2574023 [project @ 2003-12-10 16:11:54 by jwe]
jwe
parents: 4655
diff changeset
346
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
347 //! 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
348 //! 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
349 //! 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
350 //! 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
351 //! 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
352 //! 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
353 //! indices.
9840
c0b54271904b improve safe numel() calculation for arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9743
diff changeset
354
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
355 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
356
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
357 bool any_neg (void) const
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
358 {
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
359 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
360 [] (octave_idx_type dim) { return dim < 0; });
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
361 }
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
362
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
363 OCTAVE_API dim_vector squeeze (void) const;
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10420
diff changeset
364
19199
3a6fd52e1458 liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents: 17769
diff changeset
365 //! 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
366 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
367
19199
3a6fd52e1458 liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents: 17769
diff changeset
368 //! 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
369 // 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
370 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
371
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
372 //! Force certain dimensionality, preserving numel (). Missing
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
373 //! 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
374 //! 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
375 //! (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
376
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
377 OCTAVE_API dim_vector redim (int n) const;
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
378
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10150
diff changeset
379 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
380 {
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
381 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
382 return *this;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
383 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
384 return dim_vector (numel (), 1);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
385 }
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10150
diff changeset
386
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10150
diff changeset
387 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
388 {
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
389 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
390 return *this;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
391 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
392 return dim_vector (1, numel ());
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
393 }
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10150
diff changeset
394
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23487
diff changeset
395 bool isvector (void) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
396 {
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
397 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
398 }
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
399
23386
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
400 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
401 {
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
402 int num_non_one = 0;
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
403
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
404 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
405 {
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
406 if (xelem (i) != 1)
23386
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
407 {
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
408 num_non_one++;
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
409
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
410 if (num_non_one > 1)
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
411 break;
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
412 }
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 return num_non_one == 1;
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
416 }
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 // 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
419 // 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
420
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
421 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
422 {
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
423 dim_vector orig_dims;
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 if (is_nd_vector ())
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 orig_dims = *this;
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
428
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
429 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
430 {
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
431 if (orig_dims(i) != 1)
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 orig_dims(i) = n;
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
434 break;
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
435 }
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 else
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
439 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
440
f1ea44e92df8 improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
441 return orig_dims;
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
9511
cc1fd3084cb2 implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents: 9507
diff changeset
444 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
445 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
446 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
447 {
23392
77a7f2fecd74 New xelem function for fast access to dim_vector internals.
Rik <rik@octave.org>
parents: 23386
diff changeset
448 if (xelem (i) != 1)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
449 return i;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
450 }
9511
cc1fd3084cb2 implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents: 9507
diff changeset
451
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
452 return def;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
453 }
9511
cc1fd3084cb2 implement dim_vector::first_non_singleton
Jaroslav Hajek <highegg@gmail.com>
parents: 9507
diff changeset
454
22222
8a50ab960ae6 dim-vector.h: remove duplicated code.
Carnë Draug <carandraug@octave.org>
parents: 22213
diff changeset
455 //! Linear index from an index tuple.
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
456 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
457 { return compute_index (idx, ndims ()); }
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
458
22222
8a50ab960ae6 dim-vector.h: remove duplicated code.
Carnë Draug <carandraug@octave.org>
parents: 22213
diff changeset
459 //! 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
460 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
461 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
462 octave_idx_type k = 0;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
463 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
464 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
465
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
466 return k;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
467 }
10645
8645b7087859 abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents: 10586
diff changeset
468
24624
ce2eb28e0a6d doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
469 //! 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
470 //! 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
471 //! position that was changed, or length () if just cycled over.
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
472
10645
8645b7087859 abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents: 10586
diff changeset
473 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
474 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
475 int i;
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
476 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
477 {
29944
029880dbbebb prefer xelem over indexing m_rep in dim_vector class
John W. Eaton <jwe@octave.org>
parents: 29943
diff changeset
478 if (++(*idx) == xelem(i))
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
479 *idx++ = 0;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
480 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
481 break;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
482 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
483 return i;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
484 }
9739
13b57eec9440 a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 9694
diff changeset
485
19199
3a6fd52e1458 liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents: 17769
diff changeset
486 //! Return cumulative dimensions.
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
487
9739
13b57eec9440 a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 9694
diff changeset
488 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
489 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
490 int nd = ndims ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
491 dim_vector retval = alloc (nd);
9739
13b57eec9440 a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 9694
diff changeset
492
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
493 octave_idx_type k = 1;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
494 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
495 retval.xelem(i) = (k *= xelem(i));
9739
13b57eec9440 a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 9694
diff changeset
496
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
497 return retval;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
498 }
9739
13b57eec9440 a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 9694
diff changeset
499
19199
3a6fd52e1458 liboctave/array/dim-vector.h: convert comments to doxygen
Carnë Draug <carandraug@octave.org>
parents: 17769
diff changeset
500 //! 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
501 //! required to be cumulative.
10150
3778ea95adea style fixes
John W. Eaton <jwe@octave.org>
parents: 10095
diff changeset
502
10645
8645b7087859 abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents: 10586
diff changeset
503 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
504 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
505 octave_idx_type k = idx[0];
9739
13b57eec9440 a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 9694
diff changeset
506
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
507 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
508 k += xelem(i-1) * idx[i];
9739
13b57eec9440 a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 9694
diff changeset
509
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
510 return k;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
511 }
9739
13b57eec9440 a few handy methods for dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 9694
diff changeset
512
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
513 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
514 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
515
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
516 OCTAVE_API Array<octave_idx_type> as_array (void) const;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
517 };
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
518
9694
50db3c5175b5 allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents: 9666
diff changeset
519 inline bool
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
520 operator == (const dim_vector& a, const dim_vector& b)
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
521 {
9694
50db3c5175b5 allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents: 9666
diff changeset
522 // Fast case.
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
523 if (a.m_dims == b.m_dims)
9694
50db3c5175b5 allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents: 9666
diff changeset
524 return true;
50db3c5175b5 allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents: 9666
diff changeset
525
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21574
diff changeset
526 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
527 int b_len = b.ndims ();
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
528
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
529 if (a_len != b_len)
23422
206a7eb1561b Use more std:: routines in liboctave/array header files.
Rik <rik@octave.org>
parents: 23408
diff changeset
530 return false;
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
531
29945
13e9e244284e rename dim_vector data members for clarity
John W. Eaton <jwe@octave.org>
parents: 29944
diff changeset
532 return std::equal (a.m_dims, a.m_dims + a_len, b.m_dims);
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
533 }
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
534
9694
50db3c5175b5 allow unpacked form of LU
Jaroslav Hajek <highegg@gmail.com>
parents: 9666
diff changeset
535 inline bool
4543
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
536 operator != (const dim_vector& a, const dim_vector& b)
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
537 {
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
538 return ! operator == (a, b);
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
539 }
79df15d4470c [project @ 2003-10-18 03:53:52 by jwe]
jwe
parents: 4532
diff changeset
540
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents:
diff changeset
541 #endif