46 #ifndef _PEXSI_NUMVEC_IMPL_HPP_
47 #define _PEXSI_NUMVEC_IMPL_HPP_
58 template <
class F> NumVec<F>::NumVec ( Int m ) : m_(m), owndata_(true)
61 PushCallStack(
"NumVec<F>::NumVec");
62 #endif // ifndef _RELEASE_
68 #endif // ifndef _RELEASE_
71 template <
class F> NumVec<F>::NumVec ( Int m,
bool owndata, F* data ) : m_(m), owndata_(owndata)
74 PushCallStack(
"NumVec<F>::NumVec");
75 #endif // ifndef _RELEASE_
81 #endif // ifndef _RELEASE_
84 template <
class F> NumVec<F>::NumVec (
const NumVec<F>& C ) : m_(C.m_), owndata_(C.owndata_)
87 PushCallStack(
"NumVec<F>::NumVec");
88 #endif // ifndef _RELEASE_
89 this->allocate(C.data_);
92 #endif // ifndef _RELEASE_
96 template <
class F > NumVec<F>::~NumVec ( )
99 PushCallStack(
"NumVec<F>::~NumVec");
100 #endif // ifndef _RELEASE_
104 #endif // ifndef _RELEASE_
109 template <
class F >
inline NumVec<F>& NumVec<F>::operator = (
const NumVec& C )
112 PushCallStack(
"NumVec<F>::operator=");
113 #endif // ifndef _RELEASE_
116 owndata_ = C.owndata_;
117 this->allocate(C.data_);
120 #endif // ifndef _RELEASE_
126 template <
class F >
inline void NumVec<F>::Resize (
const Int m )
129 PushCallStack(
"NumVec<F>::Resize");
130 #endif // ifndef _RELEASE_
131 if( owndata_ ==
false ){
132 throw std::logic_error(
"Vector being resized must own data.");
144 #endif // ifndef _RELEASE_
149 template <
class F>
inline F& NumVec<F>::operator() ( Int i )
152 PushCallStack(
"NumVec<F>::operator()");
153 if( i < 0 || i >= m_ ){
154 throw std::logic_error(
"Index is out of bound." );
157 #endif // ifndef _RELEASE_
165 NumVec<F>::operator() ( Int i )
const
168 PushCallStack(
"NumVec<F>::operator()");
169 if( i < 0 || i >= m_ ){
170 throw std::logic_error(
"Index is out of bound." );
173 #endif // ifndef _RELEASE_
179 template <
class F>
inline F& NumVec<F>::operator[] ( Int i )
182 PushCallStack(
"NumVec<F>::operator[]");
183 if( i < 0 || i >= m_ ){
184 throw std::logic_error(
"Index is out of bound." );
187 #endif // ifndef _RELEASE_
192 template <
class F>
inline const F& NumVec<F>::operator[] ( Int i )
const
195 PushCallStack(
"NumVec<F>::operator[]");
196 if( i < 0 || i >= m_ ){
197 throw std::logic_error(
"Index is out of bound." );
200 #endif // ifndef _RELEASE_
207 if(m_>0) { data_ =
new F[m_];
if( data_ == NULL )
throw std::runtime_error(
"Cannot allocate memory."); }
else data_=NULL;
208 if(data!=NULL){std::copy(data,data+m_,data_);}
217 if(bufsize_>0) {
delete[] data_; data_ = NULL; }
226 std::fill(vec.Data(),vec.Data()+vec.m(),val);
232 for(Int i=0; i<vec.m(); i++){
233 sum += std::abs(vec(i)*vec(i));
241 #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:142
void SetValue(NumMat< F > &M, F val)
SetValue sets a numerical matrix to a constant val.
Definition: NumMat_impl.hpp:137