vl_tpsumx.c
Go to the documentation of this file.
00001 /* file:        tpsumx.c
00002 ** author:      Andrea Vedaldi
00003 ** description: vl_tpsumx - MEX definition
00004 **/
00005 
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 #include <stdlib.h>
00017 #include <math.h>
00018 
00021 #define getM(arg) mxGetM(in[arg])
00022 #define getN(arg) mxGetN(in[arg])
00023 #define getPr(arg) mxGetPr(in[arg])
00024 
00025 void
00026 mexFunction(int nout, mxArray *out[],
00027             int nin, const mxArray *in[])
00028 {
00029   enum { X=0,Y } ;
00030   enum { U } ;
00031 
00032   int NP, NCP ;
00033   int i,j ;
00034   double *X_pt, *Y_pt, *U_pt ;
00035 #undef small
00036   const double small = 2.220446049250313e-16 ;
00037 
00038   /* -----------------------------------------------------------------
00039    *                                               Check the arguments
00040    * -------------------------------------------------------------- */
00041   if (nin != 2) {
00042     vlmxError(vlmxErrNotEnoughInputArguments, NULL) ;
00043   } else if (nout > 1) {
00044     vlmxError(vlmxErrTooManyOutputArguments, NULL) ;
00045   }
00046 
00047   if(!vlmxIsMatrix(in[X], 2, -1)) {
00048     mexErrMsgTxt("X must be a 2xNP real matrix") ;
00049   }
00050 
00051   if(!vlmxIsMatrix(in[Y], 2, -1)) {
00052     mexErrMsgTxt("Y must be a 2xNCP real matrix") ;
00053   }
00054 
00055   NP  = getN(X) ;
00056   NCP = getN(Y) ;
00057 
00058   X_pt = getPr(X);
00059   Y_pt = getPr(Y) ;
00060 
00061   /* Allocate the result. */
00062   out[U] = mxCreateDoubleMatrix(NP, NCP, mxREAL) ;
00063   U_pt = mxGetPr(out[U]) ;
00064 
00065   /* -----------------------------------------------------------------
00066    *                                               Check the arguments
00067    * -------------------------------------------------------------- */
00068   for(j = 0 ; j < NCP ; ++j) {
00069     double xcp = *Y_pt++ ;
00070     double ycp = *Y_pt++ ;
00071     for(i = 0 ; i < NP ; ++i) {
00072       double dx = *X_pt++ - xcp ;
00073       double dy = *X_pt++ - ycp ;
00074       double r2 = dx*dx + dy*dy ;
00075       *U_pt++ = (r2 <= small) ? 0 : r2 * log (r2) ;
00076     }
00077     X_pt -= 2*NP ;
00078   }
00079 }


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