Mercurial > forge
changeset 12685:f26b1170ea90 octave-forge
resulting values should be really converted to output data type
author | schloegl |
---|---|
date | Sat, 12 Sep 2015 07:15:01 +0000 |
parents | 29631e455f62 |
children | 7c1bc8d8c406 |
files | extra/NaN/src/covm_mex.cpp extra/NaN/src/histo_mex.cpp extra/NaN/src/sumskipnan_mex.cpp |
diffstat | 3 files changed, 66 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/NaN/src/covm_mex.cpp Sat Sep 12 06:34:22 2015 +0000 +++ b/extra/NaN/src/covm_mex.cpp Sat Sep 12 07:15:01 2015 +0000 @@ -362,9 +362,9 @@ cc += z*W[k]; nn += W[k]; } - CC[i] = cc; + CC[i] = (typeof(*CC))cc; if (NN != NULL) - NN[i] = nn; + NN[i] = (typeof(*NN))nn; } else /* no weights, all weights are 1 */ #pragma omp for schedule(dynamic) nowait @@ -386,9 +386,9 @@ cc += z; nn++; } - CC[i] = cc; + CC[i] = (typeof(*CC))cc; if (NN != NULL) - NN[i] = (double)nn; + NN[i] = (typeof(*NN))nn; } else // if (X0==Y0) && (cX==cY) /******** X==Y, output is symetric *******/ @@ -416,11 +416,11 @@ nn += W[k]; } size_t j = jj + ii*cX; - CC[i] = cc; - CC[j] = cc; + CC[i] = (typeof(*CC))cc; + CC[j] = (typeof(*CC))cc; if (NN != NULL) { - NN[i] = nn; - NN[j] = nn; + NN[i] = (typeof(*NN))nn; + NN[j] = (typeof(*NN))nn; } } else /* no weights, all weights are 1 */ @@ -447,11 +447,11 @@ nn++; } size_t j = jj + ii*cX; - CC[i] = cc; - CC[j] = cc; + CC[i] = (typeof(*CC))cc; + CC[j] = (typeof(*CC))cc; if (NN != NULL) { - NN[i] = (double)nn; - NN[j] = (double)nn; + NN[i] = (typeof(*NN))nn; + NN[j] = (typeof(*NN))nn; } } @@ -500,9 +500,9 @@ rn= (t-nn)-y; nn= t; } - CC[i] = cc; + CC[i] = (typeof(*CC))cc; if (NN != NULL) - NN[i] = nn; + NN[i] = (typeof(*NN))nn; } else /* no weights, all weights are 1 */ #pragma omp for schedule(dynamic) nowait @@ -531,9 +531,9 @@ nn++; } - CC[i] = cc; + CC[i] = (typeof(*CC))cc; if (NN != NULL) - NN[i] = (double)nn; + NN[i] = (typeof(*NN))nn; } else // if (X0==Y0) && (cX==cY) /******** X==Y, output is symetric *******/ @@ -573,11 +573,11 @@ nn= t; } size_t j = jj + ii*cX; - CC[i] = cc; - CC[j] = cc; + CC[i] = (typeof(*CC))cc; + CC[j] = (typeof(*CC))cc; if (NN != NULL) { - NN[i] = nn; - NN[j] = nn; + NN[i] = (typeof(*NN))nn; + NN[j] = (typeof(*NN))nn; } } else /* no weights, all weights are 1 */ @@ -611,11 +611,11 @@ nn++; } size_t j = jj + ii*cX; - CC[i] = cc; - CC[j] = cc; + CC[i] = (typeof(*CC))cc; + CC[j] = (typeof(*CC))cc; if (NN != NULL) { - NN[i] = (double)nn; - NN[j] = (double)nn; + NN[i] = (typeof(*NN))nn; + NN[j] = (typeof(*NN))nn; } } }
--- a/extra/NaN/src/histo_mex.cpp Sat Sep 12 06:34:22 2015 +0000 +++ b/extra/NaN/src/histo_mex.cpp Sat Sep 12 07:15:01 2015 +0000 @@ -161,6 +161,8 @@ else if (f1>f2) z = 1; break; } + default: + mexErrMsgTxt("unsupported input type"); } i++; ix1 += Sort.Stride; @@ -234,8 +236,6 @@ mexErrMsgTxt("Error HISTO.MEX: input must be vector or matrix (no more than two dimensions)"); size_t n = SZ[0]; - size_t sz = 1; - char flag = 0; const char *fnames[] = {"datatype","X","H"}; mxArray *HIS = mxCreateStructMatrix(1, 1, 3, fnames); @@ -335,7 +335,7 @@ int8_t *x; x = (int8_t*)mxGetData(X); for (k=0; k<0x0100; k++) - x[k]=k-128; + x[k]=(int8_t)(k-128); x = (int8_t*)mxGetData(PInputs[0]); double *h = (double*)mxGetData(H); @@ -353,7 +353,7 @@ mxSetField(HIS,0,"X",X); uint8_t *x = (uint8_t*)mxGetData(X); - for (k=0; k<0x0100; k++) x[k]=k; + for (k=0; k<0x0100; k++) x[k]=(uint8_t)k; x = (uint8_t*)mxGetData(PInputs[0]); double *h = (double*)mxGetData(H); @@ -373,7 +373,7 @@ double *h = (double*)mxGetData(H); int16_t *x = (int16_t*)mxGetData(X); for (k=0; k<0x10000; k++) - x[k]=k-0x8000; + x[k]=(int16_t)(k-0x8000); x = (int16_t*)mxGetData(PInputs[0]); for (k=0; k<SZ[0]*SZ[1]; k++) @@ -392,7 +392,7 @@ double *h = (double*)mxGetData(H); int16_t *x = (int16_t*)mxGetData(X); for (k=0; k<0x10000; k++) - x[k]=k-0x8000; + x[k]=(uint16_t)(k-0x8000); uint16_t *x16 = (uint16_t*)mxGetData(PInputs[0]); for (k=0; k<SZ[0]*SZ[1]; k++) @@ -410,12 +410,13 @@ mxSetField(HIS,0,"H",H); mxSetField(HIS,0,"X",X); + /* double *h = (double*)mxGetData(H); int16_t *x = (int16_t*)mxGetData(X); for (n=0; n<SZ[1]; n++) { } - + */ } } // end switch }
--- a/extra/NaN/src/sumskipnan_mex.cpp Sat Sep 12 06:34:22 2015 +0000 +++ b/extra/NaN/src/sumskipnan_mex.cpp Sat Sep 12 07:15:01 2015 +0000 @@ -327,7 +327,7 @@ /* copy to output */ for (j=0; j<D1; j++) { - LOutputSum[ix0+j] = LongOutputSum[ix0+j]; + LOutputSum[ix0+j] = (typeof(*LOutputSum))LongOutputSum[ix0+j]; } } } @@ -371,8 +371,8 @@ /* copy to output */ for (j=0; j<D1; j++) { - LOutputSum[ix0+j] = LongOutputSum[ix0+j]; - LOutputCount[ix0+j] = LongOutputCount[ix0+j]; + LOutputSum[ix0+j] = (typeof(*LOutputSum))LongOutputSum[ix0+j]; + LOutputCount[ix0+j] = (typeof(*LOutputCount))LongOutputCount[ix0+j]; } // end else } } @@ -390,7 +390,7 @@ long double x = *LInput; if (!isnan(x)) { LongOutputCount[ix2] += W[j]; - double t = W[j]*x; + long double t = W[j]*x; LongOutputSum[ix2] += t; LongOutputSum2[ix2] += x*t; } @@ -419,9 +419,9 @@ /* copy to output */ for (j=0; j<D1; j++) { - LOutputSum[ix0+j] = LongOutputSum[ix0+j]; - LOutputCount[ix0+j] = LongOutputCount[ix0+j]; - LOutputSum2[ix0+j] = LongOutputSum2[ix0+j]; + LOutputSum[ix0+j] = (typeof(*LOutputSum))LongOutputSum[ix0+j]; + LOutputCount[ix0+j] = (typeof(*LOutputCount))LongOutputCount[ix0+j]; + LOutputSum2[ix0+j] = (typeof(*LOutputSum2))LongOutputSum2[ix0+j]; } } } @@ -500,7 +500,7 @@ W++; } while (data < end); - *No = count; + *No = (typeof(*No))count; } else { // w/o weight vector size_t countI = 0; @@ -518,13 +518,13 @@ data++; // stride=1 } while (data < end); - *No = (double)countI; + *No = (typeof(*No))countI; } #ifndef NO_FLAG if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1; #endif - *s = sum; + *s = (typeof(*s))sum; } @@ -556,7 +556,7 @@ W++; } while (data < end); - *No = count; + *No = (typeof(*No))count; } else { // w/o weight vector size_t countI = 0; @@ -574,14 +574,14 @@ data++; // stride=1 } while (data < end); - *No = (double)countI; + *No = (typeof(*No))countI; } #ifndef NO_FLAG if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1; #endif - *s = sum; - *s2 = msq; + *s = (typeof(*s))sum; + *s2 = (typeof(*s2))msq; } inline void __sumskipnan2wr__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W) @@ -610,7 +610,7 @@ W++; } while (data < end); - *No = count; + *No = (typeof(*No))count; } else { // w/o weight vector size_t countI = 0; @@ -628,13 +628,13 @@ data++; // stride=1 } while (data < end); - *No = (double)countI; + *No = (typeof(*No))countI; } #ifndef NO_FLAG if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1; #endif - *s = sum; + *s = (typeof(*s))sum; } @@ -684,14 +684,14 @@ data++; // stride=1 } while (data < end); - *No = (double)countI; + *No = (typeof(*No))countI; } #ifndef NO_FLAG if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1; #endif - *s = sum; - *s2 = msq; + *s = (typeof(*s))sum; + *s2 = (typeof(*s2))msq; } @@ -743,7 +743,7 @@ W++; } while (data < end); - *No = count; + *No = (typeof(*No))count; } else { // w/o weight vector size_t countI = 0; @@ -767,13 +767,13 @@ data++; // stride=1 } while (data < end); - *No = (double)countI; + *No = (typeof(*No))countI; } #ifndef NO_FLAG if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1; #endif - *s = sum; + *s = (typeof(*s))sum; } @@ -821,7 +821,7 @@ W++; } while (data < end); - *No = count; + *No = (typeof(*No))count; } else { // w/o weight vector size_t countI = 0; @@ -850,14 +850,14 @@ data++; // stride=1 } while (data < end); - *No = (double)countI; + *No = (typeof(*No))countI; } #ifndef NO_FLAG if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1; #endif - *s = sum; - *s2 = msq; + *s = (typeof(*s))sum; + *s2 = (typeof(*s))msq; } inline void __sumskipnan2wer__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W) @@ -897,7 +897,7 @@ W++; } while (data < end); - *No = count; + *No = (typeof(*No))count; } else { // w/o weight vector size_t countI = 0; @@ -921,13 +921,13 @@ data++; // stride=1 } while (data < end); - *No = (double)countI; + *No = (typeof(*No))countI; } #ifndef NO_FLAG if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1; #endif - *s = sum; + *s = (typeof(*s))sum; } @@ -975,7 +975,7 @@ W++; } while (data < end); - *No = count; + *No = (typeof(*No))count; } else { // w/o weight vector size_t countI = 0; @@ -1004,13 +1004,13 @@ data++; // stride=1 } while (data < end); - *No = (double)countI; + *No = (typeof(*No))countI; } #ifndef NO_FLAG if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1; #endif - *s = sum; - *s2 = msq; + *s = (typeof(*s))sum; + *s2 = (typeof(*s))msq; }