Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #652 from koenvandesande/master
Use CBLAS optimized vector multiplication inside SGVector::vec1_plus_scalar_times_vec2
  • Loading branch information
lisitsyn committed Jul 17, 2012
2 parents 2e7e626 + d7076c3 commit 48873ae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
26 changes: 26 additions & 0 deletions src/shogun/lib/SGVector.cpp
Expand Up @@ -291,6 +291,32 @@ void SGVector<floatmax_t>::display_vector(const floatmax_t* vector, int32_t n,
SG_SPRINT("%s]\n", prefix);
}

template <class T>
void SGVector<T>::vec1_plus_scalar_times_vec2(float64_t* vec1,
const float64_t scalar, const float64_t* vec2, int32_t n)
{
#ifdef HAVE_LAPACK
int32_t skip=1;
cblas_daxpy(n, scalar, vec2, skip, vec1, skip);
#else
for (int32_t i=0; i<n; i++)
vec1[i]+=scalar*vec2[i];
#endif
}

template <class T>
void SGVector<T>::vec1_plus_scalar_times_vec2(float32_t* vec1,
const float32_t scalar, const float32_t* vec2, int32_t n)
{
#ifdef HAVE_LAPACK
int32_t skip=1;
cblas_saxpy(n, scalar, vec2, skip, vec1, skip);
#else
for (int32_t i=0; i<n; i++)
vec1[i]+=scalar*vec2[i];
#endif
}

template <class T>
float64_t SGVector<T>::dot(const float64_t* v1, const float64_t* v2, int32_t n)
{
Expand Down
22 changes: 15 additions & 7 deletions src/shogun/lib/SGVector.h
Expand Up @@ -186,13 +186,21 @@ template<class T> class SGVector : public SGReferencedData
/// || x ||_q
static T qnorm(T* x, int32_t len, float64_t q);

/// x=x+alpha*y
static inline void vec1_plus_scalar_times_vec2(T* vec1,
T scalar, const T* vec2, int32_t n)
{
for (int32_t i=0; i<n; i++)
vec1[i]+=scalar*vec2[i];
}
// /// x=x+alpha*y
// static inline void vec1_plus_scalar_times_vec2(T* vec1,
// T scalar, const T* vec2, int32_t n)
// {
// for (int32_t i=0; i<n; i++)
// vec1[i]+=scalar*vec2[i];
// }

/// x=x+alpha*y (blas optimized)
static void vec1_plus_scalar_times_vec2(float64_t* vec1,
const float64_t scalar, const float64_t* vec2, int32_t n);

/// x=x+alpha*y (blas optimized)
static void vec1_plus_scalar_times_vec2(float32_t* vec1,
const float32_t scalar, const float32_t* vec2, int32_t n);

/// compute dot product between v1 and v2 (blas optimized)
static inline float64_t dot(const bool* v1, const bool* v2, int32_t n)
Expand Down

0 comments on commit 48873ae

Please sign in to comment.