nmpp
nmtlio.h
1
2// //
3// Header file of template of class mtr //
4// //
6#ifndef _TNMTLIO_H_INCLUDED_
7#define _TNMTLIO_H_INCLUDED_
8
9#include "nmtl.h"
10#include <iomanip>
11#ifndef NM6403
12#include <iostream>
13#endif
14#include <stdio.h>
15#include <crtdbg.h>
16
17
19//
20// Class of matrixes
21//
22
23//*****************************************************************************
58//*****************************************************************************
59
60
61
62
63#ifndef NM6403
64__INLINE__ ostream& operator<< (ostream& s, mtr<unsigned char>& mtr)
65{
66// char str[255];
67 s <<"{\n";
68 for(int y=0;y<mtr.m_height-1;y++)
69 {
70 s << "\t{ ";
71 for(int x=0;x<mtr.m_width-1;x++)
72 {
73 s<< int(mtr[y][x]) << ", ";
74 }
75 s<< int(mtr[y][mtr.m_width-1]) << " },\n";
76 }
77 //Last string
78 s << "\t{ ";
79 for(int x=0;x<mtr.m_width-1;x++)
80 {
81 s<< int(mtr[mtr.m_height-1][x]) << ", ";
82 }
83 s<<int( mtr[mtr.m_height-1][mtr.m_width-1]) << " }\n};\n";
84
85 return s;
86}
87
88__INLINE__ ostream& operator<< (ostream& s, mtr<int>& mtr)
89{
90// char str[255];
91 s <<"{\n";
92 for(int y=0;y<mtr.m_height-1;y++)
93 {
94 s << "\t{ ";
95 for(int x=0;x<mtr.m_width-1;x++)
96 {
97 //sprintf(str,"%d",mtr[y][x]);
98 //s<< dbl << ", ";
99 s<< mtr[y][x] << ", ";
100 }
101 //sprintf(dbl,"%20.20f",mtr[y][mtr.m_width-1]);
102 //s<< dbl << " },\n";
103 s<< mtr[y][mtr.m_width-1] << " },\n";
104 }
105 //Last string
106 s << "\t{ ";
107 for(int x=0;x<mtr.m_width-1;x++)
108 {
109 s<< mtr[mtr.m_height-1][x] << ", ";
110 }
111 s<< mtr[mtr.m_height-1][mtr.m_width-1] << " }\n};\n";
112
113 return s;
114}
115
116__INLINE__ ostream& operator<< (ostream& s, const __int64& y)
117{
118
119 int hi,lo;
120 hi=int(y>>32);
121 lo=int(y);
122 s<< "0x" << setw(8) << setiosflags(ios::hex|ios::uppercase|ios::internal) << setfill('0') << hi
123 << setw(8) << setiosflags(ios::hex|ios::uppercase|ios::internal) << setfill('0') << lo ;
124 return s;
125}
126
127
128__INLINE__ ostream& operator<< (ostream& s, mtr<__int64>& mtr)
129{
130// char str[255];
131 s <<"{\n";
132 for(int y=0;y<mtr.m_height-1;y++)
133 {
134 s << "\t{ ";
135 for(int x=0;x<mtr.m_width-1;x++)
136 {
137 //sprintf(str,"%d",mtr[y][x]);
138 //s<< dbl << ", ";
139 s<< mtr[y][x] << ", ";
140 }
141 //sprintf(dbl,"%20.20f",mtr[y][mtr.m_width-1]);
142 //s<< dbl << " },\n";
143 s<< mtr[y][mtr.m_width-1] << " },\n";
144 }
145 //Last string
146 s << "\t{ ";
147 for(int x=0;x<mtr.m_width-1;x++)
148 {
149 s<< mtr[mtr.m_height-1][x] << ", ";
150 }
151 s<< mtr[mtr.m_height-1][mtr.m_width-1] << " }\n};\n";
152
153 return s;
154}
155
156
157
158__INLINE__ ostream& operator<< (ostream& s, mtr<double>& mtr)
159{
160 char dbl[255];
161 s <<"{\n";
162 for(int y=0;y<mtr.m_height-1;y++)
163 {
164 s << "\t{ ";
165 for(int x=0;x<mtr.m_width-1;x++)
166 {
167 sprintf(dbl,"%20.20f",mtr[y][x]);
168 s<< dbl << ", ";
169 }
170 sprintf(dbl,"%20.20f",mtr[y][mtr.m_width-1]);
171 s<< dbl << " },\n";
172 }
173 //Last string
174 s << "\t{ ";
175 for(int x=0;x<mtr.m_width-1;x++)
176 {
177 sprintf(dbl,"%20.20f",mtr[mtr.m_height-1][x]);
178 s<< dbl << ", ";
179 }
180 sprintf(dbl,"%20.20f",mtr[mtr.m_height-1][mtr.m_width-1]);
181 s<< dbl << " }\n};\n";
182
183 return s;
184}
185
186/*
188template <class T> cmplx<T> sqrt(const cmplx<T>& x)
189{
190
191 cmplx<T> Result;
192 Result.re=sqrt(double_(x.re));
193 return Result;
194}
195
196template <class T> ostream& operator<< (ostream& s, const cmplx<T>& y)
197{
198 return s<< '[' << y.re << ','<< y.im <<']';
199}
200*/
201
202#ifdef WIN32
203__INLINE__ ostream& operator<< (ostream& s, const nmint<__int64>& y)
204{
205
206 int hi,lo;
207 hi=int(y.m_value>>32);
208 lo=int(y.m_value);
209 s<< "0x" << setw(8) << setiosflags(ios::hex|ios::uppercase|ios::internal) << setfill('0') << hi
210 << setw(8) << setiosflags(ios::hex|ios::uppercase|ios::internal) << setfill('0') << lo ;
211 return s;
212}
213
214__INLINE__ ostream& operator<< (ostream& s, const nmint<int>& y)
215{
216 unsigned int x=(__int32)y.m_value;
217 s<< "0x" << setw(8) << setiosflags(ios::hex|ios::uppercase|ios::internal) << setfill('0') << setiosflags(ios::uppercase) << x;
218 return s;
219}
220
221__INLINE__ ostream& operator<< (ostream& s, const nmint<short>& y)
222{
223 unsigned __int16 x=(__int16)y.m_value;
224 s<< "0x" << setw(4) << setiosflags(ios::hex|ios::uppercase|ios::internal) << setfill('0') << x ;
225 return s;
226}
227
228__INLINE__ ostream& operator<< (ostream& s, const nmint<char>& y)
229{
230 unsigned __int8 x=y.m_value;
231 s<< "0x" << setw(2) << setiosflags(ios::hex|ios::uppercase|ios::internal) << setfill('0') << x ;
232 return s;
233}
234#endif
235
236
237
238#endif
239
240#ifdef WIN32
241template <class T> __INLINE__ ostream& operator<< (ostream& s, nmmtr<T>& mtr)
242{
243 s <<"{\n";
244 for(int y=0;y<mtr.m_height-1;y++)
245 {
246 s << "\t{ ";
247 for(int x=0;x<mtr.m_width-1;x++)
248 {
249 s<< (mtr[y][x]) << ", ";
250 }
251 s << (mtr[y][mtr.m_width-1]) << " },\n";
252 }
253
254 s << "\t{ ";
255 for(int x=0;x<mtr.m_width-1;x++)
256 {
257 s<< (mtr[mtr.m_height-1][x]) << ", ";
258 }
259 s << (mtr[mtr.m_height-1][mtr.m_width-1]) << " }\n";
260 s << "};\n";
261 return s;
262}
263
264
265
266__INLINE__ ostream& AsmArray (ostream& s, nmmtr64s& mtr)
267{
268 s << " long[" << dec << mtr.m_width <<"*" << mtr.m_height << "]=(\n";
269 for(int y=0;y<mtr.m_height-1;y++)
270 {
271 for(int x=0;x<mtr.m_width;x++)
272 {
273
274 int hi,lo;
275 hi=int(mtr[y][x].m_value>>32);
276 lo=int(mtr[y][x].m_value);
277 s << "0"
278 << hex << setw(8) << setfill('0') << setiosflags(ios::uppercase) << hi << "_"
279 << hex << setw(8) << setfill('0') << setiosflags(ios::uppercase) << lo << "hl,";
280 }
281 s << "\n";
282 }
283
284 for(int x=0;x<mtr.m_width-1;x++)
285 {
286 int hi,lo;
287 hi=int(mtr[mtr.m_height-1][x].m_value>>32);
288 lo=int(mtr[mtr.m_height-1][x].m_value);
289 s << "0"
290 << hex << setw(8) << setfill('0') << setiosflags(ios::uppercase) << hi << "_"
291 << hex << setw(8) << setfill('0') << setiosflags(ios::uppercase) << lo << "hl,";
292 }
293
294 {
295 int hi,lo;
296 hi=int(mtr[mtr.m_height-1][mtr.m_width-1].m_value>>32);
297 lo=int(mtr[mtr.m_height-1][mtr.m_width-1].m_value);
298 s << "0"
299 << hex << setw(8) << setfill('0') << setiosflags(ios::uppercase) << hi << "_"
300 << hex << setw(8) << setfill('0') << setiosflags(ios::uppercase) << lo << "hl";
301 }
302 s << "\n);\n";
303
304 return s;
305}
306
307__INLINE__ ostream& AsmArray (ostream& s, nmmtr8s& mtr)
308{
309 _ASSERTE(mtr.m_width%8==0);
310 nmmtr64s mClone((__int64*)mtr.m_data,mtr.m_height,mtr.m_width/8,mtr.m_stride/8);
311 AsmArray(s,mClone);
312 return s;
313}
314
315 template<class T1, class T2> void DotMul(nmmtr<T1>& mSrcMtr1, nmmtr<T2>& mSrcMtr2, nmmtr<T2>& mDstMtr )
316 {
317 for(int y=0; y< mSrcMtr1.m_height; y++)
318 for(int x=0; x<mSrcMtr1.m_width; x++)
319 {
320 nmint<T2> res=mSrcMtr1[y][x]*mSrcMtr2[y][x];
321 mDstMtr[y][x]=res;
322 }
323 }
324
325 template<class T1, class T2> void GetSum(nmmtr<T1>& mSrcMtr1, nmint<T2>& nResSum)
326 {
327 nResSum=0;
328 for(int y=0; y< mSrcMtr1.m_height; y++)
329 for(int x=0; x<mSrcMtr1.m_width; x++)
330 nResSum+=nmint<T2> (mSrcMtr1[y][x].m_value);
331 }
332
333#endif
334#endif
Definition: tmatrix.h:88
Definition: tnmmtr.h:38
__INLINE__ ostream & operator<<(ostream &s, mtr< unsigned char > &mtr)
Definition: nmtlio.h:64