chNDArray.cc

Go to the documentation of this file.
00001 // N-D Array  manipulations.
00002 /*
00003 
00004 Copyright (C) 2003-2012 John W. Eaton
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include "Array-util.h"
00029 #include "chNDArray.h"
00030 #include "mx-base.h"
00031 #include "lo-ieee.h"
00032 #include "lo-mappers.h"
00033 #include "mx-op-defs.h"
00034 
00035 #include "bsxfun-defs.cc"
00036 
00037 // FIXME -- this is not quite the right thing.
00038 
00039 boolNDArray
00040 charNDArray::all (int dim) const
00041 {
00042   return do_mx_red_op<bool, char> (*this, dim, mx_inline_all);
00043 }
00044 
00045 boolNDArray
00046 charNDArray::any (int dim) const
00047 {
00048   return do_mx_red_op<bool, char> (*this, dim, mx_inline_any);
00049 }
00050 
00051 charNDArray
00052 charNDArray::concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx)
00053 {
00054   if (rb.numel () > 0)
00055     insert (rb, ra_idx);
00056   return *this;
00057 }
00058 
00059 charNDArray
00060 charNDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx)
00061 {
00062   charNDArray tmp (rb.dims ());
00063   octave_idx_type nel = rb.numel ();
00064 
00065   if (rb.numel () == 0)
00066     return *this;
00067 
00068   for (octave_idx_type i = 0; i < nel; i++)
00069     {
00070       double d = rb.elem (i);
00071 
00072       if (xisnan (d))
00073         {
00074           (*current_liboctave_error_handler)
00075             ("invalid conversion from NaN to character");
00076           return *this;
00077         }
00078       else
00079         {
00080           octave_idx_type ival = NINTbig (d);
00081 
00082           if (ival < 0 || ival > UCHAR_MAX)
00083             // FIXME -- is there something
00084             // better we could do? Should we warn the user?
00085             ival = 0;
00086 
00087           tmp.elem (i) = static_cast<char>(ival);
00088         }
00089     }
00090 
00091   insert (tmp, ra_idx);
00092   return *this;
00093 }
00094 
00095 charNDArray&
00096 charNDArray::insert (const charNDArray& a, octave_idx_type r, octave_idx_type c)
00097 {
00098   Array<char>::insert (a, r, c);
00099   return *this;
00100 }
00101 
00102 charNDArray&
00103 charNDArray::insert (const charNDArray& a, const Array<octave_idx_type>& ra_idx)
00104 {
00105   Array<char>::insert (a, ra_idx);
00106   return *this;
00107 }
00108 
00109 charMatrix
00110 charNDArray::matrix_value (void) const
00111 {
00112   return *this;
00113 }
00114 
00115 void
00116 charNDArray::increment_index (Array<octave_idx_type>& ra_idx,
00117                               const dim_vector& dimensions,
00118                               int start_dimension)
00119 {
00120   ::increment_index (ra_idx, dimensions, start_dimension);
00121 }
00122 
00123 octave_idx_type
00124 charNDArray::compute_index (Array<octave_idx_type>& ra_idx,
00125                             const dim_vector& dimensions)
00126 {
00127   return ::compute_index (ra_idx, dimensions);
00128 }
00129 
00130 charNDArray
00131 charNDArray::diag (octave_idx_type k) const
00132 {
00133   return Array<char>::diag (k);
00134 }
00135 
00136 NDS_CMP_OPS (charNDArray, char)
00137 NDS_BOOL_OPS (charNDArray, char)
00138 
00139 SND_CMP_OPS (char, charNDArray)
00140 SND_BOOL_OPS (char, charNDArray)
00141 
00142 NDND_CMP_OPS (charNDArray, charNDArray)
00143 NDND_BOOL_OPS (charNDArray, charNDArray)
00144 
00145 BSXFUN_STDREL_DEFS_MXLOOP (charNDArray)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines