29 #ifndef __VECTORIMPL_HPP
30 #define __VECTORIMPL_HPP
53 memcpy( m_pV, V.
m_pV, m_N*
sizeof(T) );
66 if(m_N){
delete[] m_pV;}
69 if(N){m_pV =
new T[N];}
72 memset( m_pV, 0, N*
sizeof(T) );
79 memcpy( m_pV, pV, N*
sizeof(T) );
87 memcpy( m_pV, V.
m_pV, m_N*
sizeof(T) );
119 for (std::size_t i=0; i<m_N; i++)
126 for (std::size_t i=0; i<m_N; i++)
134 for (std::size_t i=0; i<m_N; i++)
141 for (std::size_t i=0; i<m_N; i++)
149 for (std::size_t i=0; i<m_N; i++)
157 for (std::size_t i=0; i<m_N; i++)
158 m_pV[i] += V.
m_pV[i]*scale;
165 for (std::size_t i=0; i<m_N; i++)
166 m_pV[i] -= V.
m_pV[i]*scale;
172 for (std::size_t i=0; i<V1.
m_N; i++)
177 for (std::size_t i=0; i<V1.
m_N; i++)
183 for (std::size_t i=0; i<m_N; i++)
184 m_pV[i] += V.
m_pV[i];
192 for (std::size_t i=0; i<m_N; i++)
202 for (std::size_t i=0; i<m_N; i++)
203 V.
m_pV[i] = -m_pV[i];
210 for (std::size_t i=0; i<m_N; i++)
211 m_pV[i] -= V.
m_pV[i];
219 for (std::size_t i = 0; i<m_N; i++)
220 N += pow(m_pV[i], (T)Ln);
221 return pow(N, (T)1.0/Ln);
227 for (std::size_t i = 0; i<m_N; i++)
234 for (std::size_t i = 0; i<m_N; i++)
235 N += m_pV[i]*m_pV[i];
242 for (std::size_t i=0; i<m_N; i++)
243 V0 += m_pV[i]*V.
m_pV[i];
251 FILE* fp = fopen( fileName ,
"rb" );
252 if( !fp )
return false;
253 bool ret =
read( fp );
260 FILE* fp = fopen( fileName ,
"wb" );
261 if( !fp )
return false;
262 bool ret =
write( fp );
270 if( fread( &d ,
sizeof(
int) , 1 , fp )!=1 )
return false;
272 if( fread( &(*
this)[0] ,
sizeof( T ) , d , fp )!=d )
return false;
278 if( fwrite( &m_N ,
sizeof(
int ) , 1 , fp )!=1 )
return false;
279 if( fwrite( &(*
this)[0] ,
sizeof( T ) , m_N , fp )!=m_N )
return false;
287 template<
class T,
int Dim>
293 template<
class T,
int Dim>
299 memcpy( m_pV, V.
m_pV, m_N*
sizeof(T)*Dim );
301 template<
class T,
int Dim>
308 template<
class T,
int Dim>
312 if(m_N){
delete[] m_pV;}
315 if(N){m_pV =
new T[Dim*N];}
317 memset( m_pV, 0, N*
sizeof(T)*Dim );
319 template<
class T,
int Dim>
323 memcpy( m_pV, pV, N*
sizeof(T)*Dim );
325 template<
class T,
int Dim>
327 template<
class T,
int Dim>
331 memcpy( m_pV, V.
m_pV, m_N*
sizeof(T)*Dim );
334 template<
class T,
int Dim>
336 template<
class T,
int Dim>
338 template<
class T,
int Dim>
344 template<
class T,
int Dim>
349 template<
class T,
int Dim>
354 template<
class T,
int Dim>
359 template<
class T,
int Dim>
363 for (std::size_t i=0; i<m_N*Dim; i++)
367 template<
class T,
int Dim>
370 for (std::size_t i=0; i<m_N*Dim; i++)
374 template<
class T,
int Dim>
378 for (std::size_t i=0; i<m_N*Dim; i++)
382 template<
class T,
int Dim>
385 for (std::size_t i=0; i<m_N*Dim; i++)
389 template<
class T,
int Dim>
393 for (std::size_t i=0; i<m_N*Dim; i++)
398 template<
class T,
int Dim>
401 for (std::size_t i=0; i<m_N*Dim; i++)
402 m_pV[i] += V.
m_pV[i]*scale;
406 template<
class T,
int Dim>
409 for (std::size_t i=0; i<m_N*Dim; i++)
410 m_pV[i] -= V.
m_pV[i]*scale;
414 template<
class T,
int Dim>
416 for (std::size_t i=0; i<V1.
m_N*Dim; i++)
419 template<
class T,
int Dim>
421 for (std::size_t i=0; i<V1.
m_N*Dim; i++)
424 template<
class T,
int Dim>
427 for (std::size_t i=0; i<m_N*Dim; i++)
428 m_pV[i] += V.
m_pV[i];
432 template<
class T,
int Dim>
436 for (std::size_t i=0; i<m_N*Dim; i++)
441 template<
class T,
int Dim>
446 for (std::size_t i=0; i<m_N*Dim; i++)
447 V.
m_pV[i] = -m_pV[i];
451 template<
class T,
int Dim>
454 for (std::size_t i=0; i<m_N*Dim; i++)
455 m_pV[i] -= V.
m_pV[i];
459 template<
class T,
int Dim>
463 for (std::size_t i = 0; i<m_N*Dim; i++)
464 N += pow(m_pV[i], (T)Ln);
465 return pow(N, (T)1.0/Ln);
467 template<
class T,
int Dim>
471 for (std::size_t i = 0; i<m_N*3; i++)
474 template<
class T,
int Dim>
478 for (std::size_t i = 0; i<m_N*Dim; i++)
479 N += m_pV[i]*m_pV[i];
482 template<
class T,
int Dim>
486 for (std::size_t i=0; i<m_N*Dim; i++)
487 V0 += m_pV[i]*V.
m_pV[i];