00001 /* 00002 Copyright (c) 2011, Intel Corporation. All rights reserved. 00003 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 * Redistributions of source code must retain the above copyright notice, this 00008 list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, 00010 this list of conditions and the following disclaimer in the documentation 00011 and/or other materials provided with the distribution. 00012 * Neither the name of Intel Corporation nor the names of its contributors may 00013 be used to endorse or promote products derived from this software without 00014 specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00020 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00023 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 00027 ******************************************************************************** 00028 * Content : Eigen bindings to Intel(R) MKL 00029 * LU decomposition with partial pivoting based on LAPACKE_?getrf function. 00030 ******************************************************************************** 00031 */ 00032 00033 #ifndef EIGEN_PARTIALLU_LAPACK_H 00034 #define EIGEN_PARTIALLU_LAPACK_H 00035 00036 #include "Eigen/src/Core/util/MKL_support.h" 00037 00038 namespace Eigen { 00039 00040 namespace internal { 00041 00044 #define EIGEN_MKL_LU_PARTPIV(EIGTYPE, MKLTYPE, MKLPREFIX) \ 00045 template<int StorageOrder> \ 00046 struct partial_lu_impl<EIGTYPE, StorageOrder, lapack_int> \ 00047 { \ 00048 /* \internal performs the LU decomposition in-place of the matrix represented */ \ 00049 static lapack_int blocked_lu(lapack_int rows, lapack_int cols, EIGTYPE* lu_data, lapack_int luStride, lapack_int* row_transpositions, lapack_int& nb_transpositions, lapack_int maxBlockSize=256) \ 00050 { \ 00051 EIGEN_UNUSED_VARIABLE(maxBlockSize);\ 00052 lapack_int matrix_order, first_zero_pivot; \ 00053 lapack_int m, n, lda, *ipiv, info; \ 00054 EIGTYPE* a; \ 00055 /* Set up parameters for ?getrf */ \ 00056 matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ 00057 lda = luStride; \ 00058 a = lu_data; \ 00059 ipiv = row_transpositions; \ 00060 m = rows; \ 00061 n = cols; \ 00062 nb_transpositions = 0; \ 00063 \ 00064 info = LAPACKE_##MKLPREFIX##getrf( matrix_order, m, n, (MKLTYPE*)a, lda, ipiv ); \ 00065 \ 00066 for(int i=0;i<m;i++) { ipiv[i]--; if (ipiv[i]!=i) nb_transpositions++; } \ 00067 \ 00068 eigen_assert(info >= 0); \ 00069 /* something should be done with nb_transpositions */ \ 00070 \ 00071 first_zero_pivot = info; \ 00072 return first_zero_pivot; \ 00073 } \ 00074 }; 00075 00076 EIGEN_MKL_LU_PARTPIV(double, double, d) 00077 EIGEN_MKL_LU_PARTPIV(float, float, s) 00078 EIGEN_MKL_LU_PARTPIV(dcomplex, MKL_Complex16, z) 00079 EIGEN_MKL_LU_PARTPIV(scomplex, MKL_Complex8, c) 00080 00081 } // end namespace internal 00082 00083 } // end namespace Eigen 00084 00085 #endif // EIGEN_PARTIALLU_LAPACK_H