math_functions.h

00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00042 #include "fastlib/fastlib.h"
00043 //#include "fastlib/fastlib_int.h"
00044 
00045 
00061 void min_element(Matrix& element, index_t *indices) {
00062         
00063   index_t last = element.n_cols() - 1;
00064   index_t first, lowest;
00065   index_t i;
00066         
00067   for (i = 0; i < element.n_rows(); i++) {
00068                 
00069     first = lowest = 0;
00070     if (first == last) {
00071       indices[i] = last;
00072     }
00073     while (++first <= last) {
00074       if (element.get(i, first) < element.get(i, lowest)) {
00075         lowest = first;
00076       }
00077     }
00078     indices[i] = lowest;
00079   }
00080   return;
00081 }
00082 
00095 int max_element_index(float *array, int length) {
00096   
00097   int last = length - 1;
00098   int first = 0;
00099   int highest = 0;
00100         
00101   if (first == last) {
00102     return last;
00103   }
00104   while (++first <= last) {
00105     if (array[first] > array[highest]) {
00106       highest = first;
00107     }
00108   }
00109   return highest;
00110 }
00111 
00124 int max_element_index(ArrayList<float>& array){
00125 
00126   int last = array.size() - 1;
00127   int first = 0;
00128   int highest = 0;
00129 
00130   if (first == last) {
00131     return last;
00132   }
00133   while (++first <= last) {
00134     if (array[first] > array[highest]) {
00135       highest = first;
00136     }
00137   }
00138   return highest;
00139 }
00140 
00153 int max_element_index(ArrayList<double>& array) {
00154 
00155   int last = array.size() - 1;
00156   int first = 0;
00157   int highest = 0;
00158 
00159   if (first == last) {
00160     return last;
00161   }
00162   while (++first <= last) {
00163     if(array[first] > array[highest]) {
00164       highest = first;
00165     }
00166   }
00167   return highest;
00168 }
00169 
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3