46 #ifndef _PEXSI_NUMVEC_IMPL_HPP_
47 #define _PEXSI_NUMVEC_IMPL_HPP_
58 template <
class F> NumVec<F>::NumVec () : m_(0), owndata_(true), data_(NULL), bufsize_(0)
64 template <
class F> NumVec<F>::NumVec ( Int m ) : m_(m), owndata_(true), data_(NULL), bufsize_(0)
71 template <
class F> NumVec<F>::NumVec ( Int m,
bool owndata, F* data ) : m_(m), owndata_(owndata), data_(NULL), bufsize_(0)
78 template <
class F> NumVec<F>::NumVec (
const NumVec<F>& C ) : m_(C.m_), owndata_(C.owndata_), data_(NULL), bufsize_(0)
80 this->allocate(C.data_);
84 template <
class F > NumVec<F>::~NumVec ( )
91 template <
class F >
inline NumVec<F>& NumVec<F>::operator = (
const NumVec& C )
95 owndata_ = C.owndata_;
96 this->allocate(C.data_);
102 template <
class F >
inline void NumVec<F>::Resize (
const Int m )
104 if( owndata_ ==
false ){
105 ErrorHandling(
"Vector being resized must own data.");
118 template <
class F >
inline void NumVec<F>::Clear ( )
120 if( owndata_ ==
false ){
131 template <
class F>
inline F& NumVec<F>::operator() ( Int i )
133 if( i < 0 || i >= m_ ){
134 ErrorHandling(
"Index is out of bound." );
143 NumVec<F>::operator() ( Int i )
const
145 if( i < 0 || i >= m_ ){
146 ErrorHandling(
"Index is out of bound." );
153 template <
class F>
inline F& NumVec<F>::operator[] ( Int i )
155 if( i < 0 || i >= m_ ){
156 ErrorHandling(
"Index is out of bound." );
162 template <
class F>
inline const F& NumVec<F>::operator[] ( Int i )
const
164 if( i < 0 || i >= m_ ){
165 ErrorHandling(
"Index is out of bound." );
175 if( data_ == NULL ) {
176 ErrorHandling(
"Cannot allocate memory.");
183 std::copy(data,data+m_,data_);
194 if(bufsize_>0) {
delete[] data_; data_ = NULL; bufsize_=0; m_=0; }
203 std::fill(vec.Data(),vec.Data()+vec.m(),val);
209 for(Int i=0; i<vec.m(); i++){
210 sum += std::abs(vec(i)*vec(i));
218 #endif // _PEXSI_NUMVEC_IMPL_HPP_
Numerical vector.
Definition: NumVec.hpp:60
Real Energy(const NumMat< F > &M)
Energy computes the L2 norm of a matrix (treated as a vector).
Definition: NumMat_impl.hpp:158
void SetValue(NumMat< F > &M, F val)
SetValue sets a numerical matrix to a constant val.
Definition: NumMat_impl.hpp:153