![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
00001 /* 00002 * The GURLS Package in C++ 00003 * 00004 * Copyright (C) 2011-1013, IIT@MIT Lab 00005 * All rights reserved. 00006 * 00007 * author: M. Santoro 00008 * email: msantoro@mit.edu 00009 * website: http://cbcl.mit.edu/IIT@MIT/IIT@MIT.html 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions 00013 * are met: 00014 * 00015 * * Redistributions of source code must retain the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer. 00018 * * Redistributions in binary form must reproduce the above 00019 * copyright notice, this list of conditions and the following 00020 * disclaimer in the documentation and/or other materials 00021 * provided with the distribution. 00022 * * Neither the name(s) of the copyright holders nor the names 00023 * of its contributors or of the Massacusetts Institute of 00024 * Technology or of the Italian Institute of Technology may be 00025 * used to endorse or promote products derived from this software 00026 * without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00029 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00030 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00031 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00032 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00033 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00034 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00035 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00036 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00037 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00038 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00039 * POSSIBILITY OF SUCH DAMAGE. 00040 */ 00041 00042 #include "gurls++/blas_lapack.h" 00043 #include "gurls++/exports.h" 00044 00045 namespace gurls { 00046 00050 template<> 00051 GURLS_EXPORT void gemm(const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB, 00052 const int M, const int N, const int K, const float alpha, const float *A, const int lda, 00053 const float *B, const int ldb, const float beta, float *C, const int ldc) 00054 { 00055 char transA = BlasUtils::charValue(TransA); 00056 char transB = BlasUtils::charValue(TransB); 00057 00058 sgemm_(&transA, &transB, 00059 const_cast<int*>(&M), const_cast<int*>(&N), const_cast<int*>(&K), 00060 const_cast<float*>(&alpha), const_cast<float*>(A), const_cast<int*>(&lda), 00061 const_cast<float*>(B), const_cast<int*>(&ldb), const_cast<float*>(&beta), 00062 const_cast<float*>(C), const_cast<int*>(&ldc)); 00063 00064 } 00065 00069 template<> 00070 GURLS_EXPORT void gemm(const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB, 00071 const int M, const int N, const int K, const double alpha, const double *A, const int lda, 00072 const double *B, const int ldb, const double beta, double *C, const int ldc) 00073 { 00074 char transA = BlasUtils::charValue(TransA); 00075 char transB = BlasUtils::charValue(TransB); 00076 00077 dgemm_(&transA, &transB, 00078 const_cast<int*>(&M), const_cast<int*>(&N), const_cast<int*>(&K), 00079 const_cast<double*>(&alpha), const_cast<double*>(A), const_cast<int*>(&lda), 00080 const_cast<double*>(B), const_cast<int*>(&ldb), const_cast<double*>(&beta), 00081 const_cast<double*>(C), const_cast<int*>(&ldc)); 00082 } 00083 00087 template<> 00088 GURLS_EXPORT int potrf_(char *UPLO, int *n, float *a, int *lda , int *info) 00089 { 00090 return spotrf_(UPLO, n, a, lda, info); 00091 } 00092 00096 template<> 00097 GURLS_EXPORT int potrf_(char *UPLO, int *n, double *a, int *lda , int *info) 00098 { 00099 return dpotrf_(UPLO, n, a, lda, info); 00100 } 00101 00105 template<> 00106 GURLS_EXPORT void axpy(const int N, const float alpha, const float *X, const int incX, float *Y, const int incY) 00107 { 00108 saxpy_(const_cast<int*>(&N), const_cast<float*>(&alpha), const_cast<float*>(X), const_cast<int*>(&incX), Y, const_cast<int*>(&incY)); 00109 } 00110 00114 template<> 00115 GURLS_EXPORT void axpy(const int N, const double alpha, const double *X, const int incX, double *Y, const int incY) 00116 { 00117 daxpy_(const_cast<int*>(&N), const_cast<double*>(&alpha), const_cast<double*>(X), const_cast<int*>(&incX), Y, const_cast<int*>(&incY)); 00118 } 00119 00123 template <> 00124 GURLS_EXPORT float dot(const int N, const float *X, const int incX, const float *Y, const int incY) 00125 { 00126 return sdot_(const_cast<int*>(&N), const_cast<float*>(X), const_cast<int*>(&incX), const_cast<float*>(Y), const_cast<int*>(&incY)); 00127 } 00128 00132 template <> 00133 GURLS_EXPORT double dot(const int N, const double *X, const int incX, const double *Y, const int incY) 00134 { 00135 return ddot_(const_cast<int*>(&N), const_cast<double*>(X), const_cast<int*>(&incX), const_cast<double*>(Y), const_cast<int*>(&incY)); 00136 } 00137 00141 template<> 00142 GURLS_EXPORT float nrm2(const int N, const float* X, const int incX) 00143 { 00144 return snrm2_(const_cast<int*>(&N), const_cast<float*>(X), const_cast<int*>(&incX)); 00145 } 00146 00150 template<> 00151 GURLS_EXPORT double nrm2(const int N, const double* X, const int incX) 00152 { 00153 return dnrm2_(const_cast<int*>(&N), const_cast<double*>(X), const_cast<int*>(&incX)); 00154 } 00155 00159 template<> 00160 GURLS_EXPORT void scal(const int N, const float alpha, float *X, const int incX) 00161 { 00162 sscal_(const_cast<int*>(&N), const_cast<float*>(&alpha), X, const_cast<int*>(&incX)); 00163 } 00164 00168 template<> 00169 GURLS_EXPORT void scal(const int N, const double alpha, double *X, const int incX) 00170 { 00171 dscal_(const_cast<int*>(&N), const_cast<double*>(&alpha), X, const_cast<int*>(&incX)); 00172 } 00173 00177 template<> 00178 GURLS_EXPORT void gemv(const CBLAS_TRANSPOSE TransA, 00179 const int M, const int N, const float alpha, const float *A, 00180 const int lda, const float *X, const int incX, 00181 const float beta, float *Y, const int incY) 00182 { 00183 char transA = BlasUtils::charValue(TransA); 00184 00185 sgemv_(&transA, const_cast<int*>(&M), const_cast<int*>(&N), 00186 const_cast<float*>(&alpha), const_cast<float*>(A), const_cast<int*>(&lda), 00187 const_cast<float*>(X), const_cast<int*>(&incX), const_cast<float*>(&beta), 00188 const_cast<float*>(Y), const_cast<int*>(&incY)); 00189 00190 } 00191 00195 template<> 00196 GURLS_EXPORT void gemv(const CBLAS_TRANSPOSE TransA, 00197 const int M, const int N, const double alpha, const double *A, 00198 const int lda, const double *X, const int incX, 00199 const double beta, double *Y, const int incY) 00200 { 00201 char transA = BlasUtils::charValue(TransA); 00202 00203 dgemv_(&transA, const_cast<int*>(&M), const_cast<int*>(&N), 00204 const_cast<double*>(&alpha), const_cast<double*>(A), const_cast<int*>(&lda), 00205 const_cast<double*>(X), const_cast<int*>(&incX), const_cast<double*>(&beta), 00206 const_cast<double*>(Y), const_cast<int*>(&incY)); 00207 } 00208 00212 template<> 00213 GURLS_EXPORT void syev( char* jobz, char* uplo, int* n, float* a, int* lda, float* w, float* work, int* lwork, int* info) 00214 { 00215 ssyev_(jobz, uplo, n, a, lda, w, work, lwork, info); 00216 } 00217 00221 template<> 00222 GURLS_EXPORT void syev( char* jobz, char* uplo, int* n, double* a, int* lda, double* w, double* work, int* lwork, int* info) 00223 { 00224 dsyev_(jobz, uplo, n, a, lda, w, work, lwork, info); 00225 } 00226 00230 template <> 00231 GURLS_EXPORT void trsm(const CBLAS_SIDE Side, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, 00232 const int M, const int N, const float alpha, const float *A, const int lda, float *B, const int ldb) 00233 { 00234 char side = BlasUtils::charValue(Side); 00235 char uplo = BlasUtils::charValue(Uplo); 00236 char transA = BlasUtils::charValue(TransA); 00237 char diag = BlasUtils::charValue(Diag); 00238 00239 strsm_(&side, &uplo, &transA, &diag, const_cast<int*>(&M), const_cast<int*>(&N), const_cast<float*>(&alpha), const_cast<float*>(A), 00240 const_cast<int*>(&lda), const_cast<float*>(B), const_cast<int*>(&ldb)); 00241 00242 } 00243 00247 template <> 00248 GURLS_EXPORT void trsm(const CBLAS_SIDE Side, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, 00249 const int M, const int N, const double alpha, const double *A, const int lda, double *B, const int ldb) 00250 { 00251 char side = BlasUtils::charValue(Side); 00252 char uplo = BlasUtils::charValue(Uplo); 00253 char transA = BlasUtils::charValue(TransA); 00254 char diag = BlasUtils::charValue(Diag); 00255 00256 dtrsm_(&side, &uplo, &transA, &diag, const_cast<int*>(&M), const_cast<int*>(&N), const_cast<double*>(&alpha), const_cast<double*>(A), 00257 const_cast<int*>(&lda), const_cast<double*>(B), const_cast<int*>(&ldb)); 00258 } 00259 00263 template <> 00264 GURLS_EXPORT int gesvd_(char *jobu, char *jobvt, int *m, int *n, float *a, int *lda, float *s, float *u, int *ldu, float *vt, int *ldvt, float *work, int *lwork, int *info) 00265 { 00266 return sgesvd_(jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, info); 00267 } 00268 00272 template <> 00273 GURLS_EXPORT int gesvd_(char *jobu, char *jobvt, int *m, int *n, double *a, int *lda, double *s, double *u, int *ldu, double *vt, int *ldvt, double *work, int *lwork, int *info) 00274 { 00275 return dgesvd_(jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, info); 00276 } 00277 00281 template<> 00282 GURLS_EXPORT void geqp3( int *m, int *n, float *A, int *lda, int *jpvt, float *tau, float *work, int *lwork, int *info) 00283 { 00284 sgeqp3_(m, n, A, lda, jpvt, tau, work, lwork, info); 00285 } 00286 00290 template<> 00291 GURLS_EXPORT void geqp3( int *m, int *n, double *A, int *lda, int *jpvt, double *tau, double *work, int *lwork, int *info) 00292 { 00293 dgeqp3_(m, n, A, lda, jpvt, tau, work, lwork, info); 00294 } 00295 00299 template<> 00300 GURLS_EXPORT void orgqr(int *m, int *n, int *k, float *a, int *lda, float *tau, float *work, int *lwork, int *info) 00301 { 00302 sorgqr_(m, n, k, a, lda, tau, work, lwork, info); 00303 } 00304 00308 template<> 00309 GURLS_EXPORT void orgqr(int *m, int *n, int *k, double *a, int *lda, double *tau, double *work, int *lwork, int *info) 00310 { 00311 dorgqr_(m, n, k, a, lda, tau, work, lwork, info); 00312 } 00313 00317 template<> 00318 GURLS_EXPORT int gelss( int *m, int *n, int* nrhs, float *a, int *lda, float* b, int *ldb, float *s, float *rcond, int *rank, float *work, int *lwork, int *info) 00319 { 00320 return sgelss_( m, n, nrhs, a, lda, b, ldb, s, rcond, rank, work, lwork, info); 00321 } 00322 00326 template<> 00327 GURLS_EXPORT int gelss( int *m, int *n, int* nrhs, double *a, int *lda, double* b, int *ldb, double *s, double *rcond, int *rank, double *work, int *lwork, int *info) 00328 { 00329 return dgelss_( m, n, nrhs, a, lda, b, ldb, s, rcond, rank, work, lwork, info); 00330 } 00331 00335 template<> 00336 GURLS_EXPORT void swap( int n, float *x, int incx, float *y, int incy) 00337 { 00338 sswap_(&n, x, &incx, y, &incy); 00339 } 00340 00344 template<> 00345 GURLS_EXPORT void swap( int n, double *x, int incx, double *y, int incy) 00346 { 00347 dswap_(&n, x, &incx, y, &incy); 00348 } 00349 00350 }