potrf.hpp
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief -
6  *
7  * \author O. Krause
8  * \date 2011
9  *
10  *
11  * \par Copyright 1995-2015 Shark Development Team
12  *
13  * <BR><HR>
14  * This file is part of Shark.
15  * <http://image.diku.dk/shark/>
16  *
17  * Shark is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Lesser General Public License as published
19  * by the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * Shark is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
29  *
30  */
31 //===========================================================================
32 
33 #ifndef SHARK_LINALG_BLAS_KERNELS_ATLAS_POTRF_H
34 #define SHARK_LINALG_BLAS_KERNELS_ATLAS_POTRF_H
35 
36 #include "../cblas/cblas_inc.hpp"
37 extern "C"{
38  #include <clapack.h>
39 }
40 
41 namespace shark {
42 namespace blas {
43 namespace bindings {
44 
45 inline int potrf(
46  CBLAS_ORDER const Order, CBLAS_UPLO const Uplo,
47  int const N, float *A, int const lda
48 ) {
49  return clapack_spotrf(Order, Uplo, N, A, lda);
50 }
51 
52 inline int potrf(
53  CBLAS_ORDER const Order, CBLAS_UPLO const Uplo,
54  int const N, double *A, int const lda
55 ) {
56  return clapack_dpotrf(Order, Uplo, N, A, lda);
57 }
58 
59 inline int potrf(
60  CBLAS_ORDER const Order, CBLAS_UPLO const Uplo,
61  int const N, std::complex<float>* A, int const lda
62 ) {
63  return clapack_cpotrf(Order, Uplo, N, static_cast<void *>(A), lda);
64 }
65 
66 inline int potrf(
67  CBLAS_ORDER const Order, CBLAS_UPLO const Uplo,
68  int const N, std::complex<double>* A, int const lda
69 ) {
70  return clapack_zpotrf(Order, Uplo, N, static_cast<void *>(A), lda);
71 }
72 
73 template <typename Triangular, typename SymmA>
74 inline int potrf(
75  matrix_container<SymmA>& A,
76  boost::mpl::true_
77 ) {
78  CBLAS_UPLO const uplo = Triangular::is_upper ? CblasUpper : CblasLower;
79  CBLAS_ORDER const stor_ord =
80  (CBLAS_ORDER)storage_order<typename SymmA::orientation>::value;
81 
82  std::size_t n = A().size1();
83  SIZE_CHECK(n == A().size2());
84 
85  return potrf(
86  stor_ord, uplo, (int)n,
87  traits::storage(A()),
88  traits::leading_dimension(A())
89  );
90 }
91 
92 template<class Storage, class T>
93 struct optimized_potrf_detail {
94  typedef boost::mpl::false_ type;
95 };
96 template<>
97 struct optimized_potrf_detail <
98  dense_tag,
99  double
100 > {
101  typedef boost::mpl::true_ type;
102 };
103 template<>
104 struct optimized_potrf_detail <
105  dense_tag,
106  float
107 > {
108  typedef boost::mpl::true_ type;
109 };
110 template<>
111 struct optimized_potrf_detail <
112  dense_tag,
113  std::complex<double>
114 > {
115  typedef boost::mpl::true_ type;
116 };
117 
118 template<>
119 struct optimized_potrf_detail <
120  dense_tag,
121  std::complex<float>
122 > {
123  typedef boost::mpl::true_ type;
124 };
125 
126 template<class M>
127 struct has_optimized_potrf
128  : public optimized_potrf_detail <
129  typename M::storage_category,
130  typename M::value_type
131  > {};
132 }}}
133 #endif