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