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