00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
00025 #pragma implementation
00026 #endif
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032 #include "Array-util.h"
00033 #include "chNDArray.h"
00034 #include "mx-base.h"
00035 #include "lo-ieee.h"
00036 #include "lo-mappers.h"
00037
00038
00039
00040 boolNDArray
00041 charNDArray::all (int dim) const
00042 {
00043 MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (elem (iter_idx) == ' '), true);
00044 }
00045
00046 boolNDArray
00047 charNDArray::any (int dim) const
00048 {
00049 MX_ND_ANY_ALL_REDUCTION (MX_ND_ANY_EVAL (elem (iter_idx) != ' '), false);
00050 }
00051
00052 charNDArray
00053 charNDArray::concat (const charNDArray& rb, const Array<int>& ra_idx)
00054 {
00055 if (rb.numel () > 0)
00056 insert (rb, ra_idx);
00057 return *this;
00058 }
00059
00060 charNDArray
00061 charNDArray::concat (const NDArray& rb, const Array<int>& ra_idx)
00062 {
00063 charNDArray tmp (rb.dims ());
00064 int nel = rb.numel ();
00065
00066 if (rb.numel () == 0)
00067 return *this;
00068
00069 for (int i = 0; i < nel; i++)
00070 {
00071 double d = rb.elem (i);
00072
00073 if (xisnan (d))
00074 {
00075 (*current_liboctave_error_handler)
00076 ("invalid conversion from NaN to character");
00077 return *this;
00078 }
00079 else
00080 {
00081 int ival = NINT (d);
00082
00083 if (ival < 0 || ival > UCHAR_MAX)
00084
00085
00086 ival = 0;
00087
00088 tmp.elem (i) = static_cast<char>(ival);
00089 }
00090 }
00091
00092 insert (tmp, ra_idx);
00093 return *this;
00094 }
00095
00096 charNDArray&
00097 charNDArray::insert (const charNDArray& a, int r, int c)
00098 {
00099 Array<char>::insert (a, r, c);
00100 return *this;
00101 }
00102
00103 charNDArray&
00104 charNDArray::insert (const charNDArray& a, const Array<int>& ra_idx)
00105 {
00106 Array<char>::insert (a, ra_idx);
00107 return *this;
00108 }
00109
00110 charMatrix
00111 charNDArray::matrix_value (void) const
00112 {
00113 charMatrix retval;
00114
00115 int nd = ndims ();
00116
00117 switch (nd)
00118 {
00119 case 1:
00120 retval = charMatrix (Array2<char> (*this, dimensions(0), 1));
00121 break;
00122
00123 case 2:
00124 retval = charMatrix (Array2<char> (*this, dimensions(0),
00125 dimensions(1)));
00126 break;
00127
00128 default:
00129 (*current_liboctave_error_handler)
00130 ("invalid conversion of charNDArray to charMatrix");
00131 break;
00132 }
00133
00134 return retval;
00135 }
00136
00137 void
00138 charNDArray::increment_index (Array<int>& ra_idx,
00139 const dim_vector& dimensions,
00140 int start_dimension)
00141 {
00142 ::increment_index (ra_idx, dimensions, start_dimension);
00143 }
00144
00145 int
00146 charNDArray::compute_index (Array<int>& ra_idx,
00147 const dim_vector& dimensions)
00148 {
00149 return ::compute_index (ra_idx, dimensions);
00150 }
00151
00152
00153
00154
00155
00156