4514
|
1 // N-D Array manipulations. |
|
2 /* |
|
3 |
|
4 Copyright (C) 1996, 1997 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #ifdef HAVE_CONFIG_H |
|
29 #include <config.h> |
|
30 #endif |
|
31 |
|
32 #include "CNDArray.h" |
|
33 #include "mx-base.h" |
|
34 #include "lo-ieee.h" |
|
35 |
4532
|
36 #include "ArrayN-inline.h" |
|
37 |
4543
|
38 // XXX FIXME XXX -- could we use a templated mixed-type copy function |
|
39 // here? |
|
40 |
|
41 ComplexNDArray::ComplexNDArray (const NDArray& a) |
|
42 : MArrayN<Complex> (a.dims ()) |
|
43 { |
|
44 for (int i = 0; i < a.length (); i++) |
|
45 elem (i) = a.elem (i); |
|
46 } |
|
47 |
|
48 ComplexNDArray::ComplexNDArray (const boolNDArray& a) |
|
49 : MArrayN<Complex> (a.dims ()) |
|
50 { |
|
51 for (int i = 0; i < a.length (); i++) |
|
52 elem (i) = a.elem (i); |
|
53 } |
|
54 |
|
55 ComplexNDArray::ComplexNDArray (const charNDArray& a) |
|
56 : MArrayN<Complex> (a.dims ()) |
|
57 { |
|
58 for (int i = 0; i < a.length (); i++) |
|
59 elem (i) = a.elem (i); |
|
60 } |
|
61 |
|
62 // unary operations |
|
63 |
|
64 boolNDArray |
|
65 ComplexNDArray::operator ! (void) const |
|
66 { |
|
67 boolNDArray b (dims ()); |
|
68 |
|
69 for (int i = 0; i < length (); i++) |
|
70 b.elem (i) = elem (i) != 0.0; |
|
71 |
|
72 return b; |
|
73 } |
|
74 |
4514
|
75 // XXX FIXME XXX -- this is not quite the right thing. |
|
76 |
4556
|
77 boolNDArray |
4514
|
78 ComplexNDArray::all (int dim) const |
|
79 { |
4563
|
80 MX_ND_ANY_ALL (MX_ND_ALL_EVAL (real (elem (iter_idx)) == 0 |
|
81 && imag (elem (iter_idx)) == 0), true); |
4514
|
82 } |
|
83 |
4556
|
84 boolNDArray |
4514
|
85 ComplexNDArray::any (int dim) const |
|
86 { |
4563
|
87 MX_ND_ANY_ALL (MX_ND_ANY_EVAL (real (elem (iter_idx)) != 0 |
|
88 || imag (elem (iter_idx)) != 0), false); |
4514
|
89 } |
|
90 |
|
91 ComplexMatrix |
|
92 ComplexNDArray::matrix_value (void) const |
|
93 { |
|
94 ComplexMatrix retval; |
|
95 |
|
96 int nd = ndims (); |
|
97 |
|
98 switch (nd) |
|
99 { |
|
100 case 1: |
|
101 retval = ComplexMatrix (Array2<Complex> (*this, dimensions(0), 1)); |
|
102 break; |
|
103 |
|
104 case 2: |
|
105 retval = ComplexMatrix (Array2<Complex> (*this, dimensions(0), |
|
106 dimensions(1))); |
|
107 break; |
|
108 |
|
109 default: |
|
110 (*current_liboctave_error_handler) |
|
111 ("invalid converstion of ComplexNDArray to ComplexMatrix"); |
|
112 break; |
|
113 } |
|
114 |
|
115 return retval; |
|
116 } |
|
117 |
4532
|
118 void |
|
119 ComplexNDArray::increment_index (Array<int>& ra_idx, |
|
120 const dim_vector& dimensions, |
|
121 int start_dimension) |
|
122 { |
|
123 ::increment_index (ra_idx, dimensions, start_dimension); |
|
124 } |
|
125 |
4556
|
126 int |
|
127 ComplexNDArray::compute_index (Array<int>& ra_idx, |
|
128 const dim_vector& dimensions) |
|
129 { |
|
130 return ::compute_index (ra_idx, dimensions); |
|
131 } |
|
132 |
4543
|
133 NDS_CMP_OPS(ComplexNDArray, real, Complex, real) |
|
134 NDS_BOOL_OPS(ComplexNDArray, Complex, 0.0) |
|
135 |
|
136 SND_CMP_OPS(Complex, real, ComplexNDArray, real) |
|
137 SND_BOOL_OPS(Complex, ComplexNDArray, 0.0) |
|
138 |
|
139 NDND_CMP_OPS(ComplexNDArray, real, ComplexNDArray, real) |
|
140 NDND_BOOL_OPS(ComplexNDArray, ComplexNDArray, 0.0) |
|
141 |
4514
|
142 /* |
|
143 ;;; Local Variables: *** |
|
144 ;;; mode: C++ *** |
|
145 ;;; End: *** |
|
146 */ |