annotate extra/NaN/src/histo_mex.cpp @ 7889:c101c486d80a octave-forge

fix web address
author schloegl
date Thu, 27 Jan 2011 17:10:36 +0000
parents b9f35668b55e
children 6a419bec96bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
1 //-------------------------------------------------------------------
7889
c101c486d80a fix web address
schloegl
parents: 7888
diff changeset
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$
7889
c101c486d80a fix web address
schloegl
parents: 7888
diff changeset
31 // Copyright (C) 2009,2010,2011 Alois Schloegl <a.schloegl@ieee.org>
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
c101c486d80a fix web address
schloegl
parents: 7888
diff changeset
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
d14e3342cb28 fix h.X(256) for uint8
schloegl
parents: 5761
diff changeset
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
b9f35668b55e replace <inttypes.h> with <stdint.h>
schloegl
parents: 7211
diff changeset
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];
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
112 switch (isnan(f1) + 2*isnan(f2)) {
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
113 case 0:
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
114 if (f1<f2) z = -1;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
115 else if (f1>f2) z = 1;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
116 case 3:
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
117 break;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
118 case 1: z = 1; break;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
119 case 2: z = -1; break;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
120 }
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
121 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
122 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
123 case mxDOUBLE_CLASS: {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
124 double f1,f2;
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
125 f1 = ((double*)Sort.Table)[ix1];
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
126 f2 = ((double*)Sort.Table)[ix2];
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
127 switch (isnan(f1) + 2*isnan(f2)) {
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
128 case 0:
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
129 if (f1<f2) z = -1;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
130 else if (f1>f2) z = 1;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
131 case 3:
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
132 break;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
133 case 1: z = 1; break;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
134 case 2: z = -1; break;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
135 }
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
136 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
137 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
138 case mxINT16_CLASS: {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
139 int16_t f1,f2;
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
140 f1 = ((int16_t*)Sort.Table)[ix1];
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
141 f2 = ((int16_t*)Sort.Table)[ix2];
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
142 if (f1<f2) z = -1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
143 else if (f1>f2) z = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
144 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
145 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
146 case mxUINT16_CLASS: {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
147 uint16_t f1,f2;
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
148 f1 = ((uint16_t*)Sort.Table)[ix1];
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
149 f2 = ((uint16_t*)Sort.Table)[ix2];
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
150 if (f1<f2) z = -1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
151 else if (f1>f2) z = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
152 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
153 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
154 case mxINT8_CLASS: {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
155 int8_t f1,f2;
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
156 f1 = ((int8_t*)Sort.Table)[ix1];
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
157 f2 = ((int8_t*)Sort.Table)[ix2];
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
158 if (f1<f2) z = -1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
159 else if (f1>f2) z = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
160 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
161 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
162 case mxUINT8_CLASS: {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
163 uint8_t f1,f2;
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
164 f1 = ((uint8_t*)Sort.Table)[ix1];
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
165 f2 = ((uint8_t*)Sort.Table)[ix2];
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
166 if (f1<f2) z = -1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
167 else if (f1>f2) z = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
168 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
169 }
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 i++;
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
172 ix1 += Sort.Stride;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
173 ix2 += Sort.Stride;
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
174 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
175 return(z);
5726
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
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
179 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
180 {
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
181
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
182 const mwSize *SZ;
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
183 char flag_rows = 0;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
184 char done = 0;
7119
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
185 mwSize j, k, l; // running indices
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
186 const mxArray *W = NULL;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
187 double *w = NULL;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
188
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
189 // check for proper number of input and output arguments
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
190 if ((PInputCount <= 0) || (PInputCount > 3)) {
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
191 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
192 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
193 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
194
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
195 mexPrintf("see also: HISTO2, HISTO3, HISTO4\n\n");
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
196 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
197 }
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
198 if (POutputCount > 2)
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
199 mexErrMsgTxt("histo.MEX has 1 output arguments.");
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
200
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
201 // get 1st argument
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
202 if (mxIsComplex(PInputs[0]))
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
203 mexErrMsgTxt("complex argument not supported (yet). ");
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
204 // TODO: support complex argument!
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
205
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
206 if (PInputCount==1)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
207 ; // histo_mex(X)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
208 else if (mxIsChar(PInputs[1])) {
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
209 // histo_mex(X,'rows')
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
210 char *t = mxArrayToString(PInputs[1]);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
211 flag_rows = !strcmp(t,"rows");
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
212 mxFree(t);
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
213 // histo_mex(X,'rows',W)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
214 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
215 }
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
216 // histo_mex(X,W)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
217 else if (mxIsDouble(PInputs[1])) {
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
218 W = PInputs[1];
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
219 }
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
220 else
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
221 mexErrMsgTxt("Weight vector must be REAL/DOUBLE.");
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
222
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
223 if (W != NULL) {
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
224 if (mxGetM(PInputs[0])==mxGetM(W) )
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
225 w = (double*)mxGetData(W);
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
226 else
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
227 mexErrMsgTxt("number of rows in X and W do not match.");
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
228
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
229 for (k=0; (k<mxGetM(W)) && (w[k]>=0.0); k++);
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
230 if (k<mxGetM(W))
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
231 mexWarnMsgTxt("weight vector contains also non-negative numbers or NaN.");
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
232 }
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
233
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
234 // get size
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
235 mwSize ND = mxGetNumberOfDimensions(PInputs[0]);
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
236 // NN = mxGetNumberOfElements(PInputs[0]);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
237 SZ = mxGetDimensions(PInputs[0]);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
238
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
239 if (ND>2)
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
240 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
241
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
242 size_t n = SZ[0];
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
243 size_t sz = 1;
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
244 char flag = 0;
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
245
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
246 const char *fnames[] = {"datatype","X","H"};
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
247 mxArray *HIS = mxCreateStructMatrix(1, 1, 3, fnames);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
248 mxSetField(HIS,0,"datatype",mxCreateString("HISTOGRAM"));
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
249
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
250 if (flag_rows || (SZ[1]==1)) {
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
251
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
252 ///***** SORT each column: initialize sorting algorithm
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
253 size_t *idx = NULL;
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
254 idx = (size_t*) mxMalloc(SZ[0]*sizeof(size_t));
6551
schloegl
parents: 6121
diff changeset
255 for (n=0; n<SZ[0]; n++) {
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
256 idx[n]=n;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
257 }
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
258 Sort.Type = mxGetClassID(PInputs[0]);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
259 Sort.Table = (uint8_t*) mxGetData(PInputs[0]);
5900
264f3fd4b27f support of logical data added
schloegl
parents: 5894
diff changeset
260
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
261 switch (mxGetClassID(PInputs[0])) {
5900
264f3fd4b27f support of logical data added
schloegl
parents: 5894
diff changeset
262 case mxLOGICAL_CLASS:
264f3fd4b27f support of logical data added
schloegl
parents: 5894
diff changeset
263 Sort.Size = sizeof(mxLogical);
264f3fd4b27f support of logical data added
schloegl
parents: 5894
diff changeset
264 break;
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
265 case mxINT8_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
266 case mxUINT8_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
267 Sort.Size = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
268 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
269 case mxINT16_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
270 case mxUINT16_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
271 Sort.Size = 2;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
272 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
273 case mxINT32_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
274 case mxUINT32_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
275 case mxSINGLE_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
276 Sort.Size = 4;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
277 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
278 case mxINT64_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
279 case mxUINT64_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
280 case mxDOUBLE_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
281 Sort.Size = 8;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
282 break;
7119
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
283 case mxCHAR_CLASS:
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
284 Sort.Size = sizeof(mxChar);
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
285 break;
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
286 default:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
287 mexErrMsgTxt("unsupported input type");
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
288 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
289 Sort.N = flag_rows ? SZ[1] : 1;
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
290 qsort(idx,SZ[0],sizeof(*idx),compare);
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
291
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
292 // count number of different elements
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
293 n = SZ[0] ? 1 : 0;
6551
schloegl
parents: 6121
diff changeset
294 size_t k;
schloegl
parents: 6121
diff changeset
295 for (k=1; k<SZ[0]; k++) {
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
296 if (compare(idx+k-1,idx+k)) n++;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
297 }
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
298
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
299 uint64_t *tix = NULL;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
300 if (POutputCount>1) {
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
301 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
302 tix = (uint64_t*)mxGetData(POutput[1]);
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
303 }
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
304
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
305 // fill HIS.H and HIS.X
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
306 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
307 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
308 mxSetField(HIS,0,"H",H);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
309 mxSetField(HIS,0,"X",X);
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
310 double *h = (double*)mxGetData(H);
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
311 uint8_t *x = (uint8_t*)mxGetData(X);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
312
7119
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
313 l = 0;
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
314 if (tix) tix[idx[0]] = 1;
6551
schloegl
parents: 6121
diff changeset
315 for (k=0; k<SZ[0]; k++) {
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
316 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
317 for (j=0; j<SZ[1]; j++) {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
318 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
319 }
7119
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
320 l++;
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
321 }
7119
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
322 if (tix) tix[idx[k]] = l;
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
323 if (w != NULL)
7119
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
324 h[l-1]+=w[idx[k]];
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
325 else
7119
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
326 h[l-1]+=1.0;
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
327 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
328 mxFree(idx);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
329 done = 1;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
330 }
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
331
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
332 else {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
333 switch (mxGetClassID(PInputs[0])) {
7119
8b1ab99c0e1c avoid using ssize_t; support char data
schloegl
parents: 6551
diff changeset
334
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
335 case mxINT8_CLASS: {
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
336 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
337 mxArray *X = mxCreateNumericMatrix(256, 1, mxINT8_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
338 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
339 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
340
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
341 int8_t *x;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
342 x = (int8_t*)mxGetData(X);
5894
d14e3342cb28 fix h.X(256) for uint8
schloegl
parents: 5761
diff changeset
343 for (k=0; k<0x0100; k++)
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
344 x[k]=k-128;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
345
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
346 x = (int8_t*)mxGetData(PInputs[0]);
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
347 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
348 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
349 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
350
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
351 done = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
352 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
353 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
354
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
355 case mxUINT8_CLASS: {
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
356 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
357 mxArray *X = mxCreateNumericMatrix(256, 1, mxUINT8_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
358 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
359 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
360
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
361 uint8_t *x = (uint8_t*)mxGetData(X);
5894
d14e3342cb28 fix h.X(256) for uint8
schloegl
parents: 5761
diff changeset
362 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
363
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
364 x = (uint8_t*)mxGetData(PInputs[0]);
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
365 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
366 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
367 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
368
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
369 done = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
370 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
371 }
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
372
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
373 case mxINT16_CLASS: {
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
374 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
375 mxArray *X = mxCreateNumericMatrix(0x10000, 1, mxINT16_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
376 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
377 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
378
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 int16_t *x = (int16_t*)mxGetData(X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
381 for (k=0; k<0x10000; k++)
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
382 x[k]=k-0x8000;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
383
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
384 x = (int16_t*)mxGetData(PInputs[0]);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
385 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
386 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
387
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
388 done = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
389 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
390 }
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
391
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
392 case mxUINT16_CLASS: {
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
393 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
394 mxArray *X = mxCreateNumericMatrix(0x10000, 1, mxINT16_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
395 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
396 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
397
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
398 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
399 int16_t *x = (int16_t*)mxGetData(X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
400 for (k=0; k<0x10000; k++)
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
401 x[k]=k-0x8000;
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 uint16_t *x16 = (uint16_t*)mxGetData(PInputs[0]);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
404 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
405 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
406 done = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
407 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
408 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
409
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
410 default: {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
411 /* FIXME */
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
412 mexErrMsgTxt("multicolumns with int32 or larger not supported!");
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
413
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
414 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
415 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
416 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
417 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
418
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
419 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
420 int16_t *x = (int16_t*)mxGetData(X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
421
6551
schloegl
parents: 6121
diff changeset
422 for (n=0; n<SZ[1]; n++) {
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
423 }
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
424
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
425 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
426 } // end switch
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
427 }
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
428
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
429
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
430 /******* output *******/
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
431 if (done) POutput[0] = HIS;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
432
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
433 return;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
434 }