Mercurial > octave
annotate liboctave/array/Array.h @ 30429:e38202d3628d stable
provide header file for forward declaration of Array<T> template
* Array-fwd.h: New file.
* liboctave/array/module.mk: Update.
* oct-stream.h, pr-output.h, Array.h, Range.h, Sparse.h, dim-vector.h,
idx-vector.h, oct-spparms.h, qr.h, oct-base64.h, url-transfer.h:
Include Array-fwd.h instead of repeating Array<T> template declaration
in each file.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 04 Dec 2021 08:40:07 -0500 |
parents | f3f3e3793fb5 |
children | 298995435071 |
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:
27957
diff
changeset
|
3 // Copyright (C) 1993-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 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
228 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
26 #if ! defined (octave_Array_h) |
382 | 27 #define octave_Array_h 1 |
28 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
30 |
1366 | 31 #include <cassert> |
4152 | 32 #include <cstddef> |
3613 | 33 |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
34 #include <algorithm> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
35 #include <iosfwd> |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
36 #include <string> |
3933 | 37 |
30429
e38202d3628d
provide header file for forward declaration of Array<T> template
John W. Eaton <jwe@octave.org>
parents:
30394
diff
changeset
|
38 #include "Array-fwd.h" |
4513 | 39 #include "dim-vector.h" |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
40 #include "idx-vector.h" |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
41 #include "lo-error.h" |
8725 | 42 #include "lo-traits.h" |
3613 | 43 #include "lo-utils.h" |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23420
diff
changeset
|
44 #include "oct-refcount.h" |
7433 | 45 #include "oct-sort.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
46 #include "quit.h" |
7433 | 47 |
22273
91c5442ea9fd
doc: doxygen explaining Array<T>.
Carnë Draug <carandraug@octave.org>
parents:
22139
diff
changeset
|
48 //! N Dimensional Array with copy-on-write semantics. |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
49 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
50 //! The Array class is at the root of Octave. It provides a container |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
51 //! with an arbitrary number of dimensions. The operator () provides |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
52 //! access to individual elements via subscript and linear indexing. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
53 //! Indexing starts at 0. Arrays are column-major order as in Fortran. |
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 //! @code{.cc} |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
56 //! // 3 D Array with 10 rows, 20 columns, and 5 pages, filled with 7.0 |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
57 //! Array<double> A Array<double (dim_vector (10, 20, 5), 7.0); |
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 //! // set value for row 0, column 10, and page 3 |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
60 //! A(0, 10, 3) = 2.5; |
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 //! // get value for row 1, column 2, and page 0 |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
63 //! double v = A(1, 2, 0); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
64 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
65 //! // get value for 25th element (row 4, column 3, page 1) |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
66 //! double v = A(24); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
67 //! @endcode |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
68 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
69 //! ## Notes on STL compatibility |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
70 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
71 //! ### size() and length() |
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 //! To access the total number of elements in an Array, use numel() |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
74 //! which is short for number of elements and is equivalent to the |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
75 //! Octave function with same name. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
76 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
77 //! @code{.cc} |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
78 //! Array<int> A (dim_vector (10, 20, 4), 1); |
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 //! octave_idx_type n = A.numel (); // returns 800 (10x20x4) |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
81 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
82 //! octave_idx_type nr = A.size (0); // returns 10 (number of rows/dimension 0) |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
83 //! octave_idx_type nc = A.size (1); // returns 20 (number of columns) |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
84 //! octave_idx_type nc = A.size (2); // returns 4 (size of dimension 3) |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
85 //! octave_idx_type l6 = A.size (6); // returns 1 (implicit singleton dimension) |
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 //! // Alternatively, get a dim_vector which represents the dimensions. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
88 //! dim_vector dims = A.dims (); |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
89 //! @endcode |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
90 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
91 //! The methods size() and length() as they exist in the STL cause |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
92 //! confusion in the context of a N dimensional array. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
93 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
94 //! The size() of an array is the length of all dimensions. In Octave, |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
95 //! the size() function returns a row vector with the length of each |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
96 //! dimension, or the size of a specific dimension. Only the latter is |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
97 //! present in liboctave. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
98 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
99 //! Since there is more than 1 dimension, length() would not make sense |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
100 //! without expliciting which dimension. If the function existed, which |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
101 //! length should it return? Octave length() function returns the length |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
102 //! of the longest dimension which is an odd definition, only useful for |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
103 //! vectors and square matrices. The alternatives numel(), rows(), |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26569
diff
changeset
|
104 //! columns(), and size(d) are more explicit and recommended. |
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 //! ### size_type |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
107 //! |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
26574
diff
changeset
|
108 //! Array::size_type is 'octave_idx_type' which is a typedef for 'int' |
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
26574
diff
changeset
|
109 //! or 'long int', depending whether Octave was configured for 64-bit |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
110 //! indexing. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
111 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
112 //! This is a signed integer which may cause problems when mixed with |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
113 //! STL containers. The reason is that Octave interacts with Fortran |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
114 //! routines, providing an interface many Fortran numeric libraries. |
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 //! ## Subclasses |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
117 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
118 //! The following subclasses specializations, will be of most use: |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
119 //! - Matrix: Array<double> with only 2 dimensions |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
120 //! - ComplexMatrix: Array<std::complex<double>> with only 2 dimensions |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
121 //! - boolNDArray: N dimensional Array<bool> |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
122 //! - ColumnVector: Array<double> with 1 column |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
123 //! - string_vector: Array<std::string> with 1 column |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
124 //! - Cell: Array<octave_value>, equivalent to an Octave cell. |
22279
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
125 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
126 template <typename T> |
3585 | 127 class |
128 Array | |
228 | 129 { |
3504 | 130 protected: |
1619 | 131 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
132 //! The real representation of all arrays. |
1735 | 133 class ArrayRep |
134 { | |
135 public: | |
136 | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
137 T *m_data; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
138 octave_idx_type m_len; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
139 octave::refcount<octave_idx_type> m_count; |
1735 | 140 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
141 ArrayRep (T *d, octave_idx_type l) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
142 : m_data (new T [l]), m_len (l), m_count (1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
143 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
144 std::copy_n (d, l, m_data); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
145 } |
10364
96ed7c629bbd
remove dangerous pointer-acquiring Array ctors
Jaroslav Hajek <highegg@gmail.com>
parents:
10358
diff
changeset
|
146 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
147 template <typename U> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
148 ArrayRep (U *d, octave_idx_type l) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
149 : m_data (new T [l]), m_len (l), m_count (1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
150 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
151 std::copy_n (d, l, m_data); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
152 } |
1735 | 153 |
23401
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23386
diff
changeset
|
154 // Use new instead of setting data to 0 so that fortran_vec and |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23386
diff
changeset
|
155 // data always return valid addresses, even for zero-size arrays. |
e0c20a22da7e
eliminate some errors exposed by -fsanitize=undefined
John W. Eaton <jwe@octave.org>
parents:
23386
diff
changeset
|
156 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
157 ArrayRep (void) : m_data (new T [0]), m_len (0), m_count (1) { } |
1735 | 158 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
159 explicit ArrayRep (octave_idx_type n) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
160 : m_data (new T [n]), m_len (n), m_count (1) { } |
1735 | 161 |
5275 | 162 explicit ArrayRep (octave_idx_type n, const T& val) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
163 : m_data (new T [n]), m_len (n), m_count (1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
164 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
165 std::fill_n (m_data, n, val); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
166 } |
4513 | 167 |
30227
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
168 explicit ArrayRep (T *ptr, const dim_vector& dv) |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
169 : m_data (ptr), m_len (dv.safe_numel ()), m_count (1) |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
170 { } |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
171 |
1735 | 172 ArrayRep (const ArrayRep& a) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
173 : m_data (new T [a.m_len]), m_len (a.m_len), m_count (1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
174 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
175 std::copy_n (a.m_data, a.m_len, m_data); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
176 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
177 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
178 ~ArrayRep (void) { delete [] m_data; } |
1735 | 179 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
180 octave_idx_type numel (void) const { return m_len; } |
1735 | 181 |
4517 | 182 // No assignment! |
183 | |
29946
3e5e88d9c85f
tag ArrayRep copy assignment operator with =delete
John W. Eaton <jwe@octave.org>
parents:
29937
diff
changeset
|
184 ArrayRep& operator = (const ArrayRep&) = delete; |
1735 | 185 }; |
186 | |
4513 | 187 //-------------------------------------------------------------------- |
188 | |
6884 | 189 public: |
190 | |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
191 void make_unique (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
192 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
193 if (m_rep->m_count > 1) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
194 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
195 ArrayRep *r = new ArrayRep (m_slice_data, m_slice_len); |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12125
diff
changeset
|
196 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
197 if (--m_rep->m_count == 0) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
198 delete m_rep; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
199 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
200 m_rep = r; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
201 m_slice_data = m_rep->m_data; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
202 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
203 } |
238 | 204 |
5900 | 205 typedef T element_type; |
206 | |
22279
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
207 typedef T value_type; |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
208 |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
209 //! Used for operator(), and returned by numel() and size() |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
210 //! (beware: signed integer) |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
211 typedef octave_idx_type size_type; |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
212 |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
213 typedef typename ref_param<T>::type crefT; |
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
214 |
8725 | 215 typedef bool (*compare_fcn_type) (typename ref_param<T>::type, |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
216 typename ref_param<T>::type); |
8725 | 217 |
8524
937921654627
clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
218 protected: |
4902 | 219 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
220 dim_vector m_dimensions; |
4518 | 221 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
222 typename Array<T>::ArrayRep *m_rep; |
4513 | 223 |
8531
b01fef323c24
add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents:
8524
diff
changeset
|
224 // Rationale: |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
225 // m_slice_data is a pointer to m_rep->m_data, denoting together with m_slice_len the |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
226 // actual portion of the data referenced by this Array<T> object. This |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
227 // allows to make shallow copies not only of a whole array, but also of |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
228 // contiguous subranges. Every time m_rep is directly manipulated, m_slice_data |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
229 // and m_slice_len need to be properly updated. |
8531
b01fef323c24
add some explaining comments
Jaroslav Hajek <highegg@gmail.com>
parents:
8524
diff
changeset
|
230 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
231 T *m_slice_data; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
232 octave_idx_type m_slice_len; |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
233 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
234 //! slice constructor |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
235 Array (const Array<T>& a, const dim_vector& dv, |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
236 octave_idx_type l, octave_idx_type u) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
237 : m_dimensions (dv), m_rep(a.m_rep), m_slice_data (a.m_slice_data+l), m_slice_len (u-l) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
238 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
239 m_rep->m_count++; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
240 m_dimensions.chop_trailing_singletons (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
241 } |
4513 | 242 |
243 private: | |
244 | |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
245 static OCTARRAY_API typename Array<T>::ArrayRep *nil_rep (void); |
238 | 246 |
228 | 247 public: |
238 | 248 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
249 //! Empty ctor (0 by 0). |
1550 | 250 Array (void) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
251 : m_dimensions (), m_rep (nil_rep ()), m_slice_data (m_rep->m_data), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
252 m_slice_len (m_rep->m_len) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
253 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
254 m_rep->m_count++; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
255 } |
1550 | 256 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
257 //! nD uninitialized ctor. |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
258 explicit Array (const dim_vector& dv) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
259 : m_dimensions (dv), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
260 m_rep (new typename Array<T>::ArrayRep (dv.safe_numel ())), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
261 m_slice_data (m_rep->m_data), m_slice_len (m_rep->m_len) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
262 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
263 m_dimensions.chop_trailing_singletons (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
264 } |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
265 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
266 //! nD initialized ctor. |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
267 explicit Array (const dim_vector& dv, const T& val) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
268 : m_dimensions (dv), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
269 m_rep (new typename Array<T>::ArrayRep (dv.safe_numel ())), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
270 m_slice_data (m_rep->m_data), m_slice_len (m_rep->m_len) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
271 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
272 fill (val); |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
273 m_dimensions.chop_trailing_singletons (); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
274 } |
4513 | 275 |
30227
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
276 // Construct an Array from a pointer to an externally allocated array |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
277 // of values. PTR must be allocated with operator new. The Array |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
278 // object takes ownership of PTR and will delete it when the Array |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
279 // object is deleted. The dimension vector DV must be consistent with |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
280 // the size of the allocated PTR array. |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
281 |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
282 explicit Array (T *ptr, const dim_vector& dv) |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
283 : m_dimensions (dv), |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
284 m_rep (new typename Array<T>::ArrayRep (ptr, dv)), |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
285 m_slice_data (m_rep->m_data), m_slice_len (m_rep->m_len) |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
286 { |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
287 m_dimensions.chop_trailing_singletons (); |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
288 } |
b00ff462e0f2
improve efficiency of mxArray -> octave_value conversion
John W. Eaton <jwe@octave.org>
parents:
29954
diff
changeset
|
289 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
290 //! Reshape constructor. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
291 OCTARRAY_API Array (const Array<T>& a, const dim_vector& dv); |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
292 |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
293 //! Constructor from standard library sequence containers. |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
294 template<template <typename...> class Container> |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
295 Array (const Container<T>& a, const dim_vector& dv); |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
296 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
297 //! Type conversion case. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
298 template <typename U> |
4902 | 299 Array (const Array<U>& a) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
300 : m_dimensions (a.dims ()), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
301 m_rep (new typename Array<T>::ArrayRep (a.data (), a.numel ())), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
302 m_slice_data (m_rep->m_data), m_slice_len (m_rep->m_len) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
303 { } |
4902 | 304 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
305 //! No type conversion case. |
4513 | 306 Array (const Array<T>& a) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
307 : m_dimensions (a.m_dimensions), m_rep (a.m_rep), m_slice_data (a.m_slice_data), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
308 m_slice_len (a.m_slice_len) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
309 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
310 m_rep->m_count++; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
311 } |
1550 | 312 |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
313 Array (Array<T>&& a) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
314 : m_dimensions (std::move (a.m_dimensions)), m_rep (a.m_rep), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
315 m_slice_data (a.m_slice_data), m_slice_len (a.m_slice_len) |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
316 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
317 a.m_rep = nullptr; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
318 a.m_slice_data = nullptr; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
319 a.m_slice_len = 0; |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
320 } |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
321 |
4513 | 322 public: |
323 | |
15216
dd7c37ceb800
avoid GCC warning by declaring Array destructor virtual
John W. Eaton <jwe@octave.org>
parents:
15212
diff
changeset
|
324 virtual ~Array (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
325 { |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
326 // Because we define a move constructor and a move assignment |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
327 // operator, m_rep 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:
27216
diff
changeset
|
328 // protect the move assignment operator in a similar way. |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
329 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
330 if (m_rep && --m_rep->m_count == 0) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
331 delete m_rep; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
332 } |
228 | 333 |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
334 Array<T>& operator = (const Array<T>& a) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
335 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
336 if (this != &a) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
337 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
338 if (--m_rep->m_count == 0) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
339 delete m_rep; |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
340 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
341 m_rep = a.m_rep; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
342 m_rep->m_count++; |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
343 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
344 m_dimensions = a.m_dimensions; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
345 m_slice_data = a.m_slice_data; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
346 m_slice_len = a.m_slice_len; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
347 } |
9556
948795dc1974
make a few Array methods inline
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
348 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
349 return *this; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
350 } |
4513 | 351 |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
352 Array<T>& operator = (Array<T>&& a) |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
353 { |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
354 if (this != &a) |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
355 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
356 m_dimensions = std::move (a.m_dimensions); |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
357 |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
358 // Because we define a move constructor and a move assignment |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
359 // operator, m_rep 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:
27216
diff
changeset
|
360 // protect the destructor in a similar way. |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
361 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
362 if (m_rep && --m_rep->m_count == 0) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
363 delete m_rep; |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
364 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
365 m_rep = a.m_rep; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
366 m_slice_data = a.m_slice_data; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
367 m_slice_len = a.m_slice_len; |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
368 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
369 a.m_rep = nullptr; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
370 a.m_slice_data = nullptr; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
371 a.m_slice_len = 0; |
27352
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
372 } |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
373 |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
374 return *this; |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
375 } |
7335ebd4c798
define some move constructors and assignment operators
John W. Eaton <jwe@octave.org>
parents:
27216
diff
changeset
|
376 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
377 OCTARRAY_API void fill (const T& val); |
9624
3fc7272937ce
implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
9556
diff
changeset
|
378 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
379 OCTARRAY_API void clear (void); |
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
380 OCTARRAY_API void clear (const dim_vector& dv); |
9624
3fc7272937ce
implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
9556
diff
changeset
|
381 |
3fc7272937ce
implement Array<T>::clear overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
9556
diff
changeset
|
382 void clear (octave_idx_type r, octave_idx_type c) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
383 { clear (dim_vector (r, c)); } |
238 | 384 |
20212
6af35d4f1ba4
doxygen: document Array::length() and similar methods (bug #45138)
Piotr Held <pjheld@gmail.com>
parents:
19861
diff
changeset
|
385 //! Number of elements in the array. |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
386 octave_idx_type numel (void) const { return m_slice_len; } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
387 //@} |
4513 | 388 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
389 //! Return the array as a column vector. |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
390 Array<T> as_column (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
391 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
392 Array<T> retval (*this); |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
393 if (m_dimensions.ndims () != 2 || m_dimensions(1) != 1) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
394 retval.m_dimensions = dim_vector (numel (), 1); |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
395 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
396 return retval; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
397 } |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
398 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
399 //! Return the array as a row vector. |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
400 Array<T> as_row (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
401 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
402 Array<T> retval (*this); |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
403 if (m_dimensions.ndims () != 2 || m_dimensions(0) != 1) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
404 retval.m_dimensions = dim_vector (1, numel ()); |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
405 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
406 return retval; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
407 } |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
408 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
409 //! Return the array as a matrix. |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
410 Array<T> as_matrix (void) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
411 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
412 Array<T> retval (*this); |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
413 if (m_dimensions.ndims () != 2) |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
414 retval.m_dimensions = m_dimensions.redim (2); |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
415 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
416 return retval; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
417 } |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
418 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
419 //! @name First dimension |
19330
1f4455ff2329
Remove deprecated methods in liboctave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19326
diff
changeset
|
420 //! |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
421 //! Get the first dimension of the array (number of rows) |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
422 //@{ |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
423 octave_idx_type dim1 (void) const { return m_dimensions(0); } |
5275 | 424 octave_idx_type rows (void) const { return dim1 (); } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
425 //@} |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
426 |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
427 //! @name Second dimension |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
428 //! |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
429 //! Get the second dimension of the array (number of columns) |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
430 //@{ |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
431 octave_idx_type dim2 (void) const { return m_dimensions(1); } |
5275 | 432 octave_idx_type cols (void) const { return dim2 (); } |
433 octave_idx_type columns (void) const { return dim2 (); } | |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
434 //@} |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
435 |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
436 //! @name Third dimension |
19330
1f4455ff2329
Remove deprecated methods in liboctave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19326
diff
changeset
|
437 //! |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
438 //! Get the third dimension of the array (number of pages) |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
439 //@{ |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
440 octave_idx_type dim3 (void) const { return m_dimensions(2); } |
5275 | 441 octave_idx_type pages (void) const { return dim3 (); } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
442 //@} |
4513 | 443 |
22279
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
444 //! Size of the specified dimension. |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
445 //! |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
446 //! Dimensions beyond the Array number of dimensions return 1 as |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
447 //! those are implicit singleton dimensions. |
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
448 //! |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
26574
diff
changeset
|
449 //! Equivalent to Octave's 'size (A, DIM)' |
22279
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
450 |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
451 size_type size (const size_type d) const |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
452 { |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
453 // Should we throw for negative values? |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
454 // Should >= ndims () be handled by dim_vector operator() instead ? |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
455 return d >= ndims () ? 1 : m_dimensions(d); |
22279
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
456 } |
3bb1dc8b723e
Array: new typedef size_type and value_type, and new method size(dimension).
Carnë Draug <carandraug@octave.org>
parents:
22276
diff
changeset
|
457 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
458 std::size_t byte_size (void) const |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
459 { return static_cast<std::size_t> (numel ()) * sizeof (T); } |
4902 | 460 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
461 //! Return a const-reference so that dims ()(i) works efficiently. |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
462 const dim_vector& dims (void) const { return m_dimensions; } |
4513 | 463 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
464 //! Chop off leading singleton dimensions |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
465 OCTARRAY_API Array<T> squeeze (void) const; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
466 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
467 OCTARRAY_API octave_idx_type compute_index (octave_idx_type i, octave_idx_type j) const; |
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
468 OCTARRAY_API octave_idx_type compute_index (octave_idx_type i, octave_idx_type j, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
469 octave_idx_type k) const; |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
470 OCTARRAY_API octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx) const; |
4517 | 471 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
472 octave_idx_type compute_index_unchecked (const Array<octave_idx_type>& ra_idx) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
473 const |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
474 { return m_dimensions.compute_index (ra_idx.data (), ra_idx.numel ()); } |
10645
8645b7087859
abstract scalar index checking off Array<T> (prep for struct optimizations)
Jaroslav Hajek <highegg@gmail.com>
parents:
10636
diff
changeset
|
475 |
2108 | 476 // No checking, even for multiple references, ever. |
477 | |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
478 T& xelem (octave_idx_type n) { return m_slice_data[n]; } |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
479 crefT xelem (octave_idx_type n) const { return m_slice_data[n]; } |
2108 | 480 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
481 T& xelem (octave_idx_type i, octave_idx_type j) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
482 { return xelem (dim1 ()*j+i); } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
483 crefT xelem (octave_idx_type i, octave_idx_type j) const |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
484 { return xelem (dim1 ()*j+i); } |
4513 | 485 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
486 T& xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
487 { return xelem (i, dim2 ()*k+j); } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
488 crefT xelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
489 { return xelem (i, dim2 ()*k+j); } |
4513 | 490 |
6867 | 491 T& xelem (const Array<octave_idx_type>& ra_idx) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
492 { return xelem (compute_index_unchecked (ra_idx)); } |
4513 | 493 |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
494 crefT xelem (const Array<octave_idx_type>& ra_idx) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
495 { return xelem (compute_index_unchecked (ra_idx)); } |
4513 | 496 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
497 // FIXME: would be nice to fix this so that we don't unnecessarily force |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
498 // a copy, but that is not so easy, and I see no clean way to do it. |
2006 | 499 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
500 OCTARRAY_API T& checkelem (octave_idx_type n); |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23461
diff
changeset
|
501 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
502 OCTARRAY_API T& checkelem (octave_idx_type i, octave_idx_type j); |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23461
diff
changeset
|
503 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
504 OCTARRAY_API T& checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k); |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23461
diff
changeset
|
505 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
506 OCTARRAY_API T& checkelem (const Array<octave_idx_type>& ra_idx); |
4513 | 507 |
5275 | 508 T& elem (octave_idx_type n) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
509 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
510 make_unique (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
511 return xelem (n); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
512 } |
2306 | 513 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14616
diff
changeset
|
514 T& elem (octave_idx_type i, octave_idx_type j) { return elem (dim1 ()*j+i); } |
4513 | 515 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
516 T& elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
517 { return elem (i, dim2 ()*k+j); } |
4513 | 518 |
6867 | 519 T& elem (const Array<octave_idx_type>& ra_idx) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
520 { return Array<T>::elem (compute_index_unchecked (ra_idx)); } |
4513 | 521 |
5275 | 522 T& operator () (octave_idx_type n) { return elem (n); } |
523 T& operator () (octave_idx_type i, octave_idx_type j) { return elem (i, j); } | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
524 T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
525 { return elem (i, j, k); } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
526 T& operator () (const Array<octave_idx_type>& ra_idx) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
527 { return elem (ra_idx); } |
2006 | 528 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
529 OCTARRAY_API crefT checkelem (octave_idx_type n) const; |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23461
diff
changeset
|
530 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
531 OCTARRAY_API crefT checkelem (octave_idx_type i, octave_idx_type j) const; |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23461
diff
changeset
|
532 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
533 OCTARRAY_API crefT checkelem (octave_idx_type i, octave_idx_type j, |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
534 octave_idx_type k) const; |
23487
af2f1f3dbe06
eliminate --enable-bounds-check configure option
John W. Eaton <jwe@octave.org>
parents:
23461
diff
changeset
|
535 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
536 OCTARRAY_API crefT checkelem (const Array<octave_idx_type>& ra_idx) const; |
4513 | 537 |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
538 crefT elem (octave_idx_type n) const { return xelem (n); } |
2306 | 539 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
540 crefT elem (octave_idx_type i, octave_idx_type j) const |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
541 { return xelem (i, j); } |
4513 | 542 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
543 crefT elem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
544 { return xelem (i, j, k); } |
4513 | 545 |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
546 crefT elem (const Array<octave_idx_type>& ra_idx) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
547 { return Array<T>::xelem (compute_index_unchecked (ra_idx)); } |
4513 | 548 |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9921
diff
changeset
|
549 crefT operator () (octave_idx_type n) const { return elem (n); } |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
550 crefT operator () (octave_idx_type i, octave_idx_type j) const |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
551 { return elem (i, j); } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
552 crefT operator () (octave_idx_type i, octave_idx_type j, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
553 octave_idx_type k) const |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
554 { return elem (i, j, k); } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
555 crefT operator () (const Array<octave_idx_type>& ra_idx) const |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
556 { return elem (ra_idx); } |
2006 | 557 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
558 // Fast extractors. All of these produce shallow copies. |
9731 | 559 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
560 //! Extract column: A(:,k+1). |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
561 OCTARRAY_API Array<T> column (octave_idx_type k) const; |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
562 //! Extract page: A(:,:,k+1). |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
563 OCTARRAY_API Array<T> page (octave_idx_type k) const; |
9731 | 564 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
565 //! Extract a slice from this array as a column vector: A(:)(lo+1:up). |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
566 //! Must be 0 <= lo && up <= numel. May be up < lo. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
567 OCTARRAY_API Array<T> linear_slice (octave_idx_type lo, octave_idx_type up) const; |
9731 | 568 |
10352 | 569 Array<T> reshape (octave_idx_type nr, octave_idx_type nc) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
570 { return Array<T> (*this, dim_vector (nr, nc)); } |
10352 | 571 |
9731 | 572 Array<T> reshape (const dim_vector& new_dims) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
573 { return Array<T> (*this, new_dims); } |
4567 | 574 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
575 OCTARRAY_API Array<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const; |
5275 | 576 Array<T> ipermute (const Array<octave_idx_type>& vec) const |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
577 { return permute (vec, true); } |
4593 | 578 |
23593
a8361bc2361a
maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents:
23592
diff
changeset
|
579 bool issquare (void) const { return (dim1 () == dim2 ()); } |
a8361bc2361a
maint: Deprecate is_square and replace with issquare.
Rik <rik@octave.org>
parents:
23592
diff
changeset
|
580 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23487
diff
changeset
|
581 bool isempty (void) const { return numel () == 0; } |
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23487
diff
changeset
|
582 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
583 bool isvector (void) const { return m_dimensions.isvector (); } |
23592
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23588
diff
changeset
|
584 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
585 bool is_nd_vector (void) const { return m_dimensions.is_nd_vector (); } |
23386
f1ea44e92df8
improve compatibility for single index indexing (bug #50776)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
586 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
587 OCTARRAY_API Array<T> transpose (void) const; |
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
588 OCTARRAY_API Array<T> hermitian (T (*fcn) (const T&) = nullptr) const; |
238 | 589 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
590 const T * data (void) const { return m_slice_data; } |
228 | 591 |
29954
4c88a452519c
rename OCTAVE_USE_DEPRECATED_FUNCTIONS macro and attempt to make it work
John W. Eaton <jwe@octave.org>
parents:
29949
diff
changeset
|
592 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) |
29931
7faff48840eb
prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents:
29887
diff
changeset
|
593 OCTAVE_DEPRECATED (7, "for read-only access, use 'data' method instead") |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
594 const T * fortran_vec (void) const { return data (); } |
29954
4c88a452519c
rename OCTAVE_USE_DEPRECATED_FUNCTIONS macro and attempt to make it work
John W. Eaton <jwe@octave.org>
parents:
29949
diff
changeset
|
595 #endif |
3952 | 596 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
597 OCTARRAY_API T * fortran_vec (void); |
1560 | 598 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
599 bool is_shared (void) { return m_rep->m_count > 1; } |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9341
diff
changeset
|
600 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
601 int ndims (void) const { return m_dimensions.ndims (); } |
1560 | 602 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
603 //@{ |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
604 //! Indexing without resizing. |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
605 OCTARRAY_API Array<T> index (const octave::idx_vector& i) const; |
1560 | 606 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
607 OCTARRAY_API Array<T> index (const octave::idx_vector& i, const octave::idx_vector& j) const; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
608 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
609 OCTARRAY_API Array<T> index (const Array<octave::idx_vector>& ia) const; |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
610 //@} |
1560 | 611 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
612 virtual OCTARRAY_API T resize_fill_value (void) const; |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
613 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
614 //@{ |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
615 //! Resizing (with fill). |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
616 OCTARRAY_API void resize2 (octave_idx_type nr, octave_idx_type nc, const T& rfv); |
19330
1f4455ff2329
Remove deprecated methods in liboctave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19326
diff
changeset
|
617 void resize2 (octave_idx_type nr, octave_idx_type nc) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
618 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
619 resize2 (nr, nc, resize_fill_value ()); |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
620 } |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
621 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
622 OCTARRAY_API void resize1 (octave_idx_type n, const T& rfv); |
19330
1f4455ff2329
Remove deprecated methods in liboctave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19326
diff
changeset
|
623 void resize1 (octave_idx_type n) { resize1 (n, resize_fill_value ()); } |
1f4455ff2329
Remove deprecated methods in liboctave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19326
diff
changeset
|
624 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
625 OCTARRAY_API void resize (const dim_vector& dv, const T& rfv); |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
626 void resize (const dim_vector& dv) { resize (dv, resize_fill_value ()); } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
627 //@} |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
628 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
629 //@{ |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
630 //! Indexing with possible resizing and fill |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
631 |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
632 // FIXME: this is really a corner case, that should better be |
8333 | 633 // handled directly in liboctinterp. |
3933 | 634 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
635 OCTARRAY_API Array<T> index (const octave::idx_vector& i, bool resize_ok, const T& rfv) const; |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
636 Array<T> index (const octave::idx_vector& i, bool resize_ok) const |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
637 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
638 return index (i, resize_ok, resize_fill_value ()); |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
639 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
640 |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
641 OCTARRAY_API Array<T> index (const octave::idx_vector& i, const octave::idx_vector& j, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
642 bool resize_ok, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
643 const T& rfv) const; |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
644 Array<T> index (const octave::idx_vector& i, const octave::idx_vector& j, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
645 bool resize_ok) const |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
646 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
647 return index (i, j, resize_ok, resize_fill_value ()); |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
648 } |
4513 | 649 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
650 OCTARRAY_API Array<T> index (const Array<octave::idx_vector>& ia, bool resize_ok, |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
651 const T& rfv) const; |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
652 Array<T> index (const Array<octave::idx_vector>& ia, bool resize_ok) const |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
653 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
654 return index (ia, resize_ok, resize_fill_value ()); |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
655 } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
656 //@} |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
657 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
658 //@{ |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
659 //! Indexed assignment (always with resize & fill). |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
660 OCTARRAY_API void assign (const octave::idx_vector& i, const Array<T>& rhs, const T& rfv); |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
661 void assign (const octave::idx_vector& i, const Array<T>& rhs) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
662 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
663 assign (i, rhs, resize_fill_value ()); |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
664 } |
4513 | 665 |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
666 OCTARRAY_API void assign (const octave::idx_vector& i, const octave::idx_vector& j, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
667 const Array<T>& rhs, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
668 const T& rfv); |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
669 void assign (const octave::idx_vector& i, const octave::idx_vector& j, const Array<T>& rhs) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
670 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
671 assign (i, j, rhs, resize_fill_value ()); |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
672 } |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
673 |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
674 OCTARRAY_API void assign (const Array<octave::idx_vector>& ia, const Array<T>& rhs, const T& rfv); |
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
675 void assign (const Array<octave::idx_vector>& ia, const Array<T>& rhs) |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
676 { |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
677 assign (ia, rhs, resize_fill_value ()); |
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14557
diff
changeset
|
678 } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
679 //@} |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
680 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
681 //@{ |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
682 //! Deleting elements. |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
683 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
684 //! A(I) = [] (with a single subscript) |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
685 OCTARRAY_API void delete_elements (const octave::idx_vector& i); |
4530 | 686 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
687 //! A(:,...,I,...,:) = [] (>= 2 subscripts, one of them is non-colon) |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
688 OCTARRAY_API void delete_elements (int dim, const octave::idx_vector& i); |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8179
diff
changeset
|
689 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
690 //! Dispatcher to the above two. |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
691 OCTARRAY_API void delete_elements (const Array<octave::idx_vector>& ia); |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
692 //@} |
4513 | 693 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
694 //! Insert an array into another at a specified position. If |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
695 //! size (a) is [d1 d2 ... dN] and idx is [i1 i2 ... iN], this |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
696 //! method is equivalent to x(i1:i1+d1-1, i2:i2+d2-1, ... , |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
697 //! iN:iN+dN-1) = a. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
698 OCTARRAY_API Array<T>& insert (const Array<T>& a, const Array<octave_idx_type>& idx); |
3928 | 699 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
700 //! This is just a special case for idx = [r c 0 ...] |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
701 OCTARRAY_API Array<T>& insert (const Array<T>& a, octave_idx_type r, octave_idx_type c); |
3933 | 702 |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
703 void maybe_economize (void) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
704 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
705 if (m_rep->m_count == 1 && m_slice_len != m_rep->m_len) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
706 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
707 ArrayRep *new_rep = new ArrayRep (m_slice_data, m_slice_len); |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
708 delete m_rep; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
709 m_rep = new_rep; |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
710 m_slice_data = m_rep->m_data; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
711 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
712 } |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8503
diff
changeset
|
713 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
714 OCTARRAY_API void print_info (std::ostream& os, const std::string& prefix) const; |
5900 | 715 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
716 OCTARRAY_API Array<T> sort (int dim = 0, sortmode mode = ASCENDING) const; |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
717 OCTARRAY_API Array<T> sort (Array<octave_idx_type>& sidx, int dim = 0, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
718 sortmode mode = ASCENDING) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
719 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
720 //! Ordering is auto-detected or can be specified. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
721 OCTARRAY_API sortmode issorted (sortmode mode = UNSORTED) const; |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
722 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
723 //! Sort by rows returns only indices. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
724 OCTARRAY_API Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
725 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
726 //! Ordering is auto-detected or can be specified. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
727 OCTARRAY_API sortmode is_sorted_rows (sortmode mode = UNSORTED) const; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8700
diff
changeset
|
728 |
24624
ce2eb28e0a6d
doc: make all Doxygen comment blocks more consistent
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
729 //! Do a binary lookup in a sorted array. Must not contain NaNs. |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
730 //! Mode can be specified or is auto-detected by comparing 1st and last element. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
731 OCTARRAY_API octave_idx_type lookup (const T& value, sortmode mode = UNSORTED) const; |
8814
de16ebeef93d
improve lookup, provide Array<T>::lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8725
diff
changeset
|
732 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
733 //! Ditto, but for an array of values, specializing on the case when values |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
734 //! are sorted. NaNs get the value N. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
735 OCTARRAY_API Array<octave_idx_type> lookup (const Array<T>& values, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
736 sortmode mode = UNSORTED) const; |
9341
9fd5c56ce57a
extend lookup capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
9201
diff
changeset
|
737 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
738 //! Count nonzero elements. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
739 OCTARRAY_API octave_idx_type nnz (void) const; |
9878
ead4f9c82a9a
implement Array<T>::nnz
Jaroslav Hajek <highegg@gmail.com>
parents:
9840
diff
changeset
|
740 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
741 //! Find indices of (at most n) nonzero elements. If n is specified, |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
742 //! backward specifies search from backward. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
743 OCTARRAY_API Array<octave_idx_type> find (octave_idx_type n = -1, |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
744 bool backward = false) const; |
9025 | 745 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
746 //! Returns the n-th element in increasing order, using the same |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
747 //! ordering as used for sort. n can either be a scalar index or a |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
748 //! contiguous range. |
29569
29a1f8fd8ee6
move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
749 OCTARRAY_API Array<T> nth_element (const octave::idx_vector& n, int dim = 0) const; |
9725 | 750 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
751 //! Get the kth super or subdiagonal. The zeroth diagonal is the |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
752 //! ordinary diagonal. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
753 OCTARRAY_API Array<T> diag (octave_idx_type k = 0) const; |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
754 |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
755 OCTARRAY_API Array<T> diag (octave_idx_type m, octave_idx_type n) const; |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
756 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
757 //! Concatenation along a specified (0-based) dimension, equivalent |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
758 //! to cat(). dim = -1 corresponds to dim = 0 and dim = -2 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
759 //! corresponds to dim = 1, but apply the looser matching rules of |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
760 //! vertcat/horzcat. |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
761 static OCTARRAY_API Array<T> |
10531
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
762 cat (int dim, octave_idx_type n, const Array<T> *array_list); |
2dd8ea8bfd71
basic cat functionality in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
763 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
764 //! Apply function fcn to each element of the Array<T>. This function |
21567
3d25f9f4a62b
maint: Eliminate Britishicisms in the code.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
765 //! is optimized with a manually unrolled loop. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
766 template <typename U, typename F> |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
767 Array<U> |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
768 map (F fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
769 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
770 octave_idx_type len = numel (); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
771 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
772 const T *m = data (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
773 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
774 Array<U> result (dims ()); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
775 U *p = result.fortran_vec (); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
776 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
777 octave_idx_type i; |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
778 for (i = 0; i < len - 3; i += 4) |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
779 { |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
780 octave_quit (); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
781 |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
782 p[i] = fcn (m[i]); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
783 p[i+1] = fcn (m[i+1]); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
784 p[i+2] = fcn (m[i+2]); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
785 p[i+3] = fcn (m[i+3]); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
786 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
787 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10115
diff
changeset
|
788 octave_quit (); |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
789 |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
790 for (; i < len; i++) |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
791 p[i] = fcn (m[i]); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
792 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
793 return result; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
794 } |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8950
diff
changeset
|
795 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
796 //@{ |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
797 //! Overloads for function references. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
798 template <typename U> |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
799 Array<U> |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
800 map (U (&fcn) (T)) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
801 { return map<U, U (&) (T)> (fcn); } |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
802 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
803 template <typename U> |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
804 Array<U> |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
805 map (U (&fcn) (const T&)) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
806 { return map<U, U (&) (const T&)> (fcn); } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
807 //@} |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9800
diff
changeset
|
808 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
809 //! Generic any/all test functionality with arbitrary predicate. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
810 template <typename F, bool zero> |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
811 bool test (F fcn) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
812 { |
29937
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29931
diff
changeset
|
813 return octave::any_all_test<F, T, zero> (fcn, data (), numel ()); |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
814 } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
815 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
816 //@{ |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
817 //! Simpler calls. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
818 template <typename F> |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
819 bool test_any (F fcn) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
820 { return test<F, false> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
821 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
822 template <typename F> |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
823 bool test_all (F fcn) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
824 { return test<F, true> (fcn); } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
825 //@} |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
826 |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
827 //@{ |
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
828 //! Overloads for function references. |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
829 bool test_any (bool (&fcn) (T)) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
830 { return test<bool (&) (T), false> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
831 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
832 bool test_any (bool (&fcn) (const T&)) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
833 { return test<bool (&) (const T&), false> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
834 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
835 bool test_all (bool (&fcn) (T)) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
836 { return test<bool (&) (T), true> (fcn); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
837 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
838 bool test_all (bool (&fcn) (const T&)) const |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
839 { return test<bool (&) (const T&), true> (fcn); } |
19006
96751a74bbbb
Start doxygenising sources
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17769
diff
changeset
|
840 //@} |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
841 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
842 template <typename U> friend class Array; |
9201
472f0e22aa60
guard against implicit instantiation
Jaroslav Hajek <highegg@gmail.com>
parents:
9046
diff
changeset
|
843 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
844 //! Returns true if this->dims () == dv, and if so, replaces this->m_dimensions |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
845 //! by a shallow copy of dv. This is useful for maintaining several arrays |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21660
diff
changeset
|
846 //! with supposedly equal dimensions (e.g. structs in the interpreter). |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
847 OCTARRAY_API bool optimize_dimensions (const dim_vector& dv); |
10674
e3064439d6b4
new Array method for internal use
Jaroslav Hajek <highegg@gmail.com>
parents:
10673
diff
changeset
|
848 |
9201
472f0e22aa60
guard against implicit instantiation
Jaroslav Hajek <highegg@gmail.com>
parents:
9046
diff
changeset
|
849 private: |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
850 OCTARRAY_API static void instantiation_guard (); |
4513 | 851 }; |
4459 | 852 |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
853 // We use a variadic template for template template parameter so that |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
854 // we don't have to specify all the template parameters and limit this |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
855 // to Container<T>. http://stackoverflow.com/a/20499809/1609556 |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
856 template<typename T> |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
857 template<template <typename...> class Container> |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
858 Array<T>::Array (const Container<T>& a, const dim_vector& dv) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
859 : m_dimensions (dv), m_rep (new typename Array<T>::ArrayRep (dv.safe_numel ())), |
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
860 m_slice_data (m_rep->m_data), m_slice_len (m_rep->m_len) |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
861 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
862 if (m_dimensions.safe_numel () != octave_idx_type (a.size ())) |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
863 { |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
864 std::string new_dims_str = m_dimensions.str (); |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
865 |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
866 (*current_liboctave_error_handler) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
867 ("reshape: can't reshape %zi elements into %s array", |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
868 a.size (), new_dims_str.c_str ()); |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
869 } |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
870 |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
871 octave_idx_type i = 0; |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
872 for (const T& x : a) |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
873 m_slice_data[i++] = x; |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
874 |
29887
be669d935fb6
use m_prefix for data members in array classes
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
875 m_dimensions.chop_trailing_singletons (); |
22139
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
876 } |
f8212eb6da00
Array: add constructor from std sequence containers (patch 9047)
Carnë Draug <carandraug@octave.org>
parents:
22022
diff
changeset
|
877 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21134
diff
changeset
|
878 template <typename T> |
29224
cc4a4df4e32f
Add API tag for Array class that is exported from liboctave and liboctinterp (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27957
diff
changeset
|
879 OCTARRAY_API std::ostream& |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9731
diff
changeset
|
880 operator << (std::ostream& os, const Array<T>& a); |
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9731
diff
changeset
|
881 |
9773
01f897d8a130
optimize memory manipulation by arrays & indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
882 #endif |