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