oln 10.50: Update arrays.

Some work has to be done to factorize all this. ----------------------------------------------- Index: metalic/ChangeLog from Astrid Wang <astrid@lrde.epita.fr> * mlc/array/1d.hh: Add member function name(). Fix types in member function normalize(). Add basic arithmetic operators. * mlc/array/2d.hh: Likewise. * mlc/array/3d.hh: Likewise. Index: metalic/mlc/array/1d.hh --- metalic/mlc/array/1d.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/f/23_array1d.hh 1.10 640) +++ metalic/mlc/array/1d.hh Mon, 19 Jan 2004 18:48:11 +0100 astrid (oln/f/23_array1d.hh 1.10 640) @@ -31,9 +31,10 @@ # include <mlc/contract.hh> # include <mlc/cmp.hh> # include <mlc/array/objs.hh> - +# include <ntg/basics.hh> # include <iostream> + // impl # include <mlc/array/1d.hxx> @@ -79,20 +80,28 @@ } + // Name + + static std::string + name() + { + return std::string("array1d< Info, ") + ntg_name(T) + " >"; + } + + // // Operations on array // - typedef array1d<Info_,float> to_float; // FIXME : argh - // Normalize (absolute values -> relative values) - to_float normalize() + array1d<Info_, ntg::float_s> + normalize() { - to_float tmp; - float sum = 0.f; // FIXME: float only? - const float epsilon = 0.01f; // FIXME : epsilon should be global + array1d<Info_, ntg::float_s> tmp; + ntg::float_s sum = 0.f; + const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be global unsigned i; for (i = 0; i < Info_::card; ++i) sum += this->buffer_[i]; @@ -122,6 +131,59 @@ } + // Operators + + // FIXME: This code should be factorized between 1d, 2d and 3d. + // Think of a mechanism similar to apply() and apply2(). + + template <class U> + array1d< Info, ntg_return_type(times, T, U) > + operator*(U w) + { + array1d< Info, ntg_return_type(times, T, U) > tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] * w; + return tmp; + } + + template <class U> + array1d< Info, ntg_return_type(div, T, U) > + operator/(U w) + { + array1d< Info, ntg_return_type(div, T, U) > tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] / w; + return tmp; + } + + self operator+(const self& rhs) const + { + self tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] + rhs.buffer_[i]; + return tmp; + } + self& operator+=(const self& rhs) + { + for (unsigned i = 0; i < Info::card; ++i) + this->buffer_[i] += rhs.buffer_[i]; + return *this; + } + + self operator-(const self& rhs) const + { + self tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] - rhs.buffer_[i]; + return tmp; + } + self& operator-=(const self& rhs) + { + for (unsigned i = 0; i < Info::card; ++i) + this->buffer_[i] -= rhs.buffer_[i]; + return *this; + } + // // Accessors @@ -179,7 +241,6 @@ return *(buffer_ + Info_::center + i); } - protected: T buffer_[Info_::card]; @@ -202,8 +263,18 @@ // starter objects - static internal::array1d_start_<int> ints_1d = internal::array1d_start_<int>(); - static internal::array1d_start_<float> floats_1d = internal::array1d_start_<float>(); + // FIXME: what about other types? Replace this by a function + // returning a starter. + +# define array1d_starter(T) \ + static internal::array1d_start_<T> T##s_1d = internal::array1d_start_<T>() + + array1d_starter(int); // ints_1d + array1d_starter(float); // floats_1d + + + + // print template<class Info, class T> std::ostream& operator<<(std::ostream& ostr, const array1d<Info, T>& rhs) Index: metalic/mlc/array/2d.hh --- metalic/mlc/array/2d.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/f/21_array2d.hh 1.10 640) +++ metalic/mlc/array/2d.hh Mon, 19 Jan 2004 18:44:29 +0100 astrid (oln/f/21_array2d.hh 1.10 640) @@ -31,6 +31,7 @@ # include <mlc/array/objs.hh> # include <mlc/contract.hh> # include <mlc/cmp.hh> +# include <ntg/basics.hh> # include <iostream> @@ -78,19 +79,30 @@ return *this; } + + // Name + + static std::string + name() + { + return std::string("array2d< Info, ") + ntg_name(T) + " >"; + } + + + // // Operations on array // - typedef array2d<Info_, float> to_float; // FIXME : argh // Normalize (absolute values -> relative values) - to_float normalize() + array2d<Info_, ntg::float_s> + normalize() { - to_float tmp; - float sum = 0.f; // FIXME: float only? - const float epsilon = 0.01f; // FIXME : epsilon should be global + array2d<Info_, ntg::float_s> tmp; + ntg::float_s sum = 0.f; + const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be global unsigned i; for (i = 0; i < Info_::card; ++i) sum += this->buffer_[i]; @@ -138,6 +150,60 @@ return tmp; } + // Operators + + // FIXME: This code should be factorized between 1d, 2d and 3d. + // Think of a mechanism similar to apply() and apply2(). + + template <class U> + array2d< Info, ntg_return_type(times, T, U) > + operator*(U w) + { + array2d< Info, ntg_return_type(times, T, U) > tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] * w; + return tmp; + } + + template <class U> + array2d< Info, ntg_return_type(div, T, U) > + operator/(U w) + { + array2d< Info, ntg_return_type(div, T, U) > tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] / w; + return tmp; + } + + self operator+(const self& rhs) const + { + self tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] + rhs.buffer_[i]; + return tmp; + } + self& operator+=(const self& rhs) + { + for (unsigned i = 0; i < Info::card; ++i) + this->buffer_[i] += rhs.buffer_[i]; + return *this; + } + + self operator-(const self& rhs) const + { + self tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] - rhs.buffer_[i]; + return tmp; + } + self& operator-=(const self& rhs) + { + for (unsigned i = 0; i < Info::card; ++i) + this->buffer_[i] -= rhs.buffer_[i]; + return *this; + } + + // // Accessors // @@ -200,8 +266,6 @@ lesseq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure(); lesseq< -Info_::center_col, ncol >::ensure(); lesseq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure(); - - // FIXME: return *(buffer_ + Info_::center + (row * Info_::ncols) + col); return *(buffer_ + Info_::center + (nrow * Info_::ncols) + ncol); } @@ -228,8 +292,17 @@ // starter objects - static internal::array2d_start_<int> ints_2d = internal::array2d_start_<int>(); - static internal::array2d_start_<float> floats_2d = internal::array2d_start_<float>(); + // FIXME: what about other types? Replace this by a function + // returning a starter. + +# define array2d_starter(T) \ + static internal::array2d_start_<T> T##s_2d = internal::array2d_start_<T>() + + array2d_starter(int); // ints_2d + array2d_starter(float); // floats_2d + + + // print template<class Info, class T> std::ostream& operator<<(std::ostream& ostr, const array2d<Info, T>& rhs) Index: metalic/mlc/array/3d.hh --- metalic/mlc/array/3d.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/f/19_array3d.hh 1.11 640) +++ metalic/mlc/array/3d.hh Mon, 19 Jan 2004 18:44:57 +0100 astrid (oln/f/19_array3d.hh 1.11 640) @@ -31,6 +31,7 @@ # include <mlc/array/objs.hh> # include <mlc/contract.hh> # include <mlc/cmp.hh> +# include <ntg/basics.hh> # include <iostream> @@ -82,20 +83,28 @@ } + // Name + + static std::string + name() + { + return std::string("array3d< Info, ") + ntg_name(T) + " >"; + } + + // // Operations on array // - typedef array3d<Info_, float> to_float; // FIXME : argh - // Normalize (absolute values -> relative values) - to_float normalize() + array3d<Info_, ntg::float_s> + normalize() { - to_float tmp; - float sum = 0.f; // FIXME: float only? - const float epsilon = 0.01f; // FIXME : epsilon should be global + array3d<Info_, ntg::float_s> tmp; + ntg::float_s sum = 0.f; + const ntg::float_s epsilon = 0.01f; // FIXME : epsilon should be global unsigned i; for (i = 0; i < Info_::card; ++i) sum += this->buffer_[i]; @@ -119,7 +128,7 @@ operator-() const { enum { new_center = Info_::card - Info_::center - 1 }; - array3d<array3d_info< Info::nplanes, Info_::nrows, Info_::ncols, new_center, Info_::i>,T> tmp; + array3d<array3d_info< Info_::nplanes, Info_::nrows, Info_::ncols, new_center, Info_::i>,T> tmp; for (unsigned i = 0; i < Info_::card; ++i) tmp[Info_::card - i - 1] = this->operator[](i); @@ -129,13 +138,68 @@ // Transpose - array3d<Info, T> transpose() const // FIXME { std::cerr << "[31m===> 3D transposition not implemented yet. <===[0m" << std::endl; throw not_implemented_yet(); } + + // Operators + + // FIXME: This code should be factorized between 1d, 2d and 3d. + // Think of a mechanism similar to apply() and apply2(). + + template <class U> + array3d< Info, ntg_return_type(times, T, U) > + operator*(U w) + { + array3d< Info, ntg_return_type(times, T, U) > tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] * w; + return tmp; + } + + template <class U> + array3d< Info, ntg_return_type(div, T, U) > + operator/(U w) + { + array3d< Info, ntg_return_type(div, T, U) > tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] / w; + return tmp; + } + + self operator+(const self& rhs) const + { + self tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] + rhs.buffer_[i]; + return tmp; + } + self& operator+=(const self& rhs) + { + for (unsigned i = 0; i < Info::card; ++i) + this->buffer_[i] += rhs.buffer_[i]; + return *this; + } + + self operator-(const self& rhs) const + { + self tmp; + for (unsigned i = 0; i < Info::card; ++i) + tmp[i] = this->buffer_[i] - rhs.buffer_[i]; + return tmp; + } + self& operator-=(const self& rhs) + { + for (unsigned i = 0; i < Info::card; ++i) + this->buffer_[i] -= rhs.buffer_[i]; + return *this; + } + + + // template<class U> int operator,(U); // FIXME: why this? // @@ -207,8 +271,6 @@ lesseq< nrow, Info_::nrows - Info_::center_row - 1 >::ensure(); lesseq< -Info_::center_col, ncol >::ensure(); lesseq< ncol, Info_::ncols - Info_::center_col - 1 >::ensure(); - - //FIXME: return *(buffer_ + Info_::center + (nplane * Info::nrows * Info::ncols) + (row * Info::ncols) + col); return *(buffer_ + Info_::center + (nplane * Info::nrows * Info::ncols) + (nrow * Info::ncols) + ncol); } @@ -235,8 +297,17 @@ // starter objects - static internal::array3d_start_<int> ints_3d = internal::array3d_start_<int>(); - static internal::array3d_start_<float> floats_3d = internal::array3d_start_<float>(); + // FIXME: what about other types? Replace this by a function + // returning a starter. + +# define array3d_starter(T) \ + static internal::array3d_start_<T> T##s_3d = internal::array3d_start_<T>() + + array3d_starter(int); // ints_3d + array3d_starter(float); // floats_3d + + + // print template<class Info, class T> std::ostream& operator<<(std::ostream& ostr, const array3d<Info, T>& rhs) @@ -256,6 +327,7 @@ return ostr; } + } // end of mlc #endif // ! METALIC_ARRAY_3D_HH -- astrid
participants (2)
-
Akim Demaille
-
Astrid Wang