Mercurial > forge
annotate extra/NaN/src/histo_mex.cpp @ 7119:8b1ab99c0e1c octave-forge
avoid using ssize_t; support char data
author | schloegl |
---|---|
date | Fri, 14 May 2010 13:11:32 +0000 |
parents | 95ad0310becb |
children | d9da60ccdecb |
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$ |
7119 | 33 // Copyright (C) 2009,2010 Alois Schloegl <a.schloegl@ieee.org> |
5726
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. |
5894 | 43 support of complex data and char-strings |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
44 */ |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
45 |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
46 #include <inttypes.h> |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
47 #include <math.h> |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
48 #include <string.h> |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
49 #include "mex.h" |
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 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
52 #ifdef tmwtypes_h |
6121
ea89f0ae2495
fix version check for defining mwSize; set default ACC_LEVEL 0
schloegl
parents:
5900
diff
changeset
|
53 #if (MX_API_VER<=0x07020000) |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
54 typedef int mwSize; |
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 #endif |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
57 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
58 struct sort_t { |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
59 uint8_t *Table; // data table |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
60 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
|
61 size_t Stride; // for multicolumn data |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
62 size_t N; // number of rows |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
63 mxClassID Type; // data type |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
64 } Sort; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
65 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
66 //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
|
67 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
|
68 int z = 0; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
69 size_t i = 0; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
70 size_t ix1 = *(size_t*)a; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
71 size_t ix2 = *(size_t*)b; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
72 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
73 while ((i<Sort.N) && !z) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
74 switch (Sort.Type) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
75 case mxCHAR_CLASS: |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
76 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
|
77 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
78 case mxINT32_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
79 int32_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
80 f1 = ((int32_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
81 f2 = ((int32_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
82 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
83 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
84 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
85 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
86 case mxUINT32_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
87 uint32_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
88 f1 = ((uint32_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
89 f2 = ((uint32_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
90 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
91 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
92 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
93 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
94 case mxINT64_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
95 int64_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
96 f1 = ((int64_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
97 f2 = ((int64_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
98 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
99 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
100 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
101 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
102 case mxUINT64_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
103 uint64_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
104 f1 = ((uint64_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
105 f2 = ((uint64_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
106 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
107 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
108 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
109 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
110 case mxSINGLE_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
111 float f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
112 f1 = ((float*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
113 f2 = ((float*)Sort.Table)[ix2]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
114 switch (isnan(f1) + 2*isnan(f2)) { |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
115 case 0: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
116 if (f1<f2) z = -1; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
117 else if (f1>f2) z = 1; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
118 case 3: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
119 break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
120 case 1: z = 1; break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
121 case 2: z = -1; break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
122 } |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
123 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
124 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
125 case mxDOUBLE_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
126 double f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
127 f1 = ((double*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
128 f2 = ((double*)Sort.Table)[ix2]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
129 switch (isnan(f1) + 2*isnan(f2)) { |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
130 case 0: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
131 if (f1<f2) z = -1; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
132 else if (f1>f2) z = 1; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
133 case 3: |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
134 break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
135 case 1: z = 1; break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
136 case 2: z = -1; break; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
137 } |
5729
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 mxINT16_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
141 int16_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
142 f1 = ((int16_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
143 f2 = ((int16_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 mxUINT16_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
149 uint16_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
150 f1 = ((uint16_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
151 f2 = ((uint16_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 mxINT8_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
157 int8_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
158 f1 = ((int8_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
159 f2 = ((int8_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 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
164 case mxUINT8_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
165 uint8_t f1,f2; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
166 f1 = ((uint8_t*)Sort.Table)[ix1]; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
167 f2 = ((uint8_t*)Sort.Table)[ix2]; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
168 if (f1<f2) z = -1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
169 else if (f1>f2) z = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
170 break; |
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 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
173 i++; |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
174 ix1 += Sort.Stride; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
175 ix2 += Sort.Stride; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
176 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
177 return(z); |
5726
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 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
181 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
|
182 { |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
183 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
184 const mwSize *SZ; |
5760 | 185 char flag_rows = 0; |
186 char done = 0; | |
7119 | 187 mwSize j, k, l; // running indices |
5760 | 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*); |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
256 size_t *idx = NULL; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
257 idx = (size_t*) mxMalloc(SZ[0]*sizeof(size_t)); |
6551 | 258 for (n=0; n<SZ[0]; n++) { |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
259 idx[n]=n; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
260 } |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
261 Sort.Type = mxGetClassID(PInputs[0]); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
262 Sort.Table = (uint8_t*) mxGetData(PInputs[0]); |
5900 | 263 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
264 switch (mxGetClassID(PInputs[0])) { |
5900 | 265 case mxLOGICAL_CLASS: |
266 Sort.Size = sizeof(mxLogical); | |
267 break; | |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
268 case mxINT8_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
269 case mxUINT8_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
270 Sort.Size = 1; |
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 mxINT16_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
273 case mxUINT16_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
274 Sort.Size = 2; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
275 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
276 case mxINT32_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
277 case mxUINT32_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
278 case mxSINGLE_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
279 Sort.Size = 4; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
280 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
281 case mxINT64_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
282 case mxUINT64_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
283 case mxDOUBLE_CLASS: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
284 Sort.Size = 8; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
285 break; |
7119 | 286 case mxCHAR_CLASS: |
287 Sort.Size = sizeof(mxChar); | |
288 break; | |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
289 default: |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
290 mexErrMsgTxt("unsupported input type"); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
291 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
292 Sort.N = flag_rows ? SZ[1] : 1; |
5760 | 293 qsort(idx,SZ[0],sizeof(*idx),compare); |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
294 |
5760 | 295 // count number of different elements |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
296 n = SZ[0] ? 1 : 0; |
6551 | 297 size_t k; |
298 for (k=1; k<SZ[0]; k++) { | |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
299 if (compare(idx+k-1,idx+k)) n++; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
300 } |
5760 | 301 |
5730
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
302 uint64_t *tix = NULL; |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
303 if (POutputCount>1) { |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
304 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
|
305 tix = (uint64_t*)mxGetData(POutput[1]); |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
306 } |
c45fb9ded279
fix NaN support in HISTO_MEX; support of tix output
schloegl
parents:
5729
diff
changeset
|
307 |
5760 | 308 // fill HIS.H and HIS.X |
309 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
|
310 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
|
311 mxSetField(HIS,0,"H",H); |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
312 mxSetField(HIS,0,"X",X); |
5760 | 313 double *h = (double*)mxGetData(H); |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
314 uint8_t *x = (uint8_t*)mxGetData(X); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
315 |
7119 | 316 l = 0; |
5760 | 317 if (tix) tix[idx[0]] = 1; |
6551 | 318 for (k=0; k<SZ[0]; k++) { |
5760 | 319 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
|
320 for (j=0; j<SZ[1]; j++) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
321 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
|
322 } |
7119 | 323 l++; |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
324 } |
7119 | 325 if (tix) tix[idx[k]] = l; |
5760 | 326 if (w != NULL) |
7119 | 327 h[l-1]+=w[idx[k]]; |
5760 | 328 else |
7119 | 329 h[l-1]+=1.0; |
5729
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 mxFree(idx); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
332 done = 1; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
333 } |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
334 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
335 else { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
336 switch (mxGetClassID(PInputs[0])) { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
337 case mxCHAR_CLASS: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
338 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
|
339 mxArray *X = mxCreateNumericMatrix(256, 1, mxINT8_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
340 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
341 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
342 |
7119 | 343 mxChar *x; |
344 x = (mxChar*)mxGetData(X); | |
345 qsort(x,n,sizeof(mxChar),strcpy); | |
5729
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 } |
7119 | 348 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
349 case mxINT8_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, mxINT8_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 int8_t *x; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
356 x = (int8_t*)mxGetData(X); |
5894 | 357 for (k=0; k<0x0100; k++) |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
358 x[k]=k-128; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
359 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
360 x = (int8_t*)mxGetData(PInputs[0]); |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
361 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
362 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
|
363 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
|
364 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
365 done = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
366 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
367 } |
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 case mxUINT8_CLASS: { |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
370 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
|
371 mxArray *X = mxCreateNumericMatrix(256, 1, mxUINT8_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
372 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
373 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
374 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
375 uint8_t *x = (uint8_t*)mxGetData(X); |
5894 | 376 for (k=0; k<0x0100; k++) x[k]=k; |
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 = (uint8_t*)mxGetData(PInputs[0]); |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
379 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
380 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
|
381 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
|
382 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
383 done = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
384 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
385 } |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
386 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
387 case mxINT16_CLASS: { |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
388 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
|
389 mxArray *X = mxCreateNumericMatrix(0x10000, 1, mxINT16_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
390 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
391 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
392 |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
393 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
394 int16_t *x = (int16_t*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
395 for (k=0; k<0x10000; k++) |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
396 x[k]=k-0x8000; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
397 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
398 x = (int16_t*)mxGetData(PInputs[0]); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
399 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
|
400 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
|
401 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
402 done = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
403 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
404 } |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
405 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
406 case mxUINT16_CLASS: { |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
407 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
|
408 mxArray *X = mxCreateNumericMatrix(0x10000, 1, mxINT16_CLASS,mxREAL); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
409 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
410 mxSetField(HIS,0,"X",X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
411 |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
412 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
413 int16_t *x = (int16_t*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
414 for (k=0; k<0x10000; k++) |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
415 x[k]=k-0x8000; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
416 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
417 uint16_t *x16 = (uint16_t*)mxGetData(PInputs[0]); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
418 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
|
419 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
|
420 done = 1; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
421 break; |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
422 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
423 |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
424 default: { |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
425 /* FIXME */ |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
426 mexErrMsgTxt("multicolumns with int32 or larger not supported!"); |
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 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
|
429 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
|
430 mxSetField(HIS,0,"H",H); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
431 mxSetField(HIS,0,"X",X); |
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 double *h = (double*)mxGetData(H); |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
434 int16_t *x = (int16_t*)mxGetData(X); |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
435 |
6551 | 436 for (n=0; n<SZ[1]; n++) { |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
437 } |
5761
1dbdb1ab56ba
support for data weigthening added - fix for (u)int8/16 data
schloegl
parents:
5760
diff
changeset
|
438 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
439 } |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
440 } // end switch |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
441 } |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
442 |
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
443 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
444 /******* output *******/ |
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
445 if (done) POutput[0] = HIS; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
446 |
5729
49cec4fd294b
flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents:
5726
diff
changeset
|
447 return; |
5726
5beb367bca41
add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff
changeset
|
448 } |