Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_NORM_LINFTY_HH 00027 # define MLN_NORM_LINFTY_HH 00028 00035 00036 # include <mln/math/abs.hh> 00037 # include <mln/algebra/vec.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 namespace norm 00044 { 00045 00048 template <unsigned n, typename C> 00049 C linfty(const C (&vec)[n]); 00050 00051 template <unsigned n, typename C> 00052 C linfty(const algebra::vec<n,C>& vec); 00054 00055 00058 template <unsigned n, typename C> 00059 C linfty_distance(const C (&vec1)[n], const C (&vec2)[n]); 00060 00061 template <unsigned n, typename C> 00062 C linfty_distance(const algebra::vec<n,C>& vec1, 00063 const algebra::vec<n,C>& vec2); 00065 00066 00067 # ifndef MLN_INCLUDE_ONLY 00068 00069 namespace impl 00070 { 00071 00072 template <unsigned n, typename C, typename V> 00073 inline 00074 C linfty_(const V& vec) 00075 { 00076 C m = 0; 00077 for (unsigned i = 0; i < n; ++i) 00078 { 00079 // Compute the maximal component absolute value of the 00080 // vector. 00081 C mc = mln::math::abs(vec[i]); 00082 if (mc > m) 00083 m = mc; 00084 } 00085 return m; 00086 } 00087 00088 template <unsigned n, typename C, typename V> 00089 inline 00090 C linfty_distance_(const V& vec1, const V& vec2) 00091 { 00092 C d = 0; 00093 for (unsigned i = 0; i < n; ++i) 00094 { 00095 // Compute the maximal absolute value of the distance 00096 // between components of the same index. 00097 C dc = mln::math::abs(vec1[i] - vec2[i]); 00098 if (dc > d) 00099 d = dc; 00100 } 00101 return d; 00102 } 00103 00104 } // end of namespace mln::norm::impl 00105 00106 00107 /*----------. 00108 | Facades. | 00109 `----------*/ 00110 00111 template <unsigned n, typename C> 00112 inline 00113 C linfty(const C (&vec)[n]) 00114 { 00115 return impl::linfty_<n, C>(vec); 00116 } 00117 00118 template <unsigned n, typename C> 00119 inline 00120 C linfty(const algebra::vec<n,C>& vec) 00121 { 00122 return impl::linfty_<n, C>(vec); 00123 } 00124 00125 template <unsigned n, typename C> 00126 inline 00127 C linfty_distance(const C (&vec1)[n], const C (&vec2)[n]) 00128 { 00129 return impl::linfty_distance_<n, C>(vec1, vec2); 00130 } 00131 00132 template <unsigned n, typename C> 00133 inline 00134 C linfty_distance(const algebra::vec<n,C>& vec1, 00135 const algebra::vec<n,C>& vec2) 00136 { 00137 return impl::linfty_distance_<n, C>(vec1, vec2); 00138 } 00139 00140 # endif // ! MLN_INCLUDE_ONLY 00141 00142 } // end of namespace mln::norm 00143 00144 } // end of namespace mln 00145 00146 00147 #endif // ! MLN_NORM_LINFTY_HH