annotate extra/NaN/src/covm_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 79e7259c6ff1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
1 /*
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 COVM - 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 // covm: in-product of matrices, NaN are skipped.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
21 // usage:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
22 // [cc,nn] = covm_mex(X,Y,flag,W);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
23 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
24 // Input:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
25 // - X:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
26 // - Y: [optional], if empty, Y=X;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
27 // - flag: if not empty, it is set to 1 if some NaN was observed
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
28 // - W: weight vector to compute weighted correlation
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
29 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
30 // Output:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
31 // - CC = X' * sparse(diag(W)) * Y while NaN's are skipped
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
32 // - NN = real(~ISNAN(X)')*sparse(diag(W))*real(~ISNAN(Y)) count of valid (non-NaN) elements
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
33 // computed more efficiently
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
34 //
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
35 // $Id$
8037
6a419bec96bb update contact e-mail and www address
schloegl
parents: 7992
diff changeset
36 // Copyright (C) 2009,2010,2011 Alois Schloegl <alois.schloegl@gmail.com>
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
37 // This function is part of the NaN-toolbox
7889
c101c486d80a fix web address
schloegl
parents: 7888
diff changeset
38 // http://pub.ist.ac.at/~schloegl/matlab/NaN/
6549
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 */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
42
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
43 #ifdef __GNUC__
7888
b9f35668b55e replace <inttypes.h> with <stdint.h>
schloegl
parents: 6585
diff changeset
44 #include <stdint.h>
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
45 #endif
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
46 #include <math.h>
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
47 #include "mex.h"
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
48
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
49 /*#define NO_FLAG*/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
50
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
51 /*
6d6285a2a633 use macro ISNAN() instead of C++'s isnan() - because it supports all floating point formats not just double
schloegl
parents: 12685
diff changeset
52 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
53 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
54 */
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 #define ISNAN(a) (a!=a)
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
56
12702
29b7963bf748 define typeof() when missing; support for clang compiler added
schloegl
parents: 12697
diff changeset
57 #ifndef typeof
29b7963bf748 define typeof() when missing; support for clang compiler added
schloegl
parents: 12697
diff changeset
58 #define typeof __typeof__
29b7963bf748 define typeof() when missing; support for clang compiler added
schloegl
parents: 12697
diff changeset
59 #endif
29b7963bf748 define typeof() when missing; support for clang compiler added
schloegl
parents: 12697
diff changeset
60
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
61 void mexFunction(int POutputCount, mxArray* POutput[], int PInputCount, const mxArray *PInputs[])
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
62 {
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
63 double *X0=NULL, *Y0=NULL, *W=NULL;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
64 double *CC;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
65 double *NN = NULL;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
66
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
67 size_t rX,cX,rY,cY;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
68 size_t i;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
69 char flag_isNaN = 0;
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
70 int ACC_LEVEL;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
71
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
72 /*********** check input arguments *****************/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
73
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
74 // check for proper number of input and output arguments
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
75 if ((PInputCount <= 0) || (PInputCount > 5)) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
76 mexPrintf("usage: [CC,NN] = covm_mex(X [,Y [,flag [,W [,'E']]]])\n\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
77 mexPrintf("Do not use COVM_MEX directly, use COVM instead. \n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
78 /*
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
79 mexPrintf("\nCOVM_MEX computes the covariance matrix of real matrices and skips NaN's\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
80 mexPrintf("\t[CC,NN] = covm_mex(...)\n\t\t computes CC=X'*Y, NN contains the number of not-NaN elements\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
81 mexPrintf("\t\t CC./NN is the unbiased covariance matrix\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
82 mexPrintf("\t... = covm_mex(X,Y,...)\n\t\t computes CC=X'*sparse(diag(W))*Y, number of rows of X and Y must match\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
83 mexPrintf("\t... = covm_mex(X,[], ...)\n\t\t computes CC=X'*sparse(diag(W))*X\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
84 mexPrintf("\t... = covm_mex(...,flag,...)\n\t\t if flag is not empty, it is set to 1 if some NaN occured in X or Y\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
85 mexPrintf("\t... = covm_mex(...,W)\n\t\t W to compute weighted covariance, number of elements must match the number of rows of X\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
86 mexPrintf("\t\t if isempty(W), all weights are 1\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
87 mexPrintf("\t[CC,NN]=covm_mex(X,Y,flag,W)\n");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
88 */ return;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
89 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
90 if (POutputCount > 2)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
91 mexErrMsgTxt("covm.MEX has 1 to 2 output arguments.");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
92
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
93
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
94 // get 1st argument
12640
de98e4cb9248 check for sparse matrices and and convert to full if needed
schloegl
parents: 8037
diff changeset
95 if(mxIsDouble(PInputs[0]) && !mxIsComplex(PInputs[0]) && !mxIsSparse(PInputs[0]) )
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
96 X0 = mxGetPr(PInputs[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
97 else
12640
de98e4cb9248 check for sparse matrices and and convert to full if needed
schloegl
parents: 8037
diff changeset
98 mexErrMsgTxt("First argument must be non-sparse REAL/DOUBLE.");
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
99 rX = mxGetM(PInputs[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
100 cX = mxGetN(PInputs[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
101
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
102 // get 2nd argument
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
103 if (PInputCount > 1) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
104 if (!mxGetNumberOfElements(PInputs[1]))
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
105 ; // Y0 = NULL;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
106
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
107 else if (mxIsDouble(PInputs[1]) && !mxIsComplex(PInputs[1]))
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
108 Y0 = mxGetPr(PInputs[1]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
109
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
110 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
111 mexErrMsgTxt("Second argument must be REAL/DOUBLE.");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
112 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
113
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
114
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
115 // get weight vector for weighted sumskipnan
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
116 if (PInputCount > 3) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
117 // get 4th argument
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
118 size_t nW = mxGetNumberOfElements(PInputs[3]);
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
119 if (!nW)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
120 ;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
121 else if (nW == rX)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
122 W = mxGetPr(PInputs[3]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
123 else
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
124 mexErrMsgTxt("number of elements in W must match numbers of rows in X");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
125 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
126
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
127 #ifdef __GNUC__
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
128 ACC_LEVEL = 0;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
129 {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
130 mxArray *LEVEL = NULL;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
131 int s = mexCallMATLAB(1, &LEVEL, 0, NULL, "flag_accuracy_level");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
132 if (!s) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
133 ACC_LEVEL = (int) mxGetScalar(LEVEL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
134 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
135 mxDestroyArray(LEVEL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
136 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
137 // mexPrintf("Accuracy Level=%i\n",ACC_LEVEL);
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
138 #endif
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
139 if (Y0==NULL) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
140 Y0 = X0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
141 rY = rX;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
142 cY = cX;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
143 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
144 else {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
145 rY = mxGetM(PInputs[1]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
146 cY = mxGetN(PInputs[1]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
147 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
148 if (rX != rY)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
149 mexErrMsgTxt("number of rows in X and Y do not match");
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
150
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
151 /*********** create output arguments *****************/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
152
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
153 POutput[0] = mxCreateDoubleMatrix(cX, cY, mxREAL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
154 CC = mxGetPr(POutput[0]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
155
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
156 if (POutputCount > 1) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
157 POutput[1] = mxCreateDoubleMatrix(cX, cY, mxREAL);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
158 NN = mxGetPr(POutput[1]);
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
159 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
160
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
161
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
162 /*********** compute covariance *****************/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
163
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
164 #if 0
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
165 /*------ version 1 ---------------------
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
166 this solution is slower than the alternative solution below
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
167 for transposed matrices, this might be faster.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
168 */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
169 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
170 double w;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
171 if (W) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
172 w = W[k];
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
173 for (i=0; i<cX; i++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
174 double x = X0[k+i*rX];
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
175 if (ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
176 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
177 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
178 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
179 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
180 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
181 for (j=0; j<cY; j++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
182 double y = Y0[k+j*rY];
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
183 if (ISNAN(y)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
184 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
185 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
186 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
187 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
188 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
189 CC[i+j*cX] += x*y*w;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
190 if (NN != NULL)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
191 NN[i+j*cX] += w;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
192 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
193 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
194 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
195 else for (i=0; i<cX; i++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
196 double x = X0[k+i*rX];
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
197 if (ISNAN(x)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
198 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
199 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
200 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
201 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
202 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
203 for (j=0; j<cY; j++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
204 double y = Y0[k+j*rY];
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
205 if (ISNAN(y)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
206 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
207 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
208 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
209 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
210 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
211 CC[i+j*cX] += x*y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
212 if (NN != NULL)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
213 NN[i+j*cX] += 1.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
214 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
215 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
216 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
217
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
218 #else
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
219
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
220 #pragma omp parallel
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
221 {
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
222 #ifdef __GNUC__
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
223 if (ACC_LEVEL == 0)
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
224 #endif
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
225 {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
226 /*------ version 2 ---------------------
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
227 using naive summation with double accuracy [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
228 */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
229 if ( (X0 != Y0) || (cX != cY) )
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
230 /******** X!=Y, output is not symetric *******/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
231 if (W) /* weighted version */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
232 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
233 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
234 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
235 double *X = X0 + (i%cX) * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
236 double *Y = Y0 + (i/cX) * rY;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
237 double cc = 0.0;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
238 double nw = 0.0;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
239 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
240 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
241 double z = X[k]*Y[k];
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
242 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
243 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
244 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
245 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
246 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
247 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
248 cc += z*W[k];
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
249 nw += W[k];
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
250 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
251 CC[i] = cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
252 if (NN != NULL)
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
253 NN[i] = nw;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
254 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
255 else /* no weights, all weights are 1 */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
256 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
257 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
258 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
259 double *X = X0 + (i%cX) * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
260 double *Y = Y0 + (i/cX) * rY;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
261 double cc = 0.0;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
262 size_t nn = 0;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
263 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
264 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
265 double z = X[k]*Y[k];
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
266 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
267 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
268 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
269 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
270 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
271 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
272 cc += z;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
273 nn++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
274 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
275 CC[i] = cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
276 if (NN != NULL)
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
277 NN[i] = (double)nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
278 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
279 else // if (X0==Y0) && (cX==cY)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
280 /******** X==Y, output is symetric *******/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
281 if (W) /* weighted version */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
282 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
283 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
284 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
285 size_t ii = i%cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
286 size_t jj = i/cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
287 if (ii < jj) continue;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
288 double *X = X0 + ii * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
289 double *Y = Y0 + jj * rY;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
290 double cc = 0.0;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
291 double nw = 0.0;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
292 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
293 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
294 double z = X[k]*Y[k];
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
295 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
296 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
297 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
298 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
299 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
300 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
301 cc += z*W[k];
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
302 nw += W[k];
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
303 }
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
304 size_t j = jj + ii*cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
305 CC[i] = cc;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
306 CC[j] = cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
307 if (NN != NULL) {
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
308 NN[i] = nw;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
309 NN[j] = nw;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
310 }
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
311 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
312 else /* no weights, all weights are 1 */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
313 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
314 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
315 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
316 size_t ii = i%cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
317 size_t jj = i/cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
318 if (ii < jj) continue;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
319 double *X = X0 + ii * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
320 double *Y = Y0 + jj * rY;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
321 double cc = 0.0;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
322 size_t nn = 0;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
323 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
324 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
325 double z = X[k]*Y[k];
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(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
327 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
328 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
329 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
330 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
331 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
332 cc += z;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
333 nn++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
334 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
335 size_t j = jj + ii*cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
336 CC[i] = cc;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
337 CC[j] = cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
338 if (NN != NULL) {
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
339 NN[i] = (double)nn;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
340 NN[j] = (double)nn;
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 }
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
345
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
346 #ifdef __GNUC__
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
347
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
348 else if (ACC_LEVEL == 1) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
349 /*------ version 2 ---------------------
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
350 using naive summation with extended accuracy [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
351 */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
352 if ( (X0 != Y0) || (cX != cY) )
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
353 /******** X!=Y, output is not symetric *******/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
354 if (W) /* weighted version */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
355 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
356 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
357 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
358 double *X = X0 + (i%cX) * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
359 double *Y = Y0 + (i/cX) * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
360 long double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
361 long double nn=0.0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
362 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
363 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
364 long double z = ((long double)X[k])*Y[k];
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
365 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
366 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
367 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
368 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
369 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
370 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
371 cc += z*W[k];
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
372 nn += W[k];
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
373 }
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
374 CC[i] = (typeof(*CC))cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
375 if (NN != NULL)
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
376 NN[i] = (typeof(*NN))nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
377 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
378 else /* no weights, all weights are 1 */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
379 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
380 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
381 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
382 double *X = X0 + (i%cX) * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
383 double *Y = Y0 + (i/cX) * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
384 long double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
385 size_t nn=0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
386 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
387 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
388 long double z = ((long double)X[k])*Y[k];
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
389 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
390 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
391 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
392 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
393 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
394 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
395 cc += z;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
396 nn++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
397 }
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
398 CC[i] = (typeof(*CC))cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
399 if (NN != NULL)
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
400 NN[i] = (typeof(*NN))nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
401 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
402 else // if (X0==Y0) && (cX==cY)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
403 /******** X==Y, output is symetric *******/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
404 if (W) /* weighted version */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
405 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
406 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
407 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
408 size_t ii = i%cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
409 size_t jj = i/cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
410 if (ii < jj) continue;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
411 double *X = X0 + ii * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
412 double *Y = Y0 + jj * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
413 long double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
414 long double nn=0.0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
415 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
416 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
417 long double z = ((long double)X[k])*Y[k];
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
418 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
419 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
420 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
421 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
422 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
423 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
424 cc += z*W[k];
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
425 nn += W[k];
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
426 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
427 size_t j = jj + ii*cX;
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
428 CC[i] = (typeof(*CC))cc;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
429 CC[j] = (typeof(*CC))cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
430 if (NN != NULL) {
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
431 NN[i] = (typeof(*NN))nn;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
432 NN[j] = (typeof(*NN))nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
433 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
434 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
435 else /* no weights, all weights are 1 */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
436 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
437 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
438 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
439 size_t ii = i%cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
440 size_t jj = i/cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
441 if (ii < jj) continue;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
442 double *X = X0 + ii * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
443 double *Y = Y0 + jj * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
444 long double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
445 size_t nn=0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
446 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
447 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
448 long double z = ((long double)X[k])*Y[k];
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
449 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
450 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
451 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
452 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
453 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
454 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
455 cc += z;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
456 nn++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
457 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
458 size_t j = jj + ii*cX;
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
459 CC[i] = (typeof(*CC))cc;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
460 CC[j] = (typeof(*CC))cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
461 if (NN != NULL) {
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
462 NN[i] = (typeof(*NN))nn;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
463 NN[j] = (typeof(*NN))nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
464 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
465 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
466
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
467 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
468 else if (ACC_LEVEL == 3) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
469 /*------ version 3 ---------------------
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
470 using Kahan's summation with extended (long double) accuracy [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
471 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
472 However, first test show an increase in computational time of only about 25 %.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
473
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
474 [1] David Goldberg,
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
475 What Every Computer Scientist Should Know About Floating-Point Arithmetic
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
476 ACM Computing Surveys, Vol 23, No 1, March 1991
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
477 */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
478 if ( (X0 != Y0) || (cX != cY) )
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
479 /******** X!=Y, output is not symetric *******/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
480 if (W) /* weighted version */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
481 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
482 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
483 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
484 double *X = X0 + (i%cX) * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
485 double *Y = Y0 + (i/cX) * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
486 long double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
487 long double nn=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
488 long double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
489 long double rn=0.0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
490 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
491 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
492 long double t,y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
493 long double z = ((long double)X[k])*Y[k];
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
494 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
495 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
496 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
497 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
498 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
499 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
500 // cc += z*W[k]; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
501 y = z*W[k]-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
502 t = cc+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
503 rc= (t-cc)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
504 cc= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
505
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
506 // nn += W[k]; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
507 y = z*W[k]-rn;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
508 t = nn+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
509 rn= (t-nn)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
510 nn= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
511 }
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
512 CC[i] = (typeof(*CC))cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
513 if (NN != NULL)
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
514 NN[i] = (typeof(*NN))nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
515 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
516 else /* no weights, all weights are 1 */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
517 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
518 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
519 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
520 double *X = X0 + (i%cX) * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
521 double *Y = Y0 + (i/cX) * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
522 long double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
523 long double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
524 size_t nn=0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
525 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
526 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
527 long double t,y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
528 long double z = ((long double)X[k])*Y[k];
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
529 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
530 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
531 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
532 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
533 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
534 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
535 // cc += z; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
536 y = z-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
537 t = cc+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
538 rc= (t-cc)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
539 cc= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
540
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
541 nn++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
542 }
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
543 CC[i] = (typeof(*CC))cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
544 if (NN != NULL)
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
545 NN[i] = (typeof(*NN))nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
546 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
547 else // if (X0==Y0) && (cX==cY)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
548 /******** X==Y, output is symetric *******/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
549 if (W) /* weighted version */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
550 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
551 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
552 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
553 size_t ii = i%cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
554 size_t jj = i/cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
555 if (ii < jj) continue;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
556 double *X = X0 + ii * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
557 double *Y = Y0 + jj * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
558 long double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
559 long double nn=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
560 long double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
561 long double rn=0.0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
562 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
563 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
564 long double t,y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
565 long double z = ((long double)X[k])*Y[k];
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
566 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
567 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
568 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
569 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
570 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
571 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
572 // cc += z*W[k]; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
573 y = z*W[k]-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
574 t = cc+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
575 rc= (t-cc)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
576 cc= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
577
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
578 // nn += W[k]; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
579 y = z*W[k]-rn;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
580 t = nn+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
581 rn= (t-nn)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
582 nn= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
583 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
584 size_t j = jj + ii*cX;
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
585 CC[i] = (typeof(*CC))cc;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
586 CC[j] = (typeof(*CC))cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
587 if (NN != NULL) {
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
588 NN[i] = (typeof(*NN))nn;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
589 NN[j] = (typeof(*NN))nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
590 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
591 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
592 else /* no weights, all weights are 1 */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
593 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
594 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
595 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
596 size_t ii = i%cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
597 size_t jj = i/cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
598 if (ii < jj) continue;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
599 double *X = X0 + ii * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
600 double *Y = Y0 + jj * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
601 long double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
602 long double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
603 size_t nn=0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
604 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
605 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
606 long double t,y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
607 long double z = ((long double)X[k])*Y[k];
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
608 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
609 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
610 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
611 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
612 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
613 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
614 // cc += z; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
615 y = z-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
616 t = cc+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
617 rc= (t-cc)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
618 cc= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
619
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
620 nn++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
621 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
622 size_t j = jj + ii*cX;
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
623 CC[i] = (typeof(*CC))cc;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
624 CC[j] = (typeof(*CC))cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
625 if (NN != NULL) {
12685
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
626 NN[i] = (typeof(*NN))nn;
f26b1170ea90 resulting values should be really converted to output data type
schloegl
parents: 12640
diff changeset
627 NN[j] = (typeof(*NN))nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
628 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
629 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
630 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
631 else if (ACC_LEVEL == 2) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
632 /*------ version 3 ---------------------
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
633 using Kahan's summation with double accuracy [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
634 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
635 However, first test show an increase in computational time of only about 25 %.
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
636
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
637 [1] David Goldberg,
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
638 What Every Computer Scientist Should Know About Floating-Point Arithmetic
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
639 ACM Computing Surveys, Vol 23, No 1, March 1991
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
640 */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
641 if ( (X0 != Y0) || (cX != cY) )
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
642 /******** X!=Y, output is not symetric *******/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
643 if (W) /* weighted version */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
644 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
645 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
646 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
647 double *X = X0 + (i%cX) * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
648 double *Y = Y0 + (i/cX) * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
649 double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
650 double nn=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
651 double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
652 double rn=0.0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
653 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
654 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
655 double t,y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
656 double z = X[k]*Y[k];
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
657 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
658 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
659 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
660 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
661 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
662 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
663 // cc += z*W[k]; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
664 y = z*W[k]-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
665 t = cc+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
666 rc= (t-cc)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
667 cc= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
668
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
669 // nn += W[k]; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
670 y = z*W[k]-rn;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
671 t = nn+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
672 rn= (t-nn)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
673 nn= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
674 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
675 CC[i] = cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
676 if (NN != NULL)
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
677 NN[i] = nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
678 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
679 else /* no weights, all weights are 1 */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
680 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
681 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
682 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
683 double *X = X0 + (i%cX) * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
684 double *Y = Y0 + (i/cX) * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
685 double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
686 double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
687 size_t nn=0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
688 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
689 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
690 double t,y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
691 double z = X[k]*Y[k];
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
692 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
693 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
694 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
695 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
696 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
697 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
698 // cc += z; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
699 y = z-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
700 t = cc+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
701 rc= (t-cc)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
702 cc= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
703
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
704 nn++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
705 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
706 CC[i] = cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
707 if (NN != NULL)
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
708 NN[i] = (double)nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
709 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
710 else // if (X0==Y0) && (cX==cY)
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
711 /******** X==Y, output is symetric *******/
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
712 if (W) /* weighted version */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
713 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
714 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
715 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
716 size_t ii = i%cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
717 size_t jj = i/cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
718 if (ii < jj) continue;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
719 double *X = X0 + ii * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
720 double *Y = Y0 + jj * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
721 double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
722 double nn=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
723 double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
724 double rn=0.0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
725 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
726 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
727 double t,y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
728 double z = X[k]*Y[k];
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
729 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
730 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
731 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
732 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
733 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
734 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
735 // cc += z*W[k]; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
736 y = z*W[k]-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
737 t = cc+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
738 rc= (t-cc)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
739 cc= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
740
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
741 // nn += W[k]; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
742 y = z*W[k]-rn;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
743 t = nn+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
744 rn= (t-nn)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
745 nn= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
746 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
747 size_t j = jj + ii*cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
748 CC[i] = cc;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
749 CC[j] = cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
750 if (NN != NULL) {
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
751 NN[i] = nn;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
752 NN[j] = nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
753 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
754 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
755 else /* no weights, all weights are 1 */
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
756 #pragma omp for schedule(dynamic) nowait
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
757 for (i = 0; i < cX * cY; i++)
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
758 {
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
759 size_t ii = i%cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
760 size_t jj = i/cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
761 if (ii < jj) continue;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
762 double *X = X0 + ii * rX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
763 double *Y = Y0 + jj * rY;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
764 double cc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
765 double rc=0.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
766 size_t nn=0;
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
767 size_t k;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
768 for (k=0; k<rX; k++) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
769 double t,y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
770 double z = X[k]*Y[k];
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
771 if (ISNAN(z)) {
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
772 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
773 flag_isNaN = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
774 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
775 continue;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
776 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
777 // cc += z; [1]
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
778 y = z-rc;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
779 t = cc+y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
780 rc= (t-cc)-y;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
781 cc= t;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
782
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
783 nn++;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
784 }
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
785 size_t j = jj + ii*cX;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
786 CC[i] = cc;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
787 CC[j] = cc;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
788 if (NN != NULL) {
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
789 NN[i] = (double)nn;
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
790 NN[j] = (double)nn;
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
791 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
792 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
793 }
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
794 #endif
7992
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
795 } // end pragma omg parallel
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
796
db5092052107 OpenMP support included
schloegl
parents: 7889
diff changeset
797
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
798 #ifndef NO_FLAG
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
799 //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
800 /* 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
801 this requires that the input argument is a non-empty variable
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
802 */
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
803 if (flag_isNaN && (PInputCount > 2) && mxGetNumberOfElements(PInputs[2])) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
804 // set FLAG_NANS_OCCURED
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
805 switch (mxGetClassID(PInputs[2])) {
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
806 case mxDOUBLE_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
807 *(double*)mxGetData(PInputs[2]) = 1.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
808 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
809 case mxSINGLE_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
810 *(float*)mxGetData(PInputs[2]) = 1.0;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
811 break;
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
812 case mxLOGICAL_CLASS:
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
813 case mxCHAR_CLASS:
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
814 case mxINT8_CLASS:
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
815 case mxUINT8_CLASS:
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
816 *(char*)mxGetData(PInputs[2]) = 1;
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
817 break;
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
818 #ifdef __GNUC__
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
819 case mxINT16_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
820 case mxUINT16_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
821 *(uint16_t*)mxGetData(PInputs[2]) = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
822 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
823 case mxINT32_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
824 case mxUINT32_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
825 *(uint32_t*)mxGetData(PInputs[2])= 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
826 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
827 case mxINT64_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
828 case mxUINT64_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
829 *(uint64_t*)mxGetData(PInputs[2]) = 1;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
830 break;
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
831 case mxFUNCTION_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
832 case mxUNKNOWN_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
833 case mxCELL_CLASS:
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
834 case mxSTRUCT_CLASS:
6585
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
835 #endif
ae521dec5b54 partial support of lcc-win compiler
schloegl
parents: 6549
diff changeset
836 default:
12697
79e7259c6ff1 nan and tsa: Typo in MEX message - fixes bug #46568
schloegl
parents: 12691
diff changeset
837 mexPrintf("Type of 3rd input argument cannot be used to return status of NaN occurrence.");
6549
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
838 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
839 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
840 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
841 #endif
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
842 }
41e9854fe26d use *.cpp instead of *.c
schloegl
parents:
diff changeset
843