Mercurial > forge
annotate extra/NaN/src/histo_mex.cpp @ 5761:1dbdb1ab56ba octave-forge
support for data weigthening added - fix for (u)int8/16 data
author | schloegl |
---|---|
date | Mon, 15 Jun 2009 09:09:49 +0000 |
parents | 0b1b67486b3a |
children | d14e3342cb28 |
rev | line source |
---|---|
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
1 //------------------------------------------------------------------- |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
2 #pragma hdrstop |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
3 //------------------------------------------------------------------- |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
4 // C-MEX implementation of SUMSKIPNAN - this function is part of the NaN-toolbox. |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
5 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
6 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
7 // This program is free software; you can redistribute it and/or modify |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
8 // it under the terms of the GNU General Public License as published by |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
9 // the Free Software Foundation; either version 3 of the License, or |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
10 // (at your option) any later version. |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
11 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
12 // This program is distributed in the hope that it will be useful, |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
15 // GNU General Public License for more details. |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
16 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
17 // You should have received a copy of the GNU General Public License |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
18 // along with this program; if not, see <http://www.gnu.org/licenses/>. |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
19 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
20 // |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
21 // histo_mex: computes histogram |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
22 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
23 // Input: |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
24 // - data matrix |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
25 // - flag for row-wise histogram |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
26 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
27 // Output: |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
28 // - histogram |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
29 // HIS.X |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
30 // HIS.H |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
31 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
32 // $Id$ |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
33 // Copyright (C) 2009 Alois Schloegl <a.schloegl@ieee.org> |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
34 // This function is part of the NaN-toolbox |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
35 // http://hci.tugraz.at/~schloegl/matlab/NaN/ |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
36 // |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
37 //------------------------------------------------------------------- |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
38 |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
39 /* TODO: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
40 speed: its slower than the m-functions histo2/3/4 |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
41 |-> use a more efficient sorting function |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
42 resembling of histo3 for multicolumn data. |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
43 */ |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
44 |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
45 #include <inttypes.h> |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
46 #include <math.h> |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
47 #include <string.h> |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
48 #include "mex.h" |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
49 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
50 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
51 #ifdef tmwtypes_h |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
52 #if (MX_API_VER<0x07020000) |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
53 typedef int mwSize; |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
54 #endif |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
55 #endif |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
56 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
57 struct sort_t { |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
58 uint8_t *Table; // data table |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
59 size_t Size; // sizeof elements e.g. 4 for single |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
60 size_t Stride; // for multicolumn data |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
61 size_t N; // number of rows |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
62 mxClassID Type; // data type |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
63 } Sort; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
64 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
65 //inline int compare(const sqize_t *a, const size_t *b) { |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
66 int compare(const void *a, const void *b) { |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
67 int z = 0; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
68 size_t i = 0; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
69 size_t ix1 = *(size_t*)a; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
70 size_t ix2 = *(size_t*)b; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
71 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
72 while ((i<Sort.N) && !z) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
73 switch (Sort.Type) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
74 case mxCHAR_CLASS: |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
75 z = memcmp(Sort.Table+ix1*Sort.Size,Sort.Table+ix2*Sort.Size,Sort.Size); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
76 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
77 case mxINT32_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
78 int32_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
79 f1 = ((int32_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
80 f2 = ((int32_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
81 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
82 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
83 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
84 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
85 case mxUINT32_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
86 uint32_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
87 f1 = ((uint32_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
88 f2 = ((uint32_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
89 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
90 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
91 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
92 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
93 case mxINT64_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
94 int64_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
95 f1 = ((int64_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
96 f2 = ((int64_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
97 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
98 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
99 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
100 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
101 case mxUINT64_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
102 uint64_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
103 f1 = ((uint64_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
104 f2 = ((uint64_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
105 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
106 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
107 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
108 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
109 case mxSINGLE_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
110 float f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
111 f1 = ((float*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
112 f2 = ((float*)Sort.Table)[ix2]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
113 switch (isnan(f1) + 2*isnan(f2)) { |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
114 case 0: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
115 if (f1<f2) z = -1; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
116 else if (f1>f2) z = 1; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
117 case 3: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
118 break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
119 case 1: z = 1; break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
120 case 2: z = -1; break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
121 } |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
122 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
123 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
124 case mxDOUBLE_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
125 double f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
126 f1 = ((double*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
127 f2 = ((double*)Sort.Table)[ix2]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
128 switch (isnan(f1) + 2*isnan(f2)) { |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
129 case 0: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
130 if (f1<f2) z = -1; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
131 else if (f1>f2) z = 1; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
132 case 3: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
133 break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
134 case 1: z = 1; break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
135 case 2: z = -1; break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
136 } |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
137 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
138 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
139 case mxINT16_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
140 int16_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
141 f1 = ((int16_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
142 f2 = ((int16_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
143 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
144 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
145 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
146 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
147 case mxUINT16_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
148 uint16_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
149 f1 = ((uint16_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
150 f2 = ((uint16_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
151 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
152 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
153 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
154 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
155 case mxINT8_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
156 int8_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
157 f1 = ((int8_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
158 f2 = ((int8_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
159 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
160 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
161 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
162 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
163 case mxUINT8_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
164 uint8_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
165 f1 = ((uint8_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
166 f2 = ((uint8_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
167 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
168 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
169 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
170 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
171 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
172 i++; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
173 ix1 += Sort.Stride; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
174 ix2 += Sort.Stride; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
175 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
176 return(z); |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
177 } |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
178 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
179 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
180 void mexFunction(int POutputCount, mxArray* POutput[], int PInputCount, const mxArray *PInputs[]) |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
181 { |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
182 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
183 const mwSize *SZ; |
5760 | 184 char flag_rows = 0; |
185 char done = 0; | |
186 mwSize j, k; // running indices | |
187 ssize_t l; | |
188 const mxArray *W = NULL; | |
189 double *w = NULL; | |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
190 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
191 // check for proper number of input and output arguments |
5760 | 192 if ((PInputCount <= 0) || (PInputCount > 3)) { |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
193 mexPrintf("HISTO_MEX computes histogram from vector or column matrices\n\n"); |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
194 mexPrintf("usage:\tHIS = histo_mex(Y)\n\t\tComputes histogram from each column\n"); |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
195 mexPrintf("\t[HIS,tix] = histo_mex(Y,'rows')\n\t\tComputes row-wise histogram, tix is useful for data compression.\n\t\t Y = HIS.X(tix,:); \n\n"); |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
196 |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
197 mexPrintf("see also: HISTO2, HISTO3, HISTO4\n\n"); |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
198 mexErrMsgTxt("HISTO_MEX requires 1 or 2 input arguments\n"); |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
199 } |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
200 if (POutputCount > 2) |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
201 mexErrMsgTxt("histo.MEX has 1 output arguments."); |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
202 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
203 // get 1st argument |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
204 if (mxIsComplex(PInputs[0])) |
5760 | 205 mexErrMsgTxt("complex argument not supported (yet). "); |
206 // TODO: support complex argument! | |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
207 |
5760 | 208 if (PInputCount==1) |
209 ; // histo_mex(X) | |
210 else if (mxIsChar(PInputs[1])) { | |
211 // histo_mex(X,'rows') | |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
212 char *t = mxArrayToString(PInputs[1]); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
213 flag_rows = !strcmp(t,"rows"); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
214 mxFree(t); |
5760 | 215 // histo_mex(X,'rows',W) |
216 if ((PInputCount>2) && mxIsDouble(PInputs[2])) W = PInputs[2]; | |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
217 } |
5760 | 218 // histo_mex(X,W) |
219 else if (mxIsDouble(PInputs[1])) { | |
220 W = PInputs[1]; | |
221 } | |
222 else | |
223 mexErrMsgTxt("Weight vector must be REAL/DOUBLE."); | |
224 | |
225 if (W != NULL) { | |
226 if (mxGetM(PInputs[0])==mxGetM(W) ) | |
227 w = (double*)mxGetData(W); | |
228 else | |
229 mexErrMsgTxt("number of rows in X and W do not match."); | |
230 | |
231 for (k=0; (k<mxGetM(W)) && (w[k]>=0.0); k++); | |
232 if (k<mxGetM(W)) | |
233 mexWarnMsgTxt("weight vector contains also non-negative numbers or NaN."); | |
234 } | |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
235 |
5760 | 236 // get size |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
237 mwSize ND = mxGetNumberOfDimensions(PInputs[0]); |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
238 // NN = mxGetNumberOfElements(PInputs[0]); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
239 SZ = mxGetDimensions(PInputs[0]); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
240 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
241 if (ND>2) |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
242 mexErrMsgTxt("Error HISTO.MEX: input must be vector or matrix (no more than two dimensions)"); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
243 |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
244 size_t n = SZ[0]; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
245 size_t sz = 1; |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
246 char flag = 0; |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
247 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
248 const char *fnames[] = {"datatype","X","H"}; |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
249 mxArray *HIS = mxCreateStructMatrix(1, 1, 3, fnames); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
250 mxSetField(HIS,0,"datatype",mxCreateString("HISTOGRAM")); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
251 |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
252 if (flag_rows || (SZ[1]==1)) { |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
253 |
5760 | 254 ///***** SORT each column: initialize sorting algorithm |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
255 int (*compar)(const void*, const void*); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
256 size_t n; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
257 size_t *idx = NULL; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
258 idx = (size_t*) mxMalloc(SZ[0]*sizeof(size_t)); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
259 for (size_t n=0; n<SZ[0]; n++) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
260 idx[n]=n; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
261 } |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
262 Sort.Type = mxGetClassID(PInputs[0]); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
263 Sort.Table = (uint8_t*) mxGetData(PInputs[0]); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
264 switch (mxGetClassID(PInputs[0])) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
265 case mxINT8_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
266 case mxUINT8_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
267 Sort.Size = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
268 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
269 case mxINT16_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
270 case mxUINT16_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
271 Sort.Size = 2; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
272 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
273 case mxINT32_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
274 case mxUINT32_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
275 case mxSINGLE_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
276 Sort.Size = 4; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
277 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
278 case mxINT64_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
279 case mxUINT64_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
280 case mxDOUBLE_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
281 Sort.Size = 8; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
282 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
283 default: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
284 mexErrMsgTxt("unsupported input type"); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
285 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
286 Sort.N = flag_rows ? SZ[1] : 1; |
5760 | 287 qsort(idx,SZ[0],sizeof(*idx),compare); |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
288 |
5760 | 289 // count number of different elements |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
290 n = SZ[0] ? 1 : 0; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
291 for (size_t k=1; k<SZ[0]; k++) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
292 if (compare(idx+k-1,idx+k)) n++; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
293 } |
5760 | 294 |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
295 uint64_t *tix = NULL; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
296 if (POutputCount>1) { |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
297 POutput[1] = mxCreateNumericMatrix(SZ[0], 1, mxUINT64_CLASS,mxREAL); |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
298 tix = (uint64_t*)mxGetData(POutput[1]); |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
299 } |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
300 |
5760 | 301 // fill HIS.H and HIS.X |
302 mxArray *H = mxCreateNumericMatrix(n, 1, mxDOUBLE_CLASS,mxREAL); | |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
303 mxArray *X = mxCreateNumericMatrix(n, SZ[1], mxGetClassID(PInputs[0]),mxREAL); |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
304 mxSetField(HIS,0,"H",H); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
305 mxSetField(HIS,0,"X",X); |
5760 | 306 double *h = (double*)mxGetData(H); |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
307 uint8_t *x = (uint8_t*)mxGetData(X); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
308 |
5760 | 309 l = -1; |
310 if (tix) tix[idx[0]] = 1; | |
311 for (size_t k=0; k<SZ[0]; k++) { | |
312 if ((k==0) || compare(&idx[k-1], &idx[k])) { | |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
313 l++; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
314 for (j=0; j<SZ[1]; j++) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
315 memcpy(x + (l+j*n)*Sort.Size, Sort.Table+(idx[k] + j*Sort.Stride)*Sort.Size, Sort.Size); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
316 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
317 } |
5760 | 318 if (tix) tix[idx[k]] = l+1; |
319 if (w != NULL) | |
320 h[l]+=w[idx[k]]; | |
321 else | |
322 h[l]+=1.0; | |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
323 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
324 mxFree(idx); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
325 done = 1; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
326 } |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
327 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
328 else { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
329 switch (mxGetClassID(PInputs[0])) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
330 /* |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
331 case mxCHAR_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
332 mxArray *H = mxCreateNumericMatrix(256, SZ[1], mxUINT64_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
333 mxArray *X = mxCreateNumericMatrix(256, 1, mxINT8_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
334 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
335 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
336 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
337 char *x; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
338 x = (char*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
339 qsort(x,n,sz,strcpy); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
340 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
341 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
342 */ |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
343 case mxINT8_CLASS: { |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
344 mxArray *H = mxCreateNumericMatrix(256, SZ[1], mxDOUBLE_CLASS,mxREAL); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
345 mxArray *X = mxCreateNumericMatrix(256, 1, mxINT8_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
346 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
347 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
348 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
349 int8_t *x; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
350 x = (int8_t*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
351 for (k=0; k<=255; k++) |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
352 x[k]=k-128; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
353 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
354 x = (int8_t*)mxGetData(PInputs[0]); |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
355 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
356 for (k=0; k<SZ[0]*SZ[1]; k++) |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
357 h[x[k]+128+(k/SZ[0]<<8)] += (w!=NULL ? w[k%SZ[0]] : 1.0); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
358 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
359 done = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
360 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
361 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
362 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
363 case mxUINT8_CLASS: { |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
364 mxArray *H = mxCreateNumericMatrix(256, SZ[1], mxDOUBLE_CLASS,mxREAL); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
365 mxArray *X = mxCreateNumericMatrix(256, 1, mxUINT8_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
366 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
367 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
368 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
369 uint8_t *x = (uint8_t*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
370 for (k=0; k<255; k++) |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
371 x[k]=k; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
372 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
373 x = (uint8_t*)mxGetData(PInputs[0]); |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
374 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
375 for (k=0; k<SZ[0]*SZ[1]; k++) |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
376 h[x[k]+(k/SZ[0]<<8)] += (w!=NULL ? w[k%SZ[0]] : 1.0); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
377 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
378 done = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
379 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
380 } |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
381 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
382 case mxINT16_CLASS: { |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
383 mxArray *H = mxCreateNumericMatrix(0x10000, SZ[1], mxDOUBLE_CLASS,mxREAL); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
384 mxArray *X = mxCreateNumericMatrix(0x10000, 1, mxINT16_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
385 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
386 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
387 |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
388 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
389 int16_t *x = (int16_t*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
390 for (k=0; k<0x10000; k++) |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
391 x[k]=k-0x8000; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
392 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
393 x = (int16_t*)mxGetData(PInputs[0]); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
394 for (k=0; k<SZ[0]*SZ[1]; k++) |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
395 h[x[k]+0x8000+(k/SZ[0]<<16)] += (w!=NULL ? w[k%SZ[0]] : 1.0); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
396 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
397 done = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
398 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
399 } |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
400 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
401 case mxUINT16_CLASS: { |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
402 mxArray *H = mxCreateNumericMatrix(0x10000, SZ[1], mxDOUBLE_CLASS,mxREAL); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
403 mxArray *X = mxCreateNumericMatrix(0x10000, 1, mxINT16_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
404 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
405 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
406 |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
407 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
408 int16_t *x = (int16_t*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
409 for (k=0; k<0x10000; k++) |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
410 x[k]=k-0x8000; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
411 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
412 uint16_t *x16 = (uint16_t*)mxGetData(PInputs[0]); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
413 for (k=0; k<SZ[0]*SZ[1]; k++) |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
414 h[x16[k]+(k/SZ[0]<<16)] += (w!=NULL ? w[k%SZ[0]] : 1.0); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
415 done = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
416 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
417 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
418 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
419 default: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
420 /* FIXME */ |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
421 mexErrMsgTxt("multicolumns with int32 or larger not supported!"); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
422 |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
423 mxArray *H = mxCreateNumericMatrix(0x10000, SZ[1], mxDOUBLE_CLASS,mxREAL); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
424 mxArray *X = mxCreateNumericMatrix(0x10000, SZ[1], mxGetClassID(PInputs[0]),mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
425 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
426 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
427 |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
428 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
429 int16_t *x = (int16_t*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
430 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
431 for (size_t n=0; n<SZ[1]; n++) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
432 } |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
433 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
434 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
435 } // end switch |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
436 } |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
437 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
438 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
439 /******* output *******/ |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
440 if (done) POutput[0] = HIS; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
441 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
442 return; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
443 } |