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 int |
|
68 intNDArray<T>::cat (const intNDArray<T>& ra_arg, int dim, int iidx, int move) |
|
69 { |
|
70 return ::cat_ra (*this, ra_arg, dim, iidx, move); |
|
71 } |
|
72 |
|
73 template <class T> |
|
74 void |
|
75 intNDArray<T>::increment_index (Array<int>& ra_idx, |
|
76 const dim_vector& dimensions, |
|
77 int start_dimension) |
|
78 { |
|
79 ::increment_index (ra_idx, dimensions, start_dimension); |
|
80 } |
|
81 |
|
82 template <class T> |
|
83 int |
|
84 intNDArray<T>::compute_index (Array<int>& ra_idx, |
|
85 const dim_vector& dimensions) |
|
86 { |
|
87 return ::compute_index (ra_idx, dimensions); |
|
88 } |
|
89 |
|
90 // This contains no information on the array structure !!! |
|
91 |
|
92 template <class T> |
|
93 std::ostream& |
|
94 operator << (std::ostream& os, const intNDArray<T>& a) |
|
95 { |
|
96 int nel = a.nelem (); |
|
97 |
|
98 for (int i = 0; i < nel; i++) |
|
99 os << " " << a.elem (i) << "\n"; |
|
100 |
|
101 return os; |
|
102 } |
|
103 |
|
104 template <class T> |
|
105 std::istream& |
|
106 operator >> (std::istream& is, intNDArray<T>& a) |
|
107 { |
|
108 int nel = a.nelem (); |
|
109 |
|
110 if (nel < 1 ) |
|
111 is.clear (std::ios::badbit); |
|
112 else |
|
113 { |
|
114 T tmp; |
|
115 |
|
116 for (int i = 0; i < nel; i++) |
|
117 { |
|
118 is >> tmp; |
|
119 |
|
120 if (is) |
|
121 a.elem (i) = tmp; |
|
122 else |
|
123 goto done; |
|
124 } |
|
125 } |
|
126 |
|
127 done: |
|
128 |
|
129 return is; |
|
130 } |
|
131 |
|
132 /* |
|
133 ;;; Local Variables: *** |
|
134 ;;; mode: C++ *** |
|
135 ;;; End: *** |
|
136 */ |