46 #ifndef _NUMVEC_IMPL_HPP_
47 #define _NUMVEC_IMPL_HPP_
62 template <
class F> NumVec<F>::NumVec ( Int m ) : m_(m), owndata_(true)
65 PushCallStack(
"NumVec<F>::NumVec");
66 #endif // ifndef _RELEASE_
72 #endif // ifndef _RELEASE_
75 template <
class F> NumVec<F>::NumVec ( Int m,
bool owndata, F* data ) : m_(m), owndata_(owndata)
78 PushCallStack(
"NumVec<F>::NumVec");
79 #endif // ifndef _RELEASE_
85 #endif // ifndef _RELEASE_
88 template <
class F> NumVec<F>::NumVec (
const NumVec<F>& C ) : m_(C.m_), owndata_(C.owndata_)
91 PushCallStack(
"NumVec<F>::NumVec");
92 #endif // ifndef _RELEASE_
93 this->allocate(C.data_);
96 #endif // ifndef _RELEASE_
100 template <
class F > NumVec<F>::~NumVec ( )
103 PushCallStack(
"NumVec<F>::~NumVec");
104 #endif // ifndef _RELEASE_
108 #endif // ifndef _RELEASE_
113 template <
class F >
inline NumVec<F>& NumVec<F>::operator = (
const NumVec& C )
116 PushCallStack(
"NumVec<F>::operator=");
117 #endif // ifndef _RELEASE_
120 owndata_ = C.owndata_;
121 this->allocate(C.data_);
124 #endif // ifndef _RELEASE_
130 template <
class F >
inline void NumVec<F>::Resize (
const Int m )
133 PushCallStack(
"NumVec<F>::Resize");
134 #endif // ifndef _RELEASE_
135 if( owndata_ ==
false ){
136 throw std::logic_error(
"Vector being resized must own data.");
148 #endif // ifndef _RELEASE_
153 template <
class F>
inline F& NumVec<F>::operator() ( Int i )
156 PushCallStack(
"NumVec<F>::operator()");
157 if( i < 0 || i >= m_ ){
158 throw std::logic_error(
"Index is out of bound." );
161 #endif // ifndef _RELEASE_
169 NumVec<F>::operator() ( Int i )
const
172 PushCallStack(
"NumVec<F>::operator()");
173 if( i < 0 || i >= m_ ){
174 throw std::logic_error(
"Index is out of bound." );
177 #endif // ifndef _RELEASE_
183 template <
class F>
inline F& NumVec<F>::operator[] ( Int i )
186 PushCallStack(
"NumVec<F>::operator[]");
187 if( i < 0 || i >= m_ ){
188 throw std::logic_error(
"Index is out of bound." );
191 #endif // ifndef _RELEASE_
196 template <
class F>
inline const F& NumVec<F>::operator[] ( Int i )
const
199 PushCallStack(
"NumVec<F>::operator[]");
200 if( i < 0 || i >= m_ ){
201 throw std::logic_error(
"Index is out of bound." );
204 #endif // ifndef _RELEASE_
211 if(m_>0) { data_ =
new F[m_];
if( data_ == NULL )
throw std::runtime_error(
"Cannot allocate memory."); }
else data_=NULL;
212 if(data!=NULL){std::copy(data,data+m_,data_);}
221 if(bufsize_>0) {
delete[] data_; data_ = NULL; }
230 std::fill(vec.Data(),vec.Data()+vec.m(),val);
236 for(Int i=0; i<vec.m(); i++){
237 sum += std::abs(vec(i)*vec(i));
245 #endif // _NUMVEC_IMPL_HPP_
Numerical vector.
Definition: numvec_decl.hpp:61
Real Energy(const NumMat< F > &M)
Energy computes the L2 norm of a matrix (treated as a vector).
Definition: nummat_impl.hpp:70
void SetValue(NumMat< F > &M, F val)
SetValue sets a numerical matrix to a constant val.
Definition: nummat_impl.hpp:61