11#ifndef EIGEN_LAPACKE_HELPERS_H
12#define EIGEN_LAPACKE_HELPERS_H
15#include "./InternalHeaderCheck.h"
18#include "mkl_lapacke.h"
29namespace lapacke_helpers {
36template <
typename Scalar>
37struct translate_type_imp;
39struct translate_type_imp<float> {
43struct translate_type_imp<double> {
47struct translate_type_imp<std::complex<double>> {
48 using type = lapack_complex_double;
51struct translate_type_imp<std::complex<float>> {
52 using type = lapack_complex_float;
56template <
typename Scalar>
57using translated_type =
typename translate_type_imp<Scalar>::type;
61template <
typename Source,
typename Target = translated_type<Source>>
62EIGEN_ALWAYS_INLINE
auto to_lapack(Source value) {
63 return static_cast<Target
>(value);
68template <
typename Source,
typename Target = translated_type<Source>>
69EIGEN_ALWAYS_INLINE
auto to_lapack(Source *value) {
70 return reinterpret_cast<Target *
>(value);
75EIGEN_ALWAYS_INLINE lapack_int to_lapack(Index index) {
return convert_index<lapack_int>(index); }
78template <
typename Derived>
79EIGEN_ALWAYS_INLINE
constexpr lapack_int lapack_storage_of(
const EigenBase<Derived> &) {
80 return Derived::IsRowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR;
97template <
typename DoubleFn,
typename SingleFn,
typename DoubleCpxFn,
typename SingleCpxFn>
98struct WrappingHelper {
104 DoubleCpxFn double_cpx_;
105 SingleCpxFn single_cpx_;
107 template <
typename... Args>
108 auto call(Args &&...args) ->
decltype(double_(std::forward<Args>(args)...)) {
109 return double_(std::forward<Args>(args)...);
112 template <
typename... Args>
113 auto call(Args &&...args) ->
decltype(single_(std::forward<Args>(args)...)) {
114 return single_(std::forward<Args>(args)...);
117 template <
typename... Args>
118 auto call(Args &&...args) ->
decltype(double_cpx_(std::forward<Args>(args)...)) {
119 return double_cpx_(std::forward<Args>(args)...);
122 template <
typename... Args>
123 auto call(Args &&...args) ->
decltype(single_cpx_(std::forward<Args>(args)...)) {
124 return single_cpx_(std::forward<Args>(args)...);
132template <
typename DoubleFn,
typename SingleFn,
typename DoubleCpxFn,
typename SingleCpxFn,
typename... Args>
133EIGEN_ALWAYS_INLINE
auto call_wrapper(DoubleFn df, SingleFn sf, DoubleCpxFn dcf, SingleCpxFn scf, Args &&...args) {
134 WrappingHelper<DoubleFn, SingleFn, DoubleCpxFn, SingleCpxFn> helper{df, sf, dcf, scf};
135 return helper.call(std::forward<Args>(args)...);
143#define EIGEN_MAKE_LAPACKE_WRAPPER(FUNCTION) \
144 template <typename... Args> \
145 EIGEN_ALWAYS_INLINE auto FUNCTION(Args &&...args) { \
146 return call_wrapper(LAPACKE_d##FUNCTION, LAPACKE_s##FUNCTION, LAPACKE_z##FUNCTION, LAPACKE_c##FUNCTION, \
147 std::forward<Args>(args)...); \
154EIGEN_MAKE_LAPACKE_WRAPPER(potrf)
155EIGEN_MAKE_LAPACKE_WRAPPER(getrf)
156EIGEN_MAKE_LAPACKE_WRAPPER(geqrf)
157EIGEN_MAKE_LAPACKE_WRAPPER(gesdd)
159#undef EIGEN_MAKE_LAPACKE_WRAPPER