4514
|
1 // N-D Array manipulations. |
|
2 /* |
|
3 |
|
4 Copyright (C) 2003 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 |
4588
|
32 #include "Array-util.h" |
4514
|
33 #include "chNDArray.h" |
|
34 #include "mx-base.h" |
|
35 #include "lo-ieee.h" |
4915
|
36 #include "lo-mappers.h" |
4514
|
37 |
|
38 // XXX FIXME XXX -- this is not quite the right thing. |
|
39 |
4556
|
40 boolNDArray |
4514
|
41 charNDArray::all (int dim) const |
|
42 { |
4569
|
43 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (elem (iter_idx) == ' '), true); |
4514
|
44 } |
|
45 |
4556
|
46 boolNDArray |
4514
|
47 charNDArray::any (int dim) const |
|
48 { |
4569
|
49 MX_ND_ANY_ALL_REDUCTION (MX_ND_ANY_EVAL (elem (iter_idx) != ' '), false); |
4514
|
50 } |
|
51 |
4915
|
52 charNDArray |
5073
|
53 charNDArray::concat (const charNDArray& rb, const Array<int>& ra_idx) |
4915
|
54 { |
4940
|
55 if (rb.numel () > 0) |
5073
|
56 insert (rb, ra_idx); |
|
57 return *this; |
4915
|
58 } |
|
59 |
|
60 charNDArray |
5073
|
61 charNDArray::concat (const NDArray& rb, const Array<int>& ra_idx) |
4758
|
62 { |
4915
|
63 charNDArray tmp (rb.dims ()); |
|
64 int nel = rb.numel (); |
|
65 |
4940
|
66 if (rb.numel () == 0) |
5073
|
67 return *this; |
4915
|
68 |
|
69 for (int i = 0; i < nel; i++) |
|
70 { |
|
71 double d = rb.elem (i); |
|
72 |
|
73 if (xisnan (d)) |
|
74 { |
|
75 (*current_liboctave_error_handler) |
|
76 ("invalid conversion from NaN to character"); |
5073
|
77 return *this; |
4915
|
78 } |
|
79 else |
|
80 { |
|
81 int ival = NINT (d); |
|
82 |
|
83 if (ival < 0 || ival > UCHAR_MAX) |
|
84 // XXX FIXME XXX -- is there something |
|
85 // better we could do? Should we warn the user? |
|
86 ival = 0; |
|
87 |
|
88 tmp.elem (i) = static_cast<char>(ival); |
|
89 } |
|
90 } |
|
91 |
5073
|
92 insert (tmp, ra_idx); |
|
93 return *this; |
4915
|
94 } |
|
95 |
|
96 charNDArray& |
|
97 charNDArray::insert (const charNDArray& a, int r, int c) |
|
98 { |
|
99 Array<char>::insert (a, r, c); |
|
100 return *this; |
|
101 } |
|
102 |
|
103 charNDArray& |
|
104 charNDArray::insert (const charNDArray& a, const Array<int>& ra_idx) |
|
105 { |
|
106 Array<char>::insert (a, ra_idx); |
|
107 return *this; |
4758
|
108 } |
|
109 |
4514
|
110 charMatrix |
|
111 charNDArray::matrix_value (void) const |
|
112 { |
|
113 charMatrix retval; |
|
114 |
|
115 int nd = ndims (); |
|
116 |
|
117 switch (nd) |
|
118 { |
|
119 case 1: |
|
120 retval = charMatrix (Array2<char> (*this, dimensions(0), 1)); |
|
121 break; |
|
122 |
|
123 case 2: |
|
124 retval = charMatrix (Array2<char> (*this, dimensions(0), |
|
125 dimensions(1))); |
|
126 break; |
|
127 |
|
128 default: |
|
129 (*current_liboctave_error_handler) |
4770
|
130 ("invalid conversion of charNDArray to charMatrix"); |
4514
|
131 break; |
|
132 } |
|
133 |
|
134 return retval; |
|
135 } |
|
136 |
4532
|
137 void |
|
138 charNDArray::increment_index (Array<int>& ra_idx, |
|
139 const dim_vector& dimensions, |
|
140 int start_dimension) |
|
141 { |
|
142 ::increment_index (ra_idx, dimensions, start_dimension); |
|
143 } |
|
144 |
4556
|
145 int |
|
146 charNDArray::compute_index (Array<int>& ra_idx, |
|
147 const dim_vector& dimensions) |
|
148 { |
|
149 return ::compute_index (ra_idx, dimensions); |
|
150 } |
|
151 |
4514
|
152 /* |
|
153 ;;; Local Variables: *** |
|
154 ;;; mode: C++ *** |
|
155 ;;; End: *** |
|
156 */ |