Mercurial > hg > octave-terminal
changeset 8956:d91fa4b20bbb
ensure nonnegative char -> real conversion
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 11 Mar 2009 10:31:08 +0100 |
parents | 6d3fcbf89267 |
children | 360aa52b5942 |
files | liboctave/CMatrix.cc liboctave/CNDArray.cc liboctave/CNDArray.h liboctave/ChangeLog liboctave/dMatrix.cc liboctave/dNDArray.cc liboctave/dNDArray.h liboctave/fCMatrix.cc liboctave/fCNDArray.cc liboctave/fCNDArray.h liboctave/fMatrix.cc liboctave/fNDArray.cc liboctave/fNDArray.h src/ChangeLog src/ov-ch-mat.cc |
diffstat | 15 files changed, 81 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -312,7 +312,7 @@ { for (octave_idx_type i = 0; i < a.rows (); i++) for (octave_idx_type j = 0; j < a.cols (); j++) - elem (i, j) = a.elem (i, j); + elem (i, j) = static_cast<unsigned char> (a.elem (i, j)); } bool
--- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -61,6 +61,14 @@ } #endif +ComplexNDArray::ComplexNDArray (const charNDArray& a) + : MArrayN<Complex> (a.dims ()) +{ + octave_idx_type n = a.numel (); + for (octave_idx_type i = 0; i < n; i++) + xelem (i) = static_cast<unsigned char> (a(i)); +} + #if defined (HAVE_FFTW3) ComplexNDArray ComplexNDArray::fourier (int dim) const
--- a/liboctave/CNDArray.h +++ b/liboctave/CNDArray.h @@ -52,6 +52,8 @@ template <class U> ComplexNDArray (const ArrayN<U>& a) : MArrayN<Complex> (a) { } + ComplexNDArray (const charNDArray&); + ComplexNDArray& operator = (const ComplexNDArray& a) { MArrayN<Complex>::operator = (a);
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,30 @@ +2009-03-11 Jaroslav Hajek <highegg@gmail.com> + + * dNDArray.cc (NDArray::NDArray (const charNDArray&)): New + constructor. + * fNDArray.cc (FloatNDArray::FloatNDArray (const charNDArray&)): + Ditto. + * CNDArray.cc (ComplexNDArray::ComplexNDArray (const charNDArray&)): + Ditto. + * fCNDArray.cc (FloatComplexNDArray::FloatComplexNDArray + (const charNDArray&)): Ditto. + + * dNDArray.h (NDArray::NDArray (const charNDArray&)): Declare. + * fNDArray.h (FloatNDArray::FloatNDArray (const charNDArray&)): + Ditto. + * CNDArray.h (ComplexNDArray::ComplexNDArray (const charNDArray&)): + Ditto. + * fCNDArray.h (FloatComplexNDArray::FloatComplexNDArray + (const charNDArray&)): Ditto. + + * dMatrix.cc (Matrix::Matrix (const charMatrix&)): Cast to unsigned + chars. + * fMatrix.cc (FloatMatrix::FloatMatrix (const charMatrix&)): Likewise. + * CMatrix.cc (ComplexMatrix::ComplexMatrix (const charMatrix&)): + Likewise. + * fCMatrix.cc (FloatComplexMatrix::FloatComplexMatrix + (const charMatrix&)): Likewise. + 2009-03-10 Jason Riedy <jason@acm.org> * sparse-base-lu.cc (Pc_vec): The column permutation should be
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -275,7 +275,7 @@ { for (octave_idx_type i = 0; i < a.rows (); i++) for (octave_idx_type j = 0; j < a.cols (); j++) - elem (i, j) = a.elem (i, j); + elem (i, j) = static_cast<unsigned char> (a.elem (i, j)); } bool
--- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -87,6 +87,14 @@ } } +NDArray::NDArray (const charNDArray& a) + : MArrayN<double> (a.dims ()) +{ + octave_idx_type n = a.numel (); + for (octave_idx_type i = 0; i < n; i++) + xelem (i) = static_cast<unsigned char> (a(i)); +} + #if defined (HAVE_FFTW3) ComplexNDArray
--- a/liboctave/dNDArray.h +++ b/liboctave/dNDArray.h @@ -60,6 +60,8 @@ template <class U> explicit NDArray (const intNDArray<U>& a) : MArrayN<double> (a) { } + NDArray (const charNDArray&); + NDArray& operator = (const NDArray& a) { MArrayN<double>::operator = (a);
--- a/liboctave/fCMatrix.cc +++ b/liboctave/fCMatrix.cc @@ -306,7 +306,7 @@ { for (octave_idx_type i = 0; i < a.rows (); i++) for (octave_idx_type j = 0; j < a.cols (); j++) - elem (i, j) = a.elem (i, j); + elem (i, j) = static_cast<unsigned char> (a.elem (i, j)); } bool
--- a/liboctave/fCNDArray.cc +++ b/liboctave/fCNDArray.cc @@ -56,6 +56,14 @@ } #endif +FloatComplexNDArray::FloatComplexNDArray (const charNDArray& a) + : MArrayN<FloatComplex> (a.dims ()) +{ + octave_idx_type n = a.numel (); + for (octave_idx_type i = 0; i < n; i++) + xelem (i) = static_cast<unsigned char> (a(i)); +} + #if defined (HAVE_FFTW3) FloatComplexNDArray FloatComplexNDArray::fourier (int dim) const
--- a/liboctave/fCNDArray.h +++ b/liboctave/fCNDArray.h @@ -52,6 +52,8 @@ template <class U> FloatComplexNDArray (const ArrayN<U>& a) : MArrayN<FloatComplex> (a) { } + FloatComplexNDArray (const charNDArray&); + FloatComplexNDArray& operator = (const FloatComplexNDArray& a) { MArrayN<FloatComplex>::operator = (a);
--- a/liboctave/fMatrix.cc +++ b/liboctave/fMatrix.cc @@ -274,7 +274,7 @@ { for (octave_idx_type i = 0; i < a.rows (); i++) for (octave_idx_type j = 0; j < a.cols (); j++) - elem (i, j) = a.elem (i, j); + elem (i, j) = static_cast<unsigned char> (a.elem (i, j)); } bool
--- a/liboctave/fNDArray.cc +++ b/liboctave/fNDArray.cc @@ -41,6 +41,14 @@ #include "oct-locbuf.h" #include "mx-op-defs.h" +FloatNDArray::FloatNDArray (const charNDArray& a) + : MArrayN<float> (a.dims ()) +{ + octave_idx_type n = a.numel (); + for (octave_idx_type i = 0; i < n; i++) + xelem (i) = static_cast<unsigned char> (a(i)); +} + #if defined (HAVE_FFTW3) #include "oct-fftw.h"
--- a/liboctave/fNDArray.h +++ b/liboctave/fNDArray.h @@ -57,6 +57,8 @@ template <class U> explicit FloatNDArray (const intNDArray<U>& a) : MArrayN<float> (a) { } + FloatNDArray (const charNDArray&); + FloatNDArray& operator = (const FloatNDArray& a) { MArrayN<float>::operator = (a);
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2009-03-11 Jaroslav Hajek <highegg@gmail.com> + + * ov-ch-mat.cc (octave_char_matrix::double_value, + octave_char_matrix::float_value, octave_char_matrix::complex_value, + octave_char_matrix::float_complex_value): Cast to unsigned char. + 2009-03-10 Jason Riedy <jason@acm.org> * DLD-FUNCTIONS/find.cc (find_nonzero_elem_idx): New override
--- a/src/ov-ch-mat.cc +++ b/src/ov-ch-mat.cc @@ -64,7 +64,7 @@ gripe_implicit_conversion ("Octave:array-as-scalar", "character matrix", "real scalar"); - retval = matrix (0, 0); + retval = static_cast<unsigned char> (matrix (0, 0)); } else gripe_invalid_conversion ("character matrix", "real scalar"); @@ -82,7 +82,7 @@ gripe_implicit_conversion ("Octave:array-as-scalar", "character matrix", "real scalar"); - retval = matrix (0, 0); + retval = static_cast<unsigned char> (matrix (0, 0)); } else gripe_invalid_conversion ("character matrix", "real scalar"); @@ -102,7 +102,7 @@ gripe_implicit_conversion ("Octave:array-as-scalar", "character matrix", "complex scalar"); - retval = matrix (0, 0); + retval = static_cast<unsigned char> (matrix (0, 0)); } else gripe_invalid_conversion ("character matrix", "complex scalar"); @@ -122,7 +122,7 @@ gripe_implicit_conversion ("Octave:array-as-scalar", "character matrix", "complex scalar"); - retval = matrix (0, 0); + retval = static_cast<unsigned char> (matrix (0, 0)); } else gripe_invalid_conversion ("character matrix", "complex scalar");