examples/homography/TooN/blasoperators.hh

00001 
00002 /*                       
00003          Copyright (C) 2005 Tom Drummond
00004 
00005      This library is free software; you can redistribute it and/or
00006      modify it under the terms of the GNU Lesser General Public
00007      License as published by the Free Software Foundation; either
00008      version 2.1 of the License, or (at your option) any later version.
00009 
00010      This library is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013      Lesser General Public License for more details.
00014 
00015      You should have received a copy of the GNU Lesser General Public
00016      License along with this library; if not, write to the Free Software
00017      Foundation, Inc.
00018      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019 */
00020 #ifndef __BLASOPERATORS_H
00021 #define __BLASOPERATORS_H
00022 
00023 extern "C" {
00024   void dgemm_(const char* TRANSA, const char* TRANSB, int* width, int* height, int* inter,
00025               double* alpha, const double* A, int *lda, const double* B, int *ldb,
00026               double* beta, double* C, int *ldc);  
00027 }
00028 
00029 
00030 
00031 
00032 template <class RET, class LHS, class RHS>
00033 inline void blasmmmult(RET& ret, const LHS& lhs, const RHS& rhs){
00034 
00035   // This awkwardness is the only way I can figure out to get at
00036   // the is_rowmajor() static function in the layout classes
00037   typedef typename RET::layout retlayout;
00038   typedef typename LHS::layout lhslayout;
00039   typedef typename RHS::layout rhslayout;
00040 
00041   const bool CM = !retlayout::is_rowmajor();
00042   const bool LCM = !lhslayout::is_rowmajor();
00043   const bool RCM = !rhslayout::is_rowmajor();
00044 
00045   int width = CM ? ret.num_cols():ret.num_rows();
00046   int height = CM ? ret.num_rows():ret.num_cols();
00047   int inter = lhs.num_cols();
00048   double alpha = 1;
00049   int lda = CM ? lhs.num_skip() : rhs.num_skip();
00050   int ldb = CM ? rhs.num_skip() : lhs.num_skip();
00051   double beta = 0;
00052   int ldc = ret.num_skip();
00053   const char* TrA = CM ? (LCM ? "N" : "T") : (RCM ? "T" : "N");
00054   const char* TrB = CM ? (RCM ? "N" : "T") : (LCM ? "T" : "N");
00055   
00056   dgemm_(TrA,TrB,&width,&height,&inter,&alpha,
00057          CM ? lhs.get_data_ptr() : rhs.get_data_ptr(),&lda,
00058          CM ? rhs.get_data_ptr() : lhs.get_data_ptr(),&ldb,
00059          &beta, ret.get_data_ptr(), &ldc);
00060 }
00061   
00062 
00063 
00064 #endif

Generated on Fri Feb 22 18:26:54 2008 for QVision by  doxygen 1.5.3