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