annotate extra/NaN/src/sumskipnan_mex.cpp @ 12702:29b7963bf748 octave-forge

define typeof() when missing; support for clang compiler added
author schloegl
date Tue, 22 Dec 2015 10:28:53 +0000
parents 13815b367946
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
1
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
2 //-------------------------------------------------------------------
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
3 // C-MEX implementation of SUMSKIPNAN - this function is part of the NaN-toolbox.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
4 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
5 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
6 // This program is free software; you can redistribute it and/or modify
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
7 // it under the terms of the GNU General Public License as published by
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
8 // the Free Software Foundation; either version 3 of the License, or
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
9 // (at your option) any later version.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
10 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
11 // This program is distributed in the hope that it will be useful,
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
14 // GNU General Public License for more details.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
15 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
16 // You should have received a copy of the GNU General Public License
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
17 // along with this program; if not, see <http://www.gnu.org/licenses/>.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
18 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
19 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
20 // sumskipnan: sums all non-NaN values
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
21 // usage:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
22 // [o,count,SSQ] = sumskipnan_mex(x,DIM,flag,W);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
23 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
24 // SUMSKIPNAN uses two techniques to reduce errors:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
25 // 1) long double (80bit) instead of 64-bit double is used internally
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
26 // 2) The Kahan Summation formula is used to reduce the error margin from N*eps to 2*eps
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
27 // The latter is only implemented in case of stride=1 (column vectors only, summation along 1st dimension).
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
28 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
29 // Input:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
30 // - x data array
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
31 // - DIM (optional) dimension to sum
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
32 // - flag (optional) is actually an output argument telling whether some NaN was observed
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
33 // - W (optional) weight vector to compute weighted sum (default 1)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
34 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
35 // Output:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
36 // - o (weighted) sum along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
37 // - count of valid elements
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
38 // - sums of squares
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
39 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
40 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
41 // $Id$
8037
6a419bec96bb update contact e-mail and www address
schloegl
parents: 8035
diff changeset
42 // Copyright (C) 2009,2010,2011 Alois Schloegl <alois.schloegl@gmail.com>
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
43 // This function is part of the NaN-toolbox
7889
c101c486d80a fix web address
schloegl
parents: 7888
diff changeset
44 // http://pub.ist.ac.at/~schloegl/matlab/NaN/
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
45 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
46 //-------------------------------------------------------------------
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
47
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
48
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
49
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
50
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
51 #include <math.h>
7888
b9f35668b55e replace <inttypes.h> with <stdint.h>
schloegl
parents: 7301
diff changeset
52 #include <stdint.h>
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
53 #include "mex.h"
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
54
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
55 /*
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
56 math.h has isnan() defined for all sizes of floating point numbers,
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
57 but c++ assumes isnan(double), causing possible conversions for float and long double
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
58 */
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
59 #define ISNAN(a) (a!=a)
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
60
12702
29b7963bf748 define typeof() when missing; support for clang compiler added
schloegl
parents: 12692
diff changeset
61 #ifndef typeof
29b7963bf748 define typeof() when missing; support for clang compiler added
schloegl
parents: 12692
diff changeset
62 #define typeof __typeof__
29b7963bf748 define typeof() when missing; support for clang compiler added
schloegl
parents: 12692
diff changeset
63 #endif
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
64
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
65 inline void __sumskipnan2w__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W);
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
66 inline void __sumskipnan3w__(double *data, size_t Ni, double *s, double *s2, double *No, char *flag_anyISNAN, double *W);
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
67 inline void __sumskipnan2wr__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W);
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
68 inline void __sumskipnan3wr__(double *data, size_t Ni, double *s, double *s2, double *No, char *flag_anyISNAN, double *W);
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
69 inline void __sumskipnan2we__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W);
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
70 inline void __sumskipnan3we__(double *data, size_t Ni, double *s, double *s2, double *No, char *flag_anyISNAN, double *W);
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
71 inline void __sumskipnan2wer__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W);
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
72 inline void __sumskipnan3wer__(double *data, size_t Ni, double *s, double *s2, double *No, char *flag_anyISNAN, double *W);
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
73
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
74 //#define NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
75
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
76 #ifdef tmwtypes_h
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
77 #if (MX_API_VER<=0x07020000)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
78 typedef int mwSize;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
79 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
80 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
81
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
82
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
83 void mexFunction(int POutputCount, mxArray* POutput[], int PInputCount, const mxArray *PInputs[])
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
84 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
85 const mwSize *SZ;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
86 double* LInput;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
87 double* LOutputSum;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
88 double* LOutputCount;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
89 double* LOutputSum2;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
90 long double* LongOutputSum = NULL;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
91 long double* LongOutputCount = NULL;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
92 long double* LongOutputSum2 = NULL;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
93 double x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
94 double* W = NULL; // weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
95
12692
13815b367946 use size_t instead of mwSize/mwIndex whenever possible
schloegl
parents: 12691
diff changeset
96 size_t DIM = 0;
13815b367946 use size_t instead of mwSize/mwIndex whenever possible
schloegl
parents: 12691
diff changeset
97 size_t D1, D2, D3; // NN; //
13815b367946 use size_t instead of mwSize/mwIndex whenever possible
schloegl
parents: 12691
diff changeset
98 size_t ND, ND2; // number of dimensions: input, output
13815b367946 use size_t instead of mwSize/mwIndex whenever possible
schloegl
parents: 12691
diff changeset
99 size_t ix0, ix1, ix2; // index to input and output
13815b367946 use size_t instead of mwSize/mwIndex whenever possible
schloegl
parents: 12691
diff changeset
100 size_t j, l; // running indices
13815b367946 use size_t instead of mwSize/mwIndex whenever possible
schloegl
parents: 12691
diff changeset
101 mwIndex *SZ2; // size of output
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
102 char flag_isNaN = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
103
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
104 // check for proper number of input and output arguments
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
105 if ((PInputCount <= 0) || (PInputCount > 4))
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
106 mexErrMsgTxt("SUMSKIPNAN.MEX requires between 1 and 4 arguments.");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
107 if (POutputCount > 4)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
108 mexErrMsgTxt("SUMSKIPNAN.MEX has 1 to 3 output arguments.");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
109
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
110 // get 1st argument
12640
de98e4cb9248 check for sparse matrices and and convert to full if needed
schloegl
parents: 12555
diff changeset
111 if(mxIsDouble(PInputs[0]) && !mxIsComplex(PInputs[0]) && !mxIsSparse(PInputs[0]) )
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
112 LInput = mxGetPr(PInputs[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
113 else
12640
de98e4cb9248 check for sparse matrices and and convert to full if needed
schloegl
parents: 12555
diff changeset
114 mexErrMsgTxt("First argument must be and not sparse REAL/DOUBLE.");
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
115
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
116 // get 2nd argument
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
117 if (PInputCount > 1) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
118 switch (mxGetNumberOfElements(PInputs[1])) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
119 case 0: x = 0.0; // accept empty element
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
120 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
121 case 1: x = (mxIsNumeric(PInputs[1]) ? mxGetScalar(PInputs[1]) : -1.0);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
122 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
123 default:x = -1.0; // invalid
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
124 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
125 if ((x < 0) || (x > 65535) || (x != floor(x)))
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
126 mexErrMsgTxt("Error SUMSKIPNAN.MEX: DIM-argument must be a positive integer scalar");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
127
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
128 DIM = (unsigned)floor(x);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
129 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
130
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
131 // get size
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
132 ND = mxGetNumberOfDimensions(PInputs[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
133 // NN = mxGetNumberOfElements(PInputs[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
134 SZ = mxGetDimensions(PInputs[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
135
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
136 // if DIM==0 (undefined), look for first dimension with more than 1 element.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
137 for (j = 0; (DIM < 1) && (j < ND); j++)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
138 if (SZ[j]>1) DIM = j+1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
139
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
140 if (DIM < 1) DIM=1; // in case DIM is still undefined
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
141
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
142 ND2 = (ND>DIM ? ND : DIM); // number of dimensions of output
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
143
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
144 SZ2 = (mwSize*)mxCalloc(ND2, sizeof(mwSize)); // allocate memory for output size
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
145
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
146 for (j=0; j<ND; j++) // copy size of input;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
147 SZ2[j] = SZ[j];
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
148 for (j=ND; j<ND2; j++) // in case DIM > ND, add extra elements 1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
149 SZ2[j] = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
150
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
151 for (j=0, D1=1; j<DIM-1; D1=D1*SZ2[j++]); // D1 is the number of elements between two elements along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
152 D2 = SZ2[DIM-1]; // D2 contains the size along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
153 for (j=DIM, D3=1; j<ND; D3=D3*SZ2[j++]); // D3 is the number of blocks containing D1*D2 elements
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
154
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
155 SZ2[DIM-1] = 1; // size of output is same as size of input but SZ(DIM)=1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
156
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
157 // get weight vector for weighted sumskipnan
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
158 if (PInputCount > 3) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
159 if (!mxGetNumberOfElements(PInputs[3]))
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
160 ; // empty weight vector - no weighting
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
161 else if (mxGetNumberOfElements(PInputs[3])==D2)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
162 W = mxGetPr(PInputs[3]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
163 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
164 mexErrMsgTxt("Error SUMSKIPNAN.MEX: length of weight vector does not match size of dimension");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
165 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
166
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
167 int ACC_LEVEL = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
168 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
169 mxArray *LEVEL = NULL;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
170 int s = mexCallMATLAB(1, &LEVEL, 0, NULL, "flag_accuracy_level");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
171 if (!s) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
172 ACC_LEVEL = (int) mxGetScalar(LEVEL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
173 if ((D1>1) && (ACC_LEVEL>2))
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
174 mexWarnMsgTxt("Warning: Kahan summation not supported with stride > 1 !");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
175 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
176 mxDestroyArray(LEVEL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
177 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
178 // mexPrintf("Accuracy Level=%i\n",ACC_LEVEL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
179
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
180 // create outputs
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
181 #define TYP mxDOUBLE_CLASS
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
182
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
183 POutput[0] = mxCreateNumericArray(ND2, SZ2, TYP, mxREAL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
184 LOutputSum = mxGetPr(POutput[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
185 if (D1!=1 && D2>0) LongOutputSum = (long double*) mxCalloc(D1*D3,sizeof(long double));
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
186 if (POutputCount >= 2) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
187 POutput[1] = mxCreateNumericArray(ND2, SZ2, TYP, mxREAL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
188 LOutputCount = mxGetPr(POutput[1]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
189 if (D1!=1 && D2>0) LongOutputCount = (long double*) mxCalloc(D1*D3,sizeof(long double));
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
190 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
191 if (POutputCount >= 3) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
192 POutput[2] = mxCreateNumericArray(ND2, SZ2, TYP, mxREAL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
193 LOutputSum2 = mxGetPr(POutput[2]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
194 if (D1!=1 && D2>0) LongOutputSum2 = (long double*) mxCalloc(D1*D3,sizeof(long double));
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
195 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
196 mxFree(SZ2);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
197
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
198
8232
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
199 if (!D1 || !D2 || !D3) // zero size array
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
200 ; // do nothing
8232
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
201 else if (D1==1) {
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
202 if (ACC_LEVEL<1) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
203 // double accuray, naive summation, error = N*2^-52
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
204 switch (POutputCount) {
8875
903fbabbd5fe return output for case of no output variable
schloegl
parents: 8232
diff changeset
205 case 0:
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
206 case 1:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
207 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
208 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
209 double count;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
210 __sumskipnan2wr__(LInput+l*D2, D2, LOutputSum+l, &count, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
211 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
212 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
213 case 2:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
214 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
215 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
216 __sumskipnan2wr__(LInput+l*D2, D2, LOutputSum+l, LOutputCount+l, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
217 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
218 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
219 case 3:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
220 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
221 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
222 __sumskipnan3wr__(LInput+l*D2, D2, LOutputSum+l, LOutputSum2+l, LOutputCount+l, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
223 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
224 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
225 }
8232
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
226 }
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
227 else if (ACC_LEVEL==1) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
228 // extended accuray, naive summation, error = N*2^-64
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
229 switch (POutputCount) {
8875
903fbabbd5fe return output for case of no output variable
schloegl
parents: 8232
diff changeset
230 case 0:
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
231 case 1:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
232 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
233 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
234 double count;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
235 __sumskipnan2w__(LInput+l*D2, D2, LOutputSum+l, &count, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
236 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
237 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
238 case 2:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
239 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
240 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
241 __sumskipnan2w__(LInput+l*D2, D2, LOutputSum+l, LOutputCount+l, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
242 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
243 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
244 case 3:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
245 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
246 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
247 __sumskipnan3w__(LInput+l*D2, D2, LOutputSum+l, LOutputSum2+l, LOutputCount+l, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
248 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
249 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
250 }
8232
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
251 }
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
252 else if (ACC_LEVEL==3) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
253 // ACC_LEVEL==3: extended accuracy and Kahan Summation, error = 2^-64
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
254 switch (POutputCount) {
8875
903fbabbd5fe return output for case of no output variable
schloegl
parents: 8232
diff changeset
255 case 0:
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
256 case 1:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
257 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
258 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
259 double count;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
260 __sumskipnan2we__(LInput+l*D2, D2, LOutputSum+l, &count, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
261 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
262 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
263 case 2:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
264 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
265 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
266 __sumskipnan2we__(LInput+l*D2, D2, LOutputSum+l, LOutputCount+l, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
267 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
268 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
269 case 3:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
270 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
271 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
272 __sumskipnan3we__(LInput+l*D2, D2, LOutputSum+l, LOutputSum2+l, LOutputCount+l, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
273 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
274 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
275 }
8232
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
276 }
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
277 else if (ACC_LEVEL==2) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
278 // ACC_LEVEL==2: double accuracy and Kahan Summation, error = 2^-52
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
279 switch (POutputCount) {
8875
903fbabbd5fe return output for case of no output variable
schloegl
parents: 8232
diff changeset
280 case 0:
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
281 case 1:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
282 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
283 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
284 double count;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
285 __sumskipnan2wer__(LInput+l*D2, D2, LOutputSum+l, &count, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
286 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
287 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
288 case 2:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
289 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
290 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
291 __sumskipnan2wer__(LInput+l*D2, D2, LOutputSum+l, LOutputCount+l, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
292 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
293 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
294 case 3:
8035
f5040c012714 move #PRAGMA OMP PARALLEL into #PRAGMA OMP PARALLEL FOR - this fixes SegFaulting on ML7.11
schloegl
parents: 7992
diff changeset
295 #pragma omp parallel for schedule(dynamic)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
296 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
297 __sumskipnan3wer__(LInput+l*D2, D2, LOutputSum+l, LOutputSum2+l, LOutputCount+l, &flag_isNaN, W);
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
298 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
299 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
300 }
8232
49c1c23128ea use only single test for (D1==1)
schloegl
parents: 8037
diff changeset
301 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
302 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
303 else if (POutputCount <= 1) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
304 // OUTER LOOP: along dimensions > DIM
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
305 for (l = 0; l<D3; l++) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
306 ix0 = l*D1; // index for output
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
307 ix1 = ix0*D2; // index for input
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
308 for (j=0; j<D2; j++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
309 // minimize cache misses
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
310 ix2 = ix0; // index for output
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
311 // Inner LOOP: along dimensions < DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
312 if (W) do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
313 long double x = *LInput;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
314 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
315 LongOutputSum[ix2] += W[j]*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
316 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
317 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
318 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
319 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
320 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
321 LInput++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
322 ix2++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
323 } while (ix2 != (l+1)*D1);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
324 else do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
325 long double x = *LInput;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
326 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
327 LongOutputSum[ix2] += x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
328 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
329 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
330 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
331 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
332 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
333 LInput++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
334 ix2++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
335 } while (ix2 != (l+1)*D1);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
336 } // end for (j=
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
337
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
338 /* copy to output */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
339 for (j=0; j<D1; j++) {
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
340 LOutputSum[ix0+j] = (typeof(*LOutputSum))LongOutputSum[ix0+j];
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
341 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
342 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
343 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
344
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
345 else if (POutputCount == 2) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
346 // OUTER LOOP: along dimensions > DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
347 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
348 ix0 = l*D1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
349 ix1 = ix0*D2; // index for input
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
350 for (j=0; j<D2; j++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
351 // minimize cache misses
12306
6eb642de94a3 update docu of TSA and NaN package: push version to 4.2.7 and 2.5.8 for TSA and NaN package, resp.
schloegl
parents: 8875
diff changeset
352 ix2 = ix0; // index for output
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
353 // Inner LOOP: along dimensions < DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
354 if (W) do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
355 long double x = *LInput;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
356 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
357 LongOutputCount[ix2] += W[j];
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
358 LongOutputSum[ix2] += W[j]*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
359 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
360 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
361 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
362 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
363 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
364 LInput++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
365 ix2++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
366 } while (ix2 != (l+1)*D1);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
367 else do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
368 long double x = *LInput;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
369 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
370 LongOutputCount[ix2] += 1.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
371 LongOutputSum[ix2] += x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
372 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
373 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
374 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
375 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
376 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
377 LInput++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
378 ix2++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
379 } while (ix2 != (l+1)*D1);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
380 } // end for (j=
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
381
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
382 /* copy to output */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
383 for (j=0; j<D1; j++) {
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
384 LOutputSum[ix0+j] = (typeof(*LOutputSum))LongOutputSum[ix0+j];
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
385 LOutputCount[ix0+j] = (typeof(*LOutputCount))LongOutputCount[ix0+j];
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
386 } // end else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
387 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
388 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
389
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
390 else if (POutputCount == 3) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
391 // OUTER LOOP: along dimensions > DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
392 for (l = 0; l<D3; l++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
393 ix0 = l*D1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
394 ix1 = ix0*D2; // index for input
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
395 for (j=0; j<D2; j++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
396 // minimize cache misses
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
397 ix2 = ix0; // index for output
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
398 // Inner LOOP: along dimensions < DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
399 if (W) do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
400 long double x = *LInput;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
401 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
402 LongOutputCount[ix2] += W[j];
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
403 long double t = W[j]*x;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
404 LongOutputSum[ix2] += t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
405 LongOutputSum2[ix2] += x*t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
406 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
407 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
408 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
409 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
410 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
411 LInput++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
412 ix2++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
413 } while (ix2 != (l+1)*D1);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
414 else do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
415 long double x = *LInput;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
416 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
417 LongOutputCount[ix2] += 1.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
418 LongOutputSum[ix2] += x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
419 LongOutputSum2[ix2] += x*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
420 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
421 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
422 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
423 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
424 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
425 LInput++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
426 ix2++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
427 } while (ix2 != (l+1)*D1);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
428 } // end for (j=
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
429
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
430 /* copy to output */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
431 for (j=0; j<D1; j++) {
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
432 LOutputSum[ix0+j] = (typeof(*LOutputSum))LongOutputSum[ix0+j];
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
433 LOutputCount[ix0+j] = (typeof(*LOutputCount))LongOutputCount[ix0+j];
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
434 LOutputSum2[ix0+j] = (typeof(*LOutputSum2))LongOutputSum2[ix0+j];
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
435 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
436 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
437 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
438
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
439 if (LongOutputSum) mxFree(LongOutputSum);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
440 if (LongOutputCount) mxFree(LongOutputCount);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
441 if (LongOutputSum2) mxFree(LongOutputSum2);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
442
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
443 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
444 //mexPrintf("Third argument must be not empty - otherwise status whether a NaN occured or not cannot be returned.");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
445 /* this is a hack, the third input argument is used to return whether a NaN occured or not.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
446 this requires that the input argument is a non-empty variable
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
447 */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
448 if (flag_isNaN && (PInputCount > 2) && mxGetNumberOfElements(PInputs[2])) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
449 // set FLAG_NANS_OCCURED
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
450 switch (mxGetClassID(PInputs[2])) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
451 case mxLOGICAL_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
452 case mxCHAR_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
453 case mxINT8_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
454 case mxUINT8_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
455 *(uint8_t*)mxGetData(PInputs[2]) = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
456 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
457 case mxDOUBLE_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
458 *(double*)mxGetData(PInputs[2]) = 1.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
459 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
460 case mxSINGLE_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
461 *(float*)mxGetData(PInputs[2]) = 1.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
462 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
463 case mxINT16_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
464 case mxUINT16_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
465 *(uint16_t*)mxGetData(PInputs[2]) = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
466 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
467 case mxINT32_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
468 case mxUINT32_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
469 *(uint32_t*)mxGetData(PInputs[2])= 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
470 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
471 case mxINT64_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
472 case mxUINT64_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
473 *(uint64_t*)mxGetData(PInputs[2]) = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
474 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
475 case mxFUNCTION_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
476 case mxUNKNOWN_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
477 case mxCELL_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
478 case mxSTRUCT_CLASS:
7301
485d1594d155 addresses undesired side-effect off in-place sorting of data
schloegl
parents: 6549
diff changeset
479 default:
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
480 mexPrintf("Type of 3rd input argument not supported.");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
481 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
482 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
483 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
484 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
485
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
486 #define stride 1
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
487 inline void __sumskipnan2w__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
488 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
489 long double sum=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
490 char flag=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
491 // LOOP along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
492
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
493 double *end = data + stride*Ni;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
494 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
495 // with weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
496 long double count = 0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
497 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
498 long double x = *data;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
499 if (!ISNAN(x))
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
500 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
501 count += *W;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
502 sum += *W*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
503 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
504 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
505 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
506 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
507 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
508
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
509 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
510 W++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
511 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
512 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
513 *No = (typeof(*No))count;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
514 } else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
515 // w/o weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
516 size_t countI = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
517 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
518 long double x = *data;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
519 if (!ISNAN(x))
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
520 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
521 countI++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
522 sum += x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
523 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
524 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
525 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
526 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
527 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
528 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
529 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
530 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
531 *No = (typeof(*No))countI;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
532 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
533
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
534 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
535 if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
536 #endif
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
537 *s = (typeof(*s))sum;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
538
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
539 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
540
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
541
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
542 inline void __sumskipnan3w__(double *data, size_t Ni, double *s, double *s2, double *No, char *flag_anyISNAN, double *W)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
543 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
544 long double sum=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
545 long double msq=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
546 char flag=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
547 // LOOP along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
548
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
549 double *end = data + stride*Ni;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
550 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
551 // with weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
552 long double count = 0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
553 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
554 long double x = *data;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
555 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
556 count += *W;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
557 long double t = *W*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
558 sum += t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
559 msq += x*t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
560 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
561 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
562 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
563 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
564 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
565 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
566 W++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
567 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
568 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
569 *No = (typeof(*No))count;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
570 } else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
571 // w/o weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
572 size_t countI = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
573 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
574 long double x = *data;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
575 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
576 countI++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
577 sum += x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
578 msq += x*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
579 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
580 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
581 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
582 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
583 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
584 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
585 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
586 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
587 *No = (typeof(*No))countI;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
588 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
589
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
590 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
591 if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
592 #endif
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
593 *s = (typeof(*s))sum;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
594 *s2 = (typeof(*s2))msq;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
595 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
596
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
597 inline void __sumskipnan2wr__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
598 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
599 double sum=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
600 char flag=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
601 // LOOP along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
602
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
603 double *end = data + stride*Ni;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
604 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
605 // with weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
606 double count = 0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
607 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
608 double x = *data;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
609 if (!ISNAN(x))
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
610 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
611 count += *W;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
612 sum += *W*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
613 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
614 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
615 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
616 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
617 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
618
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
619 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
620 W++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
621 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
622 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
623 *No = (typeof(*No))count;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
624 } else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
625 // w/o weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
626 size_t countI = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
627 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
628 double x = *data;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
629 if (!ISNAN(x))
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
630 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
631 countI++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
632 sum += x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
633 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
634 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
635 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
636 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
637 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
638 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
639 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
640 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
641 *No = (typeof(*No))countI;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
642 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
643
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
644 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
645 if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
646 #endif
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
647 *s = (typeof(*s))sum;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
648
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
649 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
650
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
651
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
652 inline void __sumskipnan3wr__(double *data, size_t Ni, double *s, double *s2, double *No, char *flag_anyISNAN, double *W)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
653 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
654 double sum=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
655 double msq=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
656 char flag=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
657 // LOOP along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
658
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
659 double *end = data + stride*Ni;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
660 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
661 // with weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
662 double count = 0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
663 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
664 double x = *data;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
665 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
666 count += *W;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
667 double t = *W*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
668 sum += t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
669 msq += x*t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
670 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
671 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
672 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
673 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
674 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
675 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
676 W++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
677 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
678 while (data < end);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
679 *No = count;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
680 } else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
681 // w/o weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
682 size_t countI = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
683 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
684 double x = *data;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
685 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
686 countI++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
687 sum += x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
688 msq += x*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
689 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
690 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
691 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
692 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
693 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
694 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
695 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
696 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
697 *No = (typeof(*No))countI;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
698 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
699
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
700 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
701 if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
702 #endif
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
703 *s = (typeof(*s))sum;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
704 *s2 = (typeof(*s2))msq;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
705 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
706
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
707
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
708
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
709 /***************************************
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
710 using Kahan's summation formula [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
711 this gives more accurate results while the computational effort within the loop is about 4x as high
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
712 First tests show a penalty of about 40% in terms of computational time.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
713
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
714 [1] David Goldberg,
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
715 What Every Computer Scientist Should Know About Floating-Point Arithmetic
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
716 ACM Computing Surveys, Vol 23, No 1, March 1991.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
717 ****************************************/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
718
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
719 inline void __sumskipnan2we__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
720 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
721 long double sum=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
722 char flag=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
723 // LOOP along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
724
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
725 double *end = data + stride*Ni;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
726 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
727 // with weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
728 long double count = 0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
729 long double rc=0.0, rn=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
730 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
731 long double x = *data;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
732 long double t,y;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
733 if (!ISNAN(x))
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
734 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
735 //count += *W; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
736 y = *W-rn;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
737 t = count+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
738 rn= (t-count)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
739 count= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
740
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
741 //sum += *W*x; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
742 y = *W*x-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
743 t = sum+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
744 rc= (t-sum)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
745 sum= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
746 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
747 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
748 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
749 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
750 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
751
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
752 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
753 W++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
754 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
755 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
756 *No = (typeof(*No))count;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
757 } else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
758 // w/o weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
759 size_t countI = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
760 long double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
761 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
762 long double x = *data;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
763 long double t,y;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
764 if (!ISNAN(x))
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
765 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
766 countI++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
767 // sum += x; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
768 y = x-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
769 t = sum+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
770 rc= (t-sum)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
771 sum= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
772 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
773 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
774 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
775 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
776 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
777 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
778 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
779 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
780 *No = (typeof(*No))countI;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
781 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
782
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
783 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
784 if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
785 #endif
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
786 *s = (typeof(*s))sum;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
787
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
788 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
789
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
790
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
791 inline void __sumskipnan3we__(double *data, size_t Ni, double *s, double *s2, double *No, char *flag_anyISNAN, double *W)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
792 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
793 long double sum=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
794 long double msq=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
795 char flag=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
796 // LOOP along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
797
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
798 double *end = data + stride*Ni;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
799 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
800 // with weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
801 long double count = 0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
802 long double rc=0.0, rn=0.0, rq=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
803 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
804 long double x = *data;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
805 long double t,y;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
806 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
807 //count += *W; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
808 y = *W-rn;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
809 t = count+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
810 rn= (t-count)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
811 count= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
812
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
813 long double w = *W*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
814 //sum += *W*x; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
815 y = *W*x-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
816 t = sum+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
817 rc= (t-sum)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
818 sum= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
819
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
820 // msq += x*w;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
821 y = w*x-rq;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
822 t = msq+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
823 rq= (t-msq)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
824 msq= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
825 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
826 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
827 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
828 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
829 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
830 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
831 W++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
832 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
833 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
834 *No = (typeof(*No))count;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
835 } else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
836 // w/o weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
837 size_t countI = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
838 long double rc=0.0, rq=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
839 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
840 long double x = *data;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
841 long double t,y;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
842 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
843 countI++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
844 //sum += x; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
845 y = x-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
846 t = sum+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
847 rc= (t-sum)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
848 sum= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
849
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
850 // msq += x*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
851 y = x*x-rq;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
852 t = msq+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
853 rq= (t-msq)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
854 msq= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
855 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
856 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
857 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
858 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
859 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
860 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
861 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
862 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
863 *No = (typeof(*No))countI;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
864 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
865
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
866 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
867 if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
868 #endif
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
869 *s = (typeof(*s))sum;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
870 *s2 = (typeof(*s))msq;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
871 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
872
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
873 inline void __sumskipnan2wer__(double *data, size_t Ni, double *s, double *No, char *flag_anyISNAN, double *W)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
874 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
875 double sum=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
876 char flag=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
877 // LOOP along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
878
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
879 double *end = data + stride*Ni;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
880 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
881 // with weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
882 double count = 0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
883 double rc=0.0, rn=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
884 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
885 double x = *data;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
886 double t,y;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
887 if (!ISNAN(x))
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
888 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
889 //count += *W; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
890 y = *W-rn;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
891 t = count+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
892 rn= (t-count)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
893 count= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
894
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
895 //sum += *W*x; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
896 y = *W*x-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
897 t = sum+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
898 rc= (t-sum)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
899 sum= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
900 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
901 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
902 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
903 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
904 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
905
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
906 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
907 W++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
908 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
909 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
910 *No = (typeof(*No))count;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
911 } else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
912 // w/o weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
913 size_t countI = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
914 double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
915 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
916 double x = *data;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
917 double t,y;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
918 if (!ISNAN(x))
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
919 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
920 countI++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
921 // sum += x; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
922 y = x-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
923 t = sum+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
924 rc= (t-sum)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
925 sum= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
926 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
927 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
928 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
929 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
930 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
931 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
932 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
933 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
934 *No = (typeof(*No))countI;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
935 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
936
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
937 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
938 if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
939 #endif
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
940 *s = (typeof(*s))sum;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
941
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
942 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
943
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
944
12555
6dea7ba11ac7 address compiler warnings on functions with no return argument
schloegl
parents: 12306
diff changeset
945 inline void __sumskipnan3wer__(double *data, size_t Ni, double *s, double *s2, double *No, char *flag_anyISNAN, double *W)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
946 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
947 double sum=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
948 double msq=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
949 char flag=0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
950 // LOOP along dimension DIM
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
951
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
952 double *end = data + stride*Ni;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
953 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
954 // with weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
955 double count = 0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
956 double rc=0.0, rn=0.0, rq=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
957 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
958 double x = *data;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
959 double t,y;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
960 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
961 //count += *W; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
962 y = *W-rn;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
963 t = count+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
964 rn= (t-count)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
965 count= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
966
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
967 double w = *W*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
968 //sum += *W*x; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
969 y = *W*x-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
970 t = sum+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
971 rc= (t-sum)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
972 sum= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
973
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
974 // msq += x*w;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
975 y = w*x-rq;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
976 t = msq+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
977 rq= (t-msq)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
978 msq= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
979 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
980 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
981 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
982 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
983 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
984 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
985 W++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
986 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
987 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
988 *No = (typeof(*No))count;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
989 } else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
990 // w/o weight vector
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
991 size_t countI = 0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
992 double rc=0.0, rq=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
993 do {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
994 double x = *data;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
995 double t,y;
12691
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
996 if (!ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
997 countI++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
998 //sum += x; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
999 y = x-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1000 t = sum+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1001 rc= (t-sum)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1002 sum= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1003
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1004 // msq += x*x;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1005 y = x*x-rq;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1006 t = msq+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1007 rq= (t-msq)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1008 msq= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1009 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1010 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1011 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1012 flag = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1013 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1014 data++; // stride=1
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1015 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1016 while (data < end);
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
1017 *No = (typeof(*No))countI;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1018 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1019
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1020 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1021 if (flag && (flag_anyISNAN != NULL)) *flag_anyISNAN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1022 #endif
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
1023 *s = (typeof(*s))sum;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
1024 *s2 = (typeof(*s))msq;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1025 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1026