Mercurial > hg > octave-lyh
annotate liboctave/intNDArray.h @ 9721:192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 13 Oct 2009 12:22:50 +0200 |
parents | 1be3c73ed7b5 |
children | b4fdfee405b5 |
rev | line source |
---|---|
4902 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
4902 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4902 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4902 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_intNDArray_h) | |
24 #define octave_intNDArray_h 1 | |
25 | |
26 #include "MArrayN.h" | |
27 #include "boolNDArray.h" | |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9607
diff
changeset
|
28 class NDArray; |
4902 | 29 |
30 template <class T> | |
31 class | |
32 intNDArray : public MArrayN<T> | |
33 { | |
34 public: | |
5992 | 35 |
8918
f5408862892f
Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents:
8780
diff
changeset
|
36 using MArrayN<T>::element_type; |
4902 | 37 |
38 intNDArray (void) : MArrayN<T> () { } | |
39 | |
40 intNDArray (T val) : MArrayN<T> (dim_vector (1, 1), val) { } | |
41 | |
42 intNDArray (const dim_vector& dv) : MArrayN<T> (dv) { } | |
43 | |
44 intNDArray (const dim_vector& dv, T val) | |
45 : MArrayN<T> (dv, val) { } | |
46 | |
47 template <class U> | |
48 explicit intNDArray (const Array<U>& a) : MArrayN<T> (a) { } | |
49 | |
50 template <class U> | |
51 explicit intNDArray (const ArrayN<U>& a) : MArrayN<T> (a) { } | |
52 | |
53 template <class U> | |
54 intNDArray (const MArrayN<U>& a) : MArrayN<T> (a) { } | |
55 | |
56 template <class U> | |
57 intNDArray (const intNDArray<U>& a) : MArrayN<T> (a) { } | |
58 | |
59 intNDArray& operator = (const intNDArray<T>& a) | |
60 { | |
61 MArrayN<T>::operator = (a); | |
62 return *this; | |
63 } | |
64 | |
65 boolNDArray operator ! (void) const; | |
66 | |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
67 bool any_element_is_nan (void) const { return false; } |
5943 | 68 bool any_element_not_one_or_zero (void) const; |
69 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
70 intNDArray diag (octave_idx_type k = 0) const; |
6979 | 71 |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
72 intNDArray& changesign (void) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
73 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
74 MArrayN<T>::changesign (); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
75 return *this; |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
76 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
77 |
5775 | 78 // FIXME -- this is not quite the right thing. |
4902 | 79 |
80 boolNDArray all (int dim = -1) const; | |
81 boolNDArray any (int dim = -1) const; | |
82 | |
7189 | 83 intNDArray max (int dim = 0) const; |
84 intNDArray max (ArrayN<octave_idx_type>& index, int dim = 0) const; | |
85 intNDArray min (int dim = 0) const; | |
86 intNDArray min (ArrayN<octave_idx_type>& index, int dim = 0) const; | |
87 | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
88 intNDArray cummax (int dim = 0) const; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
89 intNDArray cummax (ArrayN<octave_idx_type>& index, int dim = 0) const; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
90 intNDArray cummin (int dim = 0) const; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
91 intNDArray cummin (ArrayN<octave_idx_type>& index, int dim = 0) const; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
92 |
7113 | 93 intNDArray sum (int dim) const; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9607
diff
changeset
|
94 NDArray dsum (int dim) const; |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8777
diff
changeset
|
95 intNDArray cumsum (int dim) const; |
7113 | 96 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
97 intNDArray diff (octave_idx_type order = 1, int dim = 0) const; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
98 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
99 intNDArray abs (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
100 intNDArray signum (void) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7189
diff
changeset
|
101 |
4902 | 102 intNDArray squeeze (void) const |
103 { return intNDArray<T> (MArrayN<T>::squeeze ()); } | |
104 | |
105 intNDArray transpose (void) const | |
106 { return intNDArray<T> (MArrayN<T>::transpose ()); } | |
107 | |
5275 | 108 intNDArray concat (const intNDArray<T>& rb, const Array<octave_idx_type>& ra_idx); |
5073 | 109 |
5275 | 110 intNDArray& insert (const intNDArray<T>& a, octave_idx_type r, octave_idx_type c); |
111 intNDArray& insert (const intNDArray<T>& a, const Array<octave_idx_type>& ra_idx); | |
4915 | 112 |
5275 | 113 static void increment_index (Array<octave_idx_type>& ra_idx, |
4902 | 114 const dim_vector& dimensions, |
115 int start_dimension = 0); | |
116 | |
5275 | 117 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4902 | 118 const dim_vector& dimensions); |
119 | |
120 static T resize_fill_value (void) { return 0; } | |
121 | |
122 protected: | |
123 | |
124 intNDArray (T *d, dim_vector& dv) : MArrayN<T> (d, dv) { } | |
125 }; | |
126 | |
127 // i/o | |
128 | |
129 template <class T> | |
130 std::ostream& operator << (std::ostream& os, const intNDArray<T>& a); | |
131 | |
132 template <class T> | |
133 std::istream& operator >> (std::istream& is, intNDArray<T>& a); | |
134 | |
135 #endif | |
136 | |
137 /* | |
138 ;;; Local Variables: *** | |
139 ;;; mode: C++ *** | |
140 ;;; End: *** | |
141 */ |