Mercurial > hg > octave-nkf
annotate liboctave/chNDArray.cc @ 10267:479c7df0cc96
don't instantiate MArray<char>
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 04 Feb 2010 14:36:49 +0100 |
parents | 4c0cdbe0acca |
children | 07ebe522dac2 |
rev | line source |
---|---|
4514 | 1 // N-D Array manipulations. |
2 /* | |
3 | |
8920 | 4 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
4514 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
4514 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
4514 | 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" |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8750
diff
changeset
|
33 #include "mx-op-defs.h" |
4514 | 34 |
10107
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
35 #include "bsxfun-defs.cc" |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
36 |
5775 | 37 // FIXME -- this is not quite the right thing. |
4514 | 38 |
4556 | 39 boolNDArray |
4514 | 40 charNDArray::all (int dim) const |
41 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
42 return do_mx_red_op<boolMatrix, char> (*this, dim, mx_inline_all); |
4514 | 43 } |
44 | |
4556 | 45 boolNDArray |
4514 | 46 charNDArray::any (int dim) const |
47 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
48 return do_mx_red_op<boolMatrix, char> (*this, dim, mx_inline_any); |
4514 | 49 } |
50 | |
4915 | 51 charNDArray |
5275 | 52 charNDArray::concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 53 { |
4940 | 54 if (rb.numel () > 0) |
5073 | 55 insert (rb, ra_idx); |
56 return *this; | |
4915 | 57 } |
58 | |
59 charNDArray | |
5275 | 60 charNDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx) |
4758 | 61 { |
4915 | 62 charNDArray tmp (rb.dims ()); |
5275 | 63 octave_idx_type nel = rb.numel (); |
4915 | 64 |
4940 | 65 if (rb.numel () == 0) |
5073 | 66 return *this; |
4915 | 67 |
5275 | 68 for (octave_idx_type i = 0; i < nel; i++) |
4915 | 69 { |
70 double d = rb.elem (i); | |
71 | |
72 if (xisnan (d)) | |
73 { | |
74 (*current_liboctave_error_handler) | |
75 ("invalid conversion from NaN to character"); | |
5073 | 76 return *this; |
4915 | 77 } |
78 else | |
79 { | |
5275 | 80 octave_idx_type ival = NINTbig (d); |
4915 | 81 |
82 if (ival < 0 || ival > UCHAR_MAX) | |
5775 | 83 // FIXME -- is there something |
4915 | 84 // better we could do? Should we warn the user? |
85 ival = 0; | |
86 | |
87 tmp.elem (i) = static_cast<char>(ival); | |
88 } | |
89 } | |
90 | |
5073 | 91 insert (tmp, ra_idx); |
92 return *this; | |
4915 | 93 } |
94 | |
95 charNDArray& | |
5275 | 96 charNDArray::insert (const charNDArray& a, octave_idx_type r, octave_idx_type c) |
4915 | 97 { |
98 Array<char>::insert (a, r, c); | |
99 return *this; | |
100 } | |
101 | |
102 charNDArray& | |
5275 | 103 charNDArray::insert (const charNDArray& a, const Array<octave_idx_type>& ra_idx) |
4915 | 104 { |
105 Array<char>::insert (a, ra_idx); | |
106 return *this; | |
4758 | 107 } |
108 | |
4514 | 109 charMatrix |
110 charNDArray::matrix_value (void) const | |
111 { | |
112 charMatrix retval; | |
113 | |
114 int nd = ndims (); | |
115 | |
116 switch (nd) | |
117 { | |
118 case 1: | |
119 retval = charMatrix (Array2<char> (*this, dimensions(0), 1)); | |
120 break; | |
121 | |
122 case 2: | |
123 retval = charMatrix (Array2<char> (*this, dimensions(0), | |
124 dimensions(1))); | |
125 break; | |
126 | |
127 default: | |
128 (*current_liboctave_error_handler) | |
4770 | 129 ("invalid conversion of charNDArray to charMatrix"); |
4514 | 130 break; |
131 } | |
132 | |
133 return retval; | |
134 } | |
135 | |
4532 | 136 void |
5275 | 137 charNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 138 const dim_vector& dimensions, |
139 int start_dimension) | |
140 { | |
141 ::increment_index (ra_idx, dimensions, start_dimension); | |
142 } | |
143 | |
5275 | 144 octave_idx_type |
145 charNDArray::compute_index (Array<octave_idx_type>& ra_idx, | |
4556 | 146 const dim_vector& dimensions) |
147 { | |
148 return ::compute_index (ra_idx, dimensions); | |
149 } | |
150 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
151 charNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
152 charNDArray::diag (octave_idx_type k) const |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
153 { |
10267
479c7df0cc96
don't instantiate MArray<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
154 return Array<char>::diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
155 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
156 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
157 NDS_CMP_OPS (charNDArray, char) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
158 NDS_BOOL_OPS (charNDArray, char) |
6456 | 159 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
160 SND_CMP_OPS (char, charNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
161 SND_BOOL_OPS (char, charNDArray) |
6456 | 162 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
163 NDND_CMP_OPS (charNDArray, charNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
164 NDND_BOOL_OPS (charNDArray, charNDArray) |
6456 | 165 |
10107
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
166 BSXFUN_STDREL_DEFS_MXLOOP (charNDArray) |