00001
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <mexutils.h>
00016
00017 #define REPEAT1_1(m,p) m(1,p)
00018 #define REPEAT1_2(m,p) REPEAT1_1(m,p) m(2,p)
00019 #define REPEAT1_3(m,p) REPEAT1_2(m,p) m(3,p)
00020 #define REPEAT1_4(m,p) REPEAT1_3(m,p) m(4,p)
00021 #define REPEAT1_5(m,p) REPEAT1_4(m,p) m(5,p)
00022 #define REPEAT1_6(m,p) REPEAT1_5(m,p) m(6,p)
00023 #define REPEAT1_7(m,p) REPEAT1_6(m,p) m(7,p)
00024 #define REPEAT1_8(m,p) REPEAT1_7(m,p) m(8,p)
00025 #define REPEAT1_9(m,p) REPEAT1_8(m,p) m(9,p)
00026 #define REPEAT1_10(m,p) REPEAT1_9(m,p) m(10,p)
00027
00028 #define REPEAT2_1(m,p) m(1,p)
00029 #define REPEAT2_2(m,p) REPEAT2_1(m,p) m(2,p)
00030 #define REPEAT2_3(m,p) REPEAT2_2(m,p) m(3,p)
00031 #define REPEAT2_4(m,p) REPEAT2_3(m,p) m(4,p)
00032 #define REPEAT2_5(m,p) REPEAT2_4(m,p) m(5,p)
00033 #define REPEAT2_6(m,p) REPEAT2_5(m,p) m(6,p)
00034 #define REPEAT2_7(m,p) REPEAT2_6(m,p) m(7,p)
00035 #define REPEAT2_8(m,p) REPEAT2_7(m,p) m(8,p)
00036 #define REPEAT2_9(m,p) REPEAT2_8(m,p) m(9,p)
00037 #define REPEAT2_10(m,p) REPEAT2_9(m,p) m(10,p)
00038
00039 #define TYPE_1 double
00040 #define TYPE_2 float
00041 #define TYPE_3 vl_int64
00042 #define TYPE_4 vl_uint64
00043 #define TYPE_5 vl_int32
00044 #define TYPE_6 vl_uint32
00045 #define TYPE_7 vl_int16
00046 #define TYPE_8 vl_uint16
00047 #define TYPE_9 vl_int8
00048 #define TYPE_10 vl_uint8
00049 #define TYPE_AUX(x) TYPE_ ## x
00050 #define TYPE(x) TYPE_AUX(x)
00051
00052 #define CLASS_1 DOUBLE
00053 #define CLASS_2 SINGLE
00054 #define CLASS_3 INT64
00055 #define CLASS_4 UINT64
00056 #define CLASS_5 INT32
00057 #define CLASS_6 UINT32
00058 #define CLASS_7 INT16
00059 #define CLASS_8 UINT16
00060 #define CLASS_9 INT8
00061 #define CLASS_10 UINT8
00062 #define CLASS_AUX(x) CLASS_ ## x
00063 #define CLASS(x) CLASS_AUX(x)
00064
00065 #include "vl_binsum.def"
00066
00067
00068
00069
00070
00071 void
00072 mexFunction(int nout, mxArray *out[],
00073 int nin, const mxArray *in[])
00074 {
00075 enum {IN_ACCUMULATOR = 0, IN_VALUES, IN_INDEXES, IN_DIM} ;
00076 enum {OUT_ACCUMULATOR = 0} ;
00077 mxClassID valueClass ;
00078 mxClassID indexClass ;
00079 vl_index dim = 0 ;
00080
00081 if (nin < 3) {
00082 vlmxError(vlmxErrNotEnoughInputArguments, NULL) ;
00083 }
00084 if (nin > 4) {
00085 vlmxError(vlmxErrTooManyInputArguments, NULL) ;
00086 }
00087 if (nout > 1) {
00088 vlmxError(vlmxErrTooManyOutputArguments, NULL) ;
00089 }
00090
00091 if (!vlmxIsReal(IN(ACCUMULATOR))) {
00092 vlmxError(vlmxErrInvalidArgument, "ACCUMULATOR is not a numeric real array.") ;
00093 }
00094 if (!vlmxIsReal(IN(VALUES))) {
00095 vlmxError(vlmxErrInvalidArgument, "VALUES is not a numeric real array.") ;
00096 }
00097 if (!vlmxIsReal(IN(INDEXES))) {
00098 vlmxError(vlmxErrInvalidArgument, "INDEXES is not a numeric real array.") ;
00099 }
00100
00101 indexClass = mxGetClassID(IN(INDEXES)) ;
00102 valueClass = mxGetClassID(IN(ACCUMULATOR)) ;
00103
00104 if (valueClass != mxGetClassID(IN(VALUES))) {
00105 vlmxError(vlmxErrInvalidArgument, "ACCUMULATOR and VALUES do not have the same storage class.") ;
00106 }
00107
00108 if (nin > 3) {
00109 if (!vlmxIsPlainScalar(IN(DIM))) {
00110 vlmxError(vlmxErrInvalidArgument, "DIM is not a plain scalar.") ;
00111 }
00112 dim = (vl_index)mxGetScalar(IN(DIM)) ;
00113 }
00114
00115 out[0] = mxDuplicateArray(IN(ACCUMULATOR)) ;
00116
00117 #define DISPATCH(I,V) \
00118 case VL_XCAT3(mx,CLASS(I),_CLASS): \
00119 VL_XCAT4(_vl_binsum_,TYPE(V),_,TYPE(I))(out[0], IN(VALUES), IN(INDEXES), dim) ; break ;
00120
00121 #define DISPATCH_VALUE(V,_) \
00122 case VL_XCAT3(mx,CLASS(V),_CLASS) : \
00123 switch (indexClass) { \
00124 REPEAT2_10(DISPATCH,V) ; \
00125 default: \
00126 vlmxError(vlmxErrInvalidArgument, "INDEXES is not of one of the supported storage classes.") ; \
00127 } \
00128 break ;
00129
00130 switch (valueClass) {
00131 REPEAT1_10(DISPATCH_VALUE,_) ;
00132 default:
00133 vlmxError(vlmxErrInvalidArgument, "ACCUMULATOR is not of one of the supported storage classes.") ;
00134 }
00135 }