57 typedef DVectorSlice::difference_type difference_type;
62 T my_max(
const T& v1,
const T& v2 ) {
return v1 > v2 ? v1 : v2; }
66 T my_min(
const T& v1,
const T& v2 ) {
return v1 < v2 ? v1 : v2; }
70 switch(vs_lhs->overlap(vs_rhs)) {
75 BLAS_Cpp::copy( temp.dim(), temp.raw_ptr(), 1, vs_lhs->raw_ptr(), vs_lhs->stride() );
81 , vs_lhs->raw_ptr(), vs_lhs->stride() );
87 inline value_type local_prod(
const value_type &v1,
const value_type &v2 ) {
return v1*v2; }
95 if(vs_lhs->
stride() == 1) {
98 *itr_end = itr + vs_lhs->
dim();
104 itr = vs_lhs->
begin(),
105 itr_end = vs_lhs->
end();
106 while(itr != itr_end)
114 else if( alpha == 0.0 )
130 throw std::length_error(
"DenseLinAlgPack::assign(vs_lhs,alpha): DVectorSlice must be bound and sized.");
135 i_assign(vs_lhs,vs_rhs);
140 std::transform(vs_rhs1.
begin(),vs_rhs1.
end(),vs_rhs2.
begin(),vs_lhs->
begin(),std::plus<value_type>());
145 std::transform(vs_rhs1.
begin(),vs_rhs1.
end(),vs_rhs2.
begin(),vs_lhs->
begin(),std::minus<value_type>());
150 BLAS_Cpp::scal( vs_lhs->dim(), -1.0, vs_lhs->raw_ptr(), vs_lhs->stride() );
156 BLAS_Cpp::scal( vs_lhs->dim(), alpha, vs_lhs->raw_ptr(), vs_lhs->stride() );
162 #define UNARYOP_VECSLC(LHS, RHS, FUNC) \
163 DenseLinAlgPack::Vp_V_assert_sizes( (LHS)->dim(), (RHS).dim() ); \
164 DVectorSlice::iterator itr_lhs; DVectorSlice::const_iterator itr_rhs; \
165 for(itr_lhs = LHS->begin(), itr_rhs = RHS.begin(); itr_lhs != LHS->end(); ++itr_lhs, ++itr_rhs) \
166 { *itr_lhs = FUNC(*itr_rhs); }
169 #define BINARYOP_VECSLC(LHS, RHS1, RHS2, FUNC) \
170 DenseLinAlgPack::VopV_assert_sizes( (RHS1).dim(), (RHS2).dim() ); \
171 DenseLinAlgPack::Vp_V_assert_sizes( (LHS)->dim(), (RHS1).dim() ); \
172 DVectorSlice::iterator itr_lhs; DVectorSlice::const_iterator itr_rhs1, itr_rhs2; \
173 for(itr_lhs = LHS->begin(), itr_rhs1 = RHS1.begin(), itr_rhs2 = RHS2.begin(); \
174 itr_lhs != LHS->end(); ++itr_lhs, ++itr_rhs1, ++itr_rhs2) \
175 { *itr_lhs = FUNC(*itr_rhs1, *itr_rhs2); }
177 #define BINARYOP_BIND1ST_VECSLC(LHS, RHS1, RHS2, FUNC) \
178 DenseLinAlgPack::Vp_V_assert_sizes( (LHS)->dim(), (RHS2).dim() ); \
179 DVectorSlice::iterator itr_lhs; DVectorSlice::const_iterator itr_rhs2; \
180 for(itr_lhs = LHS->begin(), itr_rhs2 = RHS2.begin(); \
181 itr_lhs != LHS->end(); ++itr_lhs, ++itr_rhs2) \
182 { *itr_lhs = FUNC(RHS1, *itr_rhs2); }
184 #define BINARYOP_BIND2ND_VECSLC(LHS, RHS1, RHS2, FUNC) \
185 DenseLinAlgPack::Vp_V_assert_sizes( (LHS)->dim(), (RHS1).dim()); \
186 DVectorSlice::iterator itr_lhs; DVectorSlice::const_iterator itr_rhs1; \
187 for(itr_lhs = LHS->begin(), itr_rhs1 = RHS1.begin(); \
188 itr_lhs != LHS->end(); ++itr_lhs, ++itr_rhs1) \
189 { *itr_lhs = FUNC(*itr_rhs1, RHS2); }
226 for(itr_lhs = vs_lhs->
begin(), itr_rhs1 = vs_rhs1.
begin(), itr_rhs2 = vs_rhs2.
begin();
227 itr_lhs != vs_lhs->
end(); ++itr_lhs, ++itr_rhs1, ++itr_rhs2)
228 { *itr_lhs = my_max(*itr_rhs1, *itr_rhs2); }
233 for(itr_lhs = vs_lhs->
begin(), itr_rhs = vs_rhs.
begin(); itr_lhs != vs_lhs->
end(); ++itr_lhs, ++itr_rhs)
234 { *itr_lhs = my_max(alpha,*itr_rhs); }
240 for(itr_lhs = vs_lhs->
begin(), itr_rhs1 = vs_rhs1.
begin(), itr_rhs2 = vs_rhs2.
begin();
241 itr_lhs != vs_lhs->
end(); ++itr_lhs, ++itr_rhs1, ++itr_rhs2)
242 { *itr_lhs = my_min(*itr_rhs1, *itr_rhs2); }
247 for(itr_lhs = vs_lhs->
begin(), itr_rhs = vs_rhs.
begin(); itr_lhs != vs_lhs->
end(); ++itr_lhs, ++itr_rhs)
248 { *itr_lhs = my_min(alpha,*itr_rhs); }
286 throw std::length_error(
"DenseLinAlgPack::assign(v_lhs,alpha): DVector must be sized.");
292 i_assign( &(*v_lhs)(), vs_rhs );
298 std::transform(vs_rhs1.
begin(),vs_rhs1.
end(),vs_rhs2.
begin(),v_lhs->
begin(),std::plus<value_type>());
312 std::transform(vs_rhs1.
begin(),vs_rhs1.
end(),vs_rhs2.
begin(),v_lhs->
begin(),std::minus<value_type>());
334 #define UNARYOP_VEC(LHS, RHS, FUNC) \
335 LHS->resize(RHS.dim()); \
336 DVector::iterator itr_lhs; DVectorSlice::const_iterator itr_rhs; \
337 for(itr_lhs = LHS->begin(), itr_rhs = RHS.begin(); itr_lhs != LHS->end(); ++itr_lhs, ++itr_rhs) \
338 { *itr_lhs = FUNC(*itr_rhs); }
340 #define BINARYOP_VEC(LHS, RHS1, RHS2, FUNC) \
341 DenseLinAlgPack::assert_vs_sizes(RHS1.dim(), RHS2.dim()); LHS->resize(RHS1.dim()); \
342 DVector::iterator itr_lhs; DVectorSlice::const_iterator itr_rhs1, itr_rhs2; \
343 for(itr_lhs = LHS->begin(), itr_rhs1 = RHS1.begin(), itr_rhs2 = RHS2.begin(); \
344 itr_lhs != LHS->end(); ++itr_lhs, ++itr_rhs1, ++itr_rhs2) \
345 { *itr_lhs = FUNC(*itr_rhs1, *itr_rhs2); }
347 #define BINARYOP_BIND1ST_VEC(LHS, RHS1, RHS2, FUNC) \
348 LHS->resize(RHS2.dim()); \
349 DVector::iterator itr_lhs; DVectorSlice::const_iterator itr_rhs2; \
350 for(itr_lhs = LHS->begin(), itr_rhs2 = RHS2.begin(); \
351 itr_lhs != LHS->end(); ++itr_lhs, ++itr_rhs2) \
352 { *itr_lhs = FUNC(RHS1, *itr_rhs2); }
354 #define BINARYOP_BIND2ND_VEC(LHS, RHS1, RHS2, FUNC) \
355 LHS->resize(RHS1.dim()); \
356 DVector::iterator itr_lhs; DVectorSlice::const_iterator itr_rhs1; \
357 for(itr_lhs = LHS->begin(), itr_rhs1 = RHS1.begin(); \
358 itr_lhs != LHS->end(); ++itr_lhs, ++itr_rhs1) \
359 { *itr_lhs = FUNC(*itr_rhs1, RHS2); }
396 for(itr_lhs = v_lhs->
begin(), itr_rhs1 = vs_rhs1.
begin(), itr_rhs2 = vs_rhs2.
begin();
397 itr_lhs != v_lhs->
end(); ++itr_lhs, ++itr_rhs1, ++itr_rhs2)
398 { *itr_lhs = my_max(*itr_rhs1, *itr_rhs2); }
403 for(itr_lhs = v_lhs->
begin(), itr_rhs = vs_rhs.
begin(); itr_lhs != v_lhs->
end(); ++itr_lhs, ++itr_rhs)
404 { *itr_lhs = my_max(alpha,*itr_rhs); }
410 for(itr_lhs = v_lhs->
begin(), itr_rhs1 = vs_rhs1.
begin(), itr_rhs2 = vs_rhs2.
begin();
411 itr_lhs != v_lhs->
end(); ++itr_lhs, ++itr_rhs1, ++itr_rhs2)
412 { *itr_lhs = my_min(*itr_rhs1, *itr_rhs2); }
417 for(itr_lhs = v_lhs->
begin(), itr_rhs = vs_rhs.
begin(); itr_lhs != v_lhs->
end(); ++itr_lhs, ++itr_rhs)
418 { *itr_lhs = my_min(alpha,*itr_rhs); }
463 {
return *std::min_element(vs_rhs.
begin(),vs_rhs.
end()); }
471 value_type max_ele = 0.0;
473 value_type ele = ::fabs(*itr++);
474 if(ele > max_ele) max_ele = ele;
AbstractLinAlgPack::size_type size_type
void scal(const f_int &N, const f_dbl_prec &ALPHA, f_dbl_prec *X, const f_int &INCX)
void max(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
vs_lhs = max(vs_rhs1,vs_rhs2)
void pow(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
vs_lhs = pow(vs_rhs1,vs_rhs2)
void Vp_StV(DVectorSlice *vs_lhs, value_type alpha, const DVectorSlice &vs_rhs)
vs_lhs += alpha * vs_rhs (BLAS xAXPY)
size_type dim() const
Returns the number of elements of the VectorSliceTmpl.
#define BINARYOP_BIND2ND_VECSLC(LHS, RHS1, RHS2, FUNC)
void sinh(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = sinh(vs_rhs)
void assign(DMatrix *gm_lhs, value_type alpha)
gm_lhs = alpha (elementwise)
value_type * start_ptr()
Return a pointer to the conceptual first element in the underlying array.
void rot(const f_int &N, f_dbl_prec *X, const f_int &INCX, f_dbl_prec *Y, const f_int &INCY, const f_dbl_prec &C, const f_dbl_prec &S)
void atan2(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
vs_lhs = atan(vs_rhs1/vs_rhs2)
void abs(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = abs(vs_rhs)
value_type max_element(const Vector &v)
Compute the maximum element in a vector.
VectorSliceTmpl< value_type > DVectorSlice
void V_VpV(DVector *v_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
v_lhs = alpha (elementwise)
#define UNARYOP_VEC(LHS, RHS, FUNC)
#define BINARYOP_BIND2ND_VEC(LHS, RHS1, RHS2, FUNC)
void resize(size_type n, value_type val=value_type())
#define BINARYOP_VECSLC(LHS, RHS1, RHS2, FUNC)
C++ Standard Library compatable iterator class for accesing nonunit stride arrays of data...
void axpy(const f_int &N, const f_dbl_prec &A, const f_dbl_prec *X, const f_int &INCX, f_dbl_prec *Y, const f_int &INCY)
void assert_vs_sizes(size_type size1, size_type size2)
void asin(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = asin(vs_rhs)
void sin(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = sin(vs_rhs)
value_type * raw_ptr()
Return a pointer to the address of the first memory location of underlying array. ...
void Vp_V_assert_sizes(size_type v_lhs_size, size_type v_rhs_size)
v_lhs += op v_rhs
void cosh(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = cosh(vs_rhs)
#define BINARYOP_BIND1ST_VECSLC(LHS, RHS1, RHS2, FUNC)
void swap(const f_int &N, f_dbl_prec *X, const f_int &INCX, f_dbl_prec *Y, const f_int &INCY)
value_type norm_2(const DVectorSlice &vs_rhs)
result = ||vs_rhs||2 (BLAS xNRM2)
void copy(const f_int &N, const f_dbl_prec *X, const f_int &INCX, f_dbl_prec *Y, const f_int &INCY)
f_dbl_prec asum(const f_int &N, const f_dbl_prec *X, const f_int &INCX)
void prod(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
vs_lhs(i) = vs_rhs1(i) * vs_rhs2(i), i = 1...n
void V_StV(DVector *v_lhs, value_type alpha, const DVectorSlice &vs_rhs)
v_lhs = alpha * vs_rhs
value_type * raw_ptr()
Return a pointer to the address of the first memory location of underlying array. ...
f_dbl_prec dot(const f_int &N, const f_dbl_prec *X, const f_int &INCX, const f_dbl_prec *Y, const f_int &INCY)
#define BINARYOP_BIND1ST_VEC(LHS, RHS1, RHS2, FUNC)
size_type dim() const
Returns the number of elements of the DVector.
void atan(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = atan(vs_rhs)
difference_type stride() const
Return the distance (+,-) (in units of elements) between adjacent elements in the underlying array...
void Vp_S(DVectorSlice *vs_lhs, value_type alpha)
vs_lhs += alpha
void exp(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = exp(vs_rhs)
value_type norm_1(const DVectorSlice &vs_rhs)
result = ||vs_rhs||1 (BLAS xASUM)
f_dbl_prec nrm2(const f_int &N, const f_dbl_prec *X, const f_int &INCX)
void V_VmV(DVector *v_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
v_lhs = vs_rhs1 - vs_rhs2
EOverLap overlap(const VectorSliceTmpl< value_type > &vs) const
void VopV_assert_sizes(size_type v_rhs1_size, size_type v_rhs2_size)
v_rhs1 op v_rhs2
void sqrt(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = sqrt(vs_rhs)
#define UNARYOP_VECSLC(LHS, RHS, FUNC)
DenseLinAlgPack::VectorSliceTmpl< value_type > DVectorSlice
void Vt_S(DVectorSlice *vs_lhs, value_type alpha)
vs_lhs *= alpha (BLAS xSCAL) (*** Note that alpha == 0.0 is handeled as vs_lhs = 0.0)
AbstractLinAlgPack::value_type value_type
difference_type stride() const
Return the distance (+,-) (in units of elements) between adjacent elements in the underlying array...
FortranTypes::f_dbl_prec value_type
Typedef for the value type of elements that is used for the library.
VectorTmpl< value_type > DVector
void V_mV(DVector *v_lhs, const DVectorSlice &vs_rhs)
v_lhs = - vs_rhs
void tanh(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = tanh(vs_rhs)
value_type norm_inf(const DVectorSlice &vs_rhs)
result = ||vs_rhs||infinity (BLAS IxAMAX)
void acos(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = acos(vs_rhs)
void tan(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = tan(vs_rhs)
void swap(DVectorSlice *vs1, DVectorSlice *vs2)
swap(vs1, vs2). Swaps the contents of vs1 and vs2
#define BINARYOP_VEC(LHS, RHS1, RHS2, FUNC)
void rot(const value_type c, const value_type s, DVectorSlice *x, DVectorSlice *y)
void cos(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = cos(vs_rhs)
void min(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
vs_lhs = min(vs_rhs1,vs_rhs2)
value_type dot(const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
result = vs_rhs1' * vs_rhs2 (BLAS xDOT)