Mercurial > hg > octave-lyh
annotate liboctave/dNDArray.h @ 7789:82be108cc558
First attempt at single precision tyeps
* * *
corrections to qrupdate single precision routines
* * *
prefer demotion to single over promotion to double
* * *
Add single precision support to log2 function
* * *
Trivial PROJECT file update
* * *
Cache optimized hermitian/transpose methods
* * *
Add tests for tranpose/hermitian and ChangeLog entry for new transpose code
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sun, 27 Apr 2008 22:34:17 +0200 |
parents | 36594d5bbe13 |
children | 9d080df0c843 |
rev | line source |
---|---|
4511 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4511 | 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. | |
4511 | 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/>. | |
4511 | 20 |
21 */ | |
22 | |
4513 | 23 #if !defined (octave_NDArray_h) |
24 #define octave_NDArray_h 1 | |
4511 | 25 |
26 #include "MArrayN.h" | |
4513 | 27 #include "dMatrix.h" |
4902 | 28 #include "intNDArray.h" |
4511 | 29 |
30 #include "mx-defs.h" | |
31 #include "mx-op-defs.h" | |
32 | |
4513 | 33 class |
6108 | 34 OCTAVE_API |
4513 | 35 NDArray : public MArrayN<double> |
4511 | 36 { |
4513 | 37 public: |
5523 | 38 |
4511 | 39 NDArray (void) : MArrayN<double> () { } |
40 | |
4587 | 41 NDArray (const dim_vector& dv) : MArrayN<double> (dv) { } |
4511 | 42 |
4587 | 43 NDArray (const dim_vector& dv, double val) |
44 : MArrayN<double> (dv, val) { } | |
4511 | 45 |
4513 | 46 NDArray (const NDArray& a) : MArrayN<double> (a) { } |
47 | |
48 NDArray (const Matrix& a) : MArrayN<double> (a) { } | |
4511 | 49 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
50 template <class U> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
51 NDArray (const MArrayN<U>& a) : MArrayN<double> (a) { } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
52 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
53 template <class U> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
54 NDArray (const ArrayN<U>& a) : MArrayN<double> (a) { } |
4511 | 55 |
4902 | 56 template <class U> |
57 explicit NDArray (const intNDArray<U>& a) : MArrayN<double> (a) { } | |
4543 | 58 |
4511 | 59 NDArray& operator = (const NDArray& a) |
60 { | |
61 MArrayN<double>::operator = (a); | |
62 return *this; | |
63 } | |
64 | |
4543 | 65 // unary operations |
66 | |
67 boolNDArray operator ! (void) const; | |
68 | |
4634 | 69 bool any_element_is_negative (bool = false) const; |
70 bool any_element_is_inf_or_nan (void) const; | |
5943 | 71 bool any_element_not_one_or_zero (void) const; |
6989 | 72 bool all_elements_are_zero (void) const; |
4634 | 73 bool all_elements_are_int_or_inf_or_nan (void) const; |
74 bool all_integers (double& max_val, double& min_val) const; | |
75 bool too_large_for_float (void) const; | |
76 | |
5775 | 77 // FIXME -- this is not quite the right thing. |
4513 | 78 |
4556 | 79 boolNDArray all (int dim = -1) const; |
80 boolNDArray any (int dim = -1) const; | |
4513 | 81 |
4584 | 82 NDArray cumprod (int dim = -1) const; |
83 NDArray cumsum (int dim = -1) const; | |
4569 | 84 NDArray prod (int dim = -1) const; |
85 NDArray sum (int dim = -1) const; | |
86 NDArray sumsq (int dim = -1) const; | |
5275 | 87 NDArray concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx); |
88 ComplexNDArray concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx); | |
89 charNDArray concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx); | |
4844 | 90 |
91 NDArray max (int dim = 0) const; | |
5275 | 92 NDArray max (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844 | 93 NDArray min (int dim = 0) const; |
5275 | 94 NDArray min (ArrayN<octave_idx_type>& index, int dim = 0) const; |
4844 | 95 |
5275 | 96 NDArray& insert (const NDArray& a, octave_idx_type r, octave_idx_type c); |
97 NDArray& insert (const NDArray& a, const Array<octave_idx_type>& ra_idx); | |
4915 | 98 |
4634 | 99 NDArray abs (void) const; |
100 | |
4773 | 101 ComplexNDArray fourier (int dim = 1) const; |
102 ComplexNDArray ifourier (int dim = 1) const; | |
103 | |
104 ComplexNDArray fourier2d (void) const; | |
105 ComplexNDArray ifourier2d (void) const; | |
106 | |
107 ComplexNDArray fourierNd (void) const; | |
108 ComplexNDArray ifourierNd (void) const; | |
109 | |
6108 | 110 friend OCTAVE_API NDArray real (const ComplexNDArray& a); |
111 friend OCTAVE_API NDArray imag (const ComplexNDArray& a); | |
4569 | 112 |
4513 | 113 Matrix matrix_value (void) const; |
114 | |
4902 | 115 NDArray squeeze (void) const { return MArrayN<double>::squeeze (); } |
4532 | 116 |
5275 | 117 static void increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 118 const dim_vector& dimensions, |
119 int start_dimension = 0); | |
120 | |
5275 | 121 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4556 | 122 const dim_vector& dimensions); |
123 | |
4511 | 124 // i/o |
125 | |
6108 | 126 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const NDArray& a); |
127 friend OCTAVE_API std::istream& operator >> (std::istream& is, NDArray& a); | |
4511 | 128 |
129 static double resize_fill_value (void) { return 0; } | |
130 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
131 NDArray diag (octave_idx_type k = 0) const; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
132 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
133 typedef double (*dmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
134 typedef Complex (*cmapper) (const Complex&); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
135 typedef bool (*bmapper) (double); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
136 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
137 NDArray map (dmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 ComplexNDArray map (cmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
139 boolNDArray map (bmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
140 |
4513 | 141 private: |
4511 | 142 |
4634 | 143 NDArray (double *d, const dim_vector& dv) : MArrayN<double> (d, dv) { } |
4511 | 144 }; |
145 | |
5508 | 146 // Publish externally used friend functions. |
147 | |
6108 | 148 extern OCTAVE_API NDArray real (const ComplexNDArray& a); |
149 extern OCTAVE_API NDArray imag (const ComplexNDArray& a); | |
5508 | 150 |
6108 | 151 extern OCTAVE_API NDArray min (double d, const NDArray& m); |
152 extern OCTAVE_API NDArray min (const NDArray& m, double d); | |
153 extern OCTAVE_API NDArray min (const NDArray& a, const NDArray& b); | |
4844 | 154 |
6108 | 155 extern OCTAVE_API NDArray max (double d, const NDArray& m); |
156 extern OCTAVE_API NDArray max (const NDArray& m, double d); | |
157 extern OCTAVE_API NDArray max (const NDArray& a, const NDArray& b); | |
4844 | 158 |
6708 | 159 NDS_CMP_OP_DECLS (NDArray, double, OCTAVE_API) |
160 NDS_BOOL_OP_DECLS (NDArray, double, OCTAVE_API) | |
4543 | 161 |
6708 | 162 SND_CMP_OP_DECLS (double, NDArray, OCTAVE_API) |
163 SND_BOOL_OP_DECLS (double, NDArray, OCTAVE_API) | |
4543 | 164 |
6708 | 165 NDND_CMP_OP_DECLS (NDArray, NDArray, OCTAVE_API) |
166 NDND_BOOL_OP_DECLS (NDArray, NDArray, OCTAVE_API) | |
4543 | 167 |
4511 | 168 MARRAY_FORWARD_DEFS (MArrayN, NDArray, double) |
169 | |
170 #endif | |
4513 | 171 |
172 /* | |
173 ;;; Local Variables: *** | |
174 ;;; mode: C++ *** | |
175 ;;; End: *** | |
176 */ |