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)
61 PushCallStack(
"NumVec<F>::NumVec");
62 #endif // ifndef _RELEASE_
66 #endif // ifndef _RELEASE_
70 template <
class F> NumVec<F>::NumVec ( Int m ) : m_(m), owndata_(true), data_(NULL), bufsize_(0)
73 PushCallStack(
"NumVec<F>::NumVec");
74 #endif // ifndef _RELEASE_
80 #endif // ifndef _RELEASE_
83 template <
class F> NumVec<F>::NumVec ( Int m,
bool owndata, F* data ) : m_(m), owndata_(owndata), data_(NULL), bufsize_(0)
86 PushCallStack(
"NumVec<F>::NumVec");
87 #endif // ifndef _RELEASE_
93 #endif // ifndef _RELEASE_
96 template <
class F> NumVec<F>::NumVec (
const NumVec<F>& C ) : m_(C.m_), owndata_(C.owndata_), data_(NULL), bufsize_(0)
99 PushCallStack(
"NumVec<F>::NumVec");
100 #endif // ifndef _RELEASE_
101 this->allocate(C.data_);
104 #endif // ifndef _RELEASE_
108 template <
class F > NumVec<F>::~NumVec ( )
111 PushCallStack(
"NumVec<F>::~NumVec");
112 #endif // ifndef _RELEASE_
116 #endif // ifndef _RELEASE_
121 template <
class F >
inline NumVec<F>& NumVec<F>::operator = (
const NumVec& C )
124 PushCallStack(
"NumVec<F>::operator=");
125 #endif // ifndef _RELEASE_
128 owndata_ = C.owndata_;
129 this->allocate(C.data_);
132 #endif // ifndef _RELEASE_
138 template <
class F >
inline void NumVec<F>::Resize (
const Int m )
141 PushCallStack(
"NumVec<F>::Resize");
142 #endif // ifndef _RELEASE_
143 if( owndata_ ==
false ){
147 throw std::logic_error(
"Vector being resized must own data.");
159 #endif // ifndef _RELEASE_
163 template <
class F >
inline void NumVec<F>::Clear ( )
166 PushCallStack(
"NumVec<F>::Clear");
167 #endif // ifndef _RELEASE_
168 if( owndata_ ==
false ){
176 #endif // ifndef _RELEASE_
182 template <
class F>
inline F& NumVec<F>::operator() ( Int i )
185 PushCallStack(
"NumVec<F>::operator()");
186 if( i < 0 || i >= m_ ){
190 throw std::logic_error(
"Index is out of bound." );
193 #endif // ifndef _RELEASE_
201 NumVec<F>::operator() ( Int i )
const
204 PushCallStack(
"NumVec<F>::operator()");
205 if( i < 0 || i >= m_ ){
209 throw std::logic_error(
"Index is out of bound." );
212 #endif // ifndef _RELEASE_
218 template <
class F>
inline F& NumVec<F>::operator[] ( Int i )
221 PushCallStack(
"NumVec<F>::operator[]");
222 if( i < 0 || i >= m_ ){
226 throw std::logic_error(
"Index is out of bound." );
229 #endif // ifndef _RELEASE_
234 template <
class F>
inline const F& NumVec<F>::operator[] ( Int i )
const
237 PushCallStack(
"NumVec<F>::operator[]");
238 if( i < 0 || i >= m_ ){
242 throw std::logic_error(
"Index is out of bound." );
245 #endif // ifndef _RELEASE_
254 if( data_ == NULL ) {
258 throw std::runtime_error(
"Cannot allocate memory.");
265 std::copy(data,data+m_,data_);
276 if(bufsize_>0) {
delete[] data_; data_ = NULL; bufsize_=0; m_=0; }
285 std::fill(vec.Data(),vec.Data()+vec.m(),val);
291 for(Int i=0; i<vec.m(); i++){
292 sum += std::abs(vec(i)*vec(i));
300 #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:176
void SetValue(NumMat< F > &M, F val)
SetValue sets a numerical matrix to a constant val.
Definition: NumMat_impl.hpp:171