annotate extra/NaN/src/histo_mex.cpp @ 5894:d14e3342cb28 octave-forge

fix h.X(256) for uint8
author schloegl
date Thu, 06 Aug 2009 13:44:45 +0000
parents 1dbdb1ab56ba
children 264f3fd4b27f
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 //-------------------------------------------------------------------
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
2 #pragma hdrstop
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
3 //-------------------------------------------------------------------
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
4 // C-MEX implementation of SUMSKIPNAN - this function is part of the NaN-toolbox.
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
5 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
6 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
7 // This program is free software; you can redistribute it and/or modify
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
8 // it under the terms of the GNU General Public License as published by
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
9 // the Free Software Foundation; either version 3 of the License, or
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
10 // (at your option) any later version.
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
11 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
12 // This program is distributed in the hope that it will be useful,
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
15 // GNU General Public License for more details.
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
16 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
17 // You should have received a copy of the GNU General Public License
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
18 // along with this program; if not, see <http://www.gnu.org/licenses/>.
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
19 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
20 //
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
21 // histo_mex: computes histogram
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
22 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
23 // Input:
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
24 // - data matrix
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
25 // - flag for row-wise histogram
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
26 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
27 // Output:
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
28 // - histogram
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
29 // HIS.X
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
30 // HIS.H
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
31 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
32 // $Id$
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
33 // Copyright (C) 2009 Alois Schloegl <a.schloegl@ieee.org>
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
34 // This function is part of the NaN-toolbox
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
35 // http://hci.tugraz.at/~schloegl/matlab/NaN/
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
36 //
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
37 //-------------------------------------------------------------------
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
38
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
39 /* TODO:
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
40 speed: its slower than the m-functions histo2/3/4
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
41 |-> use a more efficient sorting function
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
42 resembling of histo3 for multicolumn data.
5894
d14e3342cb28 fix h.X(256) for uint8
schloegl
parents: 5761
diff changeset
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
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
53 #if (MX_API_VER<0x07020000)
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
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
185 char flag_rows = 0;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
186 char done = 0;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
187 mwSize j, k; // running indices
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
188 ssize_t l;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
189 const mxArray *W = NULL;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
190 double *w = NULL;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
191
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
192 // check for proper number of input and output arguments
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
193 if ((PInputCount <= 0) || (PInputCount > 3)) {
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
194 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
195 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
196 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
197
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
198 mexPrintf("see also: HISTO2, HISTO3, HISTO4\n\n");
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
199 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
200 }
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
201 if (POutputCount > 2)
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
202 mexErrMsgTxt("histo.MEX has 1 output arguments.");
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
203
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
204 // get 1st argument
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
205 if (mxIsComplex(PInputs[0]))
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
206 mexErrMsgTxt("complex argument not supported (yet). ");
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
207 // TODO: support complex argument!
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
208
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
209 if (PInputCount==1)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
210 ; // histo_mex(X)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
211 else if (mxIsChar(PInputs[1])) {
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
212 // histo_mex(X,'rows')
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
213 char *t = mxArrayToString(PInputs[1]);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
214 flag_rows = !strcmp(t,"rows");
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
215 mxFree(t);
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
216 // histo_mex(X,'rows',W)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
217 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
218 }
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
219 // histo_mex(X,W)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
220 else if (mxIsDouble(PInputs[1])) {
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
221 W = PInputs[1];
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
222 }
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
223 else
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
224 mexErrMsgTxt("Weight vector must be REAL/DOUBLE.");
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
225
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
226 if (W != NULL) {
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
227 if (mxGetM(PInputs[0])==mxGetM(W) )
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
228 w = (double*)mxGetData(W);
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
229 else
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
230 mexErrMsgTxt("number of rows in X and W do not match.");
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
231
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
232 for (k=0; (k<mxGetM(W)) && (w[k]>=0.0); k++);
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
233 if (k<mxGetM(W))
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
234 mexWarnMsgTxt("weight vector contains also non-negative numbers or NaN.");
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
235 }
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
236
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
237 // get size
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
238 mwSize ND = mxGetNumberOfDimensions(PInputs[0]);
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
239 // NN = mxGetNumberOfElements(PInputs[0]);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
240 SZ = mxGetDimensions(PInputs[0]);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
241
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
242 if (ND>2)
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
243 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
244
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
245 size_t n = SZ[0];
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
246 size_t sz = 1;
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
247 char flag = 0;
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
248
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
249 const char *fnames[] = {"datatype","X","H"};
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
250 mxArray *HIS = mxCreateStructMatrix(1, 1, 3, fnames);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
251 mxSetField(HIS,0,"datatype",mxCreateString("HISTOGRAM"));
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
252
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
253 if (flag_rows || (SZ[1]==1)) {
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
254
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
255 ///***** SORT each column: initialize sorting algorithm
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
256 int (*compar)(const void*, const void*);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
257 size_t n;
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
258 size_t *idx = NULL;
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
259 idx = (size_t*) mxMalloc(SZ[0]*sizeof(size_t));
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
260 for (size_t n=0; n<SZ[0]; n++) {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
261 idx[n]=n;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
262 }
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
263 Sort.Type = mxGetClassID(PInputs[0]);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
264 Sort.Table = (uint8_t*) mxGetData(PInputs[0]);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
265 switch (mxGetClassID(PInputs[0])) {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
266 case mxINT8_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
267 case mxUINT8_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
268 Sort.Size = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
269 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
270 case mxINT16_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
271 case mxUINT16_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
272 Sort.Size = 2;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
273 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
274 case mxINT32_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
275 case mxUINT32_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
276 case mxSINGLE_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
277 Sort.Size = 4;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
278 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
279 case mxINT64_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
280 case mxUINT64_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
281 case mxDOUBLE_CLASS:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
282 Sort.Size = 8;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
283 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
284 default:
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
285 mexErrMsgTxt("unsupported input type");
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
286 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
287 Sort.N = flag_rows ? SZ[1] : 1;
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
288 qsort(idx,SZ[0],sizeof(*idx),compare);
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
289
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
290 // count number of different elements
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
291 n = SZ[0] ? 1 : 0;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
292 for (size_t k=1; k<SZ[0]; k++) {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
293 if (compare(idx+k-1,idx+k)) n++;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
294 }
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
295
5730
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
296 uint64_t *tix = NULL;
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
297 if (POutputCount>1) {
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
298 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
299 tix = (uint64_t*)mxGetData(POutput[1]);
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
300 }
c45fb9ded279 fix NaN support in HISTO_MEX; support of tix output
schloegl
parents: 5729
diff changeset
301
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
302 // fill HIS.H and HIS.X
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
303 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
304 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
305 mxSetField(HIS,0,"H",H);
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
306 mxSetField(HIS,0,"X",X);
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
307 double *h = (double*)mxGetData(H);
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
308 uint8_t *x = (uint8_t*)mxGetData(X);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
309
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
310 l = -1;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
311 if (tix) tix[idx[0]] = 1;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
312 for (size_t k=0; k<SZ[0]; k++) {
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
313 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
314 l++;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
315 for (j=0; j<SZ[1]; j++) {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
316 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
317 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
318 }
5760
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
319 if (tix) tix[idx[k]] = l+1;
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
320 if (w != NULL)
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
321 h[l]+=w[idx[k]];
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
322 else
0b1b67486b3a support for data weigthening added
schloegl
parents: 5730
diff changeset
323 h[l]+=1.0;
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
324 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
325 mxFree(idx);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
326 done = 1;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
327 }
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
328
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
329 else {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
330 switch (mxGetClassID(PInputs[0])) {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
331 /*
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
332 case mxCHAR_CLASS: {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
333 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
334 mxArray *X = mxCreateNumericMatrix(256, 1, mxINT8_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
335 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
336 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
337
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
338 char *x;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
339 x = (char*)mxGetData(X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
340 qsort(x,n,sz,strcpy);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
341 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
342 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
343 */
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
344 case mxINT8_CLASS: {
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
345 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
346 mxArray *X = mxCreateNumericMatrix(256, 1, mxINT8_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
347 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
348 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
349
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
350 int8_t *x;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
351 x = (int8_t*)mxGetData(X);
5894
d14e3342cb28 fix h.X(256) for uint8
schloegl
parents: 5761
diff changeset
352 for (k=0; k<0x0100; k++)
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
353 x[k]=k-128;
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 x = (int8_t*)mxGetData(PInputs[0]);
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
356 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
357 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
358 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
359
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
360 done = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
361 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
362 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
363
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
364 case mxUINT8_CLASS: {
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
365 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
366 mxArray *X = mxCreateNumericMatrix(256, 1, mxUINT8_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
367 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
368 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
369
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
370 uint8_t *x = (uint8_t*)mxGetData(X);
5894
d14e3342cb28 fix h.X(256) for uint8
schloegl
parents: 5761
diff changeset
371 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
372
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
373 x = (uint8_t*)mxGetData(PInputs[0]);
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
374 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
375 for (k=0; k<SZ[0]*SZ[1]; k++)
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
376 h[x[k]+(k/SZ[0]<<8)] += (w!=NULL ? w[k%SZ[0]] : 1.0);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
377
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
378 done = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
379 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
380 }
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
381
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
382 case mxINT16_CLASS: {
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
383 mxArray *H = mxCreateNumericMatrix(0x10000, SZ[1], mxDOUBLE_CLASS,mxREAL);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
384 mxArray *X = mxCreateNumericMatrix(0x10000, 1, mxINT16_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
385 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
386 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
387
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
388 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
389 int16_t *x = (int16_t*)mxGetData(X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
390 for (k=0; k<0x10000; k++)
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
391 x[k]=k-0x8000;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
392
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
393 x = (int16_t*)mxGetData(PInputs[0]);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
394 for (k=0; k<SZ[0]*SZ[1]; k++)
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
395 h[x[k]+0x8000+(k/SZ[0]<<16)] += (w!=NULL ? w[k%SZ[0]] : 1.0);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
396
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
397 done = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
398 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
399 }
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
400
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
401 case mxUINT16_CLASS: {
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
402 mxArray *H = mxCreateNumericMatrix(0x10000, SZ[1], mxDOUBLE_CLASS,mxREAL);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
403 mxArray *X = mxCreateNumericMatrix(0x10000, 1, mxINT16_CLASS,mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
404 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
405 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
406
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
407 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
408 int16_t *x = (int16_t*)mxGetData(X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
409 for (k=0; k<0x10000; k++)
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
410 x[k]=k-0x8000;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
411
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
412 uint16_t *x16 = (uint16_t*)mxGetData(PInputs[0]);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
413 for (k=0; k<SZ[0]*SZ[1]; k++)
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
414 h[x16[k]+(k/SZ[0]<<16)] += (w!=NULL ? w[k%SZ[0]] : 1.0);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
415 done = 1;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
416 break;
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
417 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
418
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
419 default: {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
420 /* FIXME */
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
421 mexErrMsgTxt("multicolumns with int32 or larger not supported!");
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
422
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
423 mxArray *H = mxCreateNumericMatrix(0x10000, SZ[1], mxDOUBLE_CLASS,mxREAL);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
424 mxArray *X = mxCreateNumericMatrix(0x10000, SZ[1], mxGetClassID(PInputs[0]),mxREAL);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
425 mxSetField(HIS,0,"H",H);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
426 mxSetField(HIS,0,"X",X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
427
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
428 double *h = (double*)mxGetData(H);
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
429 int16_t *x = (int16_t*)mxGetData(X);
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
430
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
431 for (size_t n=0; n<SZ[1]; n++) {
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
432 }
5761
1dbdb1ab56ba support for data weigthening added - fix for (u)int8/16 data
schloegl
parents: 5760
diff changeset
433
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
434 }
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
435 } // end switch
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
436 }
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
437
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
438
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
439 /******* output *******/
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
440 if (done) POutput[0] = HIS;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
441
5729
49cec4fd294b flag_rows done, single vector, and (u)int8/16 done;
schloegl
parents: 5726
diff changeset
442 return;
5726
5beb367bca41 add histo_mex, currently only (u)int8/16 are supported
schloegl
parents:
diff changeset
443 }