Eigen  3.3.3
PartialPivLU_LAPACKE.h
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 LAPACKe
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 namespace Eigen { 
00037 
00038 namespace internal {
00039 
00042 #define EIGEN_LAPACKE_LU_PARTPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \
00043 template<int StorageOrder> \
00044 struct partial_lu_impl<EIGTYPE, StorageOrder, lapack_int> \
00045 { \
00046   /* \internal performs the LU decomposition in-place of the matrix represented */ \
00047   static lapack_int blocked_lu(Index rows, Index cols, EIGTYPE* lu_data, Index luStride, lapack_int* row_transpositions, lapack_int& nb_transpositions, lapack_int maxBlockSize=256) \
00048   { \
00049     EIGEN_UNUSED_VARIABLE(maxBlockSize);\
00050     lapack_int matrix_order, first_zero_pivot; \
00051     lapack_int m, n, lda, *ipiv, info; \
00052     EIGTYPE* a; \
00053 /* Set up parameters for ?getrf */ \
00054     matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \
00055     lda = convert_index<lapack_int>(luStride); \
00056     a = lu_data; \
00057     ipiv = row_transpositions; \
00058     m = convert_index<lapack_int>(rows); \
00059     n = convert_index<lapack_int>(cols); \
00060     nb_transpositions = 0; \
00061 \
00062     info = LAPACKE_##LAPACKE_PREFIX##getrf( matrix_order, m, n, (LAPACKE_TYPE*)a, lda, ipiv ); \
00063 \
00064     for(int i=0;i<m;i++) { ipiv[i]--; if (ipiv[i]!=i) nb_transpositions++; } \
00065 \
00066     eigen_assert(info >= 0); \
00067 /* something should be done with nb_transpositions */ \
00068 \
00069     first_zero_pivot = info; \
00070     return first_zero_pivot; \
00071   } \
00072 };
00073 
00074 EIGEN_LAPACKE_LU_PARTPIV(double, double, d)
00075 EIGEN_LAPACKE_LU_PARTPIV(float, float, s)
00076 EIGEN_LAPACKE_LU_PARTPIV(dcomplex, lapack_complex_double, z)
00077 EIGEN_LAPACKE_LU_PARTPIV(scomplex, lapack_complex_float,  c)
00078 
00079 } // end namespace internal
00080 
00081 } // end namespace Eigen
00082 
00083 #endif // EIGEN_PARTIALLU_LAPACK_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends