Skip to content

Commit

Permalink
Gracefully fallback to loop based matrix multiply
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jul 27, 2012
1 parent bea8e08 commit 1a157fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/shogun/lib/SGMatrix.cpp
Expand Up @@ -623,14 +623,25 @@ SGMatrix<float64_t> SGMatrix<T>::matrix_multiply(

/* allocate result matrix */
SGMatrix<float64_t> C(rows_A, cols_B);

C.zero();
#ifdef HAVE_LAPACK
/* multiply */
cblas_dgemm(CblasColMajor,
transpose_A ? CblasTrans : CblasNoTrans,
transpose_B ? CblasTrans : CblasNoTrans,
rows_A, cols_B, cols_A, scale,
A.matrix, A.num_rows, B.matrix, B.num_rows,
0.0, C.matrix, C.num_rows);
#else
for (int32_t i=0; i<rows_A; i++)
{
for (int32_t j=0; j<cols_B; j++)
{
for (int32_t k=0; k<cols_A; k++)
C(i,j) += A(i,k)*B(k,j);
}
}
#endif

return C;
}
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/lib/SGMatrix.h
Expand Up @@ -196,7 +196,7 @@ template<class T> class SGMatrix : public SGReferencedData
*/
void compute_few_eigenvectors(double* matrix_, double*& eigenvalues, double*& eigenvectors,
int n, int il, int iu);

#endif
/* Computes scale* A*B, where A and B may be transposed.
* Asserts for matching inner dimensions.
* @param A matrix A
Expand All @@ -209,7 +209,7 @@ template<class T> class SGMatrix : public SGReferencedData
SGMatrix<float64_t> A, SGMatrix<float64_t> B,
bool transpose_A=false, bool transpose_B=false,
float64_t scale=1.0);

#ifdef HAVE_LAPACK
/// inverses square matrix in-place
static void inverse(SGMatrix<float64_t> matrix);

Expand Down

0 comments on commit 1a157fe

Please sign in to comment.