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