File: smat.misc.h

package info (click to toggle)
r-cran-pcapp 1.9-73-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 800 kB
  • sloc: cpp: 5,961; ansic: 917; sh: 13; makefile: 2
file content (298 lines) | stat: -rw-r--r-- 5,948 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
    SMat - Simple Matrix Classes v0.1beta
    Copyright (C) 2011 by Heinrich Fritz (heinrich_fritz@hotmail.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SMAT_MISC_H
#define SMAT_MISC_H

#include "smat.base.h"
#include "smat.elop.h"

/////////////////////
//	Min Max Limit  //
/////////////////////

	template <class TA>
	void limit (const SVData<TA> &a, const TA &l, const TA &u)
	{
		THROW (l <= u) ;
		limit_nc (a, l, u) ;
	}

	template <class TA, class TB, class TC>
	void limit_NC (const SVData<TA> &a, const TB &l, const TC &u)
	{
		ASSERT (l <= u) ;
		EO<SOP::a_limit>::VScSc (a, l, u) ;
	}

	template <class TA, class TB>
	void limit_l (const SVData<TA> &a, const TB &l)
	{
		EO<SOP::a_limit_l>::VSc (a, l) ;
	}

	template <class TA, class TB>
	void limit_u (const SVData<TA> &a, const TB &u)
	{
		EO<SOP::a_limit_u>::VSc (a, u) ;
	}

	template <class TA>
	const TA &max (const SCData<TA> &a)
	{
		return EO<SOP::is_greater>::Vc_transitive (a) ;
	}

	template <class TA>
	const TA &min (const SCData<TA> &a)
	{
		return EO<SOP::is_less>::Vc_transitive (a) ;
	}

	template <class TA>
	void minmax (const SCData<TA> &a, TA &min, TA &max, BOOL bInit= TRUE)
	{
		if (!a.size ())
			return ;
		if (bInit)
		{
			const double *pA = a ;
			min = max = *pA ;
			EO<SOP::a_minmax>::SSVc_raw (min, max, pA + 1, a.GetDataEnd ()) ;
		}
		else
			EO<SOP::a_minmax>::SSVc (min, max, a) ;
	}

	template <class TA>
	t_size getMaxIdx (const SCData <TA> &a)
	{
		t_size idx = 0 ;
		EO<SOP::a_max_idx>::SVc (idx, a) ;
		return idx ;
	}

	template <class TA>
	TA min (const TA *pA, t_size n)
	{
		return min (pA, pA + n) ;
	}

	template <class TA>
	TA min (const TA *pA, TA const * const pEndA)
	{
		TA min = *pA ;

		for (++pA; pA < pEndA; ++pA)
			if (*pA < min)
				min = * pA ;
		return min ;
	}

	template <class TA>
	const TA *minP (const TA *pA, t_size n)
	{
		return minP (pA, pA + n) ;
	}

	template <class TA>
	const TA *minP (const TA *pA, TA const * const pEndA)
	{

		const TA *pMin = pA ;

		for (++pA; pA < pEndA; ++pA)
			if (*pA < *pMin)
				pMin = pA ;
		return pMin ;
	}


	template <class TA>
	const TA max (const TA *pA, t_size n)
	{
		return max (pA, pA + n) ;
	}

	template <class TA>
	const TA max (const TA *pA, TA const * const pEndA)
	{
		TA max = *pA ;

		for (++pA; pA < pEndA; ++pA)
			if (*pA > max)
				max = *pA ;
		return max ;
	}

	template <class TA>
	const TA *maxP (const TA *pA, t_size n)
	{
		return maxP (pA, pA + n) ;
	}

	template <class TA>
	const TA *maxP (const TA *pA, TA const * const pEndA)
	{

		const TA *pMax = pA ;

		for (++pA; pA < pEndA; ++pA)
			if (*pA > *pMax)
				pMax = pA ;
		return pMax ;
	}

////////////
//	Misc  //
////////////

	template <class TA>
	void set_neg (const SVData<TA> &a)
	{
//		EO<OPA::neg>::vd (a) ;
		EO<SOP::a_neg>::V (a) ;
	}

	template <class TA>
	void set_inv (const SVData<TA> &a)
	{
//		EO<OPA::inv>::vd (a) ;
		EO<SOP::a_inv>::V (a) ;
	}

	template <class TA, class TB>
	BOOL equal (const SCData <TA> &a, const SCData <TB> &b)
	{
		if (a.size () != b.size ())
			return FALSE ;

		TA const *pA = a ;
		TA const * const pEndA = a.GetDataEnd () ;
		TB const *pB = b ;

		while (pA < pEndA)
		{
			if (*pA != *pB)
				return FALSE ;
			++pA ;
			++pB ;
		}

		return TRUE ;
	}

	template <class TA, class TB>
	t_size CountMatches (const SCData <TA> &a, const TB &b)
	{
		t_size n = 0 ;
		EO<SOP::inc_a_if_b_equals_c>::SScVc (n, b, a) ;
		return n ;
	}

	template <class TA>
	t_size CountTrue (const SCData <TA> &a)
	{
		t_size n = 0 ;
		EO<SOP::inc_a_if_b>::SVc(n, a) ;
		return n ;
	}

//////////////////////////
//	Printing Functions  //
//////////////////////////

	void Print (const double &v) ;
	void Print (const float &v) ;
	void Print (const int &v) ;
	void Print (const t_size &v) ;

	template <class TA>
	void Print_NC (const t_size dwRe, const SCMat <TA> &a, const t_size dwCe)
	{
		Print_NC (0, dwRe, a, 0, dwCe) ;
	}

	template <class TA>
	void Print_NC (const SCMat <TA> &a, const t_size dwCs, const t_size dwCe)
	{
		Print_NC (0, a.nrow (), a, dwCs, dwCe) ;
	}

	template <class TA>
	void Print_NC (const t_size dwRs, const t_size dwRe, const SCMat <TA> &a)
	{
		Print_NC (dwRs, dwRe, a) ;
	}
	
	template <class TA>
	void Print_NC (const SCMat <TA> &a, const t_size dwCe)
	{
		Print_NC (0, a.nrow (), a, 0, dwCe) ;
	}

	template <class TA>
	void Print_NC (const t_size dwRe, const SCMat <TA> &a)
	{
		Print_NC (0, dwRe, a, 0, a.ncol ()) ;
	}

	template <class TA>
	void Print_NC (const SCMat <TA> &a)
	{
		Print_NC (0, a.nrow (), a, 0, a.ncol ()) ;
	}

	template <class TA>
	void Print_NC (const t_size dwRs, const t_size dwRe, const SCMat <TA> &a, const t_size dwCs, const t_size dwCe)
	{
		ASSERT (dwRs <= dwRe) ;
		ASSERT (dwCs <= dwCe) ;
		ASSERT (dwRe <= a.nrow ()) ;
		ASSERT (dwCe <= a.ncol ()) ;

		t_size r, c ;
		const TA *pA ;
		for (r = dwRs; r < dwRe; ++r)
		{
			pA = a.GetData (r, dwCs) ;
			for (c = dwCs; c < dwCe; ++c)
			{
				Print (*pA) ;
				meal_printf ("\t") ; 
				pA += a.GetColInc () ;
			}
			meal_printf ("\n") ; 
		}
		meal_printf ("\n") ; 
	}

	template <class TA>
	void Print_NC (const SCData <TA> &a)
	{
		const TA *pA = a, * const pEndA = a.GetDataEnd () ;

		while (pA < pEndA)
		{
				Print (*pA) ;
				meal_printf ("\t") ; 
				++pA ;
		}
		meal_printf ("\n") ;
	}
#endif	//	#ifndef SMAT_MISC_H