dbl_eg_numutil.h

Go to the documentation of this file.
00001 /* EGlib "Efficient General Library" provides some basic structures and
00002  * algorithms commons in many optimization algorithms.
00003  *
00004  * Copyright (C) 2005 Daniel Espinoza and Marcos Goycoolea.
00005  * 
00006  * This library is free software; you can redistribute it and/or modify it
00007  * under the terms of the GNU Lesser General Public License as published by the
00008  * Free Software Foundation; either version 2.1 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful, but 
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
00013  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
00014  * License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this library; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
00019  * */
00020 #ifndef dbl___EG_NUMUTIL_H__
00021 #define dbl___EG_NUMUTIL_H__
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <string.h>
00025 #include <limits.h>
00026 #include <math.h>
00027 #include <float.h>
00028 #include "eg_macros.h"
00029 #include "eg_nummacros.h"
00030 #include "eg_lpnum.h"
00031 
00032 /* ========================================================================= */
00033 /** @defgroup EGlpNumUtil General Number Utilities
00034  * Here we put some utilities common for different number types but thaat we
00035  * want to implement as templates, like permutation sorting, inner product of
00036  * vectors, and so-on..
00037  * 
00038  * @par History:
00039  * Revision 0.0.2
00040  *  - 2007-10-08
00041  *            - Separate template file and independet file into eg_nummacros.h
00042  *            - Move EGabs, EGswap, EGmin and EGmax to this file
00043  *  - 2005-10-31
00044  *            - First implementation.
00045  * */
00046 /** @{*/
00047 /** @file
00048  * @brief This file provide the user interface and function definitions for
00049  * general number utilities.
00050  * */
00051 /* ========================================================================= */
00052 /** @brief compute the inner product of two arrays.
00053  * @param arr1 first array.
00054  * @param arr2 second array.
00055  * @param length number of entries to consider in both arrays, from zero to
00056  * length - 1.
00057  * @param rop where to store the result.
00058  * */
00059 #define dbl_EGlpNumInnProd(rop,arr1,arr2,length) do{\
00060   double*const restrict __EGa1 = (arr1);\
00061   double*const restrict __EGa2 = (arr2);\
00062   register unsigned __EGdim = (length);\
00063   dbl_EGlpNumZero(rop);\
00064   while(__EGdim--) EGlpNumAddInnProdTo(rop,__EGa1[__EGdim],__EGa2[__EGdim]);\
00065   } while(0)
00066 
00067 /* ========================================================================= */
00068 /** @brief Sort a sub-set of entries in an array using quicksort, by
00069  * permutating the order of the elements in the subset rather than in the whole
00070  * original array, this function sort from min to max value.
00071  * @param sz length of the permutation array.
00072  * @param perm array of indices of elements that we want to sort.
00073  * @param elem array (of length at least max(perm[k]:k=0,...,sz-1)) containing
00074  * the elements to be sorted.
00075  * @note The array of elements is not changed by this function.
00076  * @note This code is based in concorde's implementation of
00077  * permutation-quick-sort.
00078  * */
00079 void dbl_EGutilPermSort (const size_t sz,
00080                      int *const perm,
00081                      double * const elem);
00082 
00083 /* ========================================================================= */
00084 /** @brief Sort (in incresing order) a sub-set of entries in an array using 
00085  * quicksort, by permutating the order of the elements in the subset rather 
00086  * than in the whole original array.
00087  * @param sz length of the permutation array.
00088  * @param perm array of indices of elements that we want to sort.
00089  * @param elem array (of length at least max(perm[k]:k=0,...,sz-1)) containing
00090  * the elements to be sorted.
00091  * @note The array of elements is not changed by this function.
00092  * @note This code is based in concorde's implementation of
00093  * permutation-quick-sort.
00094  * */
00095 void dbl_EGutilPermSort2 (const size_t sz,
00096                      int*const perm,
00097                      double*const elem);
00098 
00099 /* ========================================================================= */
00100 /** @}*/
00101 #endif

Generated on Wed Nov 21 09:38:13 2007 for MTgomory by  doxygen 1.4.6