6#ifndef _Tnmmtrpack_H_INCLUDED_
7#define _Tnmmtrpack_H_INCLUDED_
43 int m_height,m_width,m_size,m_stride,m_border;
46 nmmtrpack(
int Height,
int Width,
int Border=0):m_height(Height), m_width(Width),m_flag_new(
true)
51 nmppsMalloc_64s(&m_container,(m_height+2*m_border)*m_width);
52 m_data=nmppsAddr_(m_container,m_border*m_width);
53 m_size=m_width*m_height;
55 _ASSERTE(m_data!=NULL);
69 _ASSERTE(y>=-m_border);
70 _ASSERTE(y<m_height+m_border);
71 return nmvecpack<T>(nmppsAddr_(m_data,y*m_stride),m_width);
77 m_height=
mtr.m_height;
79 m_border=
mtr.m_border;
83 nmppsMalloc_64s(&m_container,(m_height+2*m_border)*m_width);
84 m_data=nmppsAddr_(m_container,m_border*m_width);
88 for(
int y=0; y<m_height; y++)
94 nmmtrpack(T* Data,
int Height,
int Width,
int Stride=0):m_height(Height), m_width(Width), m_data(Data),m_flag_new(
false),m_stride(Stride),m_border(0)
98 m_size =m_height*m_width;
102 nmmtrpack(
const T* Data,
int Height,
int Width,
int Stride=0):m_height(Height), m_width(Width), m_data((T*)Data),m_flag_new(
false),m_stride(Stride),m_border(0)
106 m_size =m_height*m_width;
114 nmppsFree(m_container);
119 _ASSERTE(
mtr.m_height==m_height);
120 _ASSERTE(
mtr.m_width ==m_width);
121 for(
int y=0; y<m_height; y++)
129 for(
int y=0; y< m_height; y++,pData+=m_stride)
130 for(
int x=0; x<m_width; x++)
131 pData[x]*=val.m_value;
135 template <
class T2>
nmmtrpack<T2> operator* (
const nmint<T2>& val)
138 T* pResData=mRes.m_data;
140 for(
int y=0; y< m_height; y++,pResData+=m_stride,pData+=m_stride)
141 for(
int x=0; x<m_width; x++)
142 pResData[x]=pData[x]*val.m_value;
146 template <
class T2> nmvec<T2> operator* (
const nmvec<T2>&
vec)
148 _ASSERTE(m_width==
vec.m_size);
149 nmvec<T2> vRes(m_height);
151 for(
int y=0;y<m_height;y++,pData+=m_stride)
154 for(
int x=0; x<m_width; x++)
155 nSum+=pData[x]*
vec.m_data[x];
163 _ASSERTE(m_width==
mtr.m_height);
165 for(
int y=0; y<mRes.m_height; y++)
166 for(
int x=0; x<mRes.m_width; x++)
169 for(
int i=0;i<m_width;i++)
170 sum+=m_data[m_stride*y+i]*
mtr.m_data[
mtr.m_stride*i+x];
171 mRes.m_data[y*mRes.m_stride+x]=sum;
176 nmvec<T>& operator+= (
const nmint<T> &val)
179 for(
int y=0; y< m_height; y++,pData+=m_stride)
180 for(
int x=0; x<m_width; x++)
181 pData[x]+=val.m_value;
187 _ASSERTE (
mtr.m_size==m_size);
189 T* pParData =
mtr.m_data;
191 for(
int y=0; y< m_height; y++,pParData+=
mtr.m_stride,pData+=m_stride)
192 for(
int x=0; x<m_width; x++)
193 pData[x]+=pParData[x];
200 _ASSERTE (
mtr.m_size==m_size);
208 _ASSERTE (
mtr.m_size==m_size);
209 T* pParData =
mtr.m_data;
211 for(
int y=0; y< m_height; y++,pParData+=
mtr.m_stride,pData+=m_stride)
212 for(
int x=0; x<m_width; x++)
213 pData[x]-=pParData[x];
219 _ASSERTE (
mtr.m_size==m_size);
220 nmmtrpack <T> res(*
this);
228 T* pResData =mRes.m_data;
230 for(
int y=0; y< m_height; y++, pResData+=mRes.m_stride, pData+=m_stride)
231 for(
int x=0; x<m_width; x++)
232 pResData[x]=-pData[x];
240 for(
int y=0; y<m_height; y++, pData+=m_stride)
241 for(
int x=0; x<m_width; x++)
260 for(
int y=0; y<m_height; y++, pData+=m_stride)
261 for(
int x=0; x<m_width; x++)
280 for(
int y=0; y<m_height; y++, pData+=m_stride)
281 for(
int x=0; x<m_width; x++)
296 _ASSERTE (
mtr.m_size==m_size);
297 T* pParData =
mtr.m_data;
299 for(
int y=0; y< m_height; y++,pParData+=
mtr.m_stride,pData+=m_stride)
300 for(
int x=0; x<m_width; x++)
301 pData[x]|=pParData[x];
307 _ASSERTE (
mtr.m_size==m_size);
308 nmmtrpack <T> res(*
this);
315 _ASSERTE (
mtr.m_size==m_size);
316 T* pParData =
mtr.m_data;
318 for(
int y=0; y< m_height; y++,pParData+=
mtr.m_stride,pData+=m_stride)
319 for(
int x=0; x<m_width; x++)
320 pData[x]&=pParData[x];
326 _ASSERTE (
mtr.m_size==m_size);
335 for(
int y=0; y< m_height; y++,pData+=m_stride)
336 for(
int x=0; x<m_width; x++)
337 pData[x]^=val.m_value;
351 T* pResData =res.m_data;
353 for(
int y=0; y< m_height; y++,pResData+=res.m_stride,pData+=m_stride)
354 for(
int x=0; x<m_width; x++)
355 pResData[x]=~pData[x];
372 __INLINE__ nmvec<T>
GetVec(
int y)
375 _ASSERTE(y<m_height);
376 return nmvec<T>(m_data+y*m_stride,m_width);
379 __INLINE__ nmvec<T>
GetVec(
int y,
int x,
int len)
382 _ASSERTE(y<m_height);
383 return nmvec<T>(m_data+y*m_stride+x,len);
388 T* dst=m_data+y*m_width+x;
390 for(
int i=0;i<mSrc.m_height;i++)
392 memcpy(dst,src,mSrc.m_stride*
sizeof(T));
401 T* src=m_data+y*m_stride+x;
403 for(
int i=0;i<mRes.m_height;i++)
405 memcpy(dst,src,mRes.m_stride*
sizeof(T));
412 __INLINE__
nmmtrpack<T> GetMtr(
int y,
int x,
int height,
int width)
419 __INLINE__ T* Addr(
int y,
int x)
421 return m_data+y*m_stride+x;
476 T* pSrcData=mSrcMtr.m_data;
478 for(
int y=0; y< m_height; y++, pDstData+=m_stride, pSrcData+=mSrcMtr.m_stride)
479 for(
int x=0; x<m_width; x++)
480 *pDstData[x]=pSrcData[x];
484 void InitConst(nmint<T> &nVal)
487 for(
int y=0; y< m_height; y++, pData+=m_stride)
488 for(
int x=0; x<m_width; x++)
489 pData[x]=nVal.m_value;;
495 for(
int y=0;y<m_height;y++)
496 for(
int x=0;x<m_width;x++)
497 Z[x][y]=(*
this)[y][x];
512 if (m_width==m_stride)
515 memset(m_container,0,m_stride*(m_height+m_border*2)*
sizeof(T));
517 memset(m_data,0,m_stride*m_height*
sizeof(T));
522 for(
int y=0;y<m_width;y++,p+=m_stride)
523 memset(p,0,m_width*
sizeof(T));
Definition: tnmmtrpack.h:38
Definition: tnmvecpack.h:138
#define GetVec
Definition: tmatrix.h:60