7 #ifndef __solve_DenseVector_h__ 8 #define __solve_DenseVector_h__ 31 T &operator[](U32 index);
32 T operator[](U32 index)
const;
34 U32 size(
void)
const {
return m_size; }
39 void initialize(U32 size);
59 m_pData=
new T[m_size];
97 for(U32 i=0; i<m_size; i++)
108 memset(m_pData,0,m_size*
sizeof(F32));
117 memset(m_pData,0,m_size*
sizeof(F64));
125 if(index >= m_size) { feX(e_invalidRange); }
127 return m_pData[index];
134 if(index >= m_size) { feX(e_invalidRange); }
136 return m_pData[index];
142 if(m_size!=other.m_size)
147 m_pData=
new T[m_size];
156 for(U32 i = 0; i < m_size; i++)
158 m_pData[i] = other[i];
161 memcpy(m_pData,other.m_pData,m_size*
sizeof(T));
185 const U32 size=lhs.size();
186 for(U32 i = 0; i < size; i++)
209 template<
class T,
class U>
213 const U32 size=lhs.size();
215 if(size != rhs.size()) { feX(e_invalidRange); }
218 for(U32 i = 0; i < size; i++)
220 lhs[i] += rhs[i] * scalar;
231 template<
class T,
class U>
235 const U32 size=lhs.size();
237 if(size != rhs.size()) { feX(e_invalidRange); }
240 for(U32 i = 0; i < size; i++)
242 lhs[i] = lhs[i] * scalar + rhs[i];
254 const U32 size=lhs.size();
256 if(size != rhs.size()) { feX(e_invalidRange); }
259 for(U32 i = 0; i < size; i++)
273 const U32 size=lhs.size();
275 if(size != rhs.size()) { feX(e_invalidRange); }
278 for(U32 i = 0; i < size; i++)
291 const U32 size=rhs.size();
294 for(U32 i = 0; i < size; i++)
308 const U32 size=lhs.size();
310 if(size != rhs.size()) { feX(e_invalidRange); }
313 for(U32 i = 0; i < size; i++)
315 lhs[i] = lhs[i] * rhs[i];
323 template<
class T,
class U>
326 const U32 size=lhs.size();
328 for(U32 i = 0; i < size; i++)
341 const U32 size=lhs.size();
343 if(size != rhs.size()) { feX(e_invalidRange); }
347 for(U32 i = 0; i < size; i++)
349 t += lhs[i] * rhs[i];
361 const U32 size=rhs.size();
364 for(U32 i = 0; i < size; i++)
366 mag += (T)rhs[i] * (T)rhs[i];
377 const U32 size=rhs.size();
380 for(U32 i = 0; i < size; i++)
382 mag += (T)rhs[i] * (T)rhs[i];
393 const U32 size=rhs.size();
399 "attempt to normalize zero magnitude vector");
401 const T inv = 1.0/mag;
403 for(U32 i = 0; i < size; i++)
416 const U32 size=lhs.size();
421 feX(
"DenseVector<T>::normal",
422 "attempt to normalize zero magnitude vector");
424 const T inv = 1.0/mag;
425 for(U32 i = 0; i < size; i++)
439 const U32 size=lhs.size();
441 if(size != rhs.size()) { feX(e_invalidRange); }
445 for(U32 i = 0; i < size; i++)
447 v[i] = lhs[i] + rhs[i];
459 const U32 size=lhs.size();
461 if(size != rhs.size()) { feX(e_invalidRange); }
465 for(U32 i = 0; i < size; i++)
467 v[i] = lhs[i] - rhs[i];
478 const U32 size=lhs.size();
480 if(size != rhs.size()) { feX(e_invalidRange); }
483 for(U32 i = 0; i < size; i++)
500 const U32 size=lhs.size();
502 if(size != rhs.size()) { feX(e_invalidRange); }
505 for(U32 i = 0; i < size; i++)
507 if(FE_INVALID_SCALAR(lhs[i]) ||
508 FE_INVALID_SCALAR(rhs[i]) ||
509 fabs(rhs[i] - lhs[i]) > margin)
524 const U32 size=lhs.size();
526 if(size != rhs.size()) { feX(e_invalidRange); }
530 for(U32 i = 0; i < size; i++)
532 v[i] = lhs[i] * rhs[i];
540 template<
class T,
class U>
543 const U32 size=rhs.size();
546 for(U32 i = 0; i < size; i++)
556 template<
class T,
class U>
559 const U32 size=lhs.size();
561 if(size != rhs.size()) { feX(e_invalidRange); }
565 for(U32 i = 0; i < size; i++)
575 template<
class T,
class U>
579 feX(e_unsolvable,
"operator/(DenseVector<T>,T)",
"divide by zero");
580 return lhs*(1.0f/rhs);
600 const U32 size=lhs.size();
602 if(size != rhs.size()) { feX(e_invalidRange); }
605 for(U32 i = 0; i < size; i++)
607 result[i] = lhs[i] * rhs[i];
623 const U32 size=rhs.size();
626 for(U32 i = 0; i < size; i++)
632 s.
catf(
"%.6G", rhs[i]);
T magnitudeSquared(const DenseVector< T > &rhs)
Square of the length.
Definition: DenseVector.h:375
DenseVector< T > & setAt(DenseVector< T > &lhs, U32 index, const T value)
Set the value at the index.
Definition: DenseVector.h:197
DenseVector< T > & scaleAndAdd(DenseVector< T > &lhs, U scalar, const DenseVector< T > &rhs)
Scale then add.
Definition: DenseVector.h:232
DenseVector< T > operator*(const DenseVector< T > &lhs, const DenseVector< T > &rhs)
Piecewise multiply operation.
Definition: DenseVector.h:521
DenseVector< T > operator*(const U lhs, const DenseVector< T > &rhs)
Scale operation.
Definition: DenseVector.h:541
DenseVector< T > & operator+=(DenseVector< T > &lhs, const DenseVector< T > &rhs)
In place add operator.
Definition: DenseVector.h:251
Dense vector - size fixed at construction or reset.
Definition: DenseVector.h:21
DenseVector< T > operator/(const DenseVector< T > &lhs, const U rhs)
Inverse Scale operation.
Definition: DenseVector.h:576
DenseVector< T > operator-(const DenseVector< T > &rhs)
Negate operation.
Definition: DenseVector.h:289
DenseVector< T > & operator-=(DenseVector< T > &lhs, const DenseVector< T > &rhs)
In place subtract operator.
Definition: DenseVector.h:270
bool operator==(const DenseVector< T > &lhs, const DenseVector< T > &rhs)
equality test
Definition: DenseVector.h:476
kernel
Definition: namespace.dox:3
DenseVector< T > & operator*=(DenseVector< T > &lhs, U scale)
In place piecewise scale operator.
Definition: DenseVector.h:324
DenseVector< T > normal(const DenseVector< T > &rhs)
Return normal.
Definition: DenseVector.h:391
bool equivalent(const DenseVector< T > &lhs, const DenseVector< T > &rhs, T margin)
Equivalence test within the given tolerance margin.
Definition: DenseVector.h:497
DenseVector< T > & addScaled(DenseVector< T > &lhs, U scalar, const DenseVector< T > &rhs)
Add with scaling.
Definition: DenseVector.h:210
DenseVector< T > & setAll(DenseVector< T > &lhs, const T value)
Set all the elements to the given value.
Definition: DenseVector.h:183
T dot(const DenseVector< T > &lhs, const DenseVector< T > &rhs)
Dot (inner) product.
Definition: DenseVector.h:339
DenseVector< T > & normalize(DenseVector< T > &lhs)
In place normalize operator.
Definition: DenseVector.h:414
DenseVector< T > operator+(const DenseVector< T > &lhs, const DenseVector< T > &rhs)
add operation
Definition: DenseVector.h:436
String & cat(const char *operand)
Append the current String with the given text.
Definition: String.cc:545
T magnitude(const DenseVector< T > &rhs)
Frobenius norm operation.
Definition: DenseVector.h:359
Automatically reference-counted string container.
Definition: String.h:128
DenseVector< T > operator*(const DenseVector< T > &lhs, const U rhs)
Scale operation.
Definition: DenseVector.h:557
U32 size(const DenseVector< T > &lhs)
Return number of elements.
Definition: DenseVector.h:587
String & catf(const char *fmt,...)
Populate the string as with sPrintf(), but by concatenating the results to the existing string...
Definition: String.cc:554
DenseVector< T > & componentMultiply(DenseVector< T > &result, const DenseVector< T > &lhs, const DenseVector< T > &rhs)
Multiply each pair of components.
Definition: DenseVector.h:597
DenseVector< T > operator-(const DenseVector< T > &lhs, const DenseVector< T > &rhs)
subtractoperation
Definition: DenseVector.h:456
DenseVector< T > & operator*=(DenseVector< T > &lhs, const DenseVector< T > &rhs)
In place piecewise multiply operator.
Definition: DenseVector.h:305