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 { |
|
42 boolNDArray b (dims ()); |
|
43 |
|
44 for (int i = 0; i < length (); i++) |
|
45 b.elem (i) = ! elem (i); |
|
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 { |
|
56 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (elem (iter_idx) == T (0)), true); |
|
57 } |
|
58 |
|
59 template <class T> |
|
60 boolNDArray |
|
61 intNDArray<T>::any (int dim) const |
|
62 { |
|
63 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (elem (iter_idx) == T (0)), false); |
|
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> |
|
84 intNDArray<T>& |
|
85 intNDArray<T>::insert (const intNDArray<T>& a, int r, int c) |
|
86 { |
|
87 Array<T>::insert (a, r, c); |
|
88 return *this; |
|
89 } |
|
90 |
|
91 template <class T> |
|
92 intNDArray<T>& |
|
93 intNDArray<T>::insert (const intNDArray<T>& a, const Array<int>& ra_idx) |
|
94 { |
|
95 Array<T>::insert (a, ra_idx); |
|
96 return *this; |
|
97 } |
|
98 |
4902
|
99 // This contains no information on the array structure !!! |
|
100 |
|
101 template <class T> |
|
102 std::ostream& |
|
103 operator << (std::ostream& os, const intNDArray<T>& a) |
|
104 { |
|
105 int nel = a.nelem (); |
|
106 |
|
107 for (int i = 0; i < nel; i++) |
|
108 os << " " << a.elem (i) << "\n"; |
|
109 |
|
110 return os; |
|
111 } |
|
112 |
|
113 template <class T> |
|
114 std::istream& |
|
115 operator >> (std::istream& is, intNDArray<T>& a) |
|
116 { |
|
117 int nel = a.nelem (); |
|
118 |
|
119 if (nel < 1 ) |
|
120 is.clear (std::ios::badbit); |
|
121 else |
|
122 { |
|
123 T tmp; |
|
124 |
|
125 for (int i = 0; i < nel; i++) |
|
126 { |
|
127 is >> tmp; |
|
128 |
|
129 if (is) |
|
130 a.elem (i) = tmp; |
|
131 else |
|
132 goto done; |
|
133 } |
|
134 } |
|
135 |
|
136 done: |
|
137 |
|
138 return is; |
|
139 } |
|
140 |
|
141 /* |
|
142 ;;; Local Variables: *** |
|
143 ;;; mode: C++ *** |
|
144 ;;; End: *** |
|
145 */ |