vl_cummax.c
Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
00008 All rights reserved.
00009 
00010 This file is part of the VLFeat library and is made available under
00011 the terms of the BSD license (see the COPYING file).
00012 */
00013 
00014 #include <mexutils.h>
00015 
00016 #define REPEAT1_1(m,p) m(1,p)
00017 #define REPEAT1_2(m,p) REPEAT1_1(m,p) m(2,p)
00018 #define REPEAT1_3(m,p) REPEAT1_2(m,p) m(3,p)
00019 #define REPEAT1_4(m,p) REPEAT1_3(m,p) m(4,p)
00020 #define REPEAT1_5(m,p) REPEAT1_4(m,p) m(5,p)
00021 #define REPEAT1_6(m,p) REPEAT1_5(m,p) m(6,p)
00022 #define REPEAT1_7(m,p) REPEAT1_6(m,p) m(7,p)
00023 #define REPEAT1_8(m,p) REPEAT1_7(m,p) m(8,p)
00024 #define REPEAT1_9(m,p) REPEAT1_8(m,p) m(9,p)
00025 #define REPEAT1_10(m,p) REPEAT1_9(m,p) m(10,p)
00026 
00027 #define TYPE_1 double
00028 #define TYPE_2 float
00029 #define TYPE_3 vl_int64
00030 #define TYPE_4 vl_uint64
00031 #define TYPE_5 vl_int32
00032 #define TYPE_6 vl_uint32
00033 #define TYPE_7 vl_int16
00034 #define TYPE_8 vl_uint16
00035 #define TYPE_9 vl_int8
00036 #define TYPE_10 vl_uint8
00037 #define TYPE_AUX(x) TYPE_ ## x
00038 #define TYPE(x) TYPE_AUX(x)
00039 
00040 #define CLASS_1  DOUBLE
00041 #define CLASS_2  SINGLE
00042 #define CLASS_3  INT64
00043 #define CLASS_4  UINT64
00044 #define CLASS_5  INT32
00045 #define CLASS_6  UINT32
00046 #define CLASS_7  INT16
00047 #define CLASS_8  UINT16
00048 #define CLASS_9  INT8
00049 #define CLASS_10 UINT8
00050 #define CLASS_AUX(x) CLASS_ ## x
00051 #define CLASS(x) CLASS_AUX(x)
00052 
00053 #include "vl_cummax.def"
00054 
00055 void
00056 mexFunction(int nout, mxArray *out[],
00057             int nin, const mxArray *in[])
00058 {
00059   enum {IN_X, IN_DIM, IN_END} ;
00060   enum {OUT_Y = 0} ;
00061   vl_index whichDimension = 0 ;
00062   vl_size dimension ;
00063   vl_size numDimensions ;
00064   mwSize const * dimensions ;
00065   mxClassID classId ;
00066   vl_size stride = 1 ;
00067   vl_index k ;
00068 
00069   /* -----------------------------------------------------------------
00070    *                                               Check the arguments
00071    * -------------------------------------------------------------- */
00072   if (nin < 1) {
00073     vlmxError(vlmxErrNotEnoughInputArguments, NULL) ;
00074   } else if (nout > 1) {
00075     vlmxError(vlmxErrTooManyOutputArguments, NULL) ;
00076   } else if (nin > 2) {
00077     vlmxError(vlmxErrTooManyInputArguments, NULL) ;
00078   }
00079 
00080   /* get information on the data */
00081   if (!mxIsNumeric(IN(X))) {
00082     vlmxError(vlmxErrInvalidArgument, "X is not a numeric array.") ;
00083   }
00084   classId = mxGetClassID(IN(X)) ;
00085   numDimensions = mxGetNumberOfDimensions(IN(X)) ;
00086   dimensions = mxGetDimensions(IN(X)) ;
00087 
00088   /* get the operating dimension */
00089   if (nin == 2) {
00090     if (!vlmxIsPlainScalar(IN(DIM))) {
00091       vlmxError(vlmxErrInvalidArgument, "DIM is not a plain scalar.") ;
00092     }
00093     whichDimension = mxGetScalar(IN(DIM)) ;
00094     if (whichDimension < 1 || whichDimension > (signed)numDimensions) {
00095       vlmxError(vlmxErrInvalidArgument,
00096                 "DIM=%d is not a valid dimension of X.", whichDimension) ;
00097     }
00098   }
00099 
00100   /* -----------------------------------------------------------------
00101    *                                                        Do the job
00102    * -------------------------------------------------------------- */
00103 
00104   OUT(Y) = mxCreateNumericArray(numDimensions, dimensions, classId, mxREAL) ;
00105 
00106   if (whichDimension >= 1) {
00107     /*
00108       Compute the stride to whichDimension.
00109     */
00110     for (k = 0 ; k < whichDimension - 1 ; ++k) {
00111       stride *= dimensions[k] ;
00112     }
00113   } else {
00114     /*
00115       Pick the first non-singleton dimension, if any. Note that in
00116       this case the stride is equal to 1.
00117     */
00118     for (k = 0 ; k < (signed)numDimensions-1 && dimensions[k] == 1 ; ++k) ;
00119     whichDimension = k + 1 ;
00120   }
00121   dimension = dimensions[whichDimension - 1] ;
00122 
00123 #define DISPATCH(I,V) \
00124 case VL_XCAT3(mx,CLASS(I),_CLASS): \
00125   VL_XCAT(_vl_cummax_,TYPE(I))(OUT(Y), IN(X), stride, dimension) ; break ;
00126 
00127   switch (classId) {
00128     REPEAT1_10(DISPATCH,_) ;
00129   default :
00130       vlmxError(vlmxErrInvalidArgument, "X is not of one of the supported storage classes.") ;
00131   }
00132 }


libvlfeat
Author(s): Andrea Vedaldi
autogenerated on Thu Jun 6 2019 20:25:51