4902
|
1 // N-D Array manipulations. |
|
2 /* |
|
3 |
|
4 Copyright (C) 2004 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 "Array-util.h" |
|
33 #include "mx-base.h" |
|
34 #include "lo-ieee.h" |
|
35 |
|
36 // unary operations |
|
37 |
|
38 template <class T> |
|
39 boolNDArray |
|
40 intNDArray<T>::operator ! (void) const |
|
41 { |
4932
|
42 boolNDArray b (this->dims ()); |
4902
|
43 |
4932
|
44 for (int i = 0; i < this->length (); i++) |
|
45 b.elem (i) = ! this->elem (i); |
4902
|
46 |
|
47 return b; |
|
48 } |
|
49 |
|
50 // XXX FIXME XXX -- this is not quite the right thing. |
|
51 |
|
52 template <class T> |
|
53 boolNDArray |
|
54 intNDArray<T>::all (int dim) const |
|
55 { |
4932
|
56 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (this->elem (iter_idx) == T (0)), true); |
4902
|
57 } |
|
58 |
|
59 template <class T> |
|
60 boolNDArray |
|
61 intNDArray<T>::any (int dim) const |
|
62 { |
4932
|
63 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (this->elem (iter_idx) == T (0)), false); |
4902
|
64 } |
|
65 |
|
66 template <class T> |
|
67 void |
|
68 intNDArray<T>::increment_index (Array<int>& ra_idx, |
|
69 const dim_vector& dimensions, |
|
70 int start_dimension) |
|
71 { |
|
72 ::increment_index (ra_idx, dimensions, start_dimension); |
|
73 } |
|
74 |
|
75 template <class T> |
|
76 int |
|
77 intNDArray<T>::compute_index (Array<int>& ra_idx, |
|
78 const dim_vector& dimensions) |
|
79 { |
|
80 return ::compute_index (ra_idx, dimensions); |
|
81 } |
|
82 |
4915
|
83 template <class T> |
5073
|
84 intNDArray<T> |
|
85 intNDArray<T>::concat (const intNDArray<T>& rb, const Array<int>& ra_idx) |
|
86 { |
|
87 if (rb.numel () > 0); |
|
88 insert (rb, ra_idx); |
|
89 return *this; |
|
90 } |
|
91 |
|
92 template <class T> |
4915
|
93 intNDArray<T>& |
|
94 intNDArray<T>::insert (const intNDArray<T>& a, int r, int c) |
|
95 { |
|
96 Array<T>::insert (a, r, c); |
|
97 return *this; |
|
98 } |
|
99 |
|
100 template <class T> |
|
101 intNDArray<T>& |
|
102 intNDArray<T>::insert (const intNDArray<T>& a, const Array<int>& ra_idx) |
|
103 { |
|
104 Array<T>::insert (a, ra_idx); |
|
105 return *this; |
|
106 } |
|
107 |
4902
|
108 // This contains no information on the array structure !!! |
|
109 |
|
110 template <class T> |
|
111 std::ostream& |
|
112 operator << (std::ostream& os, const intNDArray<T>& a) |
|
113 { |
|
114 int nel = a.nelem (); |
|
115 |
|
116 for (int i = 0; i < nel; i++) |
|
117 os << " " << a.elem (i) << "\n"; |
|
118 |
|
119 return os; |
|
120 } |
|
121 |
|
122 template <class T> |
|
123 std::istream& |
|
124 operator >> (std::istream& is, intNDArray<T>& a) |
|
125 { |
|
126 int nel = a.nelem (); |
|
127 |
|
128 if (nel < 1 ) |
|
129 is.clear (std::ios::badbit); |
|
130 else |
|
131 { |
|
132 T tmp; |
|
133 |
|
134 for (int i = 0; i < nel; i++) |
|
135 { |
|
136 is >> tmp; |
|
137 |
|
138 if (is) |
|
139 a.elem (i) = tmp; |
|
140 else |
|
141 goto done; |
|
142 } |
|
143 } |
|
144 |
|
145 done: |
|
146 |
|
147 return is; |
|
148 } |
|
149 |
|
150 /* |
|
151 ;;; Local Variables: *** |
|
152 ;;; mode: C++ *** |
|
153 ;;; End: *** |
|
154 */ |