# HG changeset patch # User jwe # Date 1087238949 0 # Node ID bd043a433918b3c15c2e66578379eabe78078fa7 # Parent 35bfb4e0b96b18a66513fc851e2edda4d0c95ac6 [project @ 2004-06-14 18:46:20 by jwe] diff -r 35bfb4e0b96b -r bd043a433918 liboctave/Array-i.cc --- a/liboctave/Array-i.cc Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/Array-i.cc Mon Jun 14 18:49:09 2004 +0000 @@ -24,6 +24,8 @@ #include #endif +#include "oct-inttypes.h" + // Instantiate Arrays of integer values. #include "Array.h" @@ -34,6 +36,26 @@ INSTANTIATE_ARRAY_ASSIGN (int, short); INSTANTIATE_ARRAY_ASSIGN (int, char); +INSTANTIATE_ARRAY_AND_ASSIGN (octave_int8); +INSTANTIATE_ARRAY_AND_ASSIGN (octave_int16); +INSTANTIATE_ARRAY_AND_ASSIGN (octave_int32); +INSTANTIATE_ARRAY_AND_ASSIGN (octave_int64); + +INSTANTIATE_ARRAY_AND_ASSIGN (octave_uint8); +INSTANTIATE_ARRAY_AND_ASSIGN (octave_uint16); +INSTANTIATE_ARRAY_AND_ASSIGN (octave_uint32); +INSTANTIATE_ARRAY_AND_ASSIGN (octave_uint64); + +INSTANTIATE_ARRAY_CAT (octave_int8); +INSTANTIATE_ARRAY_CAT (octave_int16); +INSTANTIATE_ARRAY_CAT (octave_int32); +INSTANTIATE_ARRAY_CAT (octave_int64); + +INSTANTIATE_ARRAY_CAT (octave_uint8); +INSTANTIATE_ARRAY_CAT (octave_uint16); +INSTANTIATE_ARRAY_CAT (octave_uint32); +INSTANTIATE_ARRAY_CAT (octave_uint64); + #include "Array2.h" template class Array2; diff -r 35bfb4e0b96b -r bd043a433918 liboctave/Array.h --- a/liboctave/Array.h Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/Array.h Mon Jun 14 18:49:09 2004 +0000 @@ -133,13 +133,12 @@ rep->fill (val); } - typename Array::ArrayRep *rep; - public: - // !!! WARNING !!! -- this is public because template friends don't - // work properly with versions of gcc earlier than 3.3. You should - // not access this data member directly! + // !!! WARNING !!! -- these should be protected, not public. You + // should not access these data members directly! + + typename Array::ArrayRep *rep; dim_vector dimensions; @@ -166,6 +165,18 @@ return nr; } + template + T * + coerce (const U *a, int len) + { + T *retval = new T [len]; + + for (int i = 0; i < len; i++) + retval[i] = T (a[i]); + + return retval; + } + public: Array (void) @@ -183,6 +194,15 @@ fill (val); } + // Type conversion case. + template + Array (const Array& a) + : rep (new typename Array::ArrayRep (coerce (a.data (), a.length ()), a.length ())), + dimensions (a.dimensions), idx (0), idx_count (0) + { + } + + // No type conversion case. Array (const Array& a) : rep (a.rep), dimensions (a.dimensions), idx (0), idx_count (0) { @@ -241,6 +261,8 @@ int columns (void) const { return dim2 (); } int pages (void) const { return dim3 (); } + size_t byte_size (void) const { return numel () * sizeof (T); } + dim_vector dims (void) const { return dimensions; } Array squeeze (void) const; diff -r 35bfb4e0b96b -r bd043a433918 liboctave/ArrayN.h --- a/liboctave/ArrayN.h Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/ArrayN.h Mon Jun 14 18:49:09 2004 +0000 @@ -64,13 +64,18 @@ ArrayN (const dim_vector& dv, const T& val) : Array (dv) { fill (val); } - ArrayN (const Array2& a) : Array (a, a.dims ()) { } + template + explicit ArrayN (const Array2& a) : Array (a, a.dims ()) { } - ArrayN (const ArrayN& a) : Array (a, a.dims ()) { } + template + ArrayN (const ArrayN& a) : Array (a, a.dims ()) { } - ArrayN (const Array& a) : Array (a) { } + template + ArrayN (const Array& a) : Array (a) { } - ArrayN (const Array& a, const dim_vector& dv) : Array (a, dv) { } + template + ArrayN (const Array& a, const dim_vector& dv) + : Array (a, dv) { } ~ArrayN (void) { } @@ -82,6 +87,15 @@ return *this; } + ArrayN reshape (const dim_vector& new_dims) const + { return Array::reshape (new_dims); } + + ArrayN permute (const Array& vec, bool inv = false) const + { return Array::permute (vec, inv); } + + ArrayN ipermute (const Array& vec) const + { return Array::ipermute (vec); } + void resize (const dim_vector& dv) { this->resize_no_fill (dv); } @@ -90,6 +104,8 @@ ArrayN squeeze (void) const { return Array::squeeze (); } + ArrayN transpose (void) const { return Array::transpose (); } + ArrayN& insert (const ArrayN& a, const dim_vector& dv) { Array::insert (a, dv); diff -r 35bfb4e0b96b -r bd043a433918 liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/CNDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -60,30 +60,6 @@ } #endif -// XXX FIXME XXX -- could we use a templated mixed-type copy function -// here? - -ComplexNDArray::ComplexNDArray (const NDArray& a) - : MArrayN (a.dims ()) -{ - for (int i = 0; i < a.length (); i++) - elem (i) = a.elem (i); -} - -ComplexNDArray::ComplexNDArray (const boolNDArray& a) - : MArrayN (a.dims ()) -{ - for (int i = 0; i < a.length (); i++) - elem (i) = a.elem (i); -} - -ComplexNDArray::ComplexNDArray (const charNDArray& a) - : MArrayN (a.dims ()) -{ - for (int i = 0; i < a.length (); i++) - elem (i) = a.elem (i); -} - #if defined (HAVE_FFTW3) ComplexNDArray ComplexNDArray::fourier (int dim) const diff -r 35bfb4e0b96b -r bd043a433918 liboctave/CNDArray.h --- a/liboctave/CNDArray.h Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/CNDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -54,14 +54,6 @@ ComplexNDArray (const MArrayN& a) : MArrayN (a) { } - ComplexNDArray (const ArrayN& a) : MArrayN (a) { } - - explicit ComplexNDArray (const NDArray& a); - - explicit ComplexNDArray (const boolNDArray& a); - - explicit ComplexNDArray (const charNDArray& a); - ComplexNDArray& operator = (const ComplexNDArray& a) { MArrayN::operator = (a); @@ -110,7 +102,7 @@ ComplexMatrix matrix_value (void) const; - ComplexNDArray squeeze (void) const { return ArrayN::squeeze (); } + ComplexNDArray squeeze (void) const { return MArrayN::squeeze (); } static void increment_index (Array& ra_idx, const dim_vector& dimensions, diff -r 35bfb4e0b96b -r bd043a433918 liboctave/ChangeLog --- a/liboctave/ChangeLog Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/ChangeLog Mon Jun 14 18:49:09 2004 +0000 @@ -1,3 +1,56 @@ +2004-06-14 John W. Eaton + + * mx-base.h: Include headers for new int types. + + * dNDArray.h, dNDArray.cc (NDArray::NDArray (const boolNDArray&), + NDArray::NDArray (const charNDArray&)): Delete. + (template explicit NDArray (const intNDArray&)): New + constructor. + (NDArray::squeze): Call MArrayN::squeeze, not ArrayN::squeeze. + + * chMatrix.h (CharMatrix::transpose): New forwarding functions for + return type conversion. + + * ComplexNDArray.h, ComplexNDArray.cc + (ComplexNDArray::ComplexNDArray (const ArrayN&), + (ComplexNDArray::ComplexNDArray (const NDArray&), + (ComplexNDArray::ComplexNDArray (const boolNDArray&), + (ComplexNDArray::ComplexNDArray (const charNDArray&)): Delete. + + (ComplexNDArray::squeze): Call MArrayN::squeeze, not ArrayN::squeeze. + + * MArrayN.h: + (template explicit MArrayN::MArrayN (const Array2&), + (template MArrayN::MArrayN (const ArrayN&), + (template explicit MArrayN::MArrayN (const MArray&)): + New constructors. + (ArrayN::reshape, ArrayN::permute, ArrayN::ipermute, + ArrayN::squeeze): + New forwarding functions for return type conversion. + + * ArrayN.h: + (template explicit ArrayN::ArrayN (const Array2&), + (template explicit ArrayN::ArrayN (const ArrayN&), + (template explicit ArrayN::ArrayN (const Array&), + (template explicit ArrayN::ArrayN (const Array&, + const dim_vector&)): New constructors. + (ArrayN::reshape, ArrayN::permute, ArrayN::ipermute, + ArrayN::transpose): + New forwarding functions for return type conversion. + + * Array.h (template Array::Array (const Array&)): + New constructor. + (Array::coerce, Array::byte_size): New functions. + + * Array-i.cc, MArray-i.cc: Instantiate new integer types. + + * oct-inttypes.h, int16NDArray.h, int32NDArray.h, int64NDArray.h, + int8NDArray.h , intNDArray.h, uint16NDArray.h, uint32NDArray.h, + uint64NDArray.h, uint8NDArray.h, int16NDArray.cc, int32NDArray.cc, + int64NDArray.cc, int8NDArray.cc, intNDArray.cc, uint16NDArray.cc, + uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc: New files. + * Makefile.in: Add them to the appropriate lists. + 2004-06-04 John W. Eaton * mx-inlines.cc (MX_ND_REDUCTION): New arg, RET_ELT_TYPE. Use diff -r 35bfb4e0b96b -r bd043a433918 liboctave/MArray-i.cc --- a/liboctave/MArray-i.cc Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/MArray-i.cc Mon Jun 14 18:49:09 2004 +0000 @@ -24,6 +24,8 @@ #include #endif +#include "oct-inttypes.h" + // Instantiate MArrays of int values. #include "MArray.h" @@ -33,6 +35,26 @@ INSTANTIATE_MARRAY_FRIENDS (int) +template class MArray; +template class MArray; +template class MArray; +template class MArray; + +INSTANTIATE_MARRAY_FRIENDS (octave_int8) +INSTANTIATE_MARRAY_FRIENDS (octave_int16) +INSTANTIATE_MARRAY_FRIENDS (octave_int32) +INSTANTIATE_MARRAY_FRIENDS (octave_int64) + +template class MArray; +template class MArray; +template class MArray; +template class MArray; + +INSTANTIATE_MARRAY_FRIENDS (octave_uint8) +INSTANTIATE_MARRAY_FRIENDS (octave_uint16) +INSTANTIATE_MARRAY_FRIENDS (octave_uint32) +INSTANTIATE_MARRAY_FRIENDS (octave_uint64) + #include "MArray2.h" #include "MArray2.cc" @@ -40,6 +62,33 @@ INSTANTIATE_MARRAY2_FRIENDS (int) +#include "MArrayN.h" +#include "MArrayN.cc" + +template class MArrayN; + +INSTANTIATE_MARRAYN_FRIENDS (int) + +template class MArrayN; +template class MArrayN; +template class MArrayN; +template class MArrayN; + +INSTANTIATE_MARRAYN_FRIENDS (octave_int8) +INSTANTIATE_MARRAYN_FRIENDS (octave_int16) +INSTANTIATE_MARRAYN_FRIENDS (octave_int32) +INSTANTIATE_MARRAYN_FRIENDS (octave_int64) + +template class MArrayN; +template class MArrayN; +template class MArrayN; +template class MArrayN; + +INSTANTIATE_MARRAYN_FRIENDS (octave_uint8) +INSTANTIATE_MARRAYN_FRIENDS (octave_uint16) +INSTANTIATE_MARRAYN_FRIENDS (octave_uint32) +INSTANTIATE_MARRAYN_FRIENDS (octave_uint64) + #include "MDiagArray2.h" #include "MDiagArray2.cc" diff -r 35bfb4e0b96b -r bd043a433918 liboctave/MArrayN.h --- a/liboctave/MArrayN.h Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/MArrayN.h Mon Jun 14 18:49:09 2004 +0000 @@ -56,11 +56,14 @@ MArrayN (const dim_vector& dv, const T& val) : ArrayN (dv, val) { } - MArrayN (const Array2& a) : ArrayN (a) { } + template + explicit MArrayN (const Array2& a) : ArrayN (a) { } - MArrayN (const ArrayN& a) : ArrayN (a) { } + template + MArrayN (const ArrayN& a) : ArrayN (a) { } - MArrayN (const MArrayN& a) : ArrayN (a) { } + template + MArrayN (const MArrayN& a) : ArrayN (a) { } ~MArrayN (void) { } @@ -69,6 +72,17 @@ ArrayN::operator = (a); return *this; } + + MArrayN reshape (const dim_vector& new_dims) const + { return ArrayN::reshape (new_dims); } + + MArrayN permute (const Array& vec, bool inv = false) const + { return ArrayN::permute (vec, inv); } + + MArrayN ipermute (const Array& vec) const + { return ArrayN::ipermute (vec); } + + MArrayN squeeze (void) const { return ArrayN::squeeze (); } }; #endif diff -r 35bfb4e0b96b -r bd043a433918 liboctave/Makefile.in --- a/liboctave/Makefile.in Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/Makefile.in Mon Jun 14 18:49:09 2004 +0000 @@ -32,7 +32,9 @@ CmplxSCHUR.h CmplxSVD.h EIG.h boolMatrix.h boolNDArray.h \ chMatrix.h chNDArray.h dColVector.h dDiagMatrix.h dMatrix.h \ dNDArray.h dRowVector.h dbleAEPBAL.h dbleCHOL.h dbleDET.h \ - dbleHESS.h dbleLU.h dbleQR.h dbleQRP.h dbleSCHUR.h dbleSVD.h + dbleHESS.h dbleLU.h dbleQR.h dbleQRP.h dbleSCHUR.h dbleSVD.h \ + int8NDArray.h uint8NDArray.h int16NDArray.h uint16NDArray.h \ + int32NDArray.h uint32NDArray.h int64NDArray.h uint64NDArray.h MX_OP_INC := $(shell $(AWK) -f $(srcdir)/mk-ops.awk prefix=mx list_h_files=1 $(srcdir)/mx-ops) @@ -76,10 +78,12 @@ CmplxAEPBAL.cc CmplxCHOL.cc CmplxDET.cc CmplxHESS.cc \ CmplxLU.cc CmplxQR.cc CmplxQRP.cc CmplxSCHUR.cc CmplxSVD.cc \ EIG.cc boolMatrix.cc boolNDArray.cc chMatrix.cc \ - chNDArray.cc dColVector.cc dDiagMatrix.cc dMatrix.cc \ + chNDArray.cc dColVector.cc dDiagMatrix.cc dMatrix.cc \ dNDArray.cc dRowVector.cc dbleAEPBAL.cc dbleCHOL.cc \ dbleDET.cc dbleHESS.cc dbleLU.cc dbleQR.cc dbleQRP.cc \ - dbleSCHUR.cc dbleSVD.cc + dbleSCHUR.cc dbleSVD.cc \ + int8NDArray.cc uint8NDArray.cc int16NDArray.cc uint16NDArray.cc \ + int32NDArray.cc uint32NDArray.cc int64NDArray.cc uint64NDArray.cc MX_OP_SRC := $(shell $(AWK) -f $(srcdir)/mk-ops.awk prefix=mx list_cc_files=1 $(srcdir)/mx-ops) diff -r 35bfb4e0b96b -r bd043a433918 liboctave/chMatrix.h --- a/liboctave/chMatrix.h Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/chMatrix.h Mon Jun 14 18:49:09 2004 +0000 @@ -60,6 +60,8 @@ bool operator == (const charMatrix& a) const; bool operator != (const charMatrix& a) const; + charMatrix transpose (void) const { return MArray2::transpose (); } + // destructive insert/delete/reorder operations charMatrix& insert (const char *s, int r, int c); diff -r 35bfb4e0b96b -r bd043a433918 liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/dNDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -482,20 +482,6 @@ #endif -NDArray::NDArray (const boolNDArray& a) - : MArrayN (a.dims ()) -{ - for (int i = 0; i < a.length (); i++) - elem (i) = a.elem (i); -} - -NDArray::NDArray (const charNDArray& a) - : MArrayN (a.dims ()) -{ - for (int i = 0; i < a.length (); i++) - elem (i) = a.elem (i); -} - // unary operations boolNDArray diff -r 35bfb4e0b96b -r bd043a433918 liboctave/dNDArray.h --- a/liboctave/dNDArray.h Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/dNDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -29,6 +29,7 @@ #include "MArrayN.h" #include "dMatrix.h" +#include "intNDArray.h" #include "mx-defs.h" #include "mx-op-defs.h" @@ -54,11 +55,8 @@ NDArray (const MArrayN& a) : MArrayN (a) { } - NDArray (const ArrayN& a) : MArrayN (a) { } - - explicit NDArray (const boolNDArray& a); - - explicit NDArray (const charNDArray& a); + template + explicit NDArray (const intNDArray& a) : MArrayN (a) { } NDArray& operator = (const NDArray& a) { @@ -109,7 +107,7 @@ Matrix matrix_value (void) const; - NDArray squeeze (void) const { return ArrayN::squeeze (); } + NDArray squeeze (void) const { return MArrayN::squeeze (); } static void increment_index (Array& ra_idx, const dim_vector& dimensions, diff -r 35bfb4e0b96b -r bd043a433918 liboctave/int16NDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/int16NDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,59 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "int16NDArray.h" + +#include "intNDArray.cc" + +template class intNDArray; + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& +operator >> (std::istream& is, intNDArray& a); + +NDS_CMP_OPS (int16NDArray, , octave_int16, ) +NDS_BOOL_OPS (int16NDArray, octave_int16, octave_int16 (0)) + +SND_CMP_OPS (octave_int16, , int16NDArray, ) +SND_BOOL_OPS (octave_int16, int16NDArray, octave_int16 (0)) + +NDND_CMP_OPS (int16NDArray, , int16NDArray, ) +NDND_BOOL_OPS (int16NDArray, int16NDArray, octave_int16 (0)) + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/int16NDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/int16NDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,53 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_int16NDArray_h) +#define octave_int16NDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "intNDArray.h" +#include "mx-op-defs.h" +#include "oct-inttypes.h" + +typedef intNDArray int16NDArray; + +NDS_CMP_OP_DECLS (int16NDArray, octave_int16) +NDS_BOOL_OP_DECLS (int16NDArray, octave_int16) + +SND_CMP_OP_DECLS (octave_int16, int16NDArray) +SND_BOOL_OP_DECLS (octave_int16, int16NDArray) + +NDND_CMP_OP_DECLS (int16NDArray, int16NDArray) +NDND_BOOL_OP_DECLS (int16NDArray, int16NDArray) + +MARRAY_FORWARD_DEFS (MArrayN, int16NDArray, octave_int16) + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/int32NDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/int32NDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,59 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "int32NDArray.h" + +#include "intNDArray.cc" + +template class intNDArray; + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& +operator >> (std::istream& is, intNDArray& a); + +NDS_CMP_OPS (int32NDArray, , octave_int32, ) +NDS_BOOL_OPS (int32NDArray, octave_int32, octave_int32 (0)) + +SND_CMP_OPS (octave_int32, , int32NDArray, ) +SND_BOOL_OPS (octave_int32, int32NDArray, octave_int32 (0)) + +NDND_CMP_OPS (int32NDArray, , int32NDArray, ) +NDND_BOOL_OPS (int32NDArray, int32NDArray, octave_int32 (0)) + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/int32NDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/int32NDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,53 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_int32NDArray_h) +#define octave_int32NDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "intNDArray.h" +#include "mx-op-defs.h" +#include "oct-inttypes.h" + +typedef intNDArray int32NDArray; + +NDS_CMP_OP_DECLS (int32NDArray, octave_int32) +NDS_BOOL_OP_DECLS (int32NDArray, octave_int32) + +SND_CMP_OP_DECLS (octave_int32, int32NDArray) +SND_BOOL_OP_DECLS (octave_int32, int32NDArray) + +NDND_CMP_OP_DECLS (int32NDArray, int32NDArray) +NDND_BOOL_OP_DECLS (int32NDArray, int32NDArray) + +MARRAY_FORWARD_DEFS (MArrayN, int32NDArray, octave_int32) + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/int64NDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/int64NDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,59 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "int64NDArray.h" + +#include "intNDArray.cc" + +template class intNDArray; + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& +operator >> (std::istream& is, intNDArray& a); + +NDS_CMP_OPS (int64NDArray, , octave_int64, ) +NDS_BOOL_OPS (int64NDArray, octave_int64, octave_int64 (0)) + +SND_CMP_OPS (octave_int64, , int64NDArray, ) +SND_BOOL_OPS (octave_int64, int64NDArray, octave_int64 (0)) + +NDND_CMP_OPS (int64NDArray, , int64NDArray, ) +NDND_BOOL_OPS (int64NDArray, int64NDArray, octave_int64 (0)) + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/int64NDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/int64NDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,53 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_int64NDArray_h) +#define octave_int64NDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "intNDArray.h" +#include "mx-op-defs.h" +#include "oct-inttypes.h" + +typedef intNDArray int64NDArray; + +NDS_CMP_OP_DECLS (int64NDArray, octave_int64) +NDS_BOOL_OP_DECLS (int64NDArray, octave_int64) + +SND_CMP_OP_DECLS (octave_int64, int64NDArray) +SND_BOOL_OP_DECLS (octave_int64, int64NDArray) + +NDND_CMP_OP_DECLS (int64NDArray, int64NDArray) +NDND_BOOL_OP_DECLS (int64NDArray, int64NDArray) + +MARRAY_FORWARD_DEFS (MArrayN, int64NDArray, octave_int64) + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/int8NDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/int8NDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,59 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "int8NDArray.h" + +#include "intNDArray.cc" + +template class intNDArray; + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& +operator >> (std::istream& is, intNDArray& a); + +NDS_CMP_OPS (int8NDArray, , octave_int8, ) +NDS_BOOL_OPS (int8NDArray, octave_int8, octave_int8 (0)) + +SND_CMP_OPS (octave_int8, , int8NDArray, ) +SND_BOOL_OPS (octave_int8, int8NDArray, octave_int8 (0)) + +NDND_CMP_OPS (int8NDArray, , int8NDArray, ) +NDND_BOOL_OPS (int8NDArray, int8NDArray, octave_int8 (0)) + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/int8NDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/int8NDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,53 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_int8NDArray_h) +#define octave_int8NDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "intNDArray.h" +#include "mx-op-defs.h" +#include "oct-inttypes.h" + +typedef intNDArray int8NDArray; + +NDS_CMP_OP_DECLS (int8NDArray, octave_int8) +NDS_BOOL_OP_DECLS (int8NDArray, octave_int8) + +SND_CMP_OP_DECLS (octave_int8, int8NDArray) +SND_BOOL_OP_DECLS (octave_int8, int8NDArray) + +NDND_CMP_OP_DECLS (int8NDArray, int8NDArray) +NDND_BOOL_OP_DECLS (int8NDArray, int8NDArray) + +MARRAY_FORWARD_DEFS (MArrayN, int8NDArray, octave_int8) + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/intNDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/intNDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,136 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "Array-util.h" +#include "mx-base.h" +#include "lo-ieee.h" + +// unary operations + +template +boolNDArray +intNDArray::operator ! (void) const +{ + boolNDArray b (dims ()); + + for (int i = 0; i < length (); i++) + b.elem (i) = ! elem (i); + + return b; +} + +// XXX FIXME XXX -- this is not quite the right thing. + +template +boolNDArray +intNDArray::all (int dim) const +{ + MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (elem (iter_idx) == T (0)), true); +} + +template +boolNDArray +intNDArray::any (int dim) const +{ + MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (elem (iter_idx) == T (0)), false); +} + +template +int +intNDArray::cat (const intNDArray& ra_arg, int dim, int iidx, int move) +{ + return ::cat_ra (*this, ra_arg, dim, iidx, move); +} + +template +void +intNDArray::increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension) +{ + ::increment_index (ra_idx, dimensions, start_dimension); +} + +template +int +intNDArray::compute_index (Array& ra_idx, + const dim_vector& dimensions) +{ + return ::compute_index (ra_idx, dimensions); +} + +// This contains no information on the array structure !!! + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a) +{ + int nel = a.nelem (); + + for (int i = 0; i < nel; i++) + os << " " << a.elem (i) << "\n"; + + return os; +} + +template +std::istream& +operator >> (std::istream& is, intNDArray& a) +{ + int nel = a.nelem (); + + if (nel < 1 ) + is.clear (std::ios::badbit); + else + { + T tmp; + + for (int i = 0; i < nel; i++) + { + is >> tmp; + + if (is) + a.elem (i) = tmp; + else + goto done; + } + } + + done: + + return is; +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/intNDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/intNDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,108 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_intNDArray_h) +#define octave_intNDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "MArrayN.h" +#include "boolNDArray.h" + +template +class +intNDArray : public MArrayN +{ +public: + + intNDArray (void) : MArrayN () { } + + intNDArray (T val) : MArrayN (dim_vector (1, 1), val) { } + + intNDArray (const dim_vector& dv) : MArrayN (dv) { } + + intNDArray (const dim_vector& dv, T val) + : MArrayN (dv, val) { } + + template + explicit intNDArray (const Array& a) : MArrayN (a) { } + + template + explicit intNDArray (const ArrayN& a) : MArrayN (a) { } + + template + intNDArray (const MArrayN& a) : MArrayN (a) { } + + template + intNDArray (const intNDArray& a) : MArrayN (a) { } + + intNDArray& operator = (const intNDArray& a) + { + MArrayN::operator = (a); + return *this; + } + + boolNDArray operator ! (void) const; + + // XXX FIXME XXX -- this is not quite the right thing. + + boolNDArray all (int dim = -1) const; + boolNDArray any (int dim = -1) const; + int cat (const intNDArray& ra_arg, int dim, int iidx, int move); + + intNDArray squeeze (void) const + { return intNDArray (MArrayN::squeeze ()); } + + intNDArray transpose (void) const + { return intNDArray (MArrayN::transpose ()); } + + static void increment_index (Array& ra_idx, + const dim_vector& dimensions, + int start_dimension = 0); + + static int compute_index (Array& ra_idx, + const dim_vector& dimensions); + + static T resize_fill_value (void) { return 0; } + +protected: + + intNDArray (T *d, dim_vector& dv) : MArrayN (d, dv) { } +}; + +// i/o + +template +std::ostream& operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& operator >> (std::istream& is, intNDArray& a); + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/lo-utils.h --- a/liboctave/lo-utils.h Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/lo-utils.h Mon Jun 14 18:49:09 2004 +0000 @@ -54,8 +54,8 @@ extern double octave_read_double (std::istream& is); extern Complex octave_read_complex (std::istream& is); -extern void octave_write_double (std::ostream& os, double d); -extern void octave_write_complex (std::ostream& os, const Complex& c); +extern void octave_write_double (std::ostream& os, double dval); +extern void octave_write_complex (std::ostream& os, const Complex& cval); #endif diff -r 35bfb4e0b96b -r bd043a433918 liboctave/mx-base.h --- a/liboctave/mx-base.h Mon Jun 14 18:33:02 2004 +0000 +++ b/liboctave/mx-base.h Mon Jun 14 18:49:09 2004 +0000 @@ -52,6 +52,16 @@ #include "dNDArray.h" #include "CNDArray.h" +#include "int8NDArray.h" +#include "int16NDArray.h" +#include "int32NDArray.h" +#include "int64NDArray.h" + +#include "uint8NDArray.h" +#include "uint16NDArray.h" +#include "uint32NDArray.h" +#include "uint64NDArray.h" + #endif /* diff -r 35bfb4e0b96b -r bd043a433918 liboctave/oct-inttypes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/oct-inttypes.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,291 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_inttypes_h) +#define octave_inttypes_h 1 + +#include + +#include + +#include "data-conv.h" + +typedef signed char octave_int8_t; +typedef TWO_BYTE_INT octave_int16_t; +typedef FOUR_BYTE_INT octave_int32_t; +typedef EIGHT_BYTE_INT octave_int64_t; + +typedef unsigned char octave_uint8_t; +typedef unsigned TWO_BYTE_INT octave_uint16_t; +typedef unsigned FOUR_BYTE_INT octave_uint32_t; +typedef unsigned EIGHT_BYTE_INT octave_uint64_t; + +template +class +octave_int_binop_traits +{ +public: + // The return type for a T1 by T2 binary operation. + typedef T1 TR; +}; + +#define OCTAVE_INT_BINOP_TRAIT(T1, T2, T3) \ + template<> \ + class octave_int_binop_traits \ + { \ + public: \ + typedef T3 TR; \ + } + +OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_int8_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_int16_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_int32_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_int64_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_uint8_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_uint16_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_uint32_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_uint64_t, octave_int8_t); + +OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_int8_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_int16_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_int32_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_int64_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_uint8_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_uint16_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_uint32_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_uint64_t, octave_int16_t); + +OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_int8_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_int16_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_int32_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_int64_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_uint8_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_uint16_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_uint32_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_uint64_t, octave_int32_t); + +OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_int8_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_int16_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_int32_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_int64_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_uint8_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_uint16_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_uint32_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_uint64_t, octave_int64_t); + +OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_int8_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_int16_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_int32_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_int64_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_uint8_t, octave_uint8_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_uint16_t, octave_uint8_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_uint32_t, octave_uint8_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_uint64_t, octave_uint8_t); + +OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_int8_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_int16_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_int32_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_int64_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_uint8_t, octave_uint16_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_uint16_t, octave_uint16_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_uint32_t, octave_uint16_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_uint64_t, octave_uint16_t); + +OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_int8_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_int16_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_int32_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_int64_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_uint8_t, octave_uint32_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_uint16_t, octave_uint32_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_uint32_t, octave_uint32_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_uint64_t, octave_uint32_t); + +OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_int8_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_int16_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_int32_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_int64_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_uint8_t, octave_uint64_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_uint16_t, octave_uint64_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_uint32_t, octave_uint64_t); +OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_uint64_t, octave_uint64_t); + +template +inline T2 +octave_int_fit_to_range (const T1& x, const T2& mn, const T2& mx) +{ + return (x > mx ? mx : (x < mn ? mn : static_cast (x))); +} + +#define OCTAVE_INT_FIT_TO_RANGE(r, T) \ + octave_int_fit_to_range (r, std::numeric_limits::min (), std::numeric_limits::max ()) + +#define OCTAVE_INT_MIN_VAL2(T1, T2) \ + std::numeric_limits::TR>::min () + +#define OCTAVE_INT_MAX_VAL2(T1, T2) \ + std::numeric_limits::TR>::max () + +#define OCTAVE_INT_FIT_TO_RANGE2(r, T1, T2) \ + octave_int_fit_to_range (r, \ + OCTAVE_INT_MIN_VAL2 (T1, T2), \ + OCTAVE_INT_MAX_VAL2 (T1, T2)) + +template +class +octave_int +{ +public: + + octave_int (void) : ival () { } + + template + octave_int (U i) : ival (OCTAVE_INT_FIT_TO_RANGE (i, T)) { } + + octave_int (bool b) : ival (b) { } + + template + octave_int (const octave_int& i) + : ival (OCTAVE_INT_FIT_TO_RANGE (i.value (), T)) { } + + octave_int (const octave_int& i) : ival (i.ival) { } + + octave_int& operator = (const octave_int& i) + { + ival = i.ival; + return *this; + } + + ~octave_int (void) { } + + T value (void) const { return ival; } + + bool operator ! (void) const { return ! ival; } + + T operator + (void) const { return ival; } + + T operator - (void) const + { + return std::numeric_limits::is_signed ? -ival : 0; + } + + operator double (void) const { return static_cast (value ()); } + + octave_int& operator += (const octave_int& x) + { + double t = static_cast (value ()); + double tx = static_cast (x.value ()); + ival = OCTAVE_INT_FIT_TO_RANGE (t + tx, T); + return *this; + } + + octave_int& operator -= (const octave_int& x) + { + double t = static_cast (value ()); + double tx = static_cast (x.value ()); + ival = OCTAVE_INT_FIT_TO_RANGE (t - tx, T); + return *this; + } + +private: + + T ival; +}; + +template +std::ostream& +operator << (std::ostream& os, const octave_int& ival) +{ + os << ival.value (); + return os; +} + +template +std::istream& +operator >> (std::istream& is, octave_int& ival) +{ + T tmp = 0; + is >> tmp; + ival = tmp; + return is; +} + +typedef octave_int octave_int8; +typedef octave_int octave_int16; +typedef octave_int octave_int32; +typedef octave_int octave_int64; + +typedef octave_int octave_uint8; +typedef octave_int octave_uint16; +typedef octave_int octave_uint32; +typedef octave_int octave_uint64; + +#define OCTAVE_INT_BIN_OP(OP) \ + \ + template \ + octave_int::TR> \ + operator OP (const octave_int& x, const octave_int& y) \ + { \ + double tx = static_cast (x.value ()); \ + double ty = static_cast (y.value ()); \ + double r = tx OP ty; \ + return OCTAVE_INT_FIT_TO_RANGE2 (r, T1, T2); \ + } \ + +OCTAVE_INT_BIN_OP(+) +OCTAVE_INT_BIN_OP(-) +OCTAVE_INT_BIN_OP(*) +OCTAVE_INT_BIN_OP(/) + +#define OCTAVE_INT_CMP_OP(OP) \ + \ + template \ + bool \ + operator OP (const octave_int& x, const octave_int& y) \ + { \ + return x.value () OP y.value (); \ + } \ + +OCTAVE_INT_CMP_OP (<) +OCTAVE_INT_CMP_OP (<=) +OCTAVE_INT_CMP_OP (>=) +OCTAVE_INT_CMP_OP (>) +OCTAVE_INT_CMP_OP (==) +OCTAVE_INT_CMP_OP (!=) + +#undef OCTAVE_INT_TRAIT +#undef OCTAVE_INT_BINOP_TRAIT +#undef OCTAVE_INT_MIN_VAL +#undef OCTAVE_INT_MAX_VAL +#undef OCTAVE_INT_FIT_TO_RANGE +#undef OCTAVE_INT_MIN_VAL2 +#undef OCTAVE_INT_MAX_VAL2 +#undef OCTAVE_INT_FIT_TO_RANGE2 +#undef OCTAVE_INT_BIN_OP +#undef OCTAVE_INT_CMP_OP + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/uint16NDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/uint16NDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,59 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "uint16NDArray.h" + +#include "intNDArray.cc" + +template class intNDArray; + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& +operator >> (std::istream& is, intNDArray& a); + +NDS_CMP_OPS (uint16NDArray, , octave_uint16, ) +NDS_BOOL_OPS (uint16NDArray, octave_uint16, octave_uint16 (0)) + +SND_CMP_OPS (octave_uint16, , uint16NDArray, ) +SND_BOOL_OPS (octave_uint16, uint16NDArray, octave_uint16 (0)) + +NDND_CMP_OPS (uint16NDArray, , uint16NDArray, ) +NDND_BOOL_OPS (uint16NDArray, uint16NDArray, octave_uint16 (0)) + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/uint16NDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/uint16NDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,53 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_uint16NDArray_h) +#define octave_uint16NDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "intNDArray.h" +#include "mx-op-defs.h" +#include "oct-inttypes.h" + +typedef intNDArray uint16NDArray; + +NDS_CMP_OP_DECLS (uint16NDArray, octave_uint16) +NDS_BOOL_OP_DECLS (uint16NDArray, octave_uint16) + +SND_CMP_OP_DECLS (octave_uint16, uint16NDArray) +SND_BOOL_OP_DECLS (octave_uint16, uint16NDArray) + +NDND_CMP_OP_DECLS (uint16NDArray, uint16NDArray) +NDND_BOOL_OP_DECLS (uint16NDArray, uint16NDArray) + +MARRAY_FORWARD_DEFS (MArrayN, uint16NDArray, octave_uint16) + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/uint32NDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/uint32NDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,59 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "uint32NDArray.h" + +#include "intNDArray.cc" + +template class intNDArray; + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& +operator >> (std::istream& is, intNDArray& a); + +NDS_CMP_OPS (uint32NDArray, , octave_uint32, ) +NDS_BOOL_OPS (uint32NDArray, octave_uint32, octave_uint32 (0)) + +SND_CMP_OPS (octave_uint32, , uint32NDArray, ) +SND_BOOL_OPS (octave_uint32, uint32NDArray, octave_uint32 (0)) + +NDND_CMP_OPS (uint32NDArray, , uint32NDArray, ) +NDND_BOOL_OPS (uint32NDArray, uint32NDArray, octave_uint32 (0)) + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/uint32NDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/uint32NDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,53 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_uint32NDArray_h) +#define octave_uint32NDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "intNDArray.h" +#include "mx-op-defs.h" +#include "oct-inttypes.h" + +typedef intNDArray uint32NDArray; + +NDS_CMP_OP_DECLS (uint32NDArray, octave_uint32) +NDS_BOOL_OP_DECLS (uint32NDArray, octave_uint32) + +SND_CMP_OP_DECLS (octave_uint32, uint32NDArray) +SND_BOOL_OP_DECLS (octave_uint32, uint32NDArray) + +NDND_CMP_OP_DECLS (uint32NDArray, uint32NDArray) +NDND_BOOL_OP_DECLS (uint32NDArray, uint32NDArray) + +MARRAY_FORWARD_DEFS (MArrayN, uint32NDArray, octave_uint32) + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/uint64NDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/uint64NDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,59 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "uint64NDArray.h" + +#include "intNDArray.cc" + +template class intNDArray; + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& +operator >> (std::istream& is, intNDArray& a); + +NDS_CMP_OPS (uint64NDArray, , octave_uint64, ) +NDS_BOOL_OPS (uint64NDArray, octave_uint64, octave_uint64 (0)) + +SND_CMP_OPS (octave_uint64, , uint64NDArray, ) +SND_BOOL_OPS (octave_uint64, uint64NDArray, octave_uint64 (0)) + +NDND_CMP_OPS (uint64NDArray, , uint64NDArray, ) +NDND_BOOL_OPS (uint64NDArray, uint64NDArray, octave_uint64 (0)) + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/uint64NDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/uint64NDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,53 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_uint64NDArray_h) +#define octave_uint64NDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "intNDArray.h" +#include "mx-op-defs.h" +#include "oct-inttypes.h" + +typedef intNDArray uint64NDArray; + +NDS_CMP_OP_DECLS (uint64NDArray, octave_uint64) +NDS_BOOL_OP_DECLS (uint64NDArray, octave_uint64) + +SND_CMP_OP_DECLS (octave_uint64, uint64NDArray) +SND_BOOL_OP_DECLS (octave_uint64, uint64NDArray) + +NDND_CMP_OP_DECLS (uint64NDArray, uint64NDArray) +NDND_BOOL_OP_DECLS (uint64NDArray, uint64NDArray) + +MARRAY_FORWARD_DEFS (MArrayN, uint64NDArray, octave_uint64) + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/uint8NDArray.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/uint8NDArray.cc Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,59 @@ +// N-D Array manipulations. +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "uint8NDArray.h" + +#include "intNDArray.cc" + +template class intNDArray; + +template +std::ostream& +operator << (std::ostream& os, const intNDArray& a); + +template +std::istream& +operator >> (std::istream& is, intNDArray& a); + +NDS_CMP_OPS (uint8NDArray, , octave_uint8, ) +NDS_BOOL_OPS (uint8NDArray, octave_uint8, octave_uint8 (0)) + +SND_CMP_OPS (octave_uint8, , uint8NDArray, ) +SND_BOOL_OPS (octave_uint8, uint8NDArray, octave_uint8 (0)) + +NDND_CMP_OPS (uint8NDArray, , uint8NDArray, ) +NDND_BOOL_OPS (uint8NDArray, uint8NDArray, octave_uint8 (0)) + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r 35bfb4e0b96b -r bd043a433918 liboctave/uint8NDArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/uint8NDArray.h Mon Jun 14 18:49:09 2004 +0000 @@ -0,0 +1,53 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_uint8NDArray_h) +#define octave_uint8NDArray_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include "intNDArray.h" +#include "mx-op-defs.h" +#include "oct-inttypes.h" + +typedef intNDArray uint8NDArray; + +NDS_CMP_OP_DECLS (uint8NDArray, octave_uint8) +NDS_BOOL_OP_DECLS (uint8NDArray, octave_uint8) + +SND_CMP_OP_DECLS (octave_uint8, uint8NDArray) +SND_BOOL_OP_DECLS (octave_uint8, uint8NDArray) + +NDND_CMP_OP_DECLS (uint8NDArray, uint8NDArray) +NDND_BOOL_OP_DECLS (uint8NDArray, uint8NDArray) + +MARRAY_FORWARD_DEFS (MArrayN, uint8NDArray, octave_uint8) + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/