Mercurial > octave-nkf
comparison liboctave/array/dim-vector.h @ 20271:a3bf35bd5b44
doc: doxygen documentation for dim_vector header.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Sat, 30 May 2015 13:50:14 +0100 |
parents | e914b5399c67 |
children |
comparison
equal
deleted
inserted
replaced
20270:3e8c188b20a7 | 20271:a3bf35bd5b44 |
---|---|
32 | 32 |
33 #include "lo-error.h" | 33 #include "lo-error.h" |
34 #include "lo-macros.h" | 34 #include "lo-macros.h" |
35 #include "oct-refcount.h" | 35 #include "oct-refcount.h" |
36 | 36 |
37 // Rationale: This implementation is more tricky than Array, but the | 37 //! Vector representing the dimensions (size) of an Array. |
38 // big plus is that dim_vector requires only one allocation instead of | 38 /*! |
39 // two. It is (slightly) patterned after GCC's basic_string | 39 A dim_vector is used to represent dimensions of an Array. It is used |
40 // implementation. rep is a pointer to an array of memory, comprising | 40 on its constructor to specify its size, or when reshaping it. |
41 // count, length, and the data: | 41 |
42 // | 42 @code{.cc} |
43 // <count> | 43 // Matrix with 10 rows and 20 columns. |
44 // <ndims> | 44 Matrix m Matrix (dim_vector (10, 20)); |
45 // rep --> <dims[0]> | 45 |
46 // <dims[1]> | 46 // Change its size to 5 rows and 40 columns. |
47 // ... | 47 Matrix m2 = m.reshape (dim_vector (5, 40)); |
48 // | 48 |
49 // The inlines count(), ndims() recover this data from the rep. Note | 49 // Five dimensional Array of length 10, 20, 3, 8, 7 on each dimension. |
50 // that rep points to the beginning of dims to grant faster access | 50 NDArray a (dim_vector (10, 20, 3, 8, 7)); |
51 // (reinterpret_cast is assumed to be an inexpensive operation). | 51 |
52 // Uninitialized array of same size as other. | |
53 NDArray b (a.dims ()); | |
54 @endcode | |
55 | |
56 The main thing to understand about this class, is that methods such as | |
57 ndims() and numel(), return the value for an Array of these dimensions, | |
58 not the actual number of elements in the dim_vector. | |
59 | |
60 @code{.cc} | |
61 dim_vector d (10, 5, 3); | |
62 octave_idx_type n = d.numel (); // returns 150 | |
63 octave_idx_type nd = d.ndims (); // returns 2 | |
64 @endcode | |
65 | |
66 ## Implementation details ## | |
67 | |
68 This implementation is more tricky than Array, but the big plus is that | |
69 dim_vector requires only one allocation instead of two. It is (slightly) | |
70 patterned after GCC's basic_string implementation. rep is a pointer to an | |
71 array of memory, comprising count, length, and the data: | |
72 | |
73 @verbatim | |
74 <count> | |
75 <ndims> | |
76 rep --> <dims[0]> | |
77 <dims[1]> | |
78 ... | |
79 @endverbatim | |
80 | |
81 The inlines count(), ndims() recover this data from the rep. Note | |
82 that rep points to the beginning of dims to grant faster access | |
83 (reinterpret_cast is assumed to be an inexpensive operation). | |
84 */ | |
52 | 85 |
53 class | 86 class |
54 OCTAVE_API | 87 OCTAVE_API |
55 dim_vector | 88 dim_vector |
56 { | 89 { |